From 180e07916e8cae5a55842335c3742db2bdc45d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 16:06:25 +0300 Subject: [PATCH] perf(av1): inter reconstruction adds a row at a time `PlaneBuf::reconstruct_mc_rect` re-derived `row * side + col` twice and `(y + row) * self.width + x + col` once per sample, with a bounds check on each of the three buffers. `side` is the prediction/residual stride and `self.width` the plane's, so the three row bases are now taken once per row and the row slices zipped; the arithmetic on each sample (`clamp(0, sample_max())`) is untouched, as is the bottom/right overhang truncation above it. Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment and on `palette_screen_witness.obu`. Interleaved medians against the parent build alone (3 pairs, 1080p): 11.17 s -> 11.06 s. --- crates/ec-av1/src/decode.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2f90be33..a46a4505 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -19223,11 +19223,19 @@ impl PlaneBuf { // 768..832). libaom reconstructs those rows into the frame buffer's // border; nothing reads them back, so they are simply dropped here. let (h, w) = (h.min(self.height.saturating_sub(y)), w.min(self.width.saturating_sub(x))); + // lane-perf4: one row of each operand at a time. `side` is the + // prediction/residual stride and `self.width` the plane's, so the + // 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(); for row in 0..h { - for col in 0..w { - let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col]) - .clamp(0, crate::decode::sample_max()) as u16; - self.data[(y + row) * self.width + x + col] = sample; + let src = row * side; + let dst = (y + row) * self.width + x; + let pred = &prediction[src..src + w]; + let res = &residual[src..src + w]; + let out = &mut self.data[dst..dst + w]; + for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) { + *o = (i32::from(p) + r).clamp(0, max) as u16; } } }