forge
Explore
Log in

Don't you dare go Hollow

Horizontal MC taps multiply at 16 bits

Browse files at this commit

dcac6b36b2f4cfdd5a02a0814381359ba031cda2Ahmet Kaan GümüşParent: 8c7cbe4
  • perf
    • horizontal MC taps multiply at 16 bits
Show full message
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.rsmodified+8 -1
@@ -257,10 +257,17 @@ fn hpass_row(reference: &[u16], row_base: usize, true_width: usize, x0: i32, tap
257 if start >= 0 && start as usize + block_w + 7 <= true_width {257 if start >= 0 && start as usize + block_w + 7 <= true_width {
258 let s = row_base + start as usize;258 let s = row_base + start as usize;
259 if let Some(src) = reference.get(s..s + block_w + 7) {259 if let Some(src) = reference.get(s..s + block_w + 7) {
260+ // Both factors are 16-bit (a tap is |x| <= 128, a sample fits the
261+ // bit depth), so the products are exactly the i32 ones above but
262+ // the widening multiply is one instruction per pair.
263+ let t16 = [
264+ taps[0] as i16, taps[1] as i16, taps[2] as i16, taps[3] as i16,
265+ taps[4] as i16, taps[5] as i16, taps[6] as i16, taps[7] as i16,
266+ ];
260 for (o, w) in out.iter_mut().zip(src.windows(8)) {267 for (o, w) in out.iter_mut().zip(src.windows(8)) {
261 let mut sum = 0i32;268 let mut sum = 0i32;
262 for t in 0..8 {269 for t in 0..8 {
263- sum += taps[t] * i32::from(w[t]);270+ sum += i32::from(t16[t]) * i32::from(w[t] as i16);
264 }271 }
265 *o = round2(sum, INTER_ROUND_0);272 *o = round2(sum, INTER_ROUND_0);
266 }273 }