forge
Explore
Log in

Don't you dare go Hollow

Broadcast the column transform when the row pass leaves one constant row

Browse files at this commit

7086b91b757461c9beae2c7016cd3e760831ee5fAhmet Kaan GümüşParent: c42b240
  • perf
    • broadcast the column transform when the row pass leaves one constant row
Show full message
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.rsmodified+25 -0
@@ -904,6 +904,11 @@ pub fn inverse_transform_2d_typed_wh(
904904 }
905905 let residual = &mut scratch[..w * h];
906906 let mut t = [0i32; 64];
907+ // lane-perf10: rows the row pass left non-zero, and whether the first
908+ // of them came out constant along the row -- see the fast path below.
909+ let mut nz_rows = 0usize;
910+ let mut nz_row = 0usize;
911+ let mut const_row = false;
907912 for i in 0..h {
908913 let dst = &mut residual[i * w..(i + 1) * w];
909914 // Rows at or past 32 carry no coefficients (the spec zeroes them
@@ -930,6 +935,26 @@ pub fn inverse_transform_2d_typed_wh(
930935 for (d, &v) in dst.iter_mut().zip(t[..w].iter()) {
931936 *d = clamp_range(round2(v, shift), col_clamp);
932937 }
938+ nz_rows += 1;
939+ nz_row = i;
940+ const_row = nz_rows == 1 && dst.iter().all(|&v| v == dst[0]);
941+ }
942+
943+ // A block whose row pass left exactly one non-zero row, constant along
944+ // that row, feeds every column of the column pass the same vector --
945+ // the DC-only case, which dominates inter residuals. `inverse_1d` is a
946+ // pure function of its input, so one column transform broadcast across
947+ // the block is byte-identical to `w` of them, and the per-column gather
948+ // disappears with it.
949+ if nz_rows <= 1 && const_row {
950+ t[..h].fill(0);
951+ t[nz_row] = residual[nz_row * w];
952+ inverse_1d(&mut t, log2h, col_clamp, col_kind);
953+ for i in 0..h {
954+ let dst_row = if ud_flip { h - 1 - i } else { i };
955+ out[dst_row * w..dst_row * w + w].fill(round2(t[i], 4));
956+ }
957+ return;
933958 }
934959
935960 for j in 0..w {