From c5b674a94b8b3a1684d2cd0d052ed8c96cf53a2d 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 13:39:12 +0300 Subject: [PATCH] perf(av1): an all-zero inter residual reconstructs as a prediction copy `reconstruct_mc_rect` expanded the empty all-zero marker into a `side * h` slice of the 64 KB `ZERO_RESIDUAL` static and added those zeros sample by sample -- for 60% of the units. The zero case now runs the same clamp without the residual operand (identical arithmetic at `r == 0`; the prediction->plane copy the charter names is kept). instructions:u on the 4K segment: 453.00 G -> 450.45 G at (16, 4, 2) threads, 444.33 G -> 441.90 G at one thread. --- crates/ec-av1/src/decode.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index db321403..9e57261c 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -22226,6 +22226,21 @@ impl PlaneBuf<'_> { // three row bases are computed once per row instead of a // multiply-add per sample (the samples themselves are unchanged). let max = crate::decode::sample_max(fctx); + // lane-recoparse: an all-zero residual (60% of the units) is a plain + // prediction copy -- the same arithmetic with `r == 0`, without + // reading `side * h` zeros out of [`ZERO_RESIDUAL`]. + if residual.is_empty() { + for row in 0..h { + let src = row * side; + let dst = (y + row) * self.width + x; + let pred = &prediction[src..src + w]; + let out = &mut self.data.to_mut()[dst..dst + w]; + for (o, &p) in out.iter_mut().zip(pred) { + *o = i32::from(p).clamp(0, max) as u16; + } + } + return; + } let residual = dense_residual(residual, side * h); for row in 0..h { let src = row * side;