Repository navigation
filters: multiply by the high word alone when biquad coefficients fit - #1254
Merged
Merged
Conversation
The biquad loops spend most of their instructions joining the two words of each 64-bit product, because SMUL64R's shift by S_FRAC_BITS does not land on a word boundary. A coefficient is fixed for the whole block, so it can carry that shift instead: mulh(c << 9, x) equals (c * x) >> 23 for any x, as long as c << 9 still fits, which is |c| < 0.5. Each block checks its coefficients once and runs one of two copies of the loop, written once as a macro. Output does not change. Coefficients at or above 0.5, which includes b0 of a highpass or notch at any cutoff, stay on the existing loop, as does anything without AMY_HAS_MUL64. FILT_MULH is the expression EQ_MULH already used, so the 64-bit EQ_MULH now points at it.
Collaborator
⛓️ tulipcc integration PR openedThis merge was pinned into tulipcc for full-system CI: shorepine/tulipcc#1420 Test it there and merge that PR to move tulipcc onto this AMY. |
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
When every coefficient of a biquad is below 0.5, its loop now takes one high-word
multiply per product. Six filtered saws render 11 % faster on an ESP32-S3. Output does
not change.
Context
SMUL64Rshifts by 23, so each product needs both words of the multiply plus shifts tojoin them. A biquad coefficient is fixed for the block, so it can carry the shift:
mulh(c << 9, x)equals(c * x) >> 23whilec << 9fits, which is|c| < 0.5.Each block checks its coefficients once and picks one of two copies of the loop. The
loops moved into macros because of that second copy, as with
RENDER_LUT_GUTS; thestatements are unchanged apart from the multiply and
coef[0..2]becoming locals.amy.halso builds on MSVC, which rules out a forced-inline function.EQ_MULHnowpoints at
FILT_MULH, the same expression.This covers LPF and BPF up to about 2.5 kHz at Q 0.7, 4 kHz at Q 2 and 5 kHz at Q 8.
HPF and notch never fit, because
b0stays near 1. They stay on the existing loop, asdoes anything without
AMY_HAS_MUL64. Only the two kernels the filter path callschanged; the phaser allpass could follow.
A single loop at a smaller shift would cover every coefficient, but the dropped bits go
through the feedback. With bias correction, an LPF at 100 Hz, Q 0.7 has -48.6 dBFS of
error against a double-precision filter, where main has -95.7.
Verification
ESP32-S3 at 240 MHz on v1.2.200, all loops in one image. Six saws, cycles per 256-sample
block, of a 1,280,000 budget:
Instructions in the per-sample loop when coefficients fit,
-O2, old -> new:On the ESP32-S3 the twofunctions grow from 184 to 357 and 262 to 447 bytes;
the second is
AMY_IRAM_ATTR.A host test compared
filters.cfrom main and this branch over 614 M samples, includingcoefficients around the boundary, with no mismatches.
Deliberately loosening the fit test to |c| < 1, where the shift overflows,
gives 802,018 mismatched blocks of 2.4 M, so the test catches a wrong boundary.
make test: identical to main