forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-tx2' (c084630a): explicit AVX2 Lane impl for the inverse-DCT column pass (exact i64 products, full-range equivalence test; target_feature on the leaf methods), all-zero transform units carry an empty residual marker instead of allocating and cloning zero grids; byte-exact, -4.0% instructions on the 4K segment

Browse files at this commit

140e66269d036e4f21fa9c5ced67bd5e9e1ae46eAhmet Kaan GümüşParent: e27b2d5b848139
crates/ec-av1/src/decode.rsmodified+33 -3
@@ -2088,6 +2088,11 @@ impl TxParams {
20882088 grid, self.w, self.h, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta,
20892089 self.tx_type,
20902090 );
2091+ // An all-zero grid transforms to the empty marker, and a strided copy
2092+ // of zeros is still zeros: the marker passes straight through.
2093+ if residual.is_empty() {
2094+ return residual;
2095+ }
20912096 if self.stride == 0 {
20922097 return residual;
20932098 }
@@ -2108,6 +2113,16 @@ pub(crate) enum Residual {
21082113 }
21092114
21102115 impl Residual {
2116+ /// The record for a transform unit whose coefficient grid is all zero:
2117+ /// the empty marker, so neither the grid nor the residual is cloned and
2118+ /// the worker never runs the transform (60% of the 4K segment's units).
2119+ fn coeffs(tx: TxParams, grid: &[i32]) -> Self {
2120+ if grid.iter().all(|&c| c == 0) {
2121+ return Self::Done(Vec::new());
2122+ }
2123+ Self::Coeffs(tx, grid.to_vec())
2124+ }
2125+
21112126 fn resolve(self) -> Vec<i32> {
21122127 match self {
21132128 Self::Done(v) => v,
@@ -2116,6 +2131,18 @@ impl Residual {
21162131 }
21172132 }
21182133
2134+/// An all-zero residual, for the transform units that code no coefficient:
2135+/// [`crate::transform::dequant_and_inverse_typed_wh`] returns those EMPTY,
2136+/// and the reconstruction loops below read this instead of a per-unit
2137+/// `vec![0; w * h]`. Sized for the largest stride a recorded unit can carry
2138+/// (a 128-wide inter block's prediction stride).
2139+static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128];
2140+
2141+/// `residual`, or `n` zeros when it is the empty all-zero marker.
2142+fn dense_residual(residual: &[i32], n: usize) -> &[i32] {
2143+ if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual }
2144+}
2145+
21192146 /// Where a recorded motion-compensated write reads its prediction from.
21202147 ///
21212148 /// lane-wave4: a block's whole-block prediction (mc + warp + interintra) is
@@ -2846,7 +2873,7 @@ fn push_intra_tx(
28462873 let pred = take_palette_pred(fctx);
28472874 push_op(fctx, ReconOp::Intra {
28482875 plane, x, y, bw, bh, rect, mode, angle_delta, reach,
2849- residual: Residual::Coeffs(tx, grid.to_vec()), cfl, filter_intra, smooth_neighbor, pred,
2876+ residual: Residual::coeffs(tx, grid), cfl, filter_intra, smooth_neighbor, pred,
28502877 });
28512878 }
28522879
@@ -2877,7 +2904,7 @@ fn push_mc_rect_tx(
28772904 push_op(fctx, ReconOp::Mc {
28782905 plane, x, y, stride: w, w, h,
28792906 prediction: PredSrc::Cur { plane: sp, off, src: ss },
2880- residual: Residual::Coeffs(tx, grid.to_vec()),
2907+ residual: Residual::coeffs(tx, grid),
28812908 });
28822909 return;
28832910 }
@@ -2918,7 +2945,7 @@ fn push_mc_rect_tx(
29182945 tx.stride = 0;
29192946 push_op(fctx, ReconOp::Mc {
29202947 plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(window),
2921- residual: Residual::Coeffs(tx, grid.to_vec()),
2948+ residual: Residual::coeffs(tx, grid),
29222949 });
29232950 }
29242951
@@ -12808,6 +12835,7 @@ impl PlaneBuf<'_> {
1280812835 "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), i32::from(smooth_neighbor)
1280912836 );
1281012837 }
12838+ let residual = dense_residual(residual, bw * bh);
1281112839 for row in 0..bh {
1281212840 // Same bottom/right frame-edge clip as [`Self::reconstruct`]'s
1281312841 // (lane-sb128c r8) -- a 64x128 block at the right edge of a frame
@@ -12914,6 +12942,7 @@ impl PlaneBuf<'_> {
1291412942 "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), i32::from(smooth_neighbor)
1291512943 );
1291612944 }
12945+ let residual = dense_residual(residual, side * side);
1291712946 for row in 0..side {
1291812947 // lane-sb128c r8: libaom's frame buffer is superblock
1291912948 // aligned; ours is padded to 32 (`block_grid`), so a 64x64
@@ -21888,6 +21917,7 @@ impl PlaneBuf<'_> {
2188821917 // three row bases are computed once per row instead of a
2188921918 // multiply-add per sample (the samples themselves are unchanged).
2189021919 let max = crate::decode::sample_max(fctx);
21920+ let residual = dense_residual(residual, side * h);
2189121921 for row in 0..h {
2189221922 let src = row * side;
2189321923 let dst = (y + row) * self.width + x;
crates/ec-av1/src/transform.rsmodified+262 -22
@@ -111,13 +111,26 @@ fn clamp_range(x: i32, r: usize) -> i32 {
111111 /// output share the whole network). The two impls are elementwise-identical
112112 /// integer arithmetic, so the eight-wide pass is byte-exact with the scalar
113113 /// one by construction -- the network itself is written once, above.
114+// `unsafe fn` only so the AVX2 impl can carry `#[target_feature]` (rustc
115+// rejects it on a SAFE trait method); the two scalar impls below require
116+// nothing of their caller.
117+#[allow(unsafe_code)]
114118 trait Lane: Copy {
115- /// The additive identity, for [`permute`]'s scratch.
116- const ZERO: Self;
117119 /// One butterfly rotation's two outputs, at pre-multiplied `cos`/`sin`.
118- fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self);
120+ ///
121+ /// # Safety
122+ /// An impl may require CPU features: `M256`'s is `#[target_feature]` AVX2,
123+ /// which is the only way its intrinsics compile INLINE -- as plain safe
124+ /// methods every `_mm256_*` stayed an out-of-line call (13% of the 4K
125+ /// segment's profile). `M256` values exist only inside
126+ /// [`simd::column_pass_dct`], which its caller has feature-detected; the
127+ /// scalar impls require nothing.
128+ unsafe fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self);
119129 /// One Hadamard rotation's two outputs, clamped to `r` bits.
120- fn had(a: Self, b: Self, r: usize) -> (Self, Self);
130+ ///
131+ /// # Safety
132+ /// As [`Lane::btf`].
133+ unsafe fn had(a: Self, b: Self, r: usize) -> (Self, Self);
121134 }
122135
123136 /// `Round2(x, COS_BITS)` on a butterfly's 64-bit product sum.
@@ -125,25 +138,23 @@ fn round_cos(x: i64) -> i32 {
125138 ((x + (1 << (COS_BITS - 1))) >> COS_BITS) as i32
126139 }
127140
141+#[allow(unsafe_code)]
128142 impl Lane for i32 {
129- const ZERO: Self = 0;
130-
131- fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self) {
143+ unsafe fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self) {
132144 let (ta, tb) = (i64::from(a), i64::from(b));
133145 (round_cos(ta * c - tb * s), round_cos(ta * s + tb * c))
134146 }
135147
136- fn had(a: Self, b: Self, r: usize) -> (Self, Self) {
148+ unsafe fn had(a: Self, b: Self, r: usize) -> (Self, Self) {
137149 (clamp_range(a.wrapping_add(b), r), clamp_range(a.wrapping_sub(b), r))
138150 }
139151 }
140152
141153 /// Eight columns at once. Every operation is the [`i32`] impl's, lane by lane,
142154 /// which is what the optimiser turns into one vector op per line.
155+#[allow(unsafe_code)]
143156 impl Lane for [i32; 8] {
144- const ZERO: Self = [0; 8];
145-
146- fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self) {
157+ unsafe fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self) {
147158 let mut x = [0i32; 8];
148159 let mut y = [0i32; 8];
149160 for l in 0..8 {
@@ -154,7 +165,7 @@ impl Lane for [i32; 8] {
154165 (x, y)
155166 }
156167
157- fn had(a: Self, b: Self, r: usize) -> (Self, Self) {
168+ unsafe fn had(a: Self, b: Self, r: usize) -> (Self, Self) {
158169 let mut x = [0i32; 8];
159170 let mut y = [0i32; 8];
160171 for l in 0..8 {
@@ -165,11 +176,145 @@ impl Lane for [i32; 8] {
165176 }
166177 }
167178
179+/// The same eight-wide column pass in explicit AVX2. Every operation below is
180+/// the [`i32`] impl's arithmetic, lane for lane, in 64-bit products -- so it is
181+/// byte-exact with the scalar network on every input, not only on conformant
182+/// ones (`the_avx2_dct_matches_the_scalar_one_over_the_full_range`).
183+#[cfg(target_arch = "x86_64")]
184+#[allow(unsafe_code)]
185+mod simd {
186+ use super::{COS_BITS, Lane, inverse_dct_n};
187+ use std::arch::x86_64::*;
188+
189+ /// Eight `i32` lanes in one AVX2 register.
190+ #[derive(Clone, Copy)]
191+ pub(super) struct M256(pub(super) __m256i);
192+
193+ impl Lane for M256 {
194+ /// `round_cos(a*c - b*s)`, `round_cos(a*s + b*c)`.
195+ ///
196+ /// `_mm256_mul_epi32` multiplies the sign-extended low `i32` of each
197+ /// 64-bit lane, so the four even lanes go through directly and the four
198+ /// odd ones after a shuffle; the products and their sum are exact in 64
199+ /// bits (`|a| < 2^31`, `|c| <= 2^12`), and only the low 32 bits of the
200+ /// shifted sum are kept -- which is what the scalar `as i32` keeps, so
201+ /// the logical shift below stands in for the arithmetic one exactly.
202+ #[target_feature(enable = "avx2")]
203+ unsafe fn btf(a: Self, b: Self, c: i64, s: i64) -> (Self, Self) {
204+ let cv = _mm256_set1_epi32(c as i32);
205+ let sv = _mm256_set1_epi32(s as i32);
206+ let rnd = _mm256_set1_epi64x(1 << (COS_BITS - 1));
207+ let (ae, be) = (a.0, b.0);
208+ let (ao, bo) = (_mm256_shuffle_epi32(a.0, 0xB1), _mm256_shuffle_epi32(b.0, 0xB1));
209+ let half = |x: __m256i, y: __m256i, u: __m256i, v: __m256i| {
210+ let p = _mm256_sub_epi64(_mm256_mul_epi32(x, u), _mm256_mul_epi32(y, v));
211+ let q = _mm256_add_epi64(_mm256_mul_epi32(x, v), _mm256_mul_epi32(y, u));
212+ (
213+ _mm256_srli_epi64::<{ COS_BITS as i32 }>(_mm256_add_epi64(p, rnd)),
214+ _mm256_srli_epi64::<{ COS_BITS as i32 }>(_mm256_add_epi64(q, rnd)),
215+ )
216+ };
217+ let (xe, ye) = half(ae, be, cv, sv);
218+ let (xo, yo) = half(ao, bo, cv, sv);
219+ (
220+ M256(_mm256_blend_epi32::<0xAA>(xe, _mm256_slli_epi64::<32>(xo))),
221+ M256(_mm256_blend_epi32::<0xAA>(ye, _mm256_slli_epi64::<32>(yo))),
222+ )
223+ }
224+
225+ #[target_feature(enable = "avx2")]
226+ unsafe fn had(a: Self, b: Self, r: usize) -> (Self, Self) {
227+ let hi = _mm256_set1_epi32(((1i64 << (r - 1)) - 1) as i32);
228+ let lo = _mm256_set1_epi32((-(1i64 << (r - 1))) as i32);
229+ let clamp = |v| _mm256_min_epi32(_mm256_max_epi32(v, lo), hi);
230+ (
231+ M256(clamp(_mm256_add_epi32(a.0, b.0))),
232+ M256(clamp(_mm256_sub_epi32(a.0, b.0))),
233+ )
234+ }
235+ }
236+
237+ /// [`super::inverse_dct_fixed`] over eight AVX2 lanes -- the network the
238+ /// column pass below runs, reachable on its own for the equivalence gate.
239+ ///
240+ /// # Safety
241+ /// The caller has checked for AVX2 ([`crate::mc::simd_level`]).
242+ #[target_feature(enable = "avx2")]
243+ pub(super) unsafe fn dct_x8_avx2(t: &mut [M256; 64], n: u32, r: usize) {
244+ match n {
245+ 2 => inverse_dct_n::<M256, 2>(t, r),
246+ 3 => inverse_dct_n::<M256, 3>(t, r),
247+ 4 => inverse_dct_n::<M256, 4>(t, r),
248+ 5 => inverse_dct_n::<M256, 5>(t, r),
249+ 6 => inverse_dct_n::<M256, 6>(t, r),
250+ _ => unreachable!("the inverse DCT is defined for 4..64"),
251+ }
252+ }
253+
254+ /// The whole DCT column pass of one transform unit: `residual` is the
255+ /// row-pass output (`h` rows of `w`), `out` the residual it writes.
256+ ///
257+ /// # Safety
258+ /// The caller has checked for AVX2 ([`crate::mc::simd_level`]).
259+ #[target_feature(enable = "avx2")]
260+ pub(super) unsafe fn column_pass_dct(
261+ residual: &[i32],
262+ out: &mut [i32],
263+ w: usize,
264+ h: usize,
265+ log2h: u32,
266+ r: usize,
267+ ud_flip: bool,
268+ ) {
269+ let mut t = [M256(_mm256_setzero_si256()); 64];
270+ for j in (0..w).step_by(8) {
271+ let mut any = _mm256_setzero_si256();
272+ for i in 0..h {
273+ let v = unsafe { _mm256_loadu_si256(residual[i * w + j..].as_ptr().cast()) };
274+ t[i] = M256(v);
275+ any = _mm256_or_si256(any, v);
276+ }
277+ // Zero in, zero out -- and `out` is already zero here.
278+ if _mm256_testz_si256(any, any) == 1 {
279+ continue;
280+ }
281+ // SAFETY: this function's own AVX2 contract.
282+ unsafe { dct_x8_avx2(&mut t, log2h, r) };
283+ // `round2(v, 4)` on eight lanes: the shift is arithmetic here
284+ // because the value stays in its own 32-bit lane.
285+ let rnd = _mm256_set1_epi32(8);
286+ for i in 0..h {
287+ let dst_row = if ud_flip { h - 1 - i } else { i };
288+ let v = _mm256_srai_epi32::<4>(_mm256_add_epi32(t[i].0, rnd));
289+ unsafe { _mm256_storeu_si256(out[dst_row * w + j..].as_mut_ptr().cast(), v) };
290+ }
291+ }
292+ }
293+
294+ /// The eight scalar lanes of `v`, for the equivalence gate.
295+ #[cfg(test)]
296+ pub(super) fn lanes(v: M256) -> [i32; 8] {
297+ let mut o = [0i32; 8];
298+ unsafe { _mm256_storeu_si256(o.as_mut_ptr().cast(), v.0) };
299+ o
300+ }
301+
302+ /// `M256` from eight lanes, for the equivalence gate.
303+ #[cfg(test)]
304+ pub(super) fn splat(v: [i32; 8]) -> M256 {
305+ unsafe { M256(_mm256_loadu_si256(v.as_ptr().cast())) }
306+ }
307+}
308+
168309 /// `B(a, b, angle, flip, r)` (spec 7.13.2.1): a butterfly rotation, and an
169310 /// exchange of the two entries when `flip` is set.
311+#[inline(always)]
170312 fn butterfly<T: Lane>(t: &mut [T; 64], a: usize, b: usize, angle: i32, flip: bool, _r: usize) {
171313 let (c, s) = (i64::from(cos128(angle)), i64::from(sin128(angle)));
172- let (x, y) = T::btf(t[a], t[b], c, s);
314+ // SAFETY: [`Lane::btf`] -- an `M256` reaches here only from the
315+ // feature-detected [`simd::column_pass_dct`].
316+ #[allow(unsafe_code)]
317+ let (x, y) = unsafe { T::btf(t[a], t[b], c, s) };
173318 t[a] = x;
174319 t[b] = y;
175320 if flip {
@@ -179,24 +324,30 @@ fn butterfly<T: Lane>(t: &mut [T; 64], a: usize, b: usize, angle: i32, flip: boo
179324
180325 /// `H(a, b, flip, r)` (spec 7.13.2.1): a Hadamard rotation, with the indices
181326 /// exchanged when `flip` is set.
327+#[inline(always)]
182328 fn hadamard<T: Lane>(t: &mut [T; 64], a: usize, b: usize, flip: bool, r: usize) {
183329 let (a, b) = if flip { (b, a) } else { (a, b) };
184- let (x, y) = T::had(t[a], t[b], r);
330+ // SAFETY: as [`butterfly`]'s.
331+ #[allow(unsafe_code)]
332+ let (x, y) = unsafe { T::had(t[a], t[b], r) };
185333 t[a] = x;
186334 t[b] = y;
187335 }
188336
189337 /// The inverse DCT array permutation (spec 7.13.2.2): an in-place bit-reversal
190338 /// of the first `1 << n` entries.
339+#[inline(always)]
191340 fn permute<T: Lane>(t: &mut [T; 64], n: u32) {
192341 let n0 = 1usize << n;
193- // A stack copy: this ran once per 1D transform and its `Vec` was the
194- // `malloc` at the top of every `inverse_dct` frame in the annotation.
195- let mut copy = [T::ZERO; 64];
196- copy[..n0].copy_from_slice(&t[..n0]);
342+ // In place: a bit reversal is an involution, so swapping every `i` with
343+ // `brev(i) > i` visits each transposed pair once. The scratch copy this
344+ // replaces was a `[T; 64]` fill -- 2 KB per call at `T = M256`.
197345 let tab = &BREV_TAB[n as usize];
198- for (i, v) in t[..n0].iter_mut().enumerate() {
199- *v = copy[tab[i] as usize];
346+ for i in 0..n0 {
347+ let j = tab[i] as usize;
348+ if j > i {
349+ t.swap(i, j);
350+ }
200351 }
201352 }
202353
@@ -247,6 +398,11 @@ fn inverse_dct_x8(t: &mut [[i32; 8]; 64], n: u32, r: usize) {
247398 }
248399
249400 /// [`inverse_dct_fixed`] at one fixed `N = log2(size)`.
401+// `#[inline(always)]`: the AVX2 instantiation has to land INSIDE the
402+// `target_feature` wrapper, or every `_mm256_*` in it stays an out-of-line
403+// call (measured: +5.6% instructions on the 4K segment). Every other
404+// instantiation has exactly one caller, so this costs no extra copy.
405+#[inline(always)]
250406 fn inverse_dct_n<T: Lane, const N: u32>(t: &mut [T; 64], r: usize) {
251407 permute(t, N);
252408
@@ -1063,6 +1219,15 @@ pub fn inverse_transform_2d_typed_wh(
10631219 // eight scalar ones. `lr_flip` reads the columns right-to-left, which
10641220 // is not a contiguous chunk, so it stays on the scalar path below.
10651221 if col_kind == TxType1d::Dct && w >= 8 && !lr_flip {
1222+ #[cfg(target_arch = "x86_64")]
1223+ if matches!(crate::mc::simd_level(), crate::mc::SimdLevel::Avx2) {
1224+ // SAFETY: the branch above is the AVX2 feature detection.
1225+ #[allow(unsafe_code)]
1226+ unsafe {
1227+ simd::column_pass_dct(residual, &mut out, w, h, log2h, col_clamp, ud_flip);
1228+ }
1229+ return;
1230+ }
10661231 let mut t8 = [[0i32; 8]; 64];
10671232 for j in (0..w).step_by(8) {
10681233 let mut any = 0i32;
@@ -1141,7 +1306,12 @@ pub fn dequant_and_inverse_typed(
11411306 ac_delta: i32,
11421307 tx_type: TxType,
11431308 ) -> Vec<i32> {
1144- dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type)
1309+ let r =
1310+ dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type);
1311+ // This square entry point keeps the dense contract (its callers are the
1312+ // encoder-side model and the gates, which index the result directly);
1313+ // only the decoder's `_wh` path speaks the empty marker.
1314+ if r.is_empty() { vec![0i32; side * side] } else { r }
11451315 }
11461316
11471317 /// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx). `dc_delta`/
@@ -1165,8 +1335,13 @@ pub fn dequant_and_inverse_typed_wh(
11651335 // to a zero residual, which is exactly the buffer below already returns --
11661336 // so one scan of the levels replaces the dequantization, the row pass and
11671337 // the column pass for those.
1338+ // The residual is returned EMPTY in that case, not as `w * h` zeros: an
1339+ // empty residual is this decoder's "all zero" marker (`ZERO_RESIDUAL` in
1340+ // `decode.rs`), which also drops the `vec![0; w * h]` memset here and the
1341+ // `to_vec` clone the recorded [`crate::decode::Residual`] made of it --
1342+ // together 6.5% of the 4K segment's profile (memset + memmove).
11681343 if levels.iter().all(|&l| l == 0) {
1169- return vec![0i32; w * h];
1344+ return Vec::new();
11701345 }
11711346 DQ_SCRATCH.with(|cell| {
11721347 let mut dq = cell.borrow_mut();
@@ -2019,6 +2194,71 @@ mod tests {
20192194 /// The eight-wide column kernel is the scalar network, lane for lane: a
20202195 /// pseudo-random sweep over the full coefficient range at every size and
20212196 /// both clamp widths (`bit_depth` 8 and 10) has to agree bit for bit, or
2197+ /// The AVX2 column pass against the scalar network over the FULL `i32`
2198+ /// range, not only the dequantizer's own bound: the explicit intrinsics
2199+ /// claim exact 64-bit products, so the sweep includes `i32::MIN`/`MAX`,
2200+ /// both clamp boundaries at every `r` the decoder uses, and uniform
2201+ /// full-range noise. A single differing lane at any size would be a
2202+ /// silent pixel drift on whatever stream first reaches it.
2203+ #[cfg(target_arch = "x86_64")]
2204+ #[test]
2205+ fn the_avx2_dct_matches_the_scalar_one_over_the_full_range() {
2206+ if !std::arch::is_x86_feature_detected!("avx2") {
2207+ return;
2208+ }
2209+ let mut state = 0x9E37_79B9_7F4A_7C15u64;
2210+ let mut next = move || {
2211+ state ^= state << 13;
2212+ state ^= state >> 7;
2213+ state ^= state << 17;
2214+ state
2215+ };
2216+ for n in 2..=6u32 {
2217+ for &r in &[16usize, 18, 20] {
2218+ let (hi, lo) = (((1i64 << (r - 1)) - 1) as i32, (-(1i64 << (r - 1))) as i32);
2219+ let edges = [0, 1, -1, hi, lo, hi - 1, lo + 1, i32::MAX, i32::MIN];
2220+ for round in 0..96 {
2221+ let mut wide = [[0i32; 8]; 64];
2222+ let mut cols = [[0i32; 64]; 8];
2223+ for i in 0..(1usize << n) {
2224+ for l in 0..8 {
2225+ let raw = next();
2226+ let v = match round % 3 {
2227+ // every extreme, and every pair of them
2228+ 0 => edges[(raw >> 32) as usize % edges.len()],
2229+ // uniform over the whole 32-bit range
2230+ 1 => raw as i32,
2231+ // the range a conformant stream stays inside
2232+ _ => raw as i32 % (hi / 2 + 1),
2233+ };
2234+ wide[i][l] = v;
2235+ cols[l][i] = v;
2236+ }
2237+ }
2238+ let mut avx = [simd::splat([0i32; 8]); 64];
2239+ for i in 0..(1usize << n) {
2240+ avx[i] = simd::splat(wide[i]);
2241+ }
2242+ // SAFETY: guarded by the feature detection above.
2243+ #[allow(unsafe_code)]
2244+ unsafe {
2245+ simd::dct_x8_avx2(&mut avx, n, r);
2246+ }
2247+ for (l, col) in cols.iter_mut().enumerate() {
2248+ inverse_dct_fixed(col, n, r);
2249+ for i in 0..(1usize << n) {
2250+ assert_eq!(
2251+ simd::lanes(avx[i])[l],
2252+ col[i],
2253+ "avx2 lane {l} of entry {i} at n={n} r={r} round={round}"
2254+ );
2255+ }
2256+ }
2257+ }
2258+ }
2259+ }
2260+ }
2261+
20222262 /// the column pass would drift from the decoder on some block this
20232263 /// crate's gate streams happen not to contain.
20242264 #[test]