forge
Explore
Log in

Don't you dare go Hollow

Settle an all-zero transform block before the scan-order search

Browse files at this commit

c3d93a7072e80ad87f099738ac0ec37d0bbd31a7Ahmet Kaan GümüşParent: 02bd8ae
  • perf
    • settle an all-zero transform block before the scan-order search
Show full message
perf(av1): settle an all-zero transform block before the scan-order search

Finding the end of block walks the scan backwards through one dependent
grid load per position, so an all-zero block pays the whole scan -- once
per priced candidate. A straight-line all-zero test runs first: it
vectorises, and a block that codes anything at all almost always codes its
DC, so the test stops at the first element. Byte-exact on all twelve ladder
points; 1080p ladder -0.41% instructions:u (110.14G -> 109.69G, ABAB x2).
crates/ec-av1/src/tile.rsmodified+13 -4
@@ -2266,10 +2266,19 @@ fn write_coeffs(
22662266 ec_rng_trace(|| format!("EC_PLANE plane={plane} tell_before={}", enc.tell()));
22672267 }
22682268 let side = coding.side;
2269- let eob = scan
2270- .iter()
2271- .rposition(|&pos| grid[pos as usize] != 0)
2272- .map_or(0, |i| i + 1);
2269+ // The scan-order search reads the grid in scan order, one dependent load
2270+ // per position, and an all-zero block makes it walk every one of them --
2271+ // which the pricer does for candidate after candidate. A straight-line
2272+ // pass settles that case first: it vectorises, and a block that codes
2273+ // anything at all almost always codes its DC, so it stops at the first
2274+ // element.
2275+ let eob = if grid.iter().all(|&level| level == 0) {
2276+ 0
2277+ } else {
2278+ scan.iter()
2279+ .rposition(|&pos| grid[pos as usize] != 0)
2280+ .map_or(0, |i| i + 1)
2281+ };
22732282 enc.symbol(usize::from(eob == 0), &mut coding.txb_skip[skip_ctx]);
22742283 if plane.is_some() {
22752284 ec_rng_trace(|| {