Repository navigation
perf(parlio): #2548 pipe4 — 4-position pipelining (+41% vs baseline, 11% under TX) - #2557
Conversation
…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]>
|
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)
📝 WalkthroughWalkthroughThe PR adds a fused 4-position Wave8 transpose optimization ( ChangesWave8 16x4 Fused Transpose Optimization
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 |
…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
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-l1l2l3bench branch: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)
Bit-identical results across all three paths — each variant is just a tighter interleaving of the same underlying
wave8Transpose_16dataflow.Test plan
tests/fl/channels/wave8.cppcase (500 random seeds × 4 positions, byte-by-byte equality vs four sequentialwave8Transpose_16calls)bash test wave8skipped — pre-existing wave8_spi linker error on master (undefinedrgb_2_rgbw_colorimetricfrom feat(rgbw): sub-gamut white-extraction algorithm for chromaticity-accurate RGBW output #2545 / fix(rgbw): address CodeRabbit findings from #2552 #2554) blocks the sharedfastled.dllbuild. The pipe4-specific test passes when compiled in isolation. Unblock once the master link is fixed.wave8Transpose_16x4_pipe4symbol linked from productionlibfastledand reports 6 823 µs/frame — exactly matches the bench-branch measurementbash lint --cppcleanFiles
Combined chain (L2 + pipe2 + pipe4)
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
Tests