Repository navigation
quantize: optimize QuantizeBlockNEON with 2x unrolling and streamlined zigzag loop - #194
Merged
Merged
Conversation
skal65535
force-pushed
the
skal/quant-neon
branch
3 times, most recently
from
September 19, 2026 06:03
93e0121 to
df301b4
Compare
skal65535
marked this pull request as ready for review
September 19, 2026 06:04
skal65535
force-pushed
the
skal/quant-neon
branch
from
September 19, 2026 22:04
df301b4 to
5042080
Compare
…d zigzag loop - Unroll NEON quantization loop by 2 (16 coeffs per iteration), combining weights and reducing vector-to-scalar vaddvq reductions from 8 to 4. - Factorize 8-lane quantization with an inline helper for clean code structure. - Extract shared EmitRunLevels helper for both SSE2 and NEON. - Fast exit when ac_mask == 0 for all-zero AC blocks. - Compute and store level symbols directly in natural order during zigzag bitmask generation, eliminating kZigzag lookup, CalcLog2, bitmasking, and stack array reads from the serialization loop. - 100% bit-exact across all test fixtures and qualities (+9% to +23% faster).
skal65535
force-pushed
the
skal/quant-neon
branch
from
September 20, 2026 04:59
5042080 to
2a81394
Compare
jzern
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimizes
QuantizeBlockNEONinsrc/quantize.ccfor ARM/NEON architectures and shares streamlined zigzag emission with SSE2.Key Changes
• 2x Loop Unrolling: Process 16 coefficients per iteration in the NEON quantization loop, combining dual 8-lane bit weights (
weights0andweights1) into a single 16-bit lane reduction (vaddvq_u16(vorrq_u16(nz0, nz1))), halving vector-to-scalar reduction stalls from 8 to 4 per block.• Factorized 8-Lane Helper: Factorize vector math with an inline lambda to eliminate code duplication across the unrolled loop.
• Unified
EmitRunLevels: Extracted shared helper for both SSE2 and NEON to unify zigzag bitmask remapping, eliminate redundantdc/out->idx_writes, and share fast exit logic across architectures.• Empty AC Fast Exit: Blocks with no non-zero AC coefficients (
nzn & ~1ull == 0) return immediately without entering the serialization loops.• Streamlined Zigzag Loop: Pre-compute
levels[i]during the zigzag bitmask generation loop, eliminatingkZigzag[i]lookups,CalcLog2, bitmasking, and stack array reads from the final serialization loop.Performance Gains (on Apple Silicon ARM64, 45,000 blocks)
•$q=50$ : 0.64 ms $\to$ 0.59 ms (+7.4%, 1.08x faster)$q=75$ : 0.78 ms $\to$ 0.74 ms (+5.2%, 1.05x faster)$q=85$ : 1.03 ms $\to$ 0.95 ms (+7.3%, 1.08x faster)$q=95$ : 2.00 ms $\to$ 1.86 ms (+6.7%, 1.07x faster)
•
•
•
Bit-Exactness
100% bit-exact match across all test fixtures, qualities, and the full CLIC image corpus. All unit tests pass.