From d8ca21eb05a5b32c0ce9f0bbd1d866d3ca7771cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 24 Nov 2026 01:12:23 +0300 Subject: [PATCH] ec-vp8, ec-av1, ec-h265: SIMD kernels take archmage tokens instead of bare #[target_feature]; builds with AVX2 enabled globally (target-cpu=native/x86-64-v3) no longer fail with E0133 --- Cargo.lock | 3 +- crates/ec-av1/Cargo.toml | 2 +- crates/ec-av1/src/decode/cdef.rs | 61 ++++++----- crates/ec-av1/src/decode/cdef_simd.rs | 8 +- crates/ec-av1/src/decode/deblock.rs | 43 ++++---- crates/ec-av1/src/decode/deblock_simd.rs | 4 +- crates/ec-av1/src/decode/tests.rs | 23 ++--- crates/ec-av1/src/film_grain.rs | 109 ++++++++++---------- crates/ec-av1/src/mc.rs | 123 +++++++++++------------ crates/ec-av1/src/restoration.rs | 13 +-- crates/ec-av1/src/transform.rs | 41 ++++---- crates/ec-h265/src/simd_tx.rs | 83 +++++++++------ crates/ec-vp8/Cargo.toml | 1 + crates/ec-vp8/src/lib.rs | 4 +- crates/ec-vp8/src/mc.rs | 42 +++++--- 15 files changed, 287 insertions(+), 273 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d91fca38..1b90e378 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,10 +364,10 @@ dependencies = [ name = "ec-av1" version = "0.1.0" dependencies = [ + "archmage", "bytemuck", "ec-av1-syntax", "ec-core", - "multiversion", "stats_alloc", "tracking-allocator", ] @@ -726,6 +726,7 @@ dependencies = [ name = "ec-vp8" version = "0.1.0" dependencies = [ + "archmage", "bytemuck", "ec-core", "multiversion", diff --git a/crates/ec-av1/Cargo.toml b/crates/ec-av1/Cargo.toml index 813f691b..e7237bbc 100644 --- a/crates/ec-av1/Cargo.toml +++ b/crates/ec-av1/Cargo.toml @@ -9,8 +9,8 @@ authors.workspace = true [dependencies] ec-core.workspace = true ec-av1-syntax.workspace = true +archmage = "=0.9.31-beta.1" bytemuck = "1" -multiversion = "0.9" [features] default = ["gate-counters"] diff --git a/crates/ec-av1/src/decode/cdef.rs b/crates/ec-av1/src/decode/cdef.rs index 274096bd..b03c8644 100644 --- a/crates/ec-av1/src/decode/cdef.rs +++ b/crates/ec-av1/src/decode/cdef.rs @@ -1,5 +1,6 @@ //! CDEF constants and filter kernels. //! av1split: moved out of `decode/mod.rs`; the items are unchanged apart from visibility. (D14) +use archmage::SimdToken; use super::*; /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary @@ -156,12 +157,11 @@ pub(super) fn cdef_find_dir_partials(win: &[i16], bstride: usize, coeff_shift: i /// Runtime dispatch of the direction search's partial sums: the AVX2 clone /// runs [`cdef_simd::find_dir_partials_avx2`], the baseline clone the scalar /// form. Both read the same eight rows of eight samples. -#[multiversion::multiversion(targets("x86_64+avx2"))] pub(super) fn cdef_find_dir_partials_dispatch(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] { - multiversion::target::match_target! { - "x86_64+avx2" => cdef_simd::find_dir_partials_avx2(win, bstride, coeff_shift), - _ => cdef_find_dir_partials(win, bstride, coeff_shift), + if let Some(t) = archmage::X64V3Token::summon() { + return cdef_simd::find_dir_partials_avx2(t, win, bstride, coeff_shift); } + cdef_find_dir_partials(win, bstride, coeff_shift) } pub(super) fn cdef_find_dir(win: &[i16], bstride: usize, coeff_shift: i32) -> (usize, i32) { @@ -223,7 +223,6 @@ pub(super) fn cdef_adjust_strength(strength: i32, var: i32) -> i32 { /// chroma) in place, `sample(row, col)` reading the *unfiltered* frame (a /// previously-filtered neighbour must never feed this block's own sum). #[allow(clippy::too_many_arguments)] -#[multiversion::multiversion(targets("x86_64+avx2"))] pub(super) fn cdef_filter_block( src: &[i16], dst: &mut [u16], @@ -243,34 +242,32 @@ pub(super) fn cdef_filter_block( fctx: &crate::decode::FrameCtx, ) { let smax = sample_max(fctx); - multiversion::target::match_target! { - "x86_64+avx2" => { - if (bw == 4 || bw == 8) && bh.is_multiple_of(2) { - // The kernel reads `src`'s whole (bw + 4) x (bh + 4) window - // and writes exactly the `bh` runs of `bw` samples the - // scalar form writes. - cdef_simd::filter_block_avx2( - src, - dst, - stride, - ox, - oy, - bw, - bh, - pri_strength, - sec_strength, - dir, - pri_damping, - sec_damping, - enable_primary, - enable_secondary, - coeff_shift, - smax, - ); - return; - } + if let Some(t) = archmage::X64V3Token::summon() { + if (bw == 4 || bw == 8) && bh.is_multiple_of(2) { + // The kernel reads `src`'s whole (bw + 4) x (bh + 4) window + // and writes exactly the `bh` runs of `bw` samples the + // scalar form writes. + cdef_simd::filter_block_avx2( + t, + src, + dst, + stride, + ox, + oy, + bw, + bh, + pri_strength, + sec_strength, + dir, + pri_damping, + sec_damping, + enable_primary, + enable_secondary, + coeff_shift, + smax, + ); + return; } - _ => {} } cdef_filter_block_scalar( src, diff --git a/crates/ec-av1/src/decode/cdef_simd.rs b/crates/ec-av1/src/decode/cdef_simd.rs index cff89438..40e2ca5f 100644 --- a/crates/ec-av1/src/decode/cdef_simd.rs +++ b/crates/ec-av1/src/decode/cdef_simd.rs @@ -2,6 +2,7 @@ use super::{ CDEF_BORDER, CDEF_DIRECTIONS, CDEF_PRI_TAPS, CDEF_SEC_TAPS, CDEF_VERY_LARGE, cdef_constrain_shift, }; +use archmage::{X64V3Token, arcane}; use std::arch::x86_64::*; /// Eight `i16` samples starting at `at`, as one 128-bit register. @@ -60,8 +61,8 @@ fn add4(dst: &mut [i32; 16], off: usize, v: __m128i) { /// /// `win` must hold [`super::cdef_gather`]'s 8x8 window grown by /// `CDEF_BORDER` at row stride `bstride`. -#[target_feature(enable = "avx2")] -pub fn find_dir_partials_avx2(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] { +#[arcane] +pub fn find_dir_partials_avx2(_t: X64V3Token, win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] { let mut partial = [[0i32; 16]; 8]; let shift = _mm_cvtsi32_si128(coeff_shift); let c128 = _mm256_set1_epi32(128); @@ -105,9 +106,10 @@ pub fn find_dir_partials_avx2(win: &[i16], bstride: usize, coeff_shift: i32) -> /// loads read up to 152 entries past its start, i.e. past the /// `(bw + 4) x (bh + 4)` samples themselves) and `dst` the `bh` rows of /// `bw` samples at `(ox, oy)`. -#[target_feature(enable = "avx2")] +#[arcane] #[allow(clippy::too_many_arguments)] pub fn filter_block_avx2( + _t: X64V3Token, src: &[i16], dst: &mut [u16], stride: usize, diff --git a/crates/ec-av1/src/decode/deblock.rs b/crates/ec-av1/src/decode/deblock.rs index 87c96335..04f88777 100644 --- a/crates/ec-av1/src/decode/deblock.rs +++ b/crates/ec-av1/src/decode/deblock.rs @@ -1,5 +1,6 @@ //! Deblocking filters: the edge filters, the deblock plane drivers, the filter-replay capture and the pooled plane scratch. Moved out of `decode/mod.rs` (av1split D12); the items are unchanged apart from visibility. +use archmage::SimdToken; use super::*; /// `update_sharpness`'s per-level `(blimit, limit, hev_thr)` triple. @@ -335,7 +336,6 @@ pub(super) fn filter_edge( #[allow(unused_variables)] // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] -#[multiversion::multiversion(targets("x86_64+avx2"))] pub(super) fn filter_edge16( data: &mut [u16], base: usize, @@ -346,27 +346,26 @@ pub(super) fn filter_edge16( sharpness: u8, fctx: &crate::decode::FrameCtx, ) -> bool { - multiversion::target::match_target! { - "x86_64+avx2" => { - let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness); - let shift = bit_depth(fctx) - 8; - deblock_simd::edge16( - data, - base, - stride, - vertical, - len, - blimit << shift, - limit << shift, - hev_thr << shift, - 1 << shift, - 1 << shift, - sample_max(fctx), - ); - true - } - _ => false, - } + let Some(t) = archmage::X64V3Token::summon() else { + return false; + }; + let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness); + let shift = bit_depth(fctx) - 8; + deblock_simd::edge16( + t, + data, + base, + stride, + vertical, + len, + blimit << shift, + limit << shift, + hev_thr << shift, + 1 << shift, + 1 << shift, + sample_max(fctx), + ); + true } /// One plane's worth of spec 7.14: every vertical edge across the plane, diff --git a/crates/ec-av1/src/decode/deblock_simd.rs b/crates/ec-av1/src/decode/deblock_simd.rs index f765a50f..764339f9 100644 --- a/crates/ec-av1/src/decode/deblock_simd.rs +++ b/crates/ec-av1/src/decode/deblock_simd.rs @@ -1,3 +1,4 @@ +use archmage::{X64V3Token, arcane}; use std::arch::x86_64::*; /// Bounds-checked unaligned load of 16 `u16` samples at `at`. @@ -387,9 +388,10 @@ fn filter16( /// stride + 8 <= stride` and 16 rows from `base` must be inside `data`; /// for a horizontal edge `base >= 8 * stride` and `base + 8 * stride` /// must be inside it. -#[target_feature(enable = "avx2")] +#[arcane] #[allow(clippy::too_many_arguments)] pub fn edge16( + _t: X64V3Token, data: &mut [u16], base: usize, stride: usize, diff --git a/crates/ec-av1/src/decode/tests.rs b/crates/ec-av1/src/decode/tests.rs index af7d0dba..10455077 100644 --- a/crates/ec-av1/src/decode/tests.rs +++ b/crates/ec-av1/src/decode/tests.rs @@ -1725,12 +1725,10 @@ fn cdef_find_dir_matches_the_per_sample_reference() { } } -/// The CDEF filter through a `multiversion` clone, so the AVX2 kernel is -/// reached by a safe call: the AVX2 clone runs `filter_block_avx2`, the -/// baseline clone the scalar form (the same split `cdef_filter_block` uses). +/// The CDEF filter with a summoned AVX2 token, so the AVX2 kernel is reached +/// by a safe call: the token runs `filter_block_avx2`, its absence the scalar form (the same split `cdef_filter_block` uses). #[cfg(target_arch = "x86_64")] #[allow(clippy::too_many_arguments)] -#[multiversion::multiversion(targets("x86_64+avx2"))] fn cdef_filter_block_under_test( src: &[i16], dst: &mut [u16], @@ -1749,16 +1747,16 @@ fn cdef_filter_block_under_test( coeff_shift: i32, smax: i32, ) { - multiversion::target::match_target! { - "x86_64+avx2" => super::cdef_simd::filter_block_avx2( - src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir, + if let Some(t) = archmage::X64V3Token::summon() { + return super::cdef_simd::filter_block_avx2( + t, src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir, pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax, - ), - _ => super::cdef_filter_block_scalar( - src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir, - pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax, - ), + ); } + super::cdef_filter_block_scalar( + src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir, + pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax, + ) } /// lane-perf7 step 1: the AVX2 CDEF kernel must be value-identical to @@ -2098,6 +2096,7 @@ fn filter_intra_classes_carry_their_own_libaom_default_row() { ); } } +use archmage::SimdToken; use super::*; /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR -- diff --git a/crates/ec-av1/src/film_grain.rs b/crates/ec-av1/src/film_grain.rs index 73c3ca5c..df8f96b9 100644 --- a/crates/ec-av1/src/film_grain.rs +++ b/crates/ec-av1/src/film_grain.rs @@ -21,6 +21,7 @@ //! [`crate::stream::decode_stream`] is the only caller: it applies this to //! the frame it pushes onto its output `Vec`, after saving the //! clean decode into the reference slot bank. +use archmage::SimdToken; use crate::hits::hit; use crate::decode::WithRef; @@ -620,7 +621,6 @@ fn luma_noise_row( /// 32x32 grain block is 30 wide (32 minus the 2-column overlap), never a /// multiple of 8. Hoisting the row loop into the kernel pays the prologue /// once per block and lets the tail take a 4-wide SSE step. -#[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(clippy::too_many_arguments)] fn luma_noise_rows( pixels: &mut [u16], @@ -635,26 +635,24 @@ fn luma_noise_rows( min_luma: i32, max_luma: i32, ) { - multiversion::target::match_target! { - "x86_64+avx2" => { - if n >= 4 { - simd::luma_noise_rows_avx2( - pixels, - p_stride, - grain, - g_stride, - rows, - n, - scaling, - rounding_offset, - scaling_shift, - min_luma, - max_luma, - ); - return; - } + if let Some(t) = archmage::X64V3Token::summon() { + if n >= 4 { + simd::luma_noise_rows_avx2( + t, + pixels, + p_stride, + grain, + g_stride, + rows, + n, + scaling, + rounding_offset, + scaling_shift, + min_luma, + max_luma, + ); + return; } - _ => {} } for r in 0..rows { luma_noise_row_scalar( @@ -736,7 +734,6 @@ fn chroma_noise_row( /// [`chroma_noise_row`] over `rows` consecutive chroma rows of a block; see /// [`luma_noise_rows`] for why the row loop lives inside the kernel. /// `pair` is `ss_x == 1`; see [`chroma_noise_row`] for the two luma shapes. -#[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(clippy::too_many_arguments)] fn chroma_noise_rows( chroma: &mut [u16], @@ -754,17 +751,14 @@ fn chroma_noise_rows( p: ChromaNoise, pair: bool, ) { - multiversion::target::match_target! { - "x86_64+avx2" => { - if pair && n >= 4 { - simd::chroma_noise_rows_avx2( - chroma, c_stride, luma, l_stride, grain, g_stride, rows, n, scaling, luma_mult, - mult, offset, p, - ); - return; - } + if let Some(t) = archmage::X64V3Token::summon() { + if pair && n >= 4 { + simd::chroma_noise_rows_avx2( + t, chroma, c_stride, luma, l_stride, grain, g_stride, rows, n, scaling, luma_mult, + mult, offset, p, + ); + return; } - _ => {} } let lrow = if pair { 2 * n } else { n }; for r in 0..rows { @@ -834,6 +828,7 @@ fn luma_noise_row_scalar( #[cfg(target_arch = "x86_64")] mod simd { + use archmage::{X64V3Token, arcane}; use std::arch::x86_64::*; // Bounds-checked slice <-> vector moves (no raw pointers). @@ -899,10 +894,11 @@ mod simd { /// panic. /// /// `grain` must be at least `pixels.len()` long and `scaling` non-empty. - #[target_feature(enable = "avx2")] + #[arcane] #[allow(clippy::too_many_arguments)] #[cfg(test)] pub fn luma_noise_row_avx2( + t: X64V3Token, pixels: &mut [u16], grain: &[i32], scaling: &[i32], @@ -913,6 +909,7 @@ mod simd { ) { let n = pixels.len().min(grain.len()); luma_noise_rows_avx2( + t, pixels, n, grain, @@ -933,9 +930,10 @@ mod simd { /// /// `pixels`/`grain` must cover the `rows x n` window at their strides and /// `scaling` must be non-empty. - #[target_feature(enable = "avx2")] + #[arcane] #[allow(clippy::too_many_arguments)] pub fn luma_noise_rows_avx2( + _t: X64V3Token, pixels: &mut [u16], p_stride: usize, grain: &[i32], @@ -1010,10 +1008,11 @@ mod simd { /// /// `luma` must be at least `2 * chroma.len()` long, `grain` at least /// `chroma.len()`, and `scaling` non-empty. - #[target_feature(enable = "avx2")] + #[arcane] #[allow(clippy::too_many_arguments)] #[cfg(test)] pub fn chroma_noise_row_avx2( + t: X64V3Token, chroma: &mut [u16], luma: &[u16], grain: &[i32], @@ -1025,6 +1024,7 @@ mod simd { ) { let n = chroma.len().min(grain.len()).min(luma.len() / 2); chroma_noise_rows_avx2( + t, chroma, n, luma, @@ -1047,9 +1047,10 @@ mod simd { /// /// The three slices must cover the `rows x n` window (`2 * n` for luma) at /// their strides and `scaling` must be non-empty. - #[target_feature(enable = "avx2")] + #[arcane] #[allow(clippy::too_many_arguments)] pub fn chroma_noise_rows_avx2( + _t: X64V3Token, chroma: &mut [u16], c_stride: usize, luma: &[u16], @@ -2140,10 +2141,10 @@ pub(crate) fn apply_grain( #[cfg(test)] mod perf5_tests { + use archmage::SimdToken; /// Runs the safe AVX2 kernel inside a `target_feature(avx2)` clone (the /// caller checks `is_x86_feature_detected!("avx2")` first). #[cfg(target_arch = "x86_64")] - #[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(unused_variables)] fn avx2_luma_row( pixels: &mut [u16], @@ -2154,24 +2155,21 @@ mod perf5_tests { min_luma: i32, max_luma: i32, ) { - multiversion::target::match_target! { - "x86_64+avx2" => { - super::simd::luma_noise_row_avx2( - pixels, - grain, - scaling, - rounding_offset, - scaling_shift, - min_luma, - max_luma, - ); - } - _ => {} + if let Some(t) = archmage::X64V3Token::summon() { + super::simd::luma_noise_row_avx2( + t, + pixels, + grain, + scaling, + rounding_offset, + scaling_shift, + min_luma, + max_luma, + ); } } #[cfg(target_arch = "x86_64")] - #[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(clippy::too_many_arguments)] #[allow(unused_variables)] fn avx2_chroma_row( @@ -2184,13 +2182,10 @@ mod perf5_tests { offset: i32, p: super::ChromaNoise, ) { - multiversion::target::match_target! { - "x86_64+avx2" => { - super::simd::chroma_noise_row_avx2( - chroma, luma, grain, scaling, luma_mult, mult, offset, p, - ); - } - _ => {} + if let Some(t) = archmage::X64V3Token::summon() { + super::simd::chroma_noise_row_avx2( + t, chroma, luma, grain, scaling, luma_mult, mult, offset, p, + ); } } diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index 54c2ed11..c1ba4578 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -8,6 +8,7 @@ //! in 1/16-pel steps -- luma motion vectors are stored at 1/8-pel and always //! land on an even step; chroma vectors, once scaled for subsampling, can //! land on any of the 16. +use archmage::SimdToken; use crate::hits::hit; /// `Round2` (spec 4.7): halves round up. @@ -326,9 +327,8 @@ pub(crate) fn hpass_contig(src: &[u16], t16: &[i16; 8], out: &mut [i16], round0: /// lane-mc2: `rows` rows of [`hpass_contig`], `src_stride` apart in `src` and /// packed `block_w` apart in `out`. The tap vectors and the SIMD dispatch are /// set up once for the whole block instead of once per row. -// Runtime dispatch is `multiversion`'s: the AVX2 clone runs the AVX2 kernel, -// the SSE4.1 clone the SSE2 one, anything else the scalar loop below. -#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))] +// Runtime dispatch is an archmage token summon: the AVX2 token runs the AVX2 +// kernel, the SSE4.1 token the SSE2 one, anything else the scalar loop below. pub(crate) fn hpass_rows( src: &[u16], src_stride: usize, @@ -339,16 +339,16 @@ pub(crate) fn hpass_rows( round0: u32, ) { #[cfg(target_arch = "x86_64")] - multiversion::target::match_target! { - "x86_64+avx2" => { - simd::hpass_avx2(src, src_stride, rows, block_w, t16, out, round0); + { + if let Some(t) = archmage::X64V3Token::summon() { + simd::hpass_avx2(t, src, src_stride, rows, block_w, t16, out, round0); + return; } - "x86_64+sse4.1" => { - simd::hpass_sse2(src, src_stride, rows, block_w, t16, out, round0); + if let Some(t) = archmage::X64V2Token::summon() { + simd::hpass_sse2(t, src, src_stride, rows, block_w, t16, out, round0); + return; } - _ => hpass_rows_scalar_all(src, src_stride, rows, block_w, t16, out, round0), } - #[cfg(not(target_arch = "x86_64"))] hpass_rows_scalar_all(src, src_stride, rows, block_w, t16, out, round0); } @@ -391,13 +391,13 @@ fn hpass_contig_scalar(src: &[u16], t16: &[i16; 8], out: &mut [i16], round0: u32 /// `hpass_row` + `vpass_row`. Nothing here is spec logic: each kernel is the /// scalar function's arithmetic, lane-parallel, with identical rounding. /// -/// Every kernel is a safe `#[target_feature]` function, called only from a -/// `multiversion` clone that has the feature enabled (or, for SSE2, from any -/// x86_64 code). Loads and stores go through `bytemuck` on slices, so every +/// Every kernel is a safe `#[arcane]` (or `#[target_feature]` helper) function, +/// called only with the archmage token of its feature, obtained by `summon`. Loads and stores go through `bytemuck` on slices, so every /// access is bounds-checked. #[cfg(target_arch = "x86_64")] mod simd { use super::{round2, sat16}; + use archmage::{X64V2Token, X64V3Token, arcane}; use bytemuck::Pod; use std::arch::x86_64::*; use std::mem::size_of; @@ -468,8 +468,9 @@ mod simd { /// `unpack` + `permute2x128`. /// /// Requires AVX2. `src.len()` must be at least `out.len() + 7`. - #[target_feature(enable = "avx2")] + #[arcane] pub fn hpass_avx2( + t: X64V3Token, src: &[u16], src_stride: usize, rows: usize, @@ -515,7 +516,7 @@ mod simd { c += 16; } if c < block_w { - hpass_sse2(&sp[c..], 0, 1, block_w - c, t16, &mut op[c..], round0); + hpass_sse2(t.v2(), &sp[c..], 0, 1, block_w - c, t16, &mut op[c..], round0); } } } @@ -529,8 +530,9 @@ mod simd { /// /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements /// and `acc` at least `block_w`. - #[target_feature(enable = "avx2")] + #[arcane] pub fn vpass_avx2( + _t: X64V3Token, intermediate: &[i16], block_w: usize, src_stride: usize, @@ -645,10 +647,11 @@ mod simd { /// /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements /// and `dst` at least `block_w`. - #[target_feature(enable = "avx2")] + #[arcane] // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] pub fn vpass_row_u16_avx2( + _t: X64V3Token, intermediate: &[i16], block_w: usize, src_stride: usize, @@ -768,10 +771,11 @@ mod simd { /// [`vpass_row_u16_avx2`] without the 16-column step. /// /// Requires SSE4.1; same slice contract as [`vpass_row_u16_avx2`]. - #[target_feature(enable = "sse4.1")] + #[arcane] // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] pub fn vpass_row_u16_sse41( + _t: X64V2Token, intermediate: &[i16], block_w: usize, src_stride: usize, @@ -803,8 +807,9 @@ mod simd { /// Vertical pass, SSE2: [`vpass_avx2`] without the 16-column step. /// /// SSE2 is baseline x86_64; same slice contract as [`vpass_avx2`]. - #[target_feature(enable = "sse2")] + #[arcane] pub fn vpass_sse41( + _t: X64V2Token, intermediate: &[i16], block_w: usize, src_stride: usize, @@ -834,8 +839,9 @@ mod simd { /// scalar loop, which is where 4-tap kernels mostly land anyway. /// /// `src.len()` must be at least `out.len() + 7`. SSE2 is baseline x86_64. - #[target_feature(enable = "sse2")] + #[arcane] pub fn hpass_sse2( + _t: X64V2Token, src: &[u16], src_stride: usize, rows: usize, @@ -889,12 +895,12 @@ mod simd { } } - // Test-only entry points that run one kernel under a `multiversion` - // clone with the needed feature, so the unit tests can exercise each - // tier directly (callers check the feature first). + // Test-only entry points that run one kernel with a summoned token, so + // the unit tests can exercise each tier directly (callers check the + // feature first). #[cfg(test)] pub mod entry { - #[multiversion::multiversion(targets("x86_64+sse4.1"))] + use archmage::SimdToken; #[allow(unused_variables)] pub fn hpass_sse2( src: &[u16], @@ -905,13 +911,10 @@ mod simd { out: &mut [i16], round0: u32, ) { - multiversion::target::match_target! { - "x86_64+sse4.1" => super::hpass_sse2(src, src_stride, rows, block_w, t16, out, round0), - _ => unreachable!("sse4.1 entry on a CPU without sse4.1"), - } + let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1"); + super::hpass_sse2(t, src, src_stride, rows, block_w, t16, out, round0) } - #[multiversion::multiversion(targets("x86_64+sse4.1"))] #[allow(unused_variables)] pub fn vpass_sse41( intermediate: &[i16], @@ -921,13 +924,10 @@ mod simd { taps: &[i32; 8], acc: &mut [i32], ) { - multiversion::target::match_target! { - "x86_64+sse4.1" => super::vpass_sse41(intermediate, block_w, src_stride, rows, taps, acc), - _ => unreachable!("sse4.1 entry on a CPU without sse4.1"), - } + let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1"); + super::vpass_sse41(t, intermediate, block_w, src_stride, rows, taps, acc) } - #[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(unused_variables)] pub fn hpass_avx2( src: &[u16], @@ -938,13 +938,10 @@ mod simd { out: &mut [i16], round0: u32, ) { - multiversion::target::match_target! { - "x86_64+avx2" => super::hpass_avx2(src, src_stride, rows, block_w, t16, out, round0), - _ => unreachable!("avx2 entry on a CPU without avx2"), - } + let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2"); + super::hpass_avx2(t, src, src_stride, rows, block_w, t16, out, round0) } - #[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(unused_variables)] pub fn vpass_avx2( intermediate: &[i16], @@ -954,13 +951,10 @@ mod simd { taps: &[i32; 8], acc: &mut [i32], ) { - multiversion::target::match_target! { - "x86_64+avx2" => super::vpass_avx2(intermediate, block_w, src_stride, rows, taps, acc), - _ => unreachable!("avx2 entry on a CPU without avx2"), - } + let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2"); + super::vpass_avx2(t, intermediate, block_w, src_stride, rows, taps, acc) } - #[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(unused_variables, clippy::too_many_arguments)] pub fn vpass_row_u16_avx2( intermediate: &[i16], @@ -972,13 +966,10 @@ mod simd { dst: &mut [u16], round1: u32, ) { - multiversion::target::match_target! { - "x86_64+avx2" => super::vpass_row_u16_avx2(intermediate, block_w, src_stride, rows, taps, max, dst, round1), - _ => unreachable!("avx2 entry on a CPU without avx2"), - } + let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2"); + super::vpass_row_u16_avx2(t, intermediate, block_w, src_stride, rows, taps, max, dst, round1) } - #[multiversion::multiversion(targets("x86_64+sse4.1"))] #[allow(unused_variables, clippy::too_many_arguments)] pub fn vpass_row_u16_sse41( intermediate: &[i16], @@ -990,10 +981,8 @@ mod simd { dst: &mut [u16], round1: u32, ) { - multiversion::target::match_target! { - "x86_64+sse4.1" => super::vpass_row_u16_sse41(intermediate, block_w, src_stride, rows, taps, max, dst, round1), - _ => unreachable!("sse4.1 entry on a CPU without sse4.1"), - } + let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1"); + super::vpass_row_u16_sse41(t, intermediate, block_w, src_stride, rows, taps, max, dst, round1) } } } @@ -1136,7 +1125,6 @@ fn horizontal_pass_unscaled( /// striding the intermediate by `block_w` per tap. A zero tap is skipped -- /// adding `0 * x` is exactly nothing, and the 4-tap kernels zero four of the /// eight slots. `acc` is left holding the unrounded sums. -#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))] pub(crate) fn vpass_row( intermediate: &[i16], block_w: usize, @@ -1146,16 +1134,16 @@ pub(crate) fn vpass_row( acc: &mut [i32], ) { #[cfg(target_arch = "x86_64")] - multiversion::target::match_target! { - "x86_64+avx2" => { - simd::vpass_avx2(intermediate, block_w, src_stride, rows, taps, acc); + { + if let Some(t) = archmage::X64V3Token::summon() { + simd::vpass_avx2(t, intermediate, block_w, src_stride, rows, taps, acc); + return; } - "x86_64+sse4.1" => { - simd::vpass_sse41(intermediate, block_w, src_stride, rows, taps, acc); + if let Some(t) = archmage::X64V2Token::summon() { + simd::vpass_sse41(t, intermediate, block_w, src_stride, rows, taps, acc); + return; } - _ => vpass_row_scalar_all(intermediate, block_w, src_stride, rows, taps, acc), } - #[cfg(not(target_arch = "x86_64"))] vpass_row_scalar_all(intermediate, block_w, src_stride, rows, taps, acc); } @@ -1184,7 +1172,6 @@ fn vpass_row_scalar_all( /// entry points whose destination is `u16` samples. The unrounded `i32` sums /// used to be stored to a scratch row and read straight back by a rounding /// loop; here they never leave the register. -#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))] // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] fn vpass_row_u16( @@ -1198,9 +1185,10 @@ fn vpass_row_u16( round1: u32, ) { #[cfg(target_arch = "x86_64")] - multiversion::target::match_target! { - "x86_64+avx2" => { + { + if let Some(t) = archmage::X64V3Token::summon() { simd::vpass_row_u16_avx2( + t, intermediate, block_w, src_stride, @@ -1210,9 +1198,11 @@ fn vpass_row_u16( dst, round1, ); + return; } - "x86_64+sse4.1" => { + if let Some(t) = archmage::X64V2Token::summon() { simd::vpass_row_u16_sse41( + t, intermediate, block_w, src_stride, @@ -1222,10 +1212,9 @@ fn vpass_row_u16( dst, round1, ); + return; } - _ => vpass_row_u16_scalar_all(intermediate, block_w, src_stride, rows, taps, max, dst, round1), } - #[cfg(not(target_arch = "x86_64"))] vpass_row_u16_scalar_all( intermediate, block_w, diff --git a/crates/ec-av1/src/restoration.rs b/crates/ec-av1/src/restoration.rs index 28e2aec6..239dde13 100644 --- a/crates/ec-av1/src/restoration.rs +++ b/crates/ec-av1/src/restoration.rs @@ -3,8 +3,8 @@ //! `av1_loop_restoration_corners_in_sb`, restoration.c:1277) and spec 7.17's //! two pixel filters (Wiener, self-guided/SGR). See `lanes/lr.report.md` for //! the full derivation (libaom `decodeframe.c`/`restoration.c` line refs). +use archmage::SimdToken; use crate::hits::hit; -use multiversion::target::match_target; use crate::msac::SymbolDecoder; use ec_av1_syntax::obu::floor_log2; @@ -1165,7 +1165,6 @@ fn ab_point(a: i32, b: i32, n: i32, s: i32, bd_shift: u32, one_by_x: i64) -> (i3 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time /// under AVX2 (the kernel is that arithmetic lane-wise, same widths). -#[multiversion::multiversion(targets("x86_64+avx2"))] #[allow(clippy::too_many_arguments)] fn ab_row( a_row: &[i32], @@ -1176,9 +1175,9 @@ fn ab_row( one_by_x: i64, out: &mut [(i32, i64)], ) { - let done = match_target! { - "x86_64+avx2" => sgr_simd::ab_row_avx2(a_row, b_row, n, s, bd_shift, one_by_x as i32, out), - _ => 0usize, + let done = match archmage::X64V3Token::summon() { + Some(t) => sgr_simd::ab_row_avx2(t, a_row, b_row, n, s, bd_shift, one_by_x as i32, out), + None => 0usize, }; for gj in done..out.len() { out[gj] = ab_point(a_row[gj], b_row[gj], n, s, bd_shift, one_by_x); @@ -1189,6 +1188,7 @@ fn ab_row( #[cfg(target_arch = "x86_64")] mod sgr_simd { use super::{SGRPROJ_MTABLE_BITS, SGRPROJ_RECIP_BITS, SGR_X_BY_XPLUS1}; + use archmage::{X64V3Token, arcane}; use std::arch::x86_64::*; /// Eight grid points of `super::ab_point` per iteration, returning how @@ -1199,9 +1199,10 @@ mod sgr_simd { /// `p * s < 2^38`, `(256 - A) * one_by_x < 2^21` and that times /// `b < 2^17` is `< 2^38` -- so the two 64-bit products below lose no /// bit, and the unsigned `mul_epu32` sees no negative operand. - #[target_feature(enable = "avx2")] + #[arcane] #[allow(clippy::too_many_arguments)] pub fn ab_row_avx2( + _t: X64V3Token, a_row: &[i32], b_row: &[i32], n: i32, diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index 2c24975f..3e32f238 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -195,6 +195,7 @@ impl Lane for [i32; 8] { #[cfg(target_arch = "x86_64")] mod simd { use super::{COS_BITS, Kern, inverse_dct_n}; + use archmage::{SimdToken, X64V3Token, arcane}; use std::arch::x86_64::*; /// Eight `i32` lanes in one AVX2 register. @@ -232,8 +233,8 @@ mod simd { /// bits (`|a| < 2^31`, `|c| <= 2^12`), and only the low 32 bits of the /// shifted sum are kept -- which is what the scalar `as i32` keeps, so /// the logical shift stands in for the arithmetic one exactly. - #[target_feature(enable = "avx2")] - pub(super) fn dct_x8_avx2(t: &mut [M256; 64], n: u32, r: usize) { + #[arcane] + pub(super) fn dct_x8_avx2(_tok: X64V3Token, t: &mut [M256; 64], n: u32, r: usize) { let btf = |a: M256, b: M256, c: i64, s: i64| { let cv = _mm256_set1_epi32(c as i32); let sv = _mm256_set1_epi32(s as i32); @@ -292,8 +293,9 @@ mod simd { /// The whole DCT column pass of one transform unit: `residual` is the /// row-pass output (`h` rows of `w`), `out` the residual it writes. - #[target_feature(enable = "avx2")] + #[arcane] pub(super) fn column_pass_dct( + tok: X64V3Token, residual: &[i32], out: &mut [i32], w: usize, @@ -316,7 +318,7 @@ mod simd { if _mm256_testz_si256(any, any) == 1 { continue; } - dct_x8_avx2(&mut t, log2h, r); + dct_x8_avx2(tok, &mut t, log2h, r); // `round2(v, 4)` on eight lanes: the shift is arithmetic here // because the value stays in its own 32-bit lane. let rnd = _mm256_set1_epi32(8); @@ -330,9 +332,7 @@ mod simd { } } - /// [`column_pass_dct`] when this CPU has AVX2 (the multiversion AVX2 - /// clone), or `false` with nothing done. - #[multiversion::multiversion(targets("x86_64+avx2"))] + /// [`column_pass_dct`] when this CPU has AVX2, or `false` with nothing done. pub(super) fn column_pass_dct_dispatch( residual: &[i32], out: &mut [i32], @@ -342,15 +342,12 @@ mod simd { r: usize, ud_flip: bool, ) -> bool { - multiversion::target::match_target! { - "x86_64+avx2" => { - column_pass_dct(residual, out, w, h, log2h, r, ud_flip); + match archmage::X64V3Token::summon() { + Some(t) => { + column_pass_dct(t, residual, out, w, h, log2h, r, ud_flip); true - }, - _ => { - let _ = (residual, out, w, h, log2h, r, ud_flip); - false - }, + } + None => false, } } @@ -369,17 +366,13 @@ mod simd { /// [`dct_x8_avx2`] when this CPU has AVX2; `false` with nothing done /// otherwise. For the equivalence gate. #[cfg(test)] - #[multiversion::multiversion(targets("x86_64+avx2"))] pub(super) fn dct_x8_dispatch(t: &mut [M256; 64], n: u32, r: usize) -> bool { - multiversion::target::match_target! { - "x86_64+avx2" => { - dct_x8_avx2(t, n, r); + match archmage::X64V3Token::summon() { + Some(tok) => { + dct_x8_avx2(tok, t, n, r); true - }, - _ => { - let _ = (t, n, r); - false - }, + } + None => false, } } } diff --git a/crates/ec-h265/src/simd_tx.rs b/crates/ec-h265/src/simd_tx.rs index 043548f6..49cd0e67 100644 --- a/crates/ec-h265/src/simd_tx.rs +++ b/crates/ec-h265/src/simd_tx.rs @@ -19,6 +19,7 @@ pub(crate) use x86::*; #[cfg(target_arch = "x86_64")] mod x86 { use super::*; + use archmage::{SimdToken, X64V3Token, arcane}; use multiversion::target::match_target; use std::arch::x86_64::*; @@ -356,8 +357,8 @@ mod x86 { _mm256_set1_epi32 ); - #[target_feature(enable = "avx2")] - pub(super) fn fwd(residual: &[i32], coeffs: &mut [i32], n: usize) { + #[arcane] + pub(super) fn fwd(_t: X64V3Token, residual: &[i32], coeffs: &mut [i32], n: usize) { match n { 8 => forward_2d::<64, 192>(residual, coeffs, n, false), 16 => forward_2d::<256, 768>(residual, coeffs, n, false), @@ -365,8 +366,14 @@ mod x86 { } } - #[target_feature(enable = "avx2")] - pub(super) fn inv(scaled: &[i32], residual: &mut [i32], n: usize, bd_shift: i32) { + #[arcane] + pub(super) fn inv( + _t: X64V3Token, + scaled: &[i32], + residual: &mut [i32], + n: usize, + bd_shift: i32, + ) { match n { 8 => inverse_2d::<64, 128>(scaled, residual, n, false, bd_shift), 16 => inverse_2d::<256, 512>(scaled, residual, n, false, bd_shift), @@ -411,13 +418,19 @@ mod x86 { _mm_set1_epi32 ); - #[target_feature(enable = "avx2")] - pub(super) fn fwd(residual: &[i32], coeffs: &mut [i32], dst: bool) { + #[arcane] + pub(super) fn fwd(_t: X64V3Token, residual: &[i32], coeffs: &mut [i32], dst: bool) { forward_2d::<16, 48>(residual, coeffs, 4, dst) } - #[target_feature(enable = "avx2")] - pub(super) fn inv(scaled: &[i32], residual: &mut [i32], dst: bool, bd_shift: i32) { + #[arcane] + pub(super) fn inv( + _t: X64V3Token, + scaled: &[i32], + residual: &mut [i32], + dst: bool, + bd_shift: i32, + ) { inverse_2d::<16, 32>(scaled, residual, 4, dst, bd_shift) } } @@ -434,14 +447,17 @@ mod x86 { assert!(residual.len() >= n * n && coeffs.len() >= n * n && matches!(n, 4 | 8 | 16 | 32)); assert!(!dst || n == 4); match_target! { - "x86_64+avx2" => { - if n == 4 { - v128::fwd(residual, coeffs, dst) - } else { - v256::fwd(residual, coeffs, n) + "x86_64+avx2" => match X64V3Token::summon() { + Some(t) => { + if n == 4 { + v128::fwd(t, residual, coeffs, dst) + } else { + v256::fwd(t, residual, coeffs, n) + } + true } - true - } + None => false, + }, _ => false } } @@ -459,14 +475,17 @@ mod x86 { assert!(scaled.len() >= n * n && residual.len() >= n * n && matches!(n, 4 | 8 | 16 | 32)); assert!(!dst || n == 4); match_target! { - "x86_64+avx2" => { - if n == 4 { - v128::inv(scaled, residual, dst, bd_shift) - } else { - v256::inv(scaled, residual, n, bd_shift) + "x86_64+avx2" => match X64V3Token::summon() { + Some(t) => { + if n == 4 { + v128::inv(t, scaled, residual, dst, bd_shift) + } else { + v256::inv(t, scaled, residual, n, bd_shift) + } + true } - true - } + None => false, + }, _ => { let _ = bd_shift; false @@ -474,8 +493,9 @@ mod x86 { } } - #[target_feature(enable = "avx2")] + #[arcane] fn quantize_inner( + _t: X64V3Token, coeffs: &[i32], levels: &mut [i32], count: usize, @@ -524,7 +544,8 @@ mod x86 { assert!(count.is_multiple_of(8) && coeffs.len() >= count && levels.len() >= count); assert!((0..32).contains(&qbits)); match_target! { - "x86_64+avx2" => Some(quantize_inner(coeffs, levels, count, scale, offset, qbits)), + "x86_64+avx2" => X64V3Token::summon() + .map(|t| quantize_inner(t, coeffs, levels, count, scale, offset, qbits)), _ => { let _ = (scale, offset); None @@ -532,8 +553,9 @@ mod x86 { } } - #[target_feature(enable = "avx2")] + #[arcane] fn dequant_inner( + _t: X64V3Token, levels: &[i32], scaled: &mut [i32], count: usize, @@ -594,10 +616,13 @@ mod x86 { } assert!(scaled.len() >= count); match_target! { - "x86_64+avx2" => { - dequant_inner(levels, scaled, count, mul as i32, round as i32, bd_shift); - true - } + "x86_64+avx2" => match X64V3Token::summon() { + Some(t) => { + dequant_inner(t, levels, scaled, count, mul as i32, round as i32, bd_shift); + true + } + None => false, + }, _ => false } } diff --git a/crates/ec-vp8/Cargo.toml b/crates/ec-vp8/Cargo.toml index df6ebb7f..094e36a2 100644 --- a/crates/ec-vp8/Cargo.toml +++ b/crates/ec-vp8/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true authors.workspace = true [dependencies] +archmage = "=0.9.31-beta.1" bytemuck = "1" ec-core.workspace = true multiversion = "0.9" diff --git a/crates/ec-vp8/src/lib.rs b/crates/ec-vp8/src/lib.rs index db1d24a6..f3cbf2a7 100644 --- a/crates/ec-vp8/src/lib.rs +++ b/crates/ec-vp8/src/lib.rs @@ -9,8 +9,8 @@ //! //! # Safety //! -//! Every SIMD kernel is a safe `#[target_feature]` function, dispatched at -//! runtime by `multiversion`; the crate-level `forbid` below keeps it so. +//! Every SIMD kernel is a safe `#[arcane]` function taking a `X64V3Token` +//! proof of AVX2, obtained at runtime; the crate-level `forbid` below keeps it so. #![forbid(unsafe_code)] #![warn(missing_docs)] diff --git a/crates/ec-vp8/src/mc.rs b/crates/ec-vp8/src/mc.rs index 2db87d05..d380e006 100644 --- a/crates/ec-vp8/src/mc.rs +++ b/crates/ec-vp8/src/mc.rs @@ -21,6 +21,7 @@ //! are reproduced exactly (`i32 >> 3` and `& 7` on negatives). //! //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc6386 +use archmage::SimdToken; use multiversion::target::match_target; /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes. @@ -212,10 +213,12 @@ fn sixtap_2d( match_target! { "x86_64+avx2" => { - if (sy + rows - 2) * stride + sx + 19 <= src.len() { - simd::sixtap_h(src, stride, sx, sy, hf, &mut tmp, rows); - simd::sixtap_v(&tmp, vf, dst, dst_stride, bw, bh); - return; + if let Some(t) = archmage::X64V3Token::summon() { + if (sy + rows - 2) * stride + sx + 19 <= src.len() { + simd::sixtap_h(t, src, stride, sx, sy, hf, &mut tmp, rows); + simd::sixtap_v(t, &tmp, vf, dst, dst_stride, bw, bh); + return; + } } } _ => {} @@ -292,10 +295,10 @@ fn sixtap_v_scalar( /// worst-case input bytes. /// /// The kernels are safe functions. Their only precondition is AVX2, which -/// the `#[target_feature]` attribute states; they can be called only from a -/// context that has AVX2 enabled, which is what [`sixtap_2d`] and -/// [`bilinear_2d`] guarantee by dispatching at runtime. Loads and stores go -/// through `bytemuck` on slices, so every access is bounds-checked. +/// the `X64V3Token` argument proves; the token comes only from `summon()`, +/// which checks the CPU at runtime, so [`sixtap_2d`] and [`bilinear_2d`] +/// pass it only when AVX2 is present. Loads and stores go through `bytemuck` +/// on slices, so every access is bounds-checked. /// /// Exactness notes shared by the six-tap kernels: /// - `_mm*_madd_epi16` multiplies *pairs of samples* by a packed tap pair @@ -312,6 +315,7 @@ fn sixtap_v_scalar( #[cfg(target_arch = "x86_64")] mod simd { use super::{VP8_FILTER_SHIFT, VP8_FILTER_WEIGHT}; + use archmage::{X64V3Token, arcane}; use std::arch::x86_64::*; /// Tap pair `[t0, t1]` packed into one `i32`, the operand shape @@ -366,8 +370,9 @@ mod simd { /// The caller guarantees that for every `i < rows`, the 21 bytes /// starting at `(sy + i - 2) * stride + sx - 2` are in `src` (with /// `sx, sy >= 2`); the slice indexing below enforces it. - #[target_feature(enable = "avx2")] + #[arcane] pub(super) fn sixtap_h( + _t: X64V3Token, src: &[u8], stride: usize, sx: usize, @@ -420,8 +425,9 @@ mod simd { /// Six-tap second pass: `bh` output rows of `bw` (4/8/16) samples from /// the 16-lane-strided intermediate. `dst` must hold `bh` rows of `bw` /// bytes at `dst_stride` (slice indexing enforces it); `bw` is 4, 8 or 16. - #[target_feature(enable = "avx2")] + #[arcane] pub(super) fn sixtap_v( + _t: X64V3Token, tmp: &[u8; 21 * 16], vf: &[i32; 6], dst: &mut [u8], @@ -479,8 +485,9 @@ mod simd { /// The caller guarantees that for every `i < rows`, the 17 bytes /// starting at `(sy + i) * stride + sx` are in `src`; the slice /// indexing below enforces it. - #[target_feature(enable = "avx2")] + #[arcane] pub(super) fn bilinear_h( + _t: X64V3Token, src: &[u8], stride: usize, sx: usize, @@ -513,8 +520,9 @@ mod simd { /// exact-`i16` shape as [`bilinear_h`]. `dst` must hold `bh` rows of /// `bw` bytes at `dst_stride` (slice indexing enforces it); `bw` is /// 4, 8 or 16. - #[target_feature(enable = "avx2")] + #[arcane] pub(super) fn bilinear_v( + _t: X64V3Token, tmp: &[u8; 17 * 16], vf: &[i32; 2], dst: &mut [u8], @@ -601,10 +609,12 @@ fn bilinear_2d( match_target! { "x86_64+avx2" => { - if (sy + rows - 1) * stride + sx + 16 < src.len() { - simd::bilinear_h(src, stride, sx, sy, hf, &mut tmp, rows); - simd::bilinear_v(&tmp, vf, dst, dst_stride, bw, bh); - return; + if let Some(t) = archmage::X64V3Token::summon() { + if (sy + rows - 1) * stride + sx + 16 < src.len() { + simd::bilinear_h(t, src, stride, sx, sy, hf, &mut tmp, rows); + simd::bilinear_v(t, &tmp, vf, dst, dst_stride, bw, bh); + return; + } } } _ => {}