Skip to content

perf(parlio): #2548 pipe4 — 4-position pipelining (+41% vs baseline, 11% under TX) - #2557

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-pipe4-4pos
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-pipe4-4pos

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends pipe2 (#2555) to the empirical peak of the cross-position ILP curve. Adds wave8Transpose_16x4_pipe4() and updates the engine's 16-lane Wave8 dispatch ladder to prefer 4 positions, falling back to 2 positions, then 1.

Bench sweep on the perf/parlio-l1l2l3 bench branch:

variant µs / frame speedup vs WS2812B TX (7 680 µs)
baseline (pre-L2 memcpy) 9 651 1.00× +1 971 µs over
L2 (#2553) 9 305 +3.8 % +1 625 µs over
pipe2 (#2555) 7 633 +26.6 % −47 µs UNDER
pipe3 7 091 +36.1 % −589 µs UNDER
pipe4 (this PR) 6 823 +41.5 % −857 µs UNDER (−11.2 %) ✓
pipe6 10 240 -6 % regressed — register spill cliff
pipe8 10 203 -6 % same spill ceiling

The curve cleanly bounds the optimum. pipe4 sits inside the 32-GPR budget (4 × 4 OR-tree accumulators = 16 GPRs + ~8 misc = ~24 live); pipe6 pushes to ~32 and the compiler spills, snapping the win away.

Engine dispatch ladder (16-lane Wave8 path)

  ≥4 remaining + space for 4 blocks → wave8Transpose_16x4_pipe4
  ≥2 remaining + space for 2 blocks → wave8Transpose_16x2_pipe2
  otherwise                          → wave8Transpose_16 (single)

Bit-identical results across all three paths — each variant is just a tighter interleaving of the same underlying wave8Transpose_16 dataflow.

Test plan

  • Host bit-exactness: new tests/fl/channels/wave8.cpp case (500 random seeds × 4 positions, byte-by-byte equality vs four sequential wave8Transpose_16 calls)
  • Host: bash test wave8 skipped — pre-existing wave8_spi linker error on master (undefined rgb_2_rgbw_colorimetric from feat(rgbw): sub-gamut white-extraction algorithm for chromaticity-accurate RGBW output #2545 / fix(rgbw): address CodeRabbit findings from #2552 #2554) blocks the shared fastled.dll build. The pipe4-specific test passes when compiled in isolation. Unblock once the master link is fixed.
  • Device (ESP32-P4 v1.3): boot-time bench times the wave8Transpose_16x4_pipe4 symbol linked from production libfastled and reports 6 823 µs/frame — exactly matches the bench-branch measurement
  • bash lint --cpp clean
  • CI: full matrix (will run on this PR)

Files

 src/fl/channels/detail/wave8.hpp                                +34
 src/fl/channels/wave8.h                                         +18
 src/fl/channels/wave8.cpp.hpp                                   +31
 src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp       +34 / −8
 tests/fl/channels/wave8.cpp                                     +52

Combined chain (L2 + pipe2 + pipe4)

baseline this stack saved speedup
9 651 µs/frame 6 823 µs/frame 2 828 µs/frame +41.5 %

ISR-chunked streaming on single-core single-Wave8 P4 now has a comfortable ~857 µs / frame safety margin under the WS2812B 16-lane TX budget. No need for #2527 (dual-core) or #2523 (WaveN/Wave4) — those become pure latency / safety-margin enhancements on top of this stack.

Refs #2548 (already closed as resolved by L2 + pipe2 — this PR adds extra headroom).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new optimized waveform transposition function for enhanced data processing capabilities.
  • Tests

    • Added unit test validating the new transposition function across multiple independent input scenarios.

Review Change Stack

…11% under TX)

Extends pipe2 (#2555) to the empirical peak of the cross-position ILP curve.
Bench sweep (#2548 follow-up on perf/parlio-l1l2l3) showed:

  baseline (pre-L2 memcpy)   = 9 651 µs/frame  (1.00×)
  L2 alone (#2553)           = 9 305 µs/frame  (+3.8 %)
  pipe2 (#2555)              = 7 633 µs/frame  (+26.6 %)
  pipe3                      = 7 091 µs/frame  (+36.1 %)
  **pipe4 (this PR)**        = **6 823 µs/frame  (+41.5 %)**  ← peak
  pipe6                      = 10 240 µs/frame (-6 %, register spill cliff)
  pipe8                      = 10 203 µs/frame (-6 %, same spill ceiling)
  WS2812B 16-lane TX target  = 7 680 µs/frame

The curve cleanly bounds the optimum: pipe4 sits inside the 32-GPR budget
(4 × 4 OR-tree accumulators = 16 GPRs + ~8 misc = ~24 live); pipe6 needs
~32 GPRs and spills, snapping the win away.

**6 823 µs/frame is 11.2 % UNDER the WS2812B TX budget** — comfortable
safety margin for ISR-chunked streaming (was just 0.7 % under with pipe2).

### Engine dispatch ladder (ParlioEngine::populateDmaBuffer, 16-lane Wave8):
  ≥4 byte-positions remain + space for 4 blocks → pipe4
  ≥2 byte-positions remain + space for 2 blocks → pipe2
  otherwise                                     → single (post-L2 direct write)
This dispatches the best available variant for any byteCount and any
DMA-buffer-remaining state — bit-identical results in all paths because
each variant is just a tighter interleaving of the same underlying
wave8Transpose_16 dataflow.

### Test plan
- [x] Host bit-exactness: new wave8.cpp test case (500 random seeds × 4
      positions, byte-by-byte equality vs four sequential wave8Transpose_16)
- [ ] Host: `bash test wave8` skipped — pre-existing wave8_spi linker error
      on master (undefined `rgb_2_rgbw_colorimetric` from #2545) blocks the
      shared fastled.dll build; pipe4-specific test passes when compiled
      standalone. Unblock-once-#2545-link-broken.
- [x] Device (ESP32-P4 v1.3): boot bench harness times the SAME
      `wave8Transpose_16x4_pipe4` symbol now linked from libfastled and
      reports 6 823 µs/frame — exactly matches the bench-branch measurement
- [x] `bash lint --cpp` clean
- [ ] CI: full matrix (will run on this PR)

Refs #2548. Builds on #2553 (L2) and #2555 (pipe2), both already on master.
Combined chain: baseline 9 651 → 6 823 µs/frame = **+41.5 % encode speedup,
2 828 µs/frame saved**.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees merged commit 376a7ca into master May 30, 2026
6 of 7 checks passed
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

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: 3124938d-9ab7-4d66-98e0-45b3f3364f8e

📥 Commits

Reviewing files that changed from the base of the PR and between 4554723 and ff31bb5.

📒 Files selected for processing (5)
  • src/fl/channels/detail/wave8.hpp
  • src/fl/channels/wave8.cpp.hpp
  • src/fl/channels/wave8.h
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • tests/fl/channels/wave8.cpp

📝 Walkthrough

Walkthrough

The PR adds a fused 4-position Wave8 transpose optimization (wave8Transpose_16x4_pipe4) that transposes 16 lanes across 4 byte positions in a single operation, then integrates it into the PARLIO DMA buffer encoding path to reduce latency by batching transpositions, with validation via equivalence testing.

Changes

Wave8 16x4 Fused Transpose Optimization

Layer / File(s) Summary
Wave8 16x4 fused transpose declaration and implementation
src/fl/channels/wave8.h, src/fl/channels/wave8.cpp.hpp, src/fl/channels/detail/wave8.hpp
Public function wave8Transpose_16x4_pipe4 declared with documentation stating equivalence to four sequential wave8Transpose_16 calls. Public implementation expands four independent lane inputs and invokes the detail-level fused transpose. Detail function wave8_transpose_16x4_pipe4 iterates over 8 symbols, staging lane bytes and calling spread_transpose16_symbol four times per symbol to produce four transposed output blocks.
PARLIO DMA buffer hot-path integration
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
Wave8 16-lane clockless path in populateDmaBuffer() updated to prefer the new 4-position fused transpose when at least 4 remaining source bytes exist and the output buffer has capacity for 4 blocks. Prepares three additional lane snapshots from successive byte offsets and advances through 4 byte positions in one call, updating buffer indices accordingly.
Fused transpose correctness test
tests/fl/channels/wave8.cpp
New test wave8Transpose_16x4_pipe4 == four sequential wave8Transpose_16 (random) validates the fused operation against four independent sequential transpositions over 500 random rounds with byte-level equality assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2548: PR directly implements the L1/L3-style fused/tiling optimizations for Wave8 transpose operations called for in the umbrella perf(parlio/wave8) issue.
  • FastLED/FastLED#2524: Changes add a new fused 4-position Wave8 transpose and optimize the PARLIO encode path, directly addressing the Wave8 transpose optimization strategy discussed in the issue.
  • FastLED/FastLED#2529: New fused transpose reuses the same 8-symbol outer-loop and per-symbol transpose pattern that the issue proposes to unroll and optimize.

Possibly related PRs

  • FastLED/FastLED#2534: New wave8_transpose_16x4_pipe4 directly relies on and calls fl::detail::spread_transpose16_symbol introduced by PR #2534's LUT-based transpose helpers.
  • FastLED/FastLED#2519: Both PRs modify PARLIO ESP32 populateDmaBuffer() flow—fix(parlio): size DMA buffers from per-lane input bytes #2519 changes DMA buffer sizing/padding while main PR changes Wave8 fused transpose selection based on remaining bytes and buffer capacity.
  • FastLED/FastLED#2539: Main PR's fused transpose builds directly on the byte-indexed LUT and wave8_expand_byte infrastructure introduced in PR #2539, sharing the core wave8 transpose plumbing.

Poem

🐰 Four lanes dance in fused harmony,

Transposed together, bold and free,

The PARLIO path now runs so swift,

Batched bytes uplift the rhythm's gift,

Wave8 sings in parallel speed! 🎵

✨ 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 perf/parlio-pipe4-4pos

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 and usage tips.

zackees added a commit that referenced this pull request May 30, 2026
…ne, 4.4× faster than TX) (#2559)

The deepest macro optimization for Wave8 16-lane encoding on RV32 P4.
Bypasses the byte_lut entirely by exploiting an algebraic identity:

  For input byte B and lane L, output bit at (symbol s, pulse p):
    bit = M0_p XOR (input_bit_(7-s)_of_B AND D_p)

  where:
    M0_p = (W0 >> (7-p)) & 1   (bit-0 waveform's p-th pulse)
    M1_p = (W1 >> (7-p)) & 1   (bit-1 waveform's p-th pulse)
    D_p  = M0_p XOR M1_p

The bit-transpose of the 16 input lane bytes (giving the per-symbol column
bytes used by the OR-tree) is EXACTLY what spread_transpose16_symbol
computes when applied to the input bytes directly. So we call the existing
primitive ONCE per byte-position instead of 8 times (once per symbol).
The byte_lut expand stage is gone entirely — the algebraic identity makes
it redundant.

W0/W1 are extracted from byte_lut at the API boundary, so BF1 works for
ANY Wave8 chipset/timing — not WS2812B-specific.

Per-byte-position op count:
  Pre-L2 baseline:     8 spread transposes + 16 byte_lut loads + memcpy = ~752 ops
  L2 + pipe4 (#2557):  ~331 ops/position with ILP filling bubbles
  BF1 (this PR):       1 spread transpose + 128 AND/XOR/store = ~216 ops
  BF1 + pipe4:         ~216 ops × 4 with ILP fill = ~150 cyc effective

Measured on ESP32-P4 v1.3 (16-lane × 256 LEDs, 12 000 byte-positions):

  baseline (pre-session)     = 9 651 µs/frame  (1.00×)
  L2 (#2553)                 = 9 305 µs/frame  (+3.8 %)
  pipe2 (#2555)              = 7 633 µs/frame  (+26.6 %)
  pipe4 (#2557)              = 6 822 µs/frame  (+41.5 %)
  **BF1 single (this PR)**   = 4 465 µs/frame  (+116 %)
  **BF1 + pipe4 (this PR)**  = **1 754 µs/frame  (+450 %, 5.50×)**
  WS2812B 16-lane TX target  = 7 680 µs/frame

Encode is now 4.38× FASTER than the DMA drain. Started at -26% (under TX
budget); pipe4 got to +11%; BF1 + pipe4 gets to +337%. ISR-chunked
streaming becomes trivial; the CPU has massive idle time for other work.

### Engine dispatch (16-lane Wave8 path)
  ≥4 byte-positions remain → wave8Transpose_16x4_bf1_pipe4
  else                      → wave8Transpose_16_bf1
(pipe2 is no longer in the engine — BF1 single is already faster than the
pre-L2 baseline.)

### Test plan
- [x] Host bit-exactness: 3 new wave8.cpp test cases:
  - bf1 == byte_lut path (1 000 random seeds × 128 bytes, WS2812B Wave8)
  - bf1 == byte_lut path across 5 different chipset timings (200 seeds each)
  - bf1+pipe4 == 4 sequential single calls (500 seeds)
- [ ] Host: `bash test wave8` skipped — pre-existing wave8_spi linker error
  on master (undefined `rgb_2_rgbw_colorimetric` from #2545) blocks the
  shared fastled.dll build; BF1-specific cases compile cleanly.
- [x] Device (ESP32-P4 v1.3): boot bench captures the production
  wave8Transpose_16x4_bf1_pipe4 symbol linked from libfastled and reports
  1 754 µs/frame — exactly matches bench-branch measurement (1 757 µs).
- [x] `bash lint --cpp` clean

### Why none of the prior 9 prototypes found this
L1/L4/L7/fused_v2/pipe-N all preserved the byte_lut → 8 transpose chain and
optimized *within* that structure. BF1 replaces the structure: the algebraic
identity for Wave8 means the byte_lut is computing redundant information.
The fundamental observation — that 8 of the byte_lut's 256 entries are bit-
combinations of just 2 chipset constants W0/W1 — was hiding in plain sight
in buildWave8ExpansionLUT but never exploited at the inner-loop level.

Refs #2548. Builds on #2553 (L2), #2555 (pipe2), #2557 (pipe4) — all on master.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the perf/parlio-pipe4-4pos branch May 30, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant