Repository navigation
perf(parlio): #2548 pipe2 — 2-position pipelining (+26%, BEATS WS2812B TX) - #2555
Conversation
…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]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR introduces ChangesWave8 Fused Pipelined Transpose (16x2)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…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]>
…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]>
…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]>
…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]>
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 sequentialwave8Transpose_16calls; 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-positionwave8Transpose_16for the tail whenbyteCountis 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-l1l2l3boot-time bench harness (COM25 USB-Serial-JTAG):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
wave8Transpose_16x2_pipe2 == two sequential wave8Transpose_16runs 1 000 random seeds × 256 output bytes × 2 positions — byte-by-byte equality (tests/fl/channels/wave8.cpp).wave8Transpose_16x2_pipe2symbol now linked fromlibfastledand reports the same 7 633 µs/frame on the device.Test plan
bash test wave8— clean (new pipe2 case + all existing wave8Transpose_* cases pass)bash lint --cpp— cleanFiles
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
Chores