forge
Explore
Log in

Don't you dare go Hollow

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

Browse files at this commit

d8ca21eb05a5b32c0ce9f0bbd1d866d3ca7771cfAhmet Kaan GümüşParent: 712f5aa
Cargo.lockmodified+2 -1
@@ -364,10 +364,10 @@ dependencies = [
364 name = "ec-av1"364 name = "ec-av1"
365 version = "0.1.0"365 version = "0.1.0"
366 dependencies = [366 dependencies = [
367+ "archmage",
367 "bytemuck",368 "bytemuck",
368 "ec-av1-syntax",369 "ec-av1-syntax",
369 "ec-core",370 "ec-core",
370- "multiversion",
371 "stats_alloc",371 "stats_alloc",
372 "tracking-allocator",372 "tracking-allocator",
373 ]373 ]
@@ -726,6 +726,7 @@ dependencies = [
726 name = "ec-vp8"726 name = "ec-vp8"
727 version = "0.1.0"727 version = "0.1.0"
728 dependencies = [728 dependencies = [
729+ "archmage",
729 "bytemuck",730 "bytemuck",
730 "ec-core",731 "ec-core",
731 "multiversion",732 "multiversion",
crates/ec-av1/Cargo.tomlmodified+1 -1
@@ -9,8 +9,8 @@ authors.workspace = true
9 [dependencies]9 [dependencies]
10 ec-core.workspace = true10 ec-core.workspace = true
11 ec-av1-syntax.workspace = true11 ec-av1-syntax.workspace = true
12+archmage = "=0.9.31-beta.1"
12 bytemuck = "1"13 bytemuck = "1"
13-multiversion = "0.9"
14 14
15 [features]15 [features]
16 default = ["gate-counters"]16 default = ["gate-counters"]
crates/ec-av1/src/decode/cdef.rsmodified+29 -32
@@ -1,5 +1,6 @@
1 //! CDEF constants and filter kernels. //! av1split: moved out of `decode/mod.rs`; the items are unchanged apart from visibility. (D14)1 //! CDEF constants and filter kernels. //! av1split: moved out of `decode/mod.rs`; the items are unchanged apart from visibility. (D14)
2 2
3+use archmage::SimdToken;
3 use super::*;4 use super::*;
4 5
5 /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary6 /// 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
156 /// Runtime dispatch of the direction search's partial sums: the AVX2 clone157 /// Runtime dispatch of the direction search's partial sums: the AVX2 clone
157 /// runs [`cdef_simd::find_dir_partials_avx2`], the baseline clone the scalar158 /// runs [`cdef_simd::find_dir_partials_avx2`], the baseline clone the scalar
158 /// form. Both read the same eight rows of eight samples.159 /// form. Both read the same eight rows of eight samples.
159-#[multiversion::multiversion(targets("x86_64+avx2"))]
160 pub(super) fn cdef_find_dir_partials_dispatch(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] {160 pub(super) fn cdef_find_dir_partials_dispatch(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] {
161- multiversion::target::match_target! {161+ if let Some(t) = archmage::X64V3Token::summon() {
162- "x86_64+avx2" => cdef_simd::find_dir_partials_avx2(win, bstride, coeff_shift),162+ return cdef_simd::find_dir_partials_avx2(t, win, bstride, coeff_shift);
163- _ => cdef_find_dir_partials(win, bstride, coeff_shift),
164 }163 }
164+ cdef_find_dir_partials(win, bstride, coeff_shift)
165 }165 }
166 166
167 pub(super) fn cdef_find_dir(win: &[i16], bstride: usize, coeff_shift: i32) -> (usize, i32) {167 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 {
223 /// chroma) in place, `sample(row, col)` reading the *unfiltered* frame (a223 /// chroma) in place, `sample(row, col)` reading the *unfiltered* frame (a
224 /// previously-filtered neighbour must never feed this block's own sum).224 /// previously-filtered neighbour must never feed this block's own sum).
225 #[allow(clippy::too_many_arguments)]225 #[allow(clippy::too_many_arguments)]
226-#[multiversion::multiversion(targets("x86_64+avx2"))]
227 pub(super) fn cdef_filter_block(226 pub(super) fn cdef_filter_block(
228 src: &[i16],227 src: &[i16],
229 dst: &mut [u16],228 dst: &mut [u16],
@@ -243,34 +242,32 @@ pub(super) fn cdef_filter_block(
243 fctx: &crate::decode::FrameCtx,242 fctx: &crate::decode::FrameCtx,
244 ) {243 ) {
245 let smax = sample_max(fctx);244 let smax = sample_max(fctx);
246- multiversion::target::match_target! {245+ if let Some(t) = archmage::X64V3Token::summon() {
247- "x86_64+avx2" => {246+ if (bw == 4 || bw == 8) && bh.is_multiple_of(2) {
248- if (bw == 4 || bw == 8) && bh.is_multiple_of(2) {247+ // The kernel reads `src`'s whole (bw + 4) x (bh + 4) window
249- // The kernel reads `src`'s whole (bw + 4) x (bh + 4) window248+ // and writes exactly the `bh` runs of `bw` samples the
250- // and writes exactly the `bh` runs of `bw` samples the249+ // scalar form writes.
251- // scalar form writes.250+ cdef_simd::filter_block_avx2(
252- cdef_simd::filter_block_avx2(251+ t,
253- src,252+ src,
254- dst,253+ dst,
255- stride,254+ stride,
256- ox,255+ ox,
257- oy,256+ oy,
258- bw,257+ bw,
259- bh,258+ bh,
260- pri_strength,259+ pri_strength,
261- sec_strength,260+ sec_strength,
262- dir,261+ dir,
263- pri_damping,262+ pri_damping,
264- sec_damping,263+ sec_damping,
265- enable_primary,264+ enable_primary,
266- enable_secondary,265+ enable_secondary,
267- coeff_shift,266+ coeff_shift,
268- smax,267+ smax,
269- );268+ );
270- return;269+ return;
271- }
272 }270 }
273- _ => {}
274 }271 }
275 cdef_filter_block_scalar(272 cdef_filter_block_scalar(
276 src,273 src,
crates/ec-av1/src/decode/cdef_simd.rsmodified+5 -3
@@ -2,6 +2,7 @@ use super::{
2 CDEF_BORDER, CDEF_DIRECTIONS, CDEF_PRI_TAPS, CDEF_SEC_TAPS, CDEF_VERY_LARGE,2 CDEF_BORDER, CDEF_DIRECTIONS, CDEF_PRI_TAPS, CDEF_SEC_TAPS, CDEF_VERY_LARGE,
3 cdef_constrain_shift,3 cdef_constrain_shift,
4 };4 };
5+use archmage::{X64V3Token, arcane};
5 use std::arch::x86_64::*;6 use std::arch::x86_64::*;
6 7
7 /// Eight `i16` samples starting at `at`, as one 128-bit register.8 /// 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) {
60 ///61 ///
61 /// `win` must hold [`super::cdef_gather`]'s 8x8 window grown by62 /// `win` must hold [`super::cdef_gather`]'s 8x8 window grown by
62 /// `CDEF_BORDER` at row stride `bstride`.63 /// `CDEF_BORDER` at row stride `bstride`.
63-#[target_feature(enable = "avx2")]64+#[arcane]
64-pub fn find_dir_partials_avx2(win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] {65+pub fn find_dir_partials_avx2(_t: X64V3Token, win: &[i16], bstride: usize, coeff_shift: i32) -> [[i32; 16]; 8] {
65 let mut partial = [[0i32; 16]; 8];66 let mut partial = [[0i32; 16]; 8];
66 let shift = _mm_cvtsi32_si128(coeff_shift);67 let shift = _mm_cvtsi32_si128(coeff_shift);
67 let c128 = _mm256_set1_epi32(128);68 let c128 = _mm256_set1_epi32(128);
@@ -105,9 +106,10 @@ pub fn find_dir_partials_avx2(win: &[i16], bstride: usize, coeff_shift: i32) ->
105 /// loads read up to 152 entries past its start, i.e. past the106 /// loads read up to 152 entries past its start, i.e. past the
106 /// `(bw + 4) x (bh + 4)` samples themselves) and `dst` the `bh` rows of107 /// `(bw + 4) x (bh + 4)` samples themselves) and `dst` the `bh` rows of
107 /// `bw` samples at `(ox, oy)`.108 /// `bw` samples at `(ox, oy)`.
108-#[target_feature(enable = "avx2")]109+#[arcane]
109 #[allow(clippy::too_many_arguments)]110 #[allow(clippy::too_many_arguments)]
110 pub fn filter_block_avx2(111 pub fn filter_block_avx2(
112+ _t: X64V3Token,
111 src: &[i16],113 src: &[i16],
112 dst: &mut [u16],114 dst: &mut [u16],
113 stride: usize,115 stride: usize,
crates/ec-av1/src/decode/deblock.rsmodified+21 -22
@@ -1,5 +1,6 @@
1 //! 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.1 //! 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.
2 2
3+use archmage::SimdToken;
3 use super::*;4 use super::*;
4 5
5 /// `update_sharpness`'s per-level `(blimit, limit, hev_thr)` triple.6 /// `update_sharpness`'s per-level `(blimit, limit, hev_thr)` triple.
@@ -335,7 +336,6 @@ pub(super) fn filter_edge(
335 #[allow(unused_variables)]336 #[allow(unused_variables)]
336 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.337 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
337 #[allow(clippy::too_many_arguments)]338 #[allow(clippy::too_many_arguments)]
338-#[multiversion::multiversion(targets("x86_64+avx2"))]
339 pub(super) fn filter_edge16(339 pub(super) fn filter_edge16(
340 data: &mut [u16],340 data: &mut [u16],
341 base: usize,341 base: usize,
@@ -346,27 +346,26 @@ pub(super) fn filter_edge16(
346 sharpness: u8,346 sharpness: u8,
347 fctx: &crate::decode::FrameCtx,347 fctx: &crate::decode::FrameCtx,
348 ) -> bool {348 ) -> bool {
349- multiversion::target::match_target! {349+ let Some(t) = archmage::X64V3Token::summon() else {
350- "x86_64+avx2" => {350+ return false;
351- let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness);351+ };
352- let shift = bit_depth(fctx) - 8;352+ let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness);
353- deblock_simd::edge16(353+ let shift = bit_depth(fctx) - 8;
354- data,354+ deblock_simd::edge16(
355- base,355+ t,
356- stride,356+ data,
357- vertical,357+ base,
358- len,358+ stride,
359- blimit << shift,359+ vertical,
360- limit << shift,360+ len,
361- hev_thr << shift,361+ blimit << shift,
362- 1 << shift,362+ limit << shift,
363- 1 << shift,363+ hev_thr << shift,
364- sample_max(fctx),364+ 1 << shift,
365- );365+ 1 << shift,
366- true366+ sample_max(fctx),
367- }367+ );
368- _ => false,368+ true
369- }
370 }369 }
371 370
372 /// One plane's worth of spec 7.14: every vertical edge across the plane,371 /// One plane's worth of spec 7.14: every vertical edge across the plane,
crates/ec-av1/src/decode/deblock_simd.rsmodified+3 -1
@@ -1,3 +1,4 @@
1+use archmage::{X64V3Token, arcane};
1 use std::arch::x86_64::*;2 use std::arch::x86_64::*;
2 3
3 /// Bounds-checked unaligned load of 16 `u16` samples at `at`.4 /// Bounds-checked unaligned load of 16 `u16` samples at `at`.
@@ -387,9 +388,10 @@ fn filter16<const LEN: u8>(
387 /// stride + 8 <= stride` and 16 rows from `base` must be inside `data`;388 /// stride + 8 <= stride` and 16 rows from `base` must be inside `data`;
388 /// for a horizontal edge `base >= 8 * stride` and `base + 8 * stride`389 /// for a horizontal edge `base >= 8 * stride` and `base + 8 * stride`
389 /// must be inside it.390 /// must be inside it.
390-#[target_feature(enable = "avx2")]391+#[arcane]
391 #[allow(clippy::too_many_arguments)]392 #[allow(clippy::too_many_arguments)]
392 pub fn edge16(393 pub fn edge16(
394+ _t: X64V3Token,
393 data: &mut [u16],395 data: &mut [u16],
394 base: usize,396 base: usize,
395 stride: usize,397 stride: usize,
crates/ec-av1/src/decode/tests.rsmodified+11 -12
@@ -1725,12 +1725,10 @@ fn cdef_find_dir_matches_the_per_sample_reference() {
1725 }1725 }
1726 }1726 }
1727 1727
1728-/// The CDEF filter through a `multiversion` clone, so the AVX2 kernel is1728+/// The CDEF filter with a summoned AVX2 token, so the AVX2 kernel is reached
1729-/// reached by a safe call: the AVX2 clone runs `filter_block_avx2`, the1729+/// by a safe call: the token runs `filter_block_avx2`, its absence the scalar form (the same split `cdef_filter_block` uses).
1730-/// baseline clone the scalar form (the same split `cdef_filter_block` uses).
1731 #[cfg(target_arch = "x86_64")]1730 #[cfg(target_arch = "x86_64")]
1732 #[allow(clippy::too_many_arguments)]1731 #[allow(clippy::too_many_arguments)]
1733-#[multiversion::multiversion(targets("x86_64+avx2"))]
1734 fn cdef_filter_block_under_test(1732 fn cdef_filter_block_under_test(
1735 src: &[i16],1733 src: &[i16],
1736 dst: &mut [u16],1734 dst: &mut [u16],
@@ -1749,16 +1747,16 @@ fn cdef_filter_block_under_test(
1749 coeff_shift: i32,1747 coeff_shift: i32,
1750 smax: i32,1748 smax: i32,
1751 ) {1749 ) {
1752- multiversion::target::match_target! {1750+ if let Some(t) = archmage::X64V3Token::summon() {
1753- "x86_64+avx2" => super::cdef_simd::filter_block_avx2(1751+ return super::cdef_simd::filter_block_avx2(
1754- src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,1752+ t, src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,
1755 pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,1753 pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,
1756- ),1754+ );
1757- _ => super::cdef_filter_block_scalar(
1758- src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,
1759- pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,
1760- ),
1761 }1755 }
1756+ super::cdef_filter_block_scalar(
1757+ src, dst, stride, ox, oy, bw, bh, pri_strength, sec_strength, dir,
1758+ pri_damping, sec_damping, enable_primary, enable_secondary, coeff_shift, smax,
1759+ )
1762 }1760 }
1763 1761
1764 /// lane-perf7 step 1: the AVX2 CDEF kernel must be value-identical to1762 /// 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() {
2098 );2096 );
2099 }2097 }
2100 }2098 }
2099+use archmage::SimdToken;
2101 use super::*;2100 use super::*;
2102 2101
2103 /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR --2102 /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR --
crates/ec-av1/src/film_grain.rsmodified+52 -57
@@ -21,6 +21,7 @@
21 //! [`crate::stream::decode_stream`] is the only caller: it applies this to21 //! [`crate::stream::decode_stream`] is the only caller: it applies this to
22 //! the frame it pushes onto its output `Vec<Picture>`, after saving the22 //! the frame it pushes onto its output `Vec<Picture>`, after saving the
23 //! clean decode into the reference slot bank.23 //! clean decode into the reference slot bank.
24+use archmage::SimdToken;
24 use crate::hits::hit;25 use crate::hits::hit;
25 26
26 use crate::decode::WithRef;27 use crate::decode::WithRef;
@@ -620,7 +621,6 @@ fn luma_noise_row(
620 /// 32x32 grain block is 30 wide (32 minus the 2-column overlap), never a621 /// 32x32 grain block is 30 wide (32 minus the 2-column overlap), never a
621 /// multiple of 8. Hoisting the row loop into the kernel pays the prologue622 /// multiple of 8. Hoisting the row loop into the kernel pays the prologue
622 /// once per block and lets the tail take a 4-wide SSE step.623 /// once per block and lets the tail take a 4-wide SSE step.
623-#[multiversion::multiversion(targets("x86_64+avx2"))]
624 #[allow(clippy::too_many_arguments)]624 #[allow(clippy::too_many_arguments)]
625 fn luma_noise_rows(625 fn luma_noise_rows(
626 pixels: &mut [u16],626 pixels: &mut [u16],
@@ -635,26 +635,24 @@ fn luma_noise_rows(
635 min_luma: i32,635 min_luma: i32,
636 max_luma: i32,636 max_luma: i32,
637 ) {637 ) {
638- multiversion::target::match_target! {638+ if let Some(t) = archmage::X64V3Token::summon() {
639- "x86_64+avx2" => {639+ if n >= 4 {
640- if n >= 4 {640+ simd::luma_noise_rows_avx2(
641- simd::luma_noise_rows_avx2(641+ t,
642- pixels,642+ pixels,
643- p_stride,643+ p_stride,
644- grain,644+ grain,
645- g_stride,645+ g_stride,
646- rows,646+ rows,
647- n,647+ n,
648- scaling,648+ scaling,
649- rounding_offset,649+ rounding_offset,
650- scaling_shift,650+ scaling_shift,
651- min_luma,651+ min_luma,
652- max_luma,652+ max_luma,
653- );653+ );
654- return;654+ return;
655- }
656 }655 }
657- _ => {}
658 }656 }
659 for r in 0..rows {657 for r in 0..rows {
660 luma_noise_row_scalar(658 luma_noise_row_scalar(
@@ -736,7 +734,6 @@ fn chroma_noise_row(
736 /// [`chroma_noise_row`] over `rows` consecutive chroma rows of a block; see734 /// [`chroma_noise_row`] over `rows` consecutive chroma rows of a block; see
737 /// [`luma_noise_rows`] for why the row loop lives inside the kernel.735 /// [`luma_noise_rows`] for why the row loop lives inside the kernel.
738 /// `pair` is `ss_x == 1`; see [`chroma_noise_row`] for the two luma shapes.736 /// `pair` is `ss_x == 1`; see [`chroma_noise_row`] for the two luma shapes.
739-#[multiversion::multiversion(targets("x86_64+avx2"))]
740 #[allow(clippy::too_many_arguments)]737 #[allow(clippy::too_many_arguments)]
741 fn chroma_noise_rows(738 fn chroma_noise_rows(
742 chroma: &mut [u16],739 chroma: &mut [u16],
@@ -754,17 +751,14 @@ fn chroma_noise_rows(
754 p: ChromaNoise,751 p: ChromaNoise,
755 pair: bool,752 pair: bool,
756 ) {753 ) {
757- multiversion::target::match_target! {754+ if let Some(t) = archmage::X64V3Token::summon() {
758- "x86_64+avx2" => {755+ if pair && n >= 4 {
759- if pair && n >= 4 {756+ simd::chroma_noise_rows_avx2(
760- simd::chroma_noise_rows_avx2(757+ t, chroma, c_stride, luma, l_stride, grain, g_stride, rows, n, scaling, luma_mult,
761- chroma, c_stride, luma, l_stride, grain, g_stride, rows, n, scaling, luma_mult,758+ mult, offset, p,
762- mult, offset, p,759+ );
763- );760+ return;
764- return;
765- }
766 }761 }
767- _ => {}
768 }762 }
769 let lrow = if pair { 2 * n } else { n };763 let lrow = if pair { 2 * n } else { n };
770 for r in 0..rows {764 for r in 0..rows {
@@ -834,6 +828,7 @@ fn luma_noise_row_scalar(
834 828
835 #[cfg(target_arch = "x86_64")]829 #[cfg(target_arch = "x86_64")]
836 mod simd {830 mod simd {
831+ use archmage::{X64V3Token, arcane};
837 use std::arch::x86_64::*;832 use std::arch::x86_64::*;
838 833
839 // Bounds-checked slice <-> vector moves (no raw pointers).834 // Bounds-checked slice <-> vector moves (no raw pointers).
@@ -899,10 +894,11 @@ mod simd {
899 /// panic.894 /// panic.
900 ///895 ///
901 /// `grain` must be at least `pixels.len()` long and `scaling` non-empty.896 /// `grain` must be at least `pixels.len()` long and `scaling` non-empty.
902- #[target_feature(enable = "avx2")]897+ #[arcane]
903 #[allow(clippy::too_many_arguments)]898 #[allow(clippy::too_many_arguments)]
904 #[cfg(test)]899 #[cfg(test)]
905 pub fn luma_noise_row_avx2(900 pub fn luma_noise_row_avx2(
901+ t: X64V3Token,
906 pixels: &mut [u16],902 pixels: &mut [u16],
907 grain: &[i32],903 grain: &[i32],
908 scaling: &[i32],904 scaling: &[i32],
@@ -913,6 +909,7 @@ mod simd {
913 ) {909 ) {
914 let n = pixels.len().min(grain.len());910 let n = pixels.len().min(grain.len());
915 luma_noise_rows_avx2(911 luma_noise_rows_avx2(
912+ t,
916 pixels,913 pixels,
917 n,914 n,
918 grain,915 grain,
@@ -933,9 +930,10 @@ mod simd {
933 ///930 ///
934 /// `pixels`/`grain` must cover the `rows x n` window at their strides and931 /// `pixels`/`grain` must cover the `rows x n` window at their strides and
935 /// `scaling` must be non-empty.932 /// `scaling` must be non-empty.
936- #[target_feature(enable = "avx2")]933+ #[arcane]
937 #[allow(clippy::too_many_arguments)]934 #[allow(clippy::too_many_arguments)]
938 pub fn luma_noise_rows_avx2(935 pub fn luma_noise_rows_avx2(
936+ _t: X64V3Token,
939 pixels: &mut [u16],937 pixels: &mut [u16],
940 p_stride: usize,938 p_stride: usize,
941 grain: &[i32],939 grain: &[i32],
@@ -1010,10 +1008,11 @@ mod simd {
1010 ///1008 ///
1011 /// `luma` must be at least `2 * chroma.len()` long, `grain` at least1009 /// `luma` must be at least `2 * chroma.len()` long, `grain` at least
1012 /// `chroma.len()`, and `scaling` non-empty.1010 /// `chroma.len()`, and `scaling` non-empty.
1013- #[target_feature(enable = "avx2")]1011+ #[arcane]
1014 #[allow(clippy::too_many_arguments)]1012 #[allow(clippy::too_many_arguments)]
1015 #[cfg(test)]1013 #[cfg(test)]
1016 pub fn chroma_noise_row_avx2(1014 pub fn chroma_noise_row_avx2(
1015+ t: X64V3Token,
1017 chroma: &mut [u16],1016 chroma: &mut [u16],
1018 luma: &[u16],1017 luma: &[u16],
1019 grain: &[i32],1018 grain: &[i32],
@@ -1025,6 +1024,7 @@ mod simd {
1025 ) {1024 ) {
1026 let n = chroma.len().min(grain.len()).min(luma.len() / 2);1025 let n = chroma.len().min(grain.len()).min(luma.len() / 2);
1027 chroma_noise_rows_avx2(1026 chroma_noise_rows_avx2(
1027+ t,
1028 chroma,1028 chroma,
1029 n,1029 n,
1030 luma,1030 luma,
@@ -1047,9 +1047,10 @@ mod simd {
1047 ///1047 ///
1048 /// The three slices must cover the `rows x n` window (`2 * n` for luma) at1048 /// The three slices must cover the `rows x n` window (`2 * n` for luma) at
1049 /// their strides and `scaling` must be non-empty.1049 /// their strides and `scaling` must be non-empty.
1050- #[target_feature(enable = "avx2")]1050+ #[arcane]
1051 #[allow(clippy::too_many_arguments)]1051 #[allow(clippy::too_many_arguments)]
1052 pub fn chroma_noise_rows_avx2(1052 pub fn chroma_noise_rows_avx2(
1053+ _t: X64V3Token,
1053 chroma: &mut [u16],1054 chroma: &mut [u16],
1054 c_stride: usize,1055 c_stride: usize,
1055 luma: &[u16],1056 luma: &[u16],
@@ -2140,10 +2141,10 @@ pub(crate) fn apply_grain(
2140 2141
2141 #[cfg(test)]2142 #[cfg(test)]
2142 mod perf5_tests {2143 mod perf5_tests {
2144+ use archmage::SimdToken;
2143 /// Runs the safe AVX2 kernel inside a `target_feature(avx2)` clone (the2145 /// Runs the safe AVX2 kernel inside a `target_feature(avx2)` clone (the
2144 /// caller checks `is_x86_feature_detected!("avx2")` first).2146 /// caller checks `is_x86_feature_detected!("avx2")` first).
2145 #[cfg(target_arch = "x86_64")]2147 #[cfg(target_arch = "x86_64")]
2146- #[multiversion::multiversion(targets("x86_64+avx2"))]
2147 #[allow(unused_variables)]2148 #[allow(unused_variables)]
2148 fn avx2_luma_row(2149 fn avx2_luma_row(
2149 pixels: &mut [u16],2150 pixels: &mut [u16],
@@ -2154,24 +2155,21 @@ mod perf5_tests {
2154 min_luma: i32,2155 min_luma: i32,
2155 max_luma: i32,2156 max_luma: i32,
2156 ) {2157 ) {
2157- multiversion::target::match_target! {2158+ if let Some(t) = archmage::X64V3Token::summon() {
2158- "x86_64+avx2" => {2159+ super::simd::luma_noise_row_avx2(
2159- super::simd::luma_noise_row_avx2(2160+ t,
2160- pixels,2161+ pixels,
2161- grain,2162+ grain,
2162- scaling,2163+ scaling,
2163- rounding_offset,2164+ rounding_offset,
2164- scaling_shift,2165+ scaling_shift,
2165- min_luma,2166+ min_luma,
2166- max_luma,2167+ max_luma,
2167- );2168+ );
2168- }
2169- _ => {}
2170 }2169 }
2171 }2170 }
2172 2171
2173 #[cfg(target_arch = "x86_64")]2172 #[cfg(target_arch = "x86_64")]
2174- #[multiversion::multiversion(targets("x86_64+avx2"))]
2175 #[allow(clippy::too_many_arguments)]2173 #[allow(clippy::too_many_arguments)]
2176 #[allow(unused_variables)]2174 #[allow(unused_variables)]
2177 fn avx2_chroma_row(2175 fn avx2_chroma_row(
@@ -2184,13 +2182,10 @@ mod perf5_tests {
2184 offset: i32,2182 offset: i32,
2185 p: super::ChromaNoise,2183 p: super::ChromaNoise,
2186 ) {2184 ) {
2187- multiversion::target::match_target! {2185+ if let Some(t) = archmage::X64V3Token::summon() {
2188- "x86_64+avx2" => {2186+ super::simd::chroma_noise_row_avx2(
2189- super::simd::chroma_noise_row_avx2(2187+ t, chroma, luma, grain, scaling, luma_mult, mult, offset, p,
2190- chroma, luma, grain, scaling, luma_mult, mult, offset, p,2188+ );
2191- );
2192- }
2193- _ => {}
2194 }2189 }
2195 }2190 }
2196 2191
crates/ec-av1/src/mc.rsmodified+56 -67
@@ -8,6 +8,7 @@
8 //! in 1/16-pel steps -- luma motion vectors are stored at 1/8-pel and always8 //! in 1/16-pel steps -- luma motion vectors are stored at 1/8-pel and always
9 //! land on an even step; chroma vectors, once scaled for subsampling, can9 //! land on an even step; chroma vectors, once scaled for subsampling, can
10 //! land on any of the 16.10 //! land on any of the 16.
11+use archmage::SimdToken;
11 use crate::hits::hit;12 use crate::hits::hit;
12 13
13 /// `Round2` (spec 4.7): halves round up.14 /// `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:
326 /// lane-mc2: `rows` rows of [`hpass_contig`], `src_stride` apart in `src` and327 /// lane-mc2: `rows` rows of [`hpass_contig`], `src_stride` apart in `src` and
327 /// packed `block_w` apart in `out`. The tap vectors and the SIMD dispatch are328 /// packed `block_w` apart in `out`. The tap vectors and the SIMD dispatch are
328 /// set up once for the whole block instead of once per row.329 /// set up once for the whole block instead of once per row.
329-// Runtime dispatch is `multiversion`'s: the AVX2 clone runs the AVX2 kernel,330+// Runtime dispatch is an archmage token summon: the AVX2 token runs the AVX2
330-// the SSE4.1 clone the SSE2 one, anything else the scalar loop below.331+// kernel, the SSE4.1 token the SSE2 one, anything else the scalar loop below.
331-#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))]
332 pub(crate) fn hpass_rows(332 pub(crate) fn hpass_rows(
333 src: &[u16],333 src: &[u16],
334 src_stride: usize,334 src_stride: usize,
@@ -339,16 +339,16 @@ pub(crate) fn hpass_rows(
339 round0: u32,339 round0: u32,
340 ) {340 ) {
341 #[cfg(target_arch = "x86_64")]341 #[cfg(target_arch = "x86_64")]
342- multiversion::target::match_target! {342+ {
343- "x86_64+avx2" => {343+ if let Some(t) = archmage::X64V3Token::summon() {
344- simd::hpass_avx2(src, src_stride, rows, block_w, t16, out, round0);344+ simd::hpass_avx2(t, src, src_stride, rows, block_w, t16, out, round0);
345+ return;
345 }346 }
346- "x86_64+sse4.1" => {347+ if let Some(t) = archmage::X64V2Token::summon() {
347- simd::hpass_sse2(src, src_stride, rows, block_w, t16, out, round0);348+ simd::hpass_sse2(t, src, src_stride, rows, block_w, t16, out, round0);
349+ return;
348 }350 }
349- _ => hpass_rows_scalar_all(src, src_stride, rows, block_w, t16, out, round0),
350 }351 }
351- #[cfg(not(target_arch = "x86_64"))]
352 hpass_rows_scalar_all(src, src_stride, rows, block_w, t16, out, round0);352 hpass_rows_scalar_all(src, src_stride, rows, block_w, t16, out, round0);
353 }353 }
354 354
@@ -391,13 +391,13 @@ fn hpass_contig_scalar(src: &[u16], t16: &[i16; 8], out: &mut [i16], round0: u32
391 /// `hpass_row` + `vpass_row`. Nothing here is spec logic: each kernel is the391 /// `hpass_row` + `vpass_row`. Nothing here is spec logic: each kernel is the
392 /// scalar function's arithmetic, lane-parallel, with identical rounding.392 /// scalar function's arithmetic, lane-parallel, with identical rounding.
393 ///393 ///
394-/// Every kernel is a safe `#[target_feature]` function, called only from a394+/// Every kernel is a safe `#[arcane]` (or `#[target_feature]` helper) function,
395-/// `multiversion` clone that has the feature enabled (or, for SSE2, from any395+/// called only with the archmage token of its feature, obtained by `summon`. Loads and stores go through `bytemuck` on slices, so every
396-/// x86_64 code). Loads and stores go through `bytemuck` on slices, so every
397 /// access is bounds-checked.396 /// access is bounds-checked.
398 #[cfg(target_arch = "x86_64")]397 #[cfg(target_arch = "x86_64")]
399 mod simd {398 mod simd {
400 use super::{round2, sat16};399 use super::{round2, sat16};
400+ use archmage::{X64V2Token, X64V3Token, arcane};
401 use bytemuck::Pod;401 use bytemuck::Pod;
402 use std::arch::x86_64::*;402 use std::arch::x86_64::*;
403 use std::mem::size_of;403 use std::mem::size_of;
@@ -468,8 +468,9 @@ mod simd {
468 /// `unpack` + `permute2x128`.468 /// `unpack` + `permute2x128`.
469 ///469 ///
470 /// Requires AVX2. `src.len()` must be at least `out.len() + 7`.470 /// Requires AVX2. `src.len()` must be at least `out.len() + 7`.
471- #[target_feature(enable = "avx2")]471+ #[arcane]
472 pub fn hpass_avx2(472 pub fn hpass_avx2(
473+ t: X64V3Token,
473 src: &[u16],474 src: &[u16],
474 src_stride: usize,475 src_stride: usize,
475 rows: usize,476 rows: usize,
@@ -515,7 +516,7 @@ mod simd {
515 c += 16;516 c += 16;
516 }517 }
517 if c < block_w {518 if c < block_w {
518- hpass_sse2(&sp[c..], 0, 1, block_w - c, t16, &mut op[c..], round0);519+ hpass_sse2(t.v2(), &sp[c..], 0, 1, block_w - c, t16, &mut op[c..], round0);
519 }520 }
520 }521 }
521 }522 }
@@ -529,8 +530,9 @@ mod simd {
529 ///530 ///
530 /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements531 /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements
531 /// and `acc` at least `block_w`.532 /// and `acc` at least `block_w`.
532- #[target_feature(enable = "avx2")]533+ #[arcane]
533 pub fn vpass_avx2(534 pub fn vpass_avx2(
535+ _t: X64V3Token,
534 intermediate: &[i16],536 intermediate: &[i16],
535 block_w: usize,537 block_w: usize,
536 src_stride: usize,538 src_stride: usize,
@@ -645,10 +647,11 @@ mod simd {
645 ///647 ///
646 /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements648 /// Requires AVX2. `intermediate` must hold `(row + 8) * block_w` elements
647 /// and `dst` at least `block_w`.649 /// and `dst` at least `block_w`.
648- #[target_feature(enable = "avx2")]650+ #[arcane]
649 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.651 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
650 #[allow(clippy::too_many_arguments)]652 #[allow(clippy::too_many_arguments)]
651 pub fn vpass_row_u16_avx2(653 pub fn vpass_row_u16_avx2(
654+ _t: X64V3Token,
652 intermediate: &[i16],655 intermediate: &[i16],
653 block_w: usize,656 block_w: usize,
654 src_stride: usize,657 src_stride: usize,
@@ -768,10 +771,11 @@ mod simd {
768 /// [`vpass_row_u16_avx2`] without the 16-column step.771 /// [`vpass_row_u16_avx2`] without the 16-column step.
769 ///772 ///
770 /// Requires SSE4.1; same slice contract as [`vpass_row_u16_avx2`].773 /// Requires SSE4.1; same slice contract as [`vpass_row_u16_avx2`].
771- #[target_feature(enable = "sse4.1")]774+ #[arcane]
772 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.775 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
773 #[allow(clippy::too_many_arguments)]776 #[allow(clippy::too_many_arguments)]
774 pub fn vpass_row_u16_sse41(777 pub fn vpass_row_u16_sse41(
778+ _t: X64V2Token,
775 intermediate: &[i16],779 intermediate: &[i16],
776 block_w: usize,780 block_w: usize,
777 src_stride: usize,781 src_stride: usize,
@@ -803,8 +807,9 @@ mod simd {
803 /// Vertical pass, SSE2: [`vpass_avx2`] without the 16-column step.807 /// Vertical pass, SSE2: [`vpass_avx2`] without the 16-column step.
804 ///808 ///
805 /// SSE2 is baseline x86_64; same slice contract as [`vpass_avx2`].809 /// SSE2 is baseline x86_64; same slice contract as [`vpass_avx2`].
806- #[target_feature(enable = "sse2")]810+ #[arcane]
807 pub fn vpass_sse41(811 pub fn vpass_sse41(
812+ _t: X64V2Token,
808 intermediate: &[i16],813 intermediate: &[i16],
809 block_w: usize,814 block_w: usize,
810 src_stride: usize,815 src_stride: usize,
@@ -834,8 +839,9 @@ mod simd {
834 /// scalar loop, which is where 4-tap kernels mostly land anyway.839 /// scalar loop, which is where 4-tap kernels mostly land anyway.
835 ///840 ///
836 /// `src.len()` must be at least `out.len() + 7`. SSE2 is baseline x86_64.841 /// `src.len()` must be at least `out.len() + 7`. SSE2 is baseline x86_64.
837- #[target_feature(enable = "sse2")]842+ #[arcane]
838 pub fn hpass_sse2(843 pub fn hpass_sse2(
844+ _t: X64V2Token,
839 src: &[u16],845 src: &[u16],
840 src_stride: usize,846 src_stride: usize,
841 rows: usize,847 rows: usize,
@@ -889,12 +895,12 @@ mod simd {
889 }895 }
890 }896 }
891 897
892- // Test-only entry points that run one kernel under a `multiversion`898+ // Test-only entry points that run one kernel with a summoned token, so
893- // clone with the needed feature, so the unit tests can exercise each899+ // the unit tests can exercise each tier directly (callers check the
894- // tier directly (callers check the feature first).900+ // feature first).
895 #[cfg(test)]901 #[cfg(test)]
896 pub mod entry {902 pub mod entry {
897- #[multiversion::multiversion(targets("x86_64+sse4.1"))]903+ use archmage::SimdToken;
898 #[allow(unused_variables)]904 #[allow(unused_variables)]
899 pub fn hpass_sse2(905 pub fn hpass_sse2(
900 src: &[u16],906 src: &[u16],
@@ -905,13 +911,10 @@ mod simd {
905 out: &mut [i16],911 out: &mut [i16],
906 round0: u32,912 round0: u32,
907 ) {913 ) {
908- multiversion::target::match_target! {914+ let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1");
909- "x86_64+sse4.1" => super::hpass_sse2(src, src_stride, rows, block_w, t16, out, round0),915+ super::hpass_sse2(t, src, src_stride, rows, block_w, t16, out, round0)
910- _ => unreachable!("sse4.1 entry on a CPU without sse4.1"),
911- }
912 }916 }
913 917
914- #[multiversion::multiversion(targets("x86_64+sse4.1"))]
915 #[allow(unused_variables)]918 #[allow(unused_variables)]
916 pub fn vpass_sse41(919 pub fn vpass_sse41(
917 intermediate: &[i16],920 intermediate: &[i16],
@@ -921,13 +924,10 @@ mod simd {
921 taps: &[i32; 8],924 taps: &[i32; 8],
922 acc: &mut [i32],925 acc: &mut [i32],
923 ) {926 ) {
924- multiversion::target::match_target! {927+ let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1");
925- "x86_64+sse4.1" => super::vpass_sse41(intermediate, block_w, src_stride, rows, taps, acc),928+ super::vpass_sse41(t, intermediate, block_w, src_stride, rows, taps, acc)
926- _ => unreachable!("sse4.1 entry on a CPU without sse4.1"),
927- }
928 }929 }
929 930
930- #[multiversion::multiversion(targets("x86_64+avx2"))]
931 #[allow(unused_variables)]931 #[allow(unused_variables)]
932 pub fn hpass_avx2(932 pub fn hpass_avx2(
933 src: &[u16],933 src: &[u16],
@@ -938,13 +938,10 @@ mod simd {
938 out: &mut [i16],938 out: &mut [i16],
939 round0: u32,939 round0: u32,
940 ) {940 ) {
941- multiversion::target::match_target! {941+ let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2");
942- "x86_64+avx2" => super::hpass_avx2(src, src_stride, rows, block_w, t16, out, round0),942+ super::hpass_avx2(t, src, src_stride, rows, block_w, t16, out, round0)
943- _ => unreachable!("avx2 entry on a CPU without avx2"),
944- }
945 }943 }
946 944
947- #[multiversion::multiversion(targets("x86_64+avx2"))]
948 #[allow(unused_variables)]945 #[allow(unused_variables)]
949 pub fn vpass_avx2(946 pub fn vpass_avx2(
950 intermediate: &[i16],947 intermediate: &[i16],
@@ -954,13 +951,10 @@ mod simd {
954 taps: &[i32; 8],951 taps: &[i32; 8],
955 acc: &mut [i32],952 acc: &mut [i32],
956 ) {953 ) {
957- multiversion::target::match_target! {954+ let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2");
958- "x86_64+avx2" => super::vpass_avx2(intermediate, block_w, src_stride, rows, taps, acc),955+ super::vpass_avx2(t, intermediate, block_w, src_stride, rows, taps, acc)
959- _ => unreachable!("avx2 entry on a CPU without avx2"),
960- }
961 }956 }
962 957
963- #[multiversion::multiversion(targets("x86_64+avx2"))]
964 #[allow(unused_variables, clippy::too_many_arguments)]958 #[allow(unused_variables, clippy::too_many_arguments)]
965 pub fn vpass_row_u16_avx2(959 pub fn vpass_row_u16_avx2(
966 intermediate: &[i16],960 intermediate: &[i16],
@@ -972,13 +966,10 @@ mod simd {
972 dst: &mut [u16],966 dst: &mut [u16],
973 round1: u32,967 round1: u32,
974 ) {968 ) {
975- multiversion::target::match_target! {969+ let t = archmage::X64V3Token::summon().expect("avx2 entry on a CPU without avx2");
976- "x86_64+avx2" => super::vpass_row_u16_avx2(intermediate, block_w, src_stride, rows, taps, max, dst, round1),970+ super::vpass_row_u16_avx2(t, intermediate, block_w, src_stride, rows, taps, max, dst, round1)
977- _ => unreachable!("avx2 entry on a CPU without avx2"),
978- }
979 }971 }
980 972
981- #[multiversion::multiversion(targets("x86_64+sse4.1"))]
982 #[allow(unused_variables, clippy::too_many_arguments)]973 #[allow(unused_variables, clippy::too_many_arguments)]
983 pub fn vpass_row_u16_sse41(974 pub fn vpass_row_u16_sse41(
984 intermediate: &[i16],975 intermediate: &[i16],
@@ -990,10 +981,8 @@ mod simd {
990 dst: &mut [u16],981 dst: &mut [u16],
991 round1: u32,982 round1: u32,
992 ) {983 ) {
993- multiversion::target::match_target! {984+ let t = archmage::X64V2Token::summon().expect("sse4.1 entry on a CPU without sse4.1");
994- "x86_64+sse4.1" => super::vpass_row_u16_sse41(intermediate, block_w, src_stride, rows, taps, max, dst, round1),985+ super::vpass_row_u16_sse41(t, intermediate, block_w, src_stride, rows, taps, max, dst, round1)
995- _ => unreachable!("sse4.1 entry on a CPU without sse4.1"),
996- }
997 }986 }
998 }987 }
999 }988 }
@@ -1136,7 +1125,6 @@ fn horizontal_pass_unscaled(
1136 /// striding the intermediate by `block_w` per tap. A zero tap is skipped --1125 /// striding the intermediate by `block_w` per tap. A zero tap is skipped --
1137 /// adding `0 * x` is exactly nothing, and the 4-tap kernels zero four of the1126 /// adding `0 * x` is exactly nothing, and the 4-tap kernels zero four of the
1138 /// eight slots. `acc` is left holding the unrounded sums.1127 /// eight slots. `acc` is left holding the unrounded sums.
1139-#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))]
1140 pub(crate) fn vpass_row(1128 pub(crate) fn vpass_row(
1141 intermediate: &[i16],1129 intermediate: &[i16],
1142 block_w: usize,1130 block_w: usize,
@@ -1146,16 +1134,16 @@ pub(crate) fn vpass_row(
1146 acc: &mut [i32],1134 acc: &mut [i32],
1147 ) {1135 ) {
1148 #[cfg(target_arch = "x86_64")]1136 #[cfg(target_arch = "x86_64")]
1149- multiversion::target::match_target! {1137+ {
1150- "x86_64+avx2" => {1138+ if let Some(t) = archmage::X64V3Token::summon() {
1151- simd::vpass_avx2(intermediate, block_w, src_stride, rows, taps, acc);1139+ simd::vpass_avx2(t, intermediate, block_w, src_stride, rows, taps, acc);
1140+ return;
1152 }1141 }
1153- "x86_64+sse4.1" => {1142+ if let Some(t) = archmage::X64V2Token::summon() {
1154- simd::vpass_sse41(intermediate, block_w, src_stride, rows, taps, acc);1143+ simd::vpass_sse41(t, intermediate, block_w, src_stride, rows, taps, acc);
1144+ return;
1155 }1145 }
1156- _ => vpass_row_scalar_all(intermediate, block_w, src_stride, rows, taps, acc),
1157 }1146 }
1158- #[cfg(not(target_arch = "x86_64"))]
1159 vpass_row_scalar_all(intermediate, block_w, src_stride, rows, taps, acc);1147 vpass_row_scalar_all(intermediate, block_w, src_stride, rows, taps, acc);
1160 }1148 }
1161 1149
@@ -1184,7 +1172,6 @@ fn vpass_row_scalar_all(
1184 /// entry points whose destination is `u16` samples. The unrounded `i32` sums1172 /// entry points whose destination is `u16` samples. The unrounded `i32` sums
1185 /// used to be stored to a scratch row and read straight back by a rounding1173 /// used to be stored to a scratch row and read straight back by a rounding
1186 /// loop; here they never leave the register.1174 /// loop; here they never leave the register.
1187-#[multiversion::multiversion(targets("x86_64+avx2", "x86_64+sse4.1"))]
1188 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.1175 // Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
1189 #[allow(clippy::too_many_arguments)]1176 #[allow(clippy::too_many_arguments)]
1190 fn vpass_row_u16(1177 fn vpass_row_u16(
@@ -1198,9 +1185,10 @@ fn vpass_row_u16(
1198 round1: u32,1185 round1: u32,
1199 ) {1186 ) {
1200 #[cfg(target_arch = "x86_64")]1187 #[cfg(target_arch = "x86_64")]
1201- multiversion::target::match_target! {1188+ {
1202- "x86_64+avx2" => {1189+ if let Some(t) = archmage::X64V3Token::summon() {
1203 simd::vpass_row_u16_avx2(1190 simd::vpass_row_u16_avx2(
1191+ t,
1204 intermediate,1192 intermediate,
1205 block_w,1193 block_w,
1206 src_stride,1194 src_stride,
@@ -1210,9 +1198,11 @@ fn vpass_row_u16(
1210 dst,1198 dst,
1211 round1,1199 round1,
1212 );1200 );
1201+ return;
1213 }1202 }
1214- "x86_64+sse4.1" => {1203+ if let Some(t) = archmage::X64V2Token::summon() {
1215 simd::vpass_row_u16_sse41(1204 simd::vpass_row_u16_sse41(
1205+ t,
1216 intermediate,1206 intermediate,
1217 block_w,1207 block_w,
1218 src_stride,1208 src_stride,
@@ -1222,10 +1212,9 @@ fn vpass_row_u16(
1222 dst,1212 dst,
1223 round1,1213 round1,
1224 );1214 );
1215+ return;
1225 }1216 }
1226- _ => vpass_row_u16_scalar_all(intermediate, block_w, src_stride, rows, taps, max, dst, round1),
1227 }1217 }
1228- #[cfg(not(target_arch = "x86_64"))]
1229 vpass_row_u16_scalar_all(1218 vpass_row_u16_scalar_all(
1230 intermediate,1219 intermediate,
1231 block_w,1220 block_w,
crates/ec-av1/src/restoration.rsmodified+7 -6
@@ -3,8 +3,8 @@
3 //! `av1_loop_restoration_corners_in_sb`, restoration.c:1277) and spec 7.17's3 //! `av1_loop_restoration_corners_in_sb`, restoration.c:1277) and spec 7.17's
4 //! two pixel filters (Wiener, self-guided/SGR). See `lanes/lr.report.md` for4 //! two pixel filters (Wiener, self-guided/SGR). See `lanes/lr.report.md` for
5 //! the full derivation (libaom `decodeframe.c`/`restoration.c` line refs).5 //! the full derivation (libaom `decodeframe.c`/`restoration.c` line refs).
6+use archmage::SimdToken;
6 use crate::hits::hit;7 use crate::hits::hit;
7-use multiversion::target::match_target;
8 8
9 use crate::msac::SymbolDecoder;9 use crate::msac::SymbolDecoder;
10 use ec_av1_syntax::obu::floor_log2;10 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
1165 1165
1166 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time1166 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time
1167 /// under AVX2 (the kernel is that arithmetic lane-wise, same widths).1167 /// under AVX2 (the kernel is that arithmetic lane-wise, same widths).
1168-#[multiversion::multiversion(targets("x86_64+avx2"))]
1169 #[allow(clippy::too_many_arguments)]1168 #[allow(clippy::too_many_arguments)]
1170 fn ab_row(1169 fn ab_row(
1171 a_row: &[i32],1170 a_row: &[i32],
@@ -1176,9 +1175,9 @@ fn ab_row(
1176 one_by_x: i64,1175 one_by_x: i64,
1177 out: &mut [(i32, i64)],1176 out: &mut [(i32, i64)],
1178 ) {1177 ) {
1179- let done = match_target! {1178+ let done = match archmage::X64V3Token::summon() {
1180- "x86_64+avx2" => sgr_simd::ab_row_avx2(a_row, b_row, n, s, bd_shift, one_by_x as i32, out),1179+ Some(t) => sgr_simd::ab_row_avx2(t, a_row, b_row, n, s, bd_shift, one_by_x as i32, out),
1181- _ => 0usize,1180+ None => 0usize,
1182 };1181 };
1183 for gj in done..out.len() {1182 for gj in done..out.len() {
1184 out[gj] = ab_point(a_row[gj], b_row[gj], n, s, bd_shift, one_by_x);1183 out[gj] = ab_point(a_row[gj], b_row[gj], n, s, bd_shift, one_by_x);
@@ -1189,6 +1188,7 @@ fn ab_row(
1189 #[cfg(target_arch = "x86_64")]1188 #[cfg(target_arch = "x86_64")]
1190 mod sgr_simd {1189 mod sgr_simd {
1191 use super::{SGRPROJ_MTABLE_BITS, SGRPROJ_RECIP_BITS, SGR_X_BY_XPLUS1};1190 use super::{SGRPROJ_MTABLE_BITS, SGRPROJ_RECIP_BITS, SGR_X_BY_XPLUS1};
1191+ use archmage::{X64V3Token, arcane};
1192 use std::arch::x86_64::*;1192 use std::arch::x86_64::*;
1193 1193
1194 /// Eight grid points of `super::ab_point` per iteration, returning how1194 /// Eight grid points of `super::ab_point` per iteration, returning how
@@ -1199,9 +1199,10 @@ mod sgr_simd {
1199 /// `p * s < 2^38`, `(256 - A) * one_by_x < 2^21` and that times1199 /// `p * s < 2^38`, `(256 - A) * one_by_x < 2^21` and that times
1200 /// `b < 2^17` is `< 2^38` -- so the two 64-bit products below lose no1200 /// `b < 2^17` is `< 2^38` -- so the two 64-bit products below lose no
1201 /// bit, and the unsigned `mul_epu32` sees no negative operand.1201 /// bit, and the unsigned `mul_epu32` sees no negative operand.
1202- #[target_feature(enable = "avx2")]1202+ #[arcane]
1203 #[allow(clippy::too_many_arguments)]1203 #[allow(clippy::too_many_arguments)]
1204 pub fn ab_row_avx2(1204 pub fn ab_row_avx2(
1205+ _t: X64V3Token,
1205 a_row: &[i32],1206 a_row: &[i32],
1206 b_row: &[i32],1207 b_row: &[i32],
1207 n: i32,1208 n: i32,
crates/ec-av1/src/transform.rsmodified+17 -24
@@ -195,6 +195,7 @@ impl Lane for [i32; 8] {
195 #[cfg(target_arch = "x86_64")]195 #[cfg(target_arch = "x86_64")]
196 mod simd {196 mod simd {
197 use super::{COS_BITS, Kern, inverse_dct_n};197 use super::{COS_BITS, Kern, inverse_dct_n};
198+ use archmage::{SimdToken, X64V3Token, arcane};
198 use std::arch::x86_64::*;199 use std::arch::x86_64::*;
199 200
200 /// Eight `i32` lanes in one AVX2 register.201 /// Eight `i32` lanes in one AVX2 register.
@@ -232,8 +233,8 @@ mod simd {
232 /// bits (`|a| < 2^31`, `|c| <= 2^12`), and only the low 32 bits of the233 /// bits (`|a| < 2^31`, `|c| <= 2^12`), and only the low 32 bits of the
233 /// shifted sum are kept -- which is what the scalar `as i32` keeps, so234 /// shifted sum are kept -- which is what the scalar `as i32` keeps, so
234 /// the logical shift stands in for the arithmetic one exactly.235 /// the logical shift stands in for the arithmetic one exactly.
235- #[target_feature(enable = "avx2")]236+ #[arcane]
236- pub(super) fn dct_x8_avx2(t: &mut [M256; 64], n: u32, r: usize) {237+ pub(super) fn dct_x8_avx2(_tok: X64V3Token, t: &mut [M256; 64], n: u32, r: usize) {
237 let btf = |a: M256, b: M256, c: i64, s: i64| {238 let btf = |a: M256, b: M256, c: i64, s: i64| {
238 let cv = _mm256_set1_epi32(c as i32);239 let cv = _mm256_set1_epi32(c as i32);
239 let sv = _mm256_set1_epi32(s as i32);240 let sv = _mm256_set1_epi32(s as i32);
@@ -292,8 +293,9 @@ mod simd {
292 293
293 /// The whole DCT column pass of one transform unit: `residual` is the294 /// The whole DCT column pass of one transform unit: `residual` is the
294 /// row-pass output (`h` rows of `w`), `out` the residual it writes.295 /// row-pass output (`h` rows of `w`), `out` the residual it writes.
295- #[target_feature(enable = "avx2")]296+ #[arcane]
296 pub(super) fn column_pass_dct(297 pub(super) fn column_pass_dct(
298+ tok: X64V3Token,
297 residual: &[i32],299 residual: &[i32],
298 out: &mut [i32],300 out: &mut [i32],
299 w: usize,301 w: usize,
@@ -316,7 +318,7 @@ mod simd {
316 if _mm256_testz_si256(any, any) == 1 {318 if _mm256_testz_si256(any, any) == 1 {
317 continue;319 continue;
318 }320 }
319- dct_x8_avx2(&mut t, log2h, r);321+ dct_x8_avx2(tok, &mut t, log2h, r);
320 // `round2(v, 4)` on eight lanes: the shift is arithmetic here322 // `round2(v, 4)` on eight lanes: the shift is arithmetic here
321 // because the value stays in its own 32-bit lane.323 // because the value stays in its own 32-bit lane.
322 let rnd = _mm256_set1_epi32(8);324 let rnd = _mm256_set1_epi32(8);
@@ -330,9 +332,7 @@ mod simd {
330 }332 }
331 }333 }
332 334
333- /// [`column_pass_dct`] when this CPU has AVX2 (the multiversion AVX2335+ /// [`column_pass_dct`] when this CPU has AVX2, or `false` with nothing done.
334- /// clone), or `false` with nothing done.
335- #[multiversion::multiversion(targets("x86_64+avx2"))]
336 pub(super) fn column_pass_dct_dispatch(336 pub(super) fn column_pass_dct_dispatch(
337 residual: &[i32],337 residual: &[i32],
338 out: &mut [i32],338 out: &mut [i32],
@@ -342,15 +342,12 @@ mod simd {
342 r: usize,342 r: usize,
343 ud_flip: bool,343 ud_flip: bool,
344 ) -> bool {344 ) -> bool {
345- multiversion::target::match_target! {345+ match archmage::X64V3Token::summon() {
346- "x86_64+avx2" => {346+ Some(t) => {
347- column_pass_dct(residual, out, w, h, log2h, r, ud_flip);347+ column_pass_dct(t, residual, out, w, h, log2h, r, ud_flip);
348 true348 true
349- },349+ }
350- _ => {350+ None => false,
351- let _ = (residual, out, w, h, log2h, r, ud_flip);
352- false
353- },
354 }351 }
355 }352 }
356 353
@@ -369,17 +366,13 @@ mod simd {
369 /// [`dct_x8_avx2`] when this CPU has AVX2; `false` with nothing done366 /// [`dct_x8_avx2`] when this CPU has AVX2; `false` with nothing done
370 /// otherwise. For the equivalence gate.367 /// otherwise. For the equivalence gate.
371 #[cfg(test)]368 #[cfg(test)]
372- #[multiversion::multiversion(targets("x86_64+avx2"))]
373 pub(super) fn dct_x8_dispatch(t: &mut [M256; 64], n: u32, r: usize) -> bool {369 pub(super) fn dct_x8_dispatch(t: &mut [M256; 64], n: u32, r: usize) -> bool {
374- multiversion::target::match_target! {370+ match archmage::X64V3Token::summon() {
375- "x86_64+avx2" => {371+ Some(tok) => {
376- dct_x8_avx2(t, n, r);372+ dct_x8_avx2(tok, t, n, r);
377 true373 true
378- },374+ }
379- _ => {375+ None => false,
380- let _ = (t, n, r);
381- false
382- },
383 }376 }
384 }377 }
385 }378 }
crates/ec-h265/src/simd_tx.rsmodified+54 -29
@@ -19,6 +19,7 @@ pub(crate) use x86::*;
19 #[cfg(target_arch = "x86_64")]19 #[cfg(target_arch = "x86_64")]
20 mod x86 {20 mod x86 {
21 use super::*;21 use super::*;
22+ use archmage::{SimdToken, X64V3Token, arcane};
22 use multiversion::target::match_target;23 use multiversion::target::match_target;
23 use std::arch::x86_64::*;24 use std::arch::x86_64::*;
24 25
@@ -356,8 +357,8 @@ mod x86 {
356 _mm256_set1_epi32357 _mm256_set1_epi32
357 );358 );
358 359
359- #[target_feature(enable = "avx2")]360+ #[arcane]
360- pub(super) fn fwd(residual: &[i32], coeffs: &mut [i32], n: usize) {361+ pub(super) fn fwd(_t: X64V3Token, residual: &[i32], coeffs: &mut [i32], n: usize) {
361 match n {362 match n {
362 8 => forward_2d::<64, 192>(residual, coeffs, n, false),363 8 => forward_2d::<64, 192>(residual, coeffs, n, false),
363 16 => forward_2d::<256, 768>(residual, coeffs, n, false),364 16 => forward_2d::<256, 768>(residual, coeffs, n, false),
@@ -365,8 +366,14 @@ mod x86 {
365 }366 }
366 }367 }
367 368
368- #[target_feature(enable = "avx2")]369+ #[arcane]
369- pub(super) fn inv(scaled: &[i32], residual: &mut [i32], n: usize, bd_shift: i32) {370+ pub(super) fn inv(
371+ _t: X64V3Token,
372+ scaled: &[i32],
373+ residual: &mut [i32],
374+ n: usize,
375+ bd_shift: i32,
376+ ) {
370 match n {377 match n {
371 8 => inverse_2d::<64, 128>(scaled, residual, n, false, bd_shift),378 8 => inverse_2d::<64, 128>(scaled, residual, n, false, bd_shift),
372 16 => inverse_2d::<256, 512>(scaled, residual, n, false, bd_shift),379 16 => inverse_2d::<256, 512>(scaled, residual, n, false, bd_shift),
@@ -411,13 +418,19 @@ mod x86 {
411 _mm_set1_epi32418 _mm_set1_epi32
412 );419 );
413 420
414- #[target_feature(enable = "avx2")]421+ #[arcane]
415- pub(super) fn fwd(residual: &[i32], coeffs: &mut [i32], dst: bool) {422+ pub(super) fn fwd(_t: X64V3Token, residual: &[i32], coeffs: &mut [i32], dst: bool) {
416 forward_2d::<16, 48>(residual, coeffs, 4, dst)423 forward_2d::<16, 48>(residual, coeffs, 4, dst)
417 }424 }
418 425
419- #[target_feature(enable = "avx2")]426+ #[arcane]
420- pub(super) fn inv(scaled: &[i32], residual: &mut [i32], dst: bool, bd_shift: i32) {427+ pub(super) fn inv(
428+ _t: X64V3Token,
429+ scaled: &[i32],
430+ residual: &mut [i32],
431+ dst: bool,
432+ bd_shift: i32,
433+ ) {
421 inverse_2d::<16, 32>(scaled, residual, 4, dst, bd_shift)434 inverse_2d::<16, 32>(scaled, residual, 4, dst, bd_shift)
422 }435 }
423 }436 }
@@ -434,14 +447,17 @@ mod x86 {
434 assert!(residual.len() >= n * n && coeffs.len() >= n * n && matches!(n, 4 | 8 | 16 | 32));447 assert!(residual.len() >= n * n && coeffs.len() >= n * n && matches!(n, 4 | 8 | 16 | 32));
435 assert!(!dst || n == 4);448 assert!(!dst || n == 4);
436 match_target! {449 match_target! {
437- "x86_64+avx2" => {450+ "x86_64+avx2" => match X64V3Token::summon() {
438- if n == 4 {451+ Some(t) => {
439- v128::fwd(residual, coeffs, dst)452+ if n == 4 {
440- } else {453+ v128::fwd(t, residual, coeffs, dst)
441- v256::fwd(residual, coeffs, n)454+ } else {
455+ v256::fwd(t, residual, coeffs, n)
456+ }
457+ true
442 }458 }
443- true459+ None => false,
444- }460+ },
445 _ => false461 _ => false
446 }462 }
447 }463 }
@@ -459,14 +475,17 @@ mod x86 {
459 assert!(scaled.len() >= n * n && residual.len() >= n * n && matches!(n, 4 | 8 | 16 | 32));475 assert!(scaled.len() >= n * n && residual.len() >= n * n && matches!(n, 4 | 8 | 16 | 32));
460 assert!(!dst || n == 4);476 assert!(!dst || n == 4);
461 match_target! {477 match_target! {
462- "x86_64+avx2" => {478+ "x86_64+avx2" => match X64V3Token::summon() {
463- if n == 4 {479+ Some(t) => {
464- v128::inv(scaled, residual, dst, bd_shift)480+ if n == 4 {
465- } else {481+ v128::inv(t, scaled, residual, dst, bd_shift)
466- v256::inv(scaled, residual, n, bd_shift)482+ } else {
483+ v256::inv(t, scaled, residual, n, bd_shift)
484+ }
485+ true
467 }486 }
468- true487+ None => false,
469- }488+ },
470 _ => {489 _ => {
471 let _ = bd_shift;490 let _ = bd_shift;
472 false491 false
@@ -474,8 +493,9 @@ mod x86 {
474 }493 }
475 }494 }
476 495
477- #[target_feature(enable = "avx2")]496+ #[arcane]
478 fn quantize_inner(497 fn quantize_inner(
498+ _t: X64V3Token,
479 coeffs: &[i32],499 coeffs: &[i32],
480 levels: &mut [i32],500 levels: &mut [i32],
481 count: usize,501 count: usize,
@@ -524,7 +544,8 @@ mod x86 {
524 assert!(count.is_multiple_of(8) && coeffs.len() >= count && levels.len() >= count);544 assert!(count.is_multiple_of(8) && coeffs.len() >= count && levels.len() >= count);
525 assert!((0..32).contains(&qbits));545 assert!((0..32).contains(&qbits));
526 match_target! {546 match_target! {
527- "x86_64+avx2" => Some(quantize_inner(coeffs, levels, count, scale, offset, qbits)),547+ "x86_64+avx2" => X64V3Token::summon()
548+ .map(|t| quantize_inner(t, coeffs, levels, count, scale, offset, qbits)),
528 _ => {549 _ => {
529 let _ = (scale, offset);550 let _ = (scale, offset);
530 None551 None
@@ -532,8 +553,9 @@ mod x86 {
532 }553 }
533 }554 }
534 555
535- #[target_feature(enable = "avx2")]556+ #[arcane]
536 fn dequant_inner(557 fn dequant_inner(
558+ _t: X64V3Token,
537 levels: &[i32],559 levels: &[i32],
538 scaled: &mut [i32],560 scaled: &mut [i32],
539 count: usize,561 count: usize,
@@ -594,10 +616,13 @@ mod x86 {
594 }616 }
595 assert!(scaled.len() >= count);617 assert!(scaled.len() >= count);
596 match_target! {618 match_target! {
597- "x86_64+avx2" => {619+ "x86_64+avx2" => match X64V3Token::summon() {
598- dequant_inner(levels, scaled, count, mul as i32, round as i32, bd_shift);620+ Some(t) => {
599- true621+ dequant_inner(t, levels, scaled, count, mul as i32, round as i32, bd_shift);
600- }622+ true
623+ }
624+ None => false,
625+ },
601 _ => false626 _ => false
602 }627 }
603 }628 }
crates/ec-vp8/Cargo.tomlmodified+1 -0
@@ -7,6 +7,7 @@ license.workspace = true
7 authors.workspace = true7 authors.workspace = true
8 8
9 [dependencies]9 [dependencies]
10+archmage = "=0.9.31-beta.1"
10 bytemuck = "1"11 bytemuck = "1"
11 ec-core.workspace = true12 ec-core.workspace = true
12 multiversion = "0.9"13 multiversion = "0.9"
crates/ec-vp8/src/lib.rsmodified+2 -2
@@ -9,8 +9,8 @@
9 //!9 //!
10 //! # Safety10 //! # Safety
11 //!11 //!
12-//! Every SIMD kernel is a safe `#[target_feature]` function, dispatched at12+//! Every SIMD kernel is a safe `#[arcane]` function taking a `X64V3Token`
13-//! runtime by `multiversion`; the crate-level `forbid` below keeps it so.13+//! proof of AVX2, obtained at runtime; the crate-level `forbid` below keeps it so.
14 14
15 #![forbid(unsafe_code)]15 #![forbid(unsafe_code)]
16 #![warn(missing_docs)]16 #![warn(missing_docs)]
crates/ec-vp8/src/mc.rsmodified+26 -16
@@ -21,6 +21,7 @@
21 //! are reproduced exactly (`i32 >> 3` and `& 7` on negatives).21 //! are reproduced exactly (`i32 >> 3` and `& 7` on negatives).
22 //!22 //!
23 //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc638623 //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc6386
24+use archmage::SimdToken;
24 use multiversion::target::match_target;25 use multiversion::target::match_target;
25 26
26 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.27 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.
@@ -212,10 +213,12 @@ fn sixtap_2d(
212 213
213 match_target! {214 match_target! {
214 "x86_64+avx2" => {215 "x86_64+avx2" => {
215- if (sy + rows - 2) * stride + sx + 19 <= src.len() {216+ if let Some(t) = archmage::X64V3Token::summon() {
216- simd::sixtap_h(src, stride, sx, sy, hf, &mut tmp, rows);217+ if (sy + rows - 2) * stride + sx + 19 <= src.len() {
217- simd::sixtap_v(&tmp, vf, dst, dst_stride, bw, bh);218+ simd::sixtap_h(t, src, stride, sx, sy, hf, &mut tmp, rows);
218- return;219+ simd::sixtap_v(t, &tmp, vf, dst, dst_stride, bw, bh);
220+ return;
221+ }
219 }222 }
220 }223 }
221 _ => {}224 _ => {}
@@ -292,10 +295,10 @@ fn sixtap_v_scalar(
292 /// worst-case input bytes.295 /// worst-case input bytes.
293 ///296 ///
294 /// The kernels are safe functions. Their only precondition is AVX2, which297 /// The kernels are safe functions. Their only precondition is AVX2, which
295-/// the `#[target_feature]` attribute states; they can be called only from a298+/// the `X64V3Token` argument proves; the token comes only from `summon()`,
296-/// context that has AVX2 enabled, which is what [`sixtap_2d`] and299+/// which checks the CPU at runtime, so [`sixtap_2d`] and [`bilinear_2d`]
297-/// [`bilinear_2d`] guarantee by dispatching at runtime. Loads and stores go300+/// pass it only when AVX2 is present. Loads and stores go through `bytemuck`
298-/// through `bytemuck` on slices, so every access is bounds-checked.301+/// on slices, so every access is bounds-checked.
299 ///302 ///
300 /// Exactness notes shared by the six-tap kernels:303 /// Exactness notes shared by the six-tap kernels:
301 /// - `_mm*_madd_epi16` multiplies *pairs of samples* by a packed tap pair304 /// - `_mm*_madd_epi16` multiplies *pairs of samples* by a packed tap pair
@@ -312,6 +315,7 @@ fn sixtap_v_scalar(
312 #[cfg(target_arch = "x86_64")]315 #[cfg(target_arch = "x86_64")]
313 mod simd {316 mod simd {
314 use super::{VP8_FILTER_SHIFT, VP8_FILTER_WEIGHT};317 use super::{VP8_FILTER_SHIFT, VP8_FILTER_WEIGHT};
318+ use archmage::{X64V3Token, arcane};
315 use std::arch::x86_64::*;319 use std::arch::x86_64::*;
316 320
317 /// Tap pair `[t0, t1]` packed into one `i32`, the operand shape321 /// Tap pair `[t0, t1]` packed into one `i32`, the operand shape
@@ -366,8 +370,9 @@ mod simd {
366 /// The caller guarantees that for every `i < rows`, the 21 bytes370 /// The caller guarantees that for every `i < rows`, the 21 bytes
367 /// starting at `(sy + i - 2) * stride + sx - 2` are in `src` (with371 /// starting at `(sy + i - 2) * stride + sx - 2` are in `src` (with
368 /// `sx, sy >= 2`); the slice indexing below enforces it.372 /// `sx, sy >= 2`); the slice indexing below enforces it.
369- #[target_feature(enable = "avx2")]373+ #[arcane]
370 pub(super) fn sixtap_h(374 pub(super) fn sixtap_h(
375+ _t: X64V3Token,
371 src: &[u8],376 src: &[u8],
372 stride: usize,377 stride: usize,
373 sx: usize,378 sx: usize,
@@ -420,8 +425,9 @@ mod simd {
420 /// Six-tap second pass: `bh` output rows of `bw` (4/8/16) samples from425 /// Six-tap second pass: `bh` output rows of `bw` (4/8/16) samples from
421 /// the 16-lane-strided intermediate. `dst` must hold `bh` rows of `bw`426 /// the 16-lane-strided intermediate. `dst` must hold `bh` rows of `bw`
422 /// bytes at `dst_stride` (slice indexing enforces it); `bw` is 4, 8 or 16.427 /// bytes at `dst_stride` (slice indexing enforces it); `bw` is 4, 8 or 16.
423- #[target_feature(enable = "avx2")]428+ #[arcane]
424 pub(super) fn sixtap_v(429 pub(super) fn sixtap_v(
430+ _t: X64V3Token,
425 tmp: &[u8; 21 * 16],431 tmp: &[u8; 21 * 16],
426 vf: &[i32; 6],432 vf: &[i32; 6],
427 dst: &mut [u8],433 dst: &mut [u8],
@@ -479,8 +485,9 @@ mod simd {
479 /// The caller guarantees that for every `i < rows`, the 17 bytes485 /// The caller guarantees that for every `i < rows`, the 17 bytes
480 /// starting at `(sy + i) * stride + sx` are in `src`; the slice486 /// starting at `(sy + i) * stride + sx` are in `src`; the slice
481 /// indexing below enforces it.487 /// indexing below enforces it.
482- #[target_feature(enable = "avx2")]488+ #[arcane]
483 pub(super) fn bilinear_h(489 pub(super) fn bilinear_h(
490+ _t: X64V3Token,
484 src: &[u8],491 src: &[u8],
485 stride: usize,492 stride: usize,
486 sx: usize,493 sx: usize,
@@ -513,8 +520,9 @@ mod simd {
513 /// exact-`i16` shape as [`bilinear_h`]. `dst` must hold `bh` rows of520 /// exact-`i16` shape as [`bilinear_h`]. `dst` must hold `bh` rows of
514 /// `bw` bytes at `dst_stride` (slice indexing enforces it); `bw` is521 /// `bw` bytes at `dst_stride` (slice indexing enforces it); `bw` is
515 /// 4, 8 or 16.522 /// 4, 8 or 16.
516- #[target_feature(enable = "avx2")]523+ #[arcane]
517 pub(super) fn bilinear_v(524 pub(super) fn bilinear_v(
525+ _t: X64V3Token,
518 tmp: &[u8; 17 * 16],526 tmp: &[u8; 17 * 16],
519 vf: &[i32; 2],527 vf: &[i32; 2],
520 dst: &mut [u8],528 dst: &mut [u8],
@@ -601,10 +609,12 @@ fn bilinear_2d(
601 609
602 match_target! {610 match_target! {
603 "x86_64+avx2" => {611 "x86_64+avx2" => {
604- if (sy + rows - 1) * stride + sx + 16 < src.len() {612+ if let Some(t) = archmage::X64V3Token::summon() {
605- simd::bilinear_h(src, stride, sx, sy, hf, &mut tmp, rows);613+ if (sy + rows - 1) * stride + sx + 16 < src.len() {
606- simd::bilinear_v(&tmp, vf, dst, dst_stride, bw, bh);614+ simd::bilinear_h(t, src, stride, sx, sy, hf, &mut tmp, rows);
607- return;615+ simd::bilinear_v(t, &tmp, vf, dst, dst_stride, bw, bh);
616+ return;
617+ }
608 }618 }
609 }619 }
610 _ => {}620 _ => {}