huff2/quantize: optimize scale-factor and codebook processing - #183
Merged
Conversation
Accelerate AAC quantization and Huffman codebook selection by avoiding redundant array scans and replacing runtime math with lookup tables. - Track band maxima during quantization to avoid rescanning in huffbook() - Precompute gain and band-width lookup tables to replace powf/log10f calls - Reuse energy metrics in sfac allocation to eliminate div/sqrtf operations - Streamline loop iterations and sign checks in Huffman encoding paths - Add const and restrict annotations for better compiler optimizations Impact: - +2.7% to +4.0% overall encoding speedup - -264 bytes text footprint in libfaac.so (-0.44%)
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.
Performance optimization: Accelerates
libfaacencoding by +2.7% to +4.0% by eliminating redundant array passes, replacing expensive transcendental math (powf,sqrtf,log10f) with LUTs, and unrolling hot loops—with 100% bit-exact output.Key Changes
quantize_scalar()andquantize_sse2()now returnmaxq, removing a redundant spectral scanning pass inhuffbook().gain_lut(512 entries for quarter-dB steps) andlog10_width_sf_lut(128 entries) to replacepowf()calls in gain coupling.sf_enrg_avgvia log identities to remove duplicate division andsqrtf()operations inassign_band_codebooks().huff2.c; addedconstand__restrictannotations to hot paths.Benchmarks & Impact
libfaac.so(-0.44%).