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