You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(mp3): ESP32-S3 PIE kernels for the fixed-point polyphase and DCT-32 #4108
Carved out of #4055, which shipped the portable SSE4.1/NEON pair but no Xtensa path.
What is missing
#4055's criteria asked for compile-time-guarded ESP32-S3 PIE kernels for polyphase and DCT-32. What landed (#4107) vectorises both kernels for SSE4.1 and NEON; no Xtensa target compiles either, so ESP32-S3 currently runs the scalar fixed-point path.
What already exists to build on
mp3d_synth_taps and mp3d_dct2_bands4 in src/third_party/minimp3/minimp3.h are already factored as standalone kernels behind MP3D_HAVE_INT_SIMD, precisely so another ISA can be added without touching the surrounding code.
The vector operations needed are MP3D_V_ADDSAT, MP3D_V_SUBSAT, MP3D_V_MULSHIFT, MP3D_V_MUL_LO/HI and load/store — implementing that set for PIE is the whole job.
The bit-exactness gate is already written and architecture-aware (tests/fl/codec/mp3_fixed_point.hpp): it compares against a MINIMP3_NO_SIMD instantiation and skips where no SIMD is compiled, so a PIE path gets tested for free the moment mp3dec_dsp_uses_simd() reports true.
The bar
Exact PCM equality with the scalar fixed-point path, not a tolerance — both operate on the same integer representation, so any difference is a defect. Note the saturation range is deliberately symmetric (MP3D_SAT_MIN == -MP3D_SAT_MAX) and the rounding rule is add-half-then-arithmetic-shift, i.e. round half toward +infinity; PIE kernels must reproduce both exactly.
Verification without hardware
bash compile esp32s3 covers compilation. Bit-exactness needs either the ESP32-S3 QEMU job or on-device via examples/AutoResearch/AutoResearch.ino.
This cannot be implemented to its own bar, and here is the evidence
The bar this issue sets is exact PCM equality with the scalar fixed-point path, not a tolerance — correctly, since both paths operate on the same integer representation and any difference is a defect.
The fixed-point pipeline is 32-bit mantissas throughout. The two vector operations the named kernels are built from are:
MP3D_V_MUL_LO/HI — a 32×32→64 widening signed multiply (the polyphase is essentially nothing but these).
MP3D_V_MULSHIFT / mp3d_v_narrow — that 64-bit product narrowed by a rounded, saturating right shift (every DCT-32 butterfly stage needs it).
The ESP32-S3 PIE provides neither.
What the S3 PIE actually offers. Its multiply instructions are EE.VMUL.S8 and EE.VMUL.S16 — 8- and 16-bit element multiplies. The QACC accumulator pair holds "16 8-bit MAC results or 8 16-bit MAC results"; there is no 32-bit MAC path into it. An independent teardown of the instruction set puts it plainly, listing among the missing essentials "add or multiply with widening" and "right shift with narrowing" — which are precisely the two operations required here, named as absent.
FastLED already reached this conclusion elsewhere.src/platforms/esp/32/simd_xtensa.hpp says in its own header comment: "Operations without PIE equivalents (i32 arithmetic, float, shifts) use scalar fallback." Its add_i32_4 is a scalar loop, and the file contains no ee.* instruction anywhere — only "PIE-ready" comments marking where one might go. The 32-bit integer gap is not specific to the MP3 decoder.
Substituting 16-bit MACs is the defect #4055 already rejected. That PR documented the same trade for Cortex-M4:
SMLAD is a dual 16×16 MAC while this pipeline is 32-bit mantissas throughout, so halving an operand costs roughly 16 dB of the margin the fixed-vs-float gates currently pass with.
EE.VMUL.S16 is the same shape of instruction and the same objection applies. It would fail this issue's stated bar by construction, not by a tuning margin.
Why a partial kernel is not worth it either
MP3D_V_ADDSAT/MP3D_V_SUBSATcould map to EE.VADDS.S32/EE.VSUBS.S32, which do exist (with a vmax afterwards, since PIE saturates to INT32_MIN while this decoder's range is deliberately symmetric at -INT32_MAX).
But that is not enough to vectorise either named kernel. Every DCT-32 butterfly stage interleaves adds with a MULSHIFT, and the polyphase is dominated by MUL_LO/HI. A partial kernel would have to move each operand between PIE q registers and the AR file to do the multiplies scalar-side, once per butterfly — near-certainly a net loss against the plain scalar path, and one that would have to be measured on hardware to even claim.
Recommendation
Close as not planned, with the finding recorded rather than the issue quietly aging. ESP32-S3 continues to run the scalar fixed-point path, which is correct, gated, and within budget.
Two things would reopen this legitimately:
ESP32-P4. Its PIE is a different, larger instruction set (256-bit accumulators, RISC-V esp.* encodings rather than Xtensa ee.*). Whether it has a 32×32→64 widening multiply is a separate question worth asking on its own terms.
A relaxed bar, argued explicitly. If someone decides a 16-bit-mantissa Xtensa path is acceptable for S3 despite the precision loss, that is a real design choice — but it needs the fixed-vs-float gates re-argued at the new margin, not a quiet substitution behind an equality gate that would then fail.
Correction: I closed this against the wrong accuracy bar
My previous comment argued the 16-bit PIE multiply was precluded on precision, importing #4055's estimate that halving the mantissa costs "roughly 16 dB of the margin the fixed-vs-float gates currently pass with."
That margin is the wrong reference. The bar is parity with Helix — the decoder this work replaced — not parity with minimp3's float build. Measured against the ISO limited-accuracy reference vector (l3-hecommon):
Helix measured on the same rig at the commit before its deletion; fixed-point measured on current master.
So there is 20.4 dB of headroom against the bar that actually matters, not the ~10 dB against float I was implicitly reasoning from. Against an estimated ~16 dB cost for halving the mantissa, a 16-bit PIE path is plausibly within budget rather than precluded by it. Tight, but not excluded — and I should not have closed on that reasoning.
What is actually true about the S3 PIE
The instruction-set finding stands and is worth keeping: the ESP32-S3 PIE has no 32×32→64 widening signed multiply. Its multiplies are EE.VMUL.S8/EE.VMUL.S16, QACC accumulates "16 8-bit or 8 16-bit MAC results", and an independent teardown names the missing essentials as "multiply with widening" and "right shift with narrowing" — exactly what MP3D_V_MUL_LO/HI and mp3d_v_narrow are.
Worth noting the same is true of Helix: it needed 32×32→64 everywhere (MULSHIFT32 lowering to imul / smull / mulh, and a full 64-bit MADD64), so Helix would not have used S3 PIE either. This is not a regression introduced by minimp3.
What this issue is really blocked on
Not precision. Two things:
A decision about the gate. The current bar is exact SIMD-vs-scalar PCM equality, which any reduced-precision path fails by construction — not by a margin. A PIE path needs a different, explicitly argued gate: "stays at or above Helix's 102.87 dB against the ISO reference", measured, with the 20 dB headroom spent deliberately. That means accepting per-target numerics — an S3 whose output differs from every other target's — which is the fragmentation perf(mp3): add bit-exact SIMD kernels that outperform Helix #4055 wanted to avoid. It is a real trade, not an obvious no.
The implementation and its validation. Xtensa PIE has no C intrinsics in the toolchain here; this is inline asm against q registers. It needs the ESP32-S3 QEMU job or examples/AutoResearch/AutoResearch.ino on hardware to prove anything, and the ~16 dB figure needs measuring rather than carrying forward as an estimate.
A cheap first step that settles (1) before anyone writes assembly: simulate the precision loss in C by rounding the fixed-point multiply operands to 16 bits behind a build flag, and measure the resulting PSNR against the ISO vector. If it lands below 102.87 dB the question is closed on evidence; if it lands above, the trade is real and worth arguing.
Reopening. Sorry for the premature close — the instruction-set research was sound, the acceptance bar I applied to it was not.
I reopened this on the grounds that parity with Helix (102.87 dB) leaves 20.4 dB of headroom against #4055's estimate that 16-bit mantissas cost "roughly 16 dB". Rather than keep trading estimates, I measured it.
Method. Behind a build flag, keep only the top 16 bits of the wide operand in exactly the kernels PIE would vectorise — mp3d_mulshift (the DCT-32) and the polyphase mp3d_synth_pair. The coefficients are already 16/17-bit (29, 213, 459, 2037, 5153, 6574, 37489, 75038, 64019), so the Q26 samples are the wide side and the model is a 16x16 MAC. Then decode the ISO limited-accuracy vector l3-hecommon.bit and compute PSNR against its reference PCM.
The harness reproduces the shipping decoder's 123.24 dB exactly before the flag is applied, so it is measuring the right thing.
configuration
PSNR vs ISO reference
32-bit MACs (ships today)
123.24 dB
16-bit MACs simulated
44.37 dB
Helix (the parity bar)
102.87 dB
ISO limited-accuracy floor
60 dB
The cost is ~79 dB, not ~16 dB. That is 58 dB below Helix and, more decisively, 15 dB below the ISO limited-accuracy floor — a 16-bit path would not merely regress against Helix, it would fail ISO compliance outright.
The estimate was off by roughly 5x because it treated the loss as one halving of one operand's precision. In reality it applies at every MAC and compounds: the polyphase alone is 16 multiply-accumulates per output sample, feeding a DCT-32 that has already lost the same bits.
Fairness of the model. Truncating to the raw top 16 bits is the naive scheme; a real implementation would use per-block scaling (block floating point) to place the 16-bit window better, and would do somewhat better than 44.37 dB. But it would have to recover 59 dB — about 10 bits — to reach Helix parity. Block scaling recovers a few bits, not ten. The gap is not closeable by implementation quality.
Disposition
Closing again, this time on a measurement rather than an argument.
The instruction-set finding from the first comment stands: the ESP32-S3 PIE has no 32x32->64 widening multiply and no narrowing shift, and its MAC paths are 8- and 16-bit into QACC. Helix needed the same 32x32->64 primitive (MULSHIFT32 lowering to imul/smull/mulh, plus a full 64-bit MADD64), so it would not have used S3 PIE either — this is a property of fixed-point MP3 decoding, not a regression introduced by minimp3.
What would legitimately reopen this is ESP32-P4, whose PIE is a different and larger instruction set (256-bit accumulators, RISC-V esp.* encodings). Whether it offers a 32-bit widening multiply is a separate question worth asking on its own terms — and if it does, the kernels are already factored to accept it.
The experiment was run against a scratch build flag and is not committed; the shipping header is unchanged and still measures 123.24 dB.
Activity
zackees commentedon Sep 1, 2026
This cannot be implemented to its own bar, and here is the evidence
The bar this issue sets is exact PCM equality with the scalar fixed-point path, not a tolerance — correctly, since both paths operate on the same integer representation and any difference is a defect.
The fixed-point pipeline is 32-bit mantissas throughout. The two vector operations the named kernels are built from are:
MP3D_V_MUL_LO/HI— a 32×32→64 widening signed multiply (the polyphase is essentially nothing but these).MP3D_V_MULSHIFT/mp3d_v_narrow— that 64-bit product narrowed by a rounded, saturating right shift (every DCT-32 butterfly stage needs it).The ESP32-S3 PIE provides neither.
What the S3 PIE actually offers. Its multiply instructions are
EE.VMUL.S8andEE.VMUL.S16— 8- and 16-bit element multiplies. The QACC accumulator pair holds "16 8-bit MAC results or 8 16-bit MAC results"; there is no 32-bit MAC path into it. An independent teardown of the instruction set puts it plainly, listing among the missing essentials "add or multiply with widening" and "right shift with narrowing" — which are precisely the two operations required here, named as absent.FastLED already reached this conclusion elsewhere.
src/platforms/esp/32/simd_xtensa.hppsays in its own header comment: "Operations without PIE equivalents (i32 arithmetic, float, shifts) use scalar fallback." Itsadd_i32_4is a scalar loop, and the file contains noee.*instruction anywhere — only "PIE-ready" comments marking where one might go. The 32-bit integer gap is not specific to the MP3 decoder.Substituting 16-bit MACs is the defect #4055 already rejected. That PR documented the same trade for Cortex-M4:
EE.VMUL.S16is the same shape of instruction and the same objection applies. It would fail this issue's stated bar by construction, not by a tuning margin.Why a partial kernel is not worth it either
MP3D_V_ADDSAT/MP3D_V_SUBSATcould map toEE.VADDS.S32/EE.VSUBS.S32, which do exist (with avmaxafterwards, since PIE saturates toINT32_MINwhile this decoder's range is deliberately symmetric at-INT32_MAX).But that is not enough to vectorise either named kernel. Every DCT-32 butterfly stage interleaves adds with a
MULSHIFT, and the polyphase is dominated byMUL_LO/HI. A partial kernel would have to move each operand between PIEqregisters and the AR file to do the multiplies scalar-side, once per butterfly — near-certainly a net loss against the plain scalar path, and one that would have to be measured on hardware to even claim.Recommendation
Close as not planned, with the finding recorded rather than the issue quietly aging. ESP32-S3 continues to run the scalar fixed-point path, which is correct, gated, and within budget.
Two things would reopen this legitimately:
esp.*encodings rather than Xtensaee.*). Whether it has a 32×32→64 widening multiply is a separate question worth asking on its own terms.Sources: ESP32-S3 TRM, Espressif PIE introduction, instruction-set teardown
Refs #4055, FastLED/license#14
zackees commentedon Sep 1, 2026
Correction: I closed this against the wrong accuracy bar
My previous comment argued the 16-bit PIE multiply was precluded on precision, importing #4055's estimate that halving the mantissa costs "roughly 16 dB of the margin the fixed-vs-float gates currently pass with."
That margin is the wrong reference. The bar is parity with Helix — the decoder this work replaced — not parity with minimp3's float build. Measured against the ISO limited-accuracy reference vector (
l3-hecommon):Helix measured on the same rig at the commit before its deletion; fixed-point measured on current master.
So there is 20.4 dB of headroom against the bar that actually matters, not the ~10 dB against float I was implicitly reasoning from. Against an estimated ~16 dB cost for halving the mantissa, a 16-bit PIE path is plausibly within budget rather than precluded by it. Tight, but not excluded — and I should not have closed on that reasoning.
What is actually true about the S3 PIE
The instruction-set finding stands and is worth keeping: the ESP32-S3 PIE has no 32×32→64 widening signed multiply. Its multiplies are
EE.VMUL.S8/EE.VMUL.S16, QACC accumulates "16 8-bit or 8 16-bit MAC results", and an independent teardown names the missing essentials as "multiply with widening" and "right shift with narrowing" — exactly whatMP3D_V_MUL_LO/HIandmp3d_v_narroware.Worth noting the same is true of Helix: it needed 32×32→64 everywhere (
MULSHIFT32lowering toimul/smull/mulh, and a full 64-bitMADD64), so Helix would not have used S3 PIE either. This is not a regression introduced by minimp3.What this issue is really blocked on
Not precision. Two things:
qregisters. It needs the ESP32-S3 QEMU job orexamples/AutoResearch/AutoResearch.inoon hardware to prove anything, and the ~16 dB figure needs measuring rather than carrying forward as an estimate.A cheap first step that settles (1) before anyone writes assembly: simulate the precision loss in C by rounding the fixed-point multiply operands to 16 bits behind a build flag, and measure the resulting PSNR against the ISO vector. If it lands below 102.87 dB the question is closed on evidence; if it lands above, the trade is real and worth arguing.
Reopening. Sorry for the premature close — the instruction-set research was sound, the acceptance bar I applied to it was not.
zackees commentedon Sep 1, 2026
Measured. This supersedes both comments above.
I reopened this on the grounds that parity with Helix (102.87 dB) leaves 20.4 dB of headroom against #4055's estimate that 16-bit mantissas cost "roughly 16 dB". Rather than keep trading estimates, I measured it.
Method. Behind a build flag, keep only the top 16 bits of the wide operand in exactly the kernels PIE would vectorise —
mp3d_mulshift(the DCT-32) and the polyphasemp3d_synth_pair. The coefficients are already 16/17-bit (29, 213, 459, 2037, 5153, 6574, 37489, 75038, 64019), so the Q26 samples are the wide side and the model is a 16x16 MAC. Then decode the ISO limited-accuracy vectorl3-hecommon.bitand compute PSNR against its reference PCM.The harness reproduces the shipping decoder's 123.24 dB exactly before the flag is applied, so it is measuring the right thing.
The cost is ~79 dB, not ~16 dB. That is 58 dB below Helix and, more decisively, 15 dB below the ISO limited-accuracy floor — a 16-bit path would not merely regress against Helix, it would fail ISO compliance outright.
The estimate was off by roughly 5x because it treated the loss as one halving of one operand's precision. In reality it applies at every MAC and compounds: the polyphase alone is 16 multiply-accumulates per output sample, feeding a DCT-32 that has already lost the same bits.
Fairness of the model. Truncating to the raw top 16 bits is the naive scheme; a real implementation would use per-block scaling (block floating point) to place the 16-bit window better, and would do somewhat better than 44.37 dB. But it would have to recover 59 dB — about 10 bits — to reach Helix parity. Block scaling recovers a few bits, not ten. The gap is not closeable by implementation quality.
Disposition
Closing again, this time on a measurement rather than an argument.
The instruction-set finding from the first comment stands: the ESP32-S3 PIE has no 32x32->64 widening multiply and no narrowing shift, and its MAC paths are 8- and 16-bit into QACC. Helix needed the same 32x32->64 primitive (
MULSHIFT32lowering toimul/smull/mulh, plus a full 64-bitMADD64), so it would not have used S3 PIE either — this is a property of fixed-point MP3 decoding, not a regression introduced by minimp3.What would legitimately reopen this is ESP32-P4, whose PIE is a different and larger instruction set (256-bit accumulators, RISC-V
esp.*encodings). Whether it offers a 32-bit widening multiply is a separate question worth asking on its own terms — and if it does, the kernels are already factored to accept it.The experiment was run against a scratch build flag and is not committed; the shipping header is unchanged and still measures 123.24 dB.
Refs #4055, FastLED/license#14
feat(math): add fl::math::mulshift32 with a pinned instruction shape
feat(math): add fl::math::mulshift32 with a pinned instruction shape