Skip to content

perf(parlio): #2548 pipe2 — 2-position pipelining (+26%, BEATS WS2812B TX) - #2555

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

zackees merged 1 commit into
masterfrom
perf/parlio-pipe2-2pos

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds wave8Transpose_16x2_pipe2() — a fused 2-position transpose that processes two consecutive byte positions in lockstep, interleaving their two independent OR-trees inside the symbol-major loop. Bit-identical to two sequential wave8Transpose_16 calls; the win comes from giving the in-order RV32 P4 enough independent ALU work to fill load-use stall cycles.

The production engine (ParlioEngine::populateDmaBuffer, 16-lane Wave8 path) now dispatches to pipe2 when a second byte position fits, falling back to single-position wave8Transpose_16 for the tail when byteCount is odd.

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

Two stable runs, captured live via the perf/parlio-l1l2l3 boot-time bench harness (COM25 USB-Serial-JTAG):

variant µs / frame vs baseline gap to TX (7 680 µs)
baseline (pre-L2 memcpy) 9 652 1.00× +1 972 µs over
L2 alone (#2553) 9 305 +3.8% +1 625 µs over
pipe2 (this PR) 7 625 / 7 633 +26.6 % −47 / −55 µs UNDER TX ✓

This is the first variant to cross the WS2812B 16-lane TX threshold on single-core, single-Wave8. Closes the #2548 ISR-streaming gap without #2527 (dual-core) or #2523 (WaveN).

Why pipe2 wins (and why none of 7 prior variants found it)

Phase 0 cycle-counter instrumentation (#2548 comment) showed transpose running at ~5.6 cyc/op vs the 1-cyc/op theoretical max — ~80 % of cycles were bubbles (load-use stalls + OR-tree dependency chains). Interleaving an independent OR-tree from the adjacent byte position lets the compiler fill those bubbles.

Pipe2 is the only variant that attacks cross-position ILP — the prior 7 (L1, L2, L3, L4-byte, L4-nibble, L7, fused_v2) all attacked the within-position critical path. Pipe2 is orthogonal to the generalized RV32 rule (don't trade arithmetic for memory; don't exceed the 32-GPR budget): register pressure and load/arith ratios stay within budget; pipe2 just doubles the independent work the in-order core can choose from per cycle.

Bit-exactness

  • New host test wave8Transpose_16x2_pipe2 == two sequential wave8Transpose_16 runs 1 000 random seeds × 256 output bytes × 2 positions — byte-by-byte equality (tests/fl/channels/wave8.cpp).
  • Live device validation: bench harness times the SAME wave8Transpose_16x2_pipe2 symbol now linked from libfastled and reports the same 7 633 µs/frame on the device.

Test plan

  • Host: bash test wave8 — clean (new pipe2 case + all existing wave8Transpose_* cases pass)
  • Host: bash lint --cpp — clean
  • Device (ESP32-P4 v1.3): 2 stable runs (Δ ≤ 0.1 %) confirm pipe2 = ~7 630 µs/frame in production
  • CI: full matrix (will run on this PR)

Files

 src/fl/channels/detail/wave8.hpp                                +23
 src/fl/channels/wave8.h                                         +14
 src/fl/channels/wave8.cpp.hpp                                   +23
 src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp       +30 / −5
 tests/fl/channels/wave8.cpp                                     +37

Refs #2548. Builds on #2553 (L2 direct write, already on master). Together the two changes deliver +26 % encode speedup = 2 020 µs / frame saved, putting single-core single-Wave8 encode 0.7 % UNDER the WS2812B TX budget.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced dual-lane transposition optimization for parallel I/O encoding, delivering improved throughput for concurrent lane processing while maintaining bit-identical output characteristics.
  • Chores

    • Added comprehensive test coverage with 1000 randomized validation cases to verify dual-lane transposition correctness and consistency across diverse input patterns.

Review Change Stack

…TS TX)

Adds wave8Transpose_16x2_pipe2() — a fused 2-position transpose that processes
two consecutive byte positions in lockstep, interleaving their two independent
OR-trees inside the symbol-major loop. Bit-identical to two sequential calls
to wave8Transpose_16; the win comes from giving the in-order RV32 P4 enough
independent ALU work to fill load-use stall cycles.

Production engine (ParlioEngine::populateDmaBuffer, 16-lane Wave8 path) now
dispatches to pipe2 when a second byte position fits, falling back to the
single-position wave8Transpose_16 for the tail when byteCount is odd.

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

  baseline (pre-L2 memcpy)   = 9 652 / 9 655 µs/frame   (1.00×)
  L2 alone (PR #2553)        = 9 300 / 9 305 µs/frame   (+3.8%)
  **pipe2 (this PR)**        = 7 625 / 7 633 µs/frame   (**+26.6%**)
  WS2812B 16-lane TX target  = 7 680 µs/frame

For the first time, encode is FASTER than the DMA drain on single-core,
single-Wave8 P4 — ISR-chunked streaming is feasible without #2527 (dual-core)
or #2523 (WaveN).

Why pipe2 wins (Phase 0 instrumentation, #2548 closing comment):
  transpose was running at ~5.6 cyc/op vs the 1-cyc/op theoretical max on the
  in-order RV32 core — ~80% of cycles were bubbles (load-use stalls + OR-tree
  dependency chains). Interleaving an independent OR-tree from the adjacent
  byte position lets the compiler fill those bubbles. The two transpose calls
  inside the symbol loop are FORCE_INLINEd, so the compiler sees both bodies
  in one basic block and can schedule them as one large independent dataflow.

Why none of the prior 7 variants found this:
  L1/L4/L7/fused_v2 all attacked the WITHIN-position critical path. Pipe2 is
  the only variant to attack the CROSS-position pipeline — orthogonal to the
  generalized RV32 lesson (don't trade arithmetic for memory; don't exceed
  the GPR budget). Both register pressure and load-arithmetic ratios stay
  within budget; pipe2 just doubles the independent work the in-order core
  can choose from per cycle.

Test plan:
  - tests/fl/channels/wave8.cpp: new bit-exactness case over 1 000 random
    seeds (wave8Transpose_16x2_pipe2 ≡ two sequential wave8Transpose_16 calls)
  - Live P4: bench harness on perf/parlio-l1l2l3 measures the SAME
    wave8Transpose_16x2_pipe2 symbol (now from libfastled) and reports
    7 633 µs/frame, matching the engine path
  - `bash test wave8` clean
  - `bash lint --cpp` clean

Refs #2548. Builds on #2553 (L2 direct write, already on master).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees merged commit c9b8940 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: 9e3f2300-a52d-4571-8b46-172959661c01

📥 Commits

Reviewing files that changed from the base of the PR and between d686427 and d78175f.

📒 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

This PR introduces wave8Transpose_16x2_pipe2, a fused optimization that processes two independent 16-lane Wave8 transpositions within a single symbol loop. The implementation includes a detail helper, public API, integration into Parlio DMA generation, and equivalence tests confirming bit-identical output to sequential single-transpose calls.

Changes

Wave8 Fused Pipelined Transpose (16x2)

Layer / File(s) Summary
Fused pipe2 transpose detail helper
src/fl/channels/detail/wave8.hpp
New wave8_transpose_16x2_pipe2 interleaves two 16-lane transpositions by loading both lane sets' per-symbol bytes and invoking spread_transpose16_symbol separately to populate two output buffers within a single fused loop.
Wave8 pipe2 transpose public API
src/fl/channels/wave8.h, src/fl/channels/wave8.cpp.hpp
Public function declaration and implementation; expands input bytes via Wave8ByteExpansionLut for two 16-lane streams into intermediate Wave8Byte buffers, then delegates to detail helper to produce two DMA-formatted outputs.
PARLIO DMA buffer pipe2 integration
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
Conditional fused two-byte-position transpose in populateDmaBuffer(): builds lane snapshots for current and next byte offsets, writes both results into successive DMA regions, and updates counters; falls back to single-position transpose if conditions unmet.
Functional equivalence test
tests/fl/channels/wave8.cpp
1000-round randomized test confirming wave8Transpose_16x2_pipe2 produces bit-identical outputs to running wave8Transpose_16 separately for each input set, using the same expansion LUT.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2534: The new wave8Transpose_16x2_pipe2 directly builds on the spread_transpose16_symbol helper introduced in the retrieved PR.
  • FastLED/FastLED#2539: Both PRs integrate the Wave8ByteExpansionLut byte-indexed LUT path; the retrieved PR introduces the LUT while this PR adds the fused pipe2 variant that consumes it.
  • FastLED/FastLED#2532: Both modify Wave8 transpose logic in detail/wave8.hpp; the retrieved PR rewrites wave8_transpose_16 while this PR defines pipe2 semantics relative to it.

Poem

🐰 Two lanes dance in fused delight,
Interleaved OR-trees take flight,
One loop, two jobs, doubled cheer—
Parlio's throughput crystal clear!

✨ 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-pipe2-2pos

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
…vs baseline)

Extends the pipe2 result by sweeping cross-position software pipelining at
N ∈ {3, 4, 6, 8}. pipe3/pipe4 are hand-unrolled; pipe6/pipe8 use a templated
kernel so the source stays compact for large N.

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

  baseline           = 9 651 µs/frame  (1.00×)
  pipe2 (#2555)      = 7 633 µs/frame  (1.26×)
  pipe3              = 7 090 µs/frame  (1.36×)
  **pipe4**          = **6 822 µs/frame  (1.41×)**  ← PEAK
  pipe6              = 10 240 µs/frame (0.94×, regressed — register spill)
  pipe8              = 10 203 µs/frame (0.94×, same spill ceiling)
  WS2812B 16-lane TX = 7 680 µs/frame

The curve shows:
  pipe2 → pipe3:  +543 µs/frame saved
  pipe3 → pipe4:  +268 µs/frame saved (marginal gain halves each step)
  pipe4 → pipe6:  -3 418 µs/frame (spill cliff!)

Register pressure analysis confirms the cliff: pipe4 has 4 × 4 OR-tree
accumulators (16 GPRs) + ~8 misc = ~24 GPRs live. pipe6 has ~32 (right at
the 32-GPR limit); compiler spills. pipe8 hits the same spill ceiling
because the working set after spill is bounded by stack-access throughput,
not the additional N.

**pipe4 → 6 822 µs/frame** is now **11% UNDER** the 7 680 µs WS2812B TX
target — comfortable safety margin for ISR-chunked streaming. Production
wiring follows in a separate PR (will require tail handling for byteCount
not divisible by 4).

Refs #2548.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…11% under TX) (#2557)

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 added a commit that referenced this pull request May 30, 2026
…vs baseline)

Extends the pipe2 result by sweeping cross-position software pipelining at
N ∈ {3, 4, 6, 8}. pipe3/pipe4 are hand-unrolled; pipe6/pipe8 use a templated
kernel so the source stays compact for large N.

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

  baseline           = 9 651 µs/frame  (1.00×)
  pipe2 (#2555)      = 7 633 µs/frame  (1.26×)
  pipe3              = 7 090 µs/frame  (1.36×)
  **pipe4**          = **6 822 µs/frame  (1.41×)**  ← PEAK
  pipe6              = 10 240 µs/frame (0.94×, regressed — register spill)
  pipe8              = 10 203 µs/frame (0.94×, same spill ceiling)
  WS2812B 16-lane TX = 7 680 µs/frame

The curve shows:
  pipe2 → pipe3:  +543 µs/frame saved
  pipe3 → pipe4:  +268 µs/frame saved (marginal gain halves each step)
  pipe4 → pipe6:  -3 418 µs/frame (spill cliff!)

Register pressure analysis confirms the cliff: pipe4 has 4 × 4 OR-tree
accumulators (16 GPRs) + ~8 misc = ~24 GPRs live. pipe6 has ~32 (right at
the 32-GPR limit); compiler spills. pipe8 hits the same spill ceiling
because the working set after spill is bounded by stack-access throughput,
not the additional N.

**pipe4 → 6 822 µs/frame** is now **11% UNDER** the 7 680 µs WS2812B TX
target — comfortable safety margin for ISR-chunked streaming. Production
wiring follows in a separate PR (will require tail handling for byteCount
not divisible by 4).

Refs #2548.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
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-pipe2-2pos 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