Broadcast the column transform when the row pass leaves one constant row
Browse files at this commit7086b91b757461c9beae2c7016cd3e760831ee5fParent: c42b240- perf
- broadcast the column transform when the row pass leaves one constant row
1 changed file +25 -0
crates/ec-av1/src/transform.rsmodified+25 -0
| @@ -904,6 +904,11 @@ pub fn inverse_transform_2d_typed_wh( | |||
| 904 | } | 904 | } |
| 905 | let residual = &mut scratch[..w * h]; | 905 | let residual = &mut scratch[..w * h]; |
| 906 | let mut t = [0i32; 64]; | 906 | 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; | ||
| 907 | for i in 0..h { | 912 | for i in 0..h { |
| 908 | let dst = &mut residual[i * w..(i + 1) * w]; | 913 | let dst = &mut residual[i * w..(i + 1) * w]; |
| 909 | // Rows at or past 32 carry no coefficients (the spec zeroes them | 914 | // Rows at or past 32 carry no coefficients (the spec zeroes them |
| @@ -930,6 +935,26 @@ pub fn inverse_transform_2d_typed_wh( | |||
| 930 | for (d, &v) in dst.iter_mut().zip(t[..w].iter()) { | 935 | for (d, &v) in dst.iter_mut().zip(t[..w].iter()) { |
| 931 | *d = clamp_range(round2(v, shift), col_clamp); | 936 | *d = clamp_range(round2(v, shift), col_clamp); |
| 932 | } | 937 | } |
| 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; | ||
| 933 | } | 958 | } |
| 934 | 959 | ||
| 935 | for j in 0..w { | 960 | for j in 0..w { |