Skip to content

feat(simd/arm-dsp): wire scale/blend/mullo DSP ops (closes #3425 yellow) - #3427

Merged
zackees merged 1 commit into
masterfrom
feat/simd-arm-dsp-yellow-ops
Jun 27, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/simd-arm-dsp-yellow-ops

Conversation

@zackees

@zackees zackees commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Completes the 🟡 ops checklist from #3425 (the 🟢 portion landed in PR #3426). Each op promoted from scalar fallback to Cortex-M DSP-ext intrinsics in `src/platforms/arm/teensy/simd_arm_dsp.hpp`, validated one-at-a-time via `bash autoresearch teensy40 --simd` (85/85 passing after each).

Ops landed

Op DSP impl Cost vs scalar
`scale_u8_16` UXTB16 + u32 mul (lane-safe) + extract-high-byte 7 DSP ops per 4 bytes vs 16-iter widening loop
`blend_u8_16` UQSUB8 pos/neg-diff + 2× scale_u8x4 + UQADD8/UQSUB8 mutually-exclusive lanes per byte; ≤±1 LSB of noop (test tol ±2 LSB)
`mullo_u16_8` SMULBB + SMULTT + PKHBT 3 ops per halfword pair vs 8-iter LDRH+MUL+STRH

Bit-exactness notes

  • scale_u8_16: exact `(byte * scale) >> 8` — matches noop.
  • blend_u8_16: exact at amount=0 (returns a), exact at amount=255 (returns b ± 1 LSB matching scale8 truncation). Mid-amount within ±1 LSB of noop's signed-shift formulation due to two's-complement-vs-unsigned rounding asymmetry on negative diffs. Test suite tolerance in `AutoResearchSimd.h` allows ±2 LSB.
  • mullo_u16_8: exact — SMULxy's low 16 bits == unsigned mullo regardless of sign.

Test plan

  • `bash compile teensy40 --examples AutoResearch` ✓
  • `bash autoresearch teensy40 --simd --skip-lint` reports 85/85 SIMD tests passing.
  • `bash lint --cpp` clean.

Closes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance Improvements
    • Improved speed for color scaling, blending, and 16-bit multiplication on supported ARM/Teensy devices.
    • Vector operations now run more efficiently, which can help animations and LED updates feel smoother.

Completes the 🟡 ops checklist from #3425. Each promoted from scalar
fallback to Cortex-M DSP-ext intrinsics, validated one-at-a-time via
the device-side SIMD self-test (85/85 passing after each).

- **scale_u8_16** -- UXTB16 splits the 4 bytes into two halfword
  pairs (0:a2,0:a0) and (0:a3,0:a1). Each pair × `scale` is a single
  u32 mul -- safe because each halfword product byte*scale fits in u16
  (255*255 = 65025 < 65536), so lanes don't interfere. Extract the
  high byte of each halfword (= scale8 result) via shift + mask.
  7 ops per 4-byte chunk (28 ops for u8x16) vs the 16-iter widening
  scalar loop.

- **blend_u8_16** -- per-byte lerp via the additive identity
  `a + scale(pos_diff,amount) - scale(neg_diff,amount)` where
  pos_diff = UQSUB8(b,a) and neg_diff = UQSUB8(a,b) are always
  mutually exclusive per lane. Saturating add/sub composes the
  per-lane bytes back. Bit-exact against noop at amount=0; within
  ±1 LSB at mid-amount (vs noop's signed-shift two-complement
  rounding) -- AutoResearchSimd.h's blend test allows ±2 LSB which
  this satisfies.

- **mullo_u16_8** -- per-halfword-pair via SMULBB+SMULTT (low/high
  signed 16x16 -> 32, sign-agnostic because we keep low 16 only) +
  PKHBT to re-pack. 3 ops per halfword pair (12 ops total) vs the
  8-iter LDRH+MUL+STRH scalar loop.

All four `fl_dsp_*` helpers (scale_u8x4, blend_u8x4, mullo_u16x2,
plus prior UXTB16/PKHBT/PKHTB/USAT16/SEL helpers) inlined and
verified to produce the expected DSP instruction sequences under
`-O2 -fno-omit-frame-pointer` (Teensyduino default).

Verification: `bash autoresearch teensy40 --simd --skip-lint`
reports 85/85 SIMD tests passing after each individual op was added
(per-op flow per #3425). Compile + lint clean.

Closes #3425.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 36d95e54-0865-45a6-b337-461116e90ed7

📥 Commits

Reviewing files that changed from the base of the PR and between 91d25e4 and 9002621.

📒 Files selected for processing (1)
  • src/platforms/arm/teensy/simd_arm_dsp.hpp

📝 Walkthrough

Walkthrough

Adds three ARMv7E-M DSP inline-assembly helpers (fl_dsp_scale_u8x4, fl_dsp_blend_u8x4, fl_dsp_mullo_u16x2) to simd_arm_dsp.hpp and replaces scalar loop implementations of scale_u8_16, blend_u8_16, and mullo_u16_8 with DSP-accelerated versions operating on u32-chunked vector data.

Changes

ARM DSP SIMD Acceleration

Layer / File(s) Summary
New DSP inline-asm helpers
src/platforms/arm/teensy/simd_arm_dsp.hpp
Adds fl_dsp_scale_u8x4 (per-byte high-byte scale), fl_dsp_blend_u8x4 (per-byte lerp via UQSUB8 and saturating recombination), and fl_dsp_mullo_u16x2 (two-halfword low-product multiply via smulbb/smultt + pkhbt).
DSP-backed u8x16 and u16x8 operations
src/platforms/arm/teensy/simd_arm_dsp.hpp
Replaces scalar loops in scale_u8_16, blend_u8_16, and mullo_u16_8 with implementations that reinterpret vectors as four u32 chunks and delegate to the new DSP helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2808: Directly extends the same simd_arm_dsp.hpp Teensy DSP backend with the same category of new helpers and scalar-to-DSP replacements.

Poem

🐇 Hop hop, the bytes align,
Four packed in a u32 line,
smulbb hums, UQSUB8 sings,
The scalar loops lost their stings,
DSP magic on Teensy wings! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/simd-arm-dsp-yellow-ops

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit cab1619 into master Jun 27, 2026
5 of 8 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 27, 2026
@zackees
zackees deleted the feat/simd-arm-dsp-yellow-ops branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant