From dcac6b36b2f4cfdd5a02a0814381359ba031cda2 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 13:22:52 +0300 Subject: [PATCH] perf(av1): horizontal MC taps multiply at 16 bits The interior horizontal row had auto-vectorised, but into pmuludq/pshufd chains: an i32 x i32 lane multiply is three instructions on SSE2. A tap is |x| <= 128 and a sample is bounded by the bit depth (<= 4095 at 12-bit), so narrowing both factors to i16 before the widening multiply gives exactly the same products and one instruction per pair. Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp identical to the pre-lane binary. Interleaved medians on the 1080p segment: 22.25 s base -> 16.64 s. --- crates/ec-av1/src/mc.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index ced1efe6..ae2f3d8c 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -257,10 +257,17 @@ fn hpass_row(reference: &[u16], row_base: usize, true_width: usize, x0: i32, tap if start >= 0 && start as usize + block_w + 7 <= true_width { let s = row_base + start as usize; if let Some(src) = reference.get(s..s + block_w + 7) { + // Both factors are 16-bit (a tap is |x| <= 128, a sample fits the + // bit depth), so the products are exactly the i32 ones above but + // the widening multiply is one instruction per pair. + let t16 = [ + taps[0] as i16, taps[1] as i16, taps[2] as i16, taps[3] as i16, + taps[4] as i16, taps[5] as i16, taps[6] as i16, taps[7] as i16, + ]; for (o, w) in out.iter_mut().zip(src.windows(8)) { let mut sum = 0i32; for t in 0..8 { - sum += taps[t] * i32::from(w[t]); + sum += i32::from(t16[t]) * i32::from(w[t] as i16); } *o = round2(sum, INTER_ROUND_0); }