From 7086b91b757461c9beae2c7016cd3e760831ee5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 01:51:22 +0300 Subject: [PATCH] perf(av1): broadcast the column transform when the row pass leaves one constant row The dominant inter residual is DC-only: the row pass then writes a single non-zero row that is constant along its length, and the column pass runs the same `inverse_1d` on the same input vector once per column, `w` times over. `inverse_transform_2d_typed_wh` now counts the non-zero rows the row pass produced and whether the first of them is constant. When there is at most one such row, one column transform is run and its output broadcast across each output row -- byte-identical to the `w` transforms it replaces (`inverse_1d` is a pure function of its input), and the per-column gather goes with them. Byte-exact on seg1080/seg4k/seg4k_lr/palette_screen_witness. seg1080 190.19 G instructions (was 193.75 G, -1.84%); seg4k 602.71 G (was 604.37 G, -0.28%). --- crates/ec-av1/src/transform.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index 8cb14750..c836e34d 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -904,6 +904,11 @@ pub fn inverse_transform_2d_typed_wh( } let residual = &mut scratch[..w * h]; let mut t = [0i32; 64]; + // lane-perf10: rows the row pass left non-zero, and whether the first + // of them came out constant along the row -- see the fast path below. + let mut nz_rows = 0usize; + let mut nz_row = 0usize; + let mut const_row = false; for i in 0..h { let dst = &mut residual[i * w..(i + 1) * w]; // Rows at or past 32 carry no coefficients (the spec zeroes them @@ -930,6 +935,26 @@ pub fn inverse_transform_2d_typed_wh( for (d, &v) in dst.iter_mut().zip(t[..w].iter()) { *d = clamp_range(round2(v, shift), col_clamp); } + nz_rows += 1; + nz_row = i; + const_row = nz_rows == 1 && dst.iter().all(|&v| v == dst[0]); + } + + // A block whose row pass left exactly one non-zero row, constant along + // that row, feeds every column of the column pass the same vector -- + // the DC-only case, which dominates inter residuals. `inverse_1d` is a + // pure function of its input, so one column transform broadcast across + // the block is byte-identical to `w` of them, and the per-column gather + // disappears with it. + if nz_rows <= 1 && const_row { + t[..h].fill(0); + t[nz_row] = residual[nz_row * w]; + inverse_1d(&mut t, log2h, col_clamp, col_kind); + for i in 0..h { + let dst_row = if ud_flip { h - 1 - i } else { i }; + out[dst_row * w..dst_row * w + w].fill(round2(t[i], 4)); + } + return; } for j in 0..w {