Skip to content

Add NEON for avm_highbd_quantize_b - #5614

Merged
urvangjoshi merged 2 commits into
AOMediaCodec:av2-encfrom
jjustiss-apple:jjustiss/neon-highbd-quantize-b
Oct 24, 2026
Merged

urvangjoshi merged 2 commits into
AOMediaCodec:av2-encfrom
jjustiss-apple:jjustiss/neon-highbd-quantize-b

Conversation

@jjustiss-apple

Copy link
Copy Markdown
Contributor

Adds NEON for avm_highbd_quantize_b (avm_dsp/arm/highbd_quantize_neon.c),
which fuses the quant and quant_shift steps into one multiply, with unit
tests.

QuantizeBTest compares the C, NEON, SSE2 and AVX2 versions over every TX
size, scan order and quantizer; QuantizeBBoundTest checks that the fused
multiply's intermediates and the dequant product fit in int32 for every
quantizer table entry.

Micro-benchmark, NEON vs C (Apple M4 Pro, P-core, 99% CI), on quantize_b
calls captured from A5 RA encodes:

Row Speedup CI
QP 110 7.33x [6.70, 7.96]
QP 135 6.57x [6.04, 7.09]
QP 160 5.27x [4.85, 5.70]
QP 185 4.14x [3.84, 4.45]
QP 210 3.49x [3.25, 3.74]
QP 235 3.21x [3.06, 3.36]
16 coeffs 4.38x [4.06, 4.70]
32 coeffs 4.30x [3.99, 4.61]
64 coeffs 3.49x [3.40, 3.57]
128 coeffs 3.86x [3.58, 4.13]
256 coeffs 4.95x [4.81, 5.08]
512 coeffs 3.91x [3.73, 4.08]

CTC (RA, 33 frames, A4+A5, ARM):

cpu-used Encode time BD-rate Y/Cb/Cr
1 -0.7% 0.000%
4 -3.8% 0.000%

E2E: +0.03% encode time at cpu-used 6 (no measurable change; Apple M2
Ultra).

Tests: QuantizeTest, QuantizeBTest and QuantizeBBoundTest pass (2515
tests); bit-exact against C.

Comment thread avm_dsp/arm/highbd_quantize_neon.c
Comment thread avm_dsp/arm/highbd_quantize_neon.c
Comment thread avm_dsp/arm/highbd_quantize_neon.c
Comment thread avm_dsp/arm/highbd_quantize_neon.c
Comment thread avm_dsp/arm/highbd_quantize_neon.c Outdated
Comment thread test/quantize_b_bound_test.cc Outdated
Comment thread test/quantize_b_bound_test.cc Outdated
Comment thread avm_dsp/arm/highbd_quantize_neon.c Outdated
@jjustiss-apple

Copy link
Copy Markdown
Contributor Author

@jianj-g All addressed, thank you for the review!

- horizontal_max_s16x8: use vmaxvq_s16 on aarch64, keeping the vpmax
  chain for armv7.
- quantize_b_large_neon: take the rounded AC zbin and round values from
  the caller instead of recomputing them.
- Mark the all-below-zbin branch LIKELY so GCC does not schedule the
  quantize multiplies before it.
- QuantizeBBoundTest: drop the diagnostic printfs and the stats that only
  fed them; the bit depth goes in the failure messages instead.
@urvangjoshi
urvangjoshi force-pushed the jjustiss/neon-highbd-quantize-b branch from f19e0a0 to 1fee95d Compare October 24, 2026 01:09
@urvangjoshi
urvangjoshi merged commit bbd3008 into AOMediaCodec:av2-enc Oct 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants