Repository navigation
Description
Background
Spun out from #2628 with concrete per-op scope. FastLED's fl::simd layer (src/platforms/shared/simd_noop.hpp) falls through to scalar on all ARM Cortex-M targets. The ARMv7E-M DSP extension (Cortex-M4/M4F on Teensy 3.x, Cortex-M7 on Teensy 4.x) provides 4-lane 8-bit and 2-lane 16-bit packed-integer ops in a single 32-bit GPR.
Plan: create src/platforms/shared/simd_arm_dsp.hpp and route __ARM_FEATURE_DSP to it from the trampoline at src/platforms/simd.h. Implement one op at a time and verify each via the autoresearch SIMD test path before moving to the next.
Implementation flow (mandatory per op)
For each unchecked item below:
- Implement the op as one inline function in
src/platforms/shared/simd_arm_dsp.hppusing ARM intrinsics from<arm_acle.h>(e.g.__UQADD8,__UHADD8,__UXTB16,__SMUAD) — NOT inline asm, intrinsics are cleaner. - Wire the trampoline in
src/platforms/simd.hto route just THIS op to the new backend (leave the rest falling through tosimd_noop.hpp). - Compile for
teensy40and verify no regression:bash compile teensy40 --examples AutoResearch. - Host unit test: add or extend the existing
fl::simdtests so the new op's behavior is bit-exact equivalent to the noop fallback on the host (catches semantic regressions before they reach hardware). - Hardware validate:
bash autoresearch teensy40 --simd --skip-lint(single run is fine for SIMD — it's a deterministic compute test, not a hardware-timing test). The device runs the SIMD self-test suite and reports per-op pass/fail via JSON-RPC. - If the device crashes (RPC timeout, watchdog reset, or device disappears from serial): the issue is almost certainly an intrinsic mis-use (operand alignment, register class, or undefined behavior on the M-class core). Capture the crash log (`[FastLED.watchdog] SRC_SRSR = ...` from the next boot), bisect the new function, fix, re-run.
- Tick the checkbox + link the PR.
Why one-at-a-time: ARM DSP intrinsics are sharp — a misclassified operand or wrong intrinsic family for the lane width can cause a HardFault that takes down the whole sketch. Bisecting one op at a time keeps each crash localized.
Op checklist
🟢 Big wins — implement these first (highest ROI)
These are 1 DSP opcode per 4 bytes / 2 halfwords, vs ~16+ scalar ops with branches.
-
add_sat_u8_16— 4×__UQADD8. Hot path for every brightness step, fade, blend. Probably the single highest-impact op in FastLED. -
sub_sat_u8_16— 4×__UQSUB8. Same shape, used in fade-down and subtract-blend. -
avg_u8_16(truncating) — 4×__UHADD8. Used in averaging filters. -
avg_round_u8_16— 4×__UHADD8+ correction term. Used in 2D blur (fl/fx/2d/blend.cpp.hpp). -
avg_round_u8_32— 8×__UHADD8. u8x32 sibling for wider buffers. -
add_u16_8— 4×__UADD16. 2-halfword adds. -
widen_lo_u8_to_u16— 2×__UXTB16. Zero-extends 2 bytes to 2 halfwords in one cycle — perfect DSP fit. -
widen_hi_u8_to_u16—ROR #8+ 2×__UXTB16. Same pattern, upper-half source. -
narrow_u16_to_u8—__PKHBT/__PKHTB+__USAT8to pack halfwords back to bytes. -
widen_lo_u8x32_to_u16+widen_hi_u8x32_to_u16— u8x32 versions of the widen ops.
🟡 Possible wins — implement only if profiling shows them hot
Multi-opcode but still beats scalar. Skip unless a measurable benchmark says they matter.
-
min_u8_16—__UQSUB8+__SELbyte-mask. ~3 ops per 4 bytes. -
max_u8_16— Same shape, swapped operands. -
scale_u8_16—__UXTB16× 2 →__SMULBB× 2 → recombine via__PKHBT. 4-byte scaled-mul in ~6 cycles. -
blend_u8_16— Same shape as scale, with two sources interpolated by an 8-bit amount. -
mullo_u16_8—__SMULBB/__SMULBT/__SMULTB/__SMULTTquartet to do 2 mullo per 32-bit DSP op + low-bit mask.
🔴 Explicitly NOT in scope (and why)
DON'T waste time on these — they have no DSP-ext acceleration path:
- All
u32x4ops — DSP regs are 32-bit; u32x4 is inherently one-word-per-register. Scalar IS the SIMD on this ISA. - All
f32x4ops — DSP-ext is integer-only. Cortex-M4F/M7 has VFP (scalar float) but no vector float. NEON isn't on M-class. and_u8_16/or_u8_16/xor_u8_16/andnot_u8_16— Compiler already emits 4× 32-bit AND/ORR/EOR/BIC; DSP-ext adds nothing on byte-bitwise.load_u8_16/store_u8_16/load_u8_32/store_u8_32— LDM/STM bursts already, no widening possible.srli_u16_8,srl_u32_4,sll_u32_4,sra_i32_4— Scalar shifts are 1 cycle; no SIMD shift in DSP-ext.- All
extract_*/unpack*/set1_*/set_*— Lane manipulation; no DSP-ext win.
Verification & meta
- Final acceptance:
bash autoresearch teensy40 --simd --skip-lintreports all 🟢 ops as ENABLED (not falling through to noop) and bit-exact equivalent to the noop fallback per the host unit tests. - Cross-target check:
bash compile teensy41 --examples AutoResearch✓ (T4.1 same M7 core, same DSP-ext). - Teensy 3.x build sanity (compile-only, no hardware):
bash compile teensy31 --examples Blinkandbash compile teensy36 --examples Blink-- Cortex-M4/M4F also has DSP-ext, so the same backend should compile and link there. - No regression on non-DSP targets:
bash compile uno --examples Blink(AVR),bash compile esp32dev --examples Blink(Xtensa) -- ensure the trampoline gates on__ARM_FEATURE_DSPcorrectly and these still fall through to their own backends.
References
- Closed parent: feat(simd): add Cortex-M DSP-extension SIMD backend for Teensy 3.x / 4.x (close the SIMD-dispatch gap) #2628 (per-op scope folded into this issue)
- Existing SIMD layout:
src/platforms/shared/simd_noop.hpp(scalar fallback to mirror),src/platforms/shared/simd_x86.hpp(intrinsic-style precedent),src/platforms/esp/32/simd_xtensa.hpp(ESP32-S3 PIE precedent),src/platforms/esp/32/simd_riscv.hpp(ESP32-P4 RISC-V precedent),src/platforms/simd.h(trampoline). - ARM ARMv7-M Architecture Reference Manual §A4.4 (SIMD instructions).
- GCC
<arm_acle.h>— the intrinsics header.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(simd/arm-dsp): wire scale/blend/mullo DSP ops (closes #3425 yell…
feat(simd/arm-dsp): wire UXTB16/PKHBT/PKHTB/USAT16/SEL ops (refs Fast…