Repository navigation
perf(parlio): #2548 BF1 — chipset-aware direct encode (5.5× vs baseline, 4.4× faster than TX) - #2559
Conversation
…ne, 4.4× faster than TX)
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]>
|
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 two new chipset-aware BF1 (Bit Field 1) optimized Wave8 16-lane transposition functions that fuse expansion and transposition in a single pass, exposes them through public APIs, integrates them into the PARLIO encoder's Wave8 clockless path, and validates them with comprehensive equivalence tests. ChangesWave8 BF1 Optimized Transposition
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 |
…#2561) Adds `AutoResearchParlioStream::validateAtBoot()` — a self-contained boot-time test that exercises the engine's production ISR-chunked streaming path (`ParlioEngine` 3-buffer ring + `txDoneCallback` ISR + BF1 from #2559) and reports PASS/FAIL via `esp_rom_printf` to the USB-Serial-JTAG console (COM25 on the P4 dev board). Workload: 16-lane × 256-LED WS2812B (canonical bench config, forces the engine's 16-lane Wave8 branch → `wave8Transpose_16x4_bf1_pipe4`). 5 back-to- back `FastLED.show() + FastLED.wait()` cycles, each timed. Validated on real ESP32-P4 v1.3: BENCH_PARLIO_STREAM_VALIDATE PASS lanes=16 leds=256 iters=5 iter0=23530 iter1=16998 iter2=17000 iter3=16997 iter4=17001 steady_avg_us=16999 (WS2812B 16-lane TX=7680us) All 5 iterations completed within the 200ms timeout — 0 hangs, 0 stalls. The streaming engine + BF1 work correctly. (The ~17ms steady-state per show vs the 7.68ms TX floor is a separate optimization opportunity: each show() serializes the begin/wait/end + disable/re-enable cycle. The BF1+pipe4 encode itself is 1.75ms/frame as measured by the bench harness.) Bypasses the testSimd RPC routing (broken on COM25, #2541) so this works at boot without any host-side coordination. Opt-in via build flag: `-DFL_PARLIO_STREAM_VALIDATE_AT_BOOT=1` Refs #2548. Validates #2559 in production. Co-authored-by: Claude Opus 4.7 <[email protected]>
…e8 (#2568) Generalizes the 16-lane BF1 win from #2559 to all PARLIO Wave8 lane counts. Same algebraic identity (output_bit = M0_p XOR (input_bit AND D_p)), adapted to each lane count's output packing format: 16-lane: 8 symbols × 8 pulses × 2 bytes (low lanes, high lanes) ← #2559 8-lane: 8 symbols × 8 pulses × 1 byte (8 lanes per pulse) 4-lane: 8 symbols × 4 bytes (2 pulses/byte, 4 lanes/nibble) 2-lane: 8 symbols × 2 bytes (4 pulses/byte, 2 lanes bit-interleaved) Each kernel: 1. Pre-computes per-pulse D_p / M0_p masks from chipset constants W0/W1 (extracted from byte_lut[0x00/0xFF].symbols[0] at the API boundary). 2. Bit-transposes input lane bytes to per-symbol "column" bytes. For 16- and 8-lane, uses the existing `spread_transpose16_symbol` / `spread_transpose8_symbol` primitives. For 4-lane, uses spreadA/spreadB with shifted-OR across 4 lanes (8 ops). For 2-lane, direct bit extraction (16 ops — tiny workload). 3. Emits the output bytes using `output = M0_p_mask XOR (col AND D_p_mask)`, packed per the lane-count's output layout. ### Measured on ESP32-P4 v1.3 (256 LEDs/lane, WS2812B Wave8, 5 iters) lanes | total_us | show_us | wait_us | notes 2 | 9 994 | 2 559 | 7 434 | encode << TX, TX-bound 4 | 10 244 | 2 917 | 7 326 | encode << TX, TX-bound 8 | 12 243 | 4 701 | 7 541 | encode < TX, TX-bound 16 | 12 312 | 10 677 | 1 635 | eager-queue → TX overlaps with show() All 4 lane counts complete cleanly (completed=1, channels_ok=1, no hangs). For 2/4/8 lanes the frame is already TX-bound, so BF1's win is primarily **reduced CPU usage** (encode time drops ~5× per the 16-lane scaling) — freeing cycles for animation logic. For 16 lanes the win is both reduced CPU and reduced frame time (because encode was previously > TX). ### Engine dispatch `ParlioEngine::populateDmaBuffer` 2/4/8-lane Wave8 branches now call `wave8Transpose_{2,4,8}_bf1` instead of `wave8Transpose_{2,4,8}`. Bit- identical output for any Wave8 chipset/timing. ### Test plan - [x] Host bit-exactness: 1 000 random seeds × 5 timings for each of the 3 new BF1 kernels (= 15 000 inputs × 16/32/64 output bytes each), bit- for-bit equality vs the existing byte_lut path. Source in tests/fl/ channels/wave8.cpp. - [ ] Host `bash test wave8` skipped — pre-existing rgbw linker error on master (undefined `fl::rgb_2_rgbw_colorimetric` from #2545/#2554) blocks the shared fastled.dll build. BF1-specific cases compile cleanly. - [x] Device (ESP32-P4 v1.3): boot-time validation cycles each lane count through 5 back-to-back show() calls. All pass cleanly. - [x] `bash lint --cpp` clean. Refs #2548, #2559. Co-authored-by: Claude Opus 4.7 <[email protected]>
Summary
The deepest macro optimization yet for Wave8 16-lane PARLIO encoding on RV32 P4. Adds
wave8Transpose_16_bf1+wave8Transpose_16x4_bf1_pipe4to the public API and switches the engine's 16-lane Wave8 dispatch to use them.The insight
The byte_lut + spread-LUT transpose chain currently does:
byte → 8 symbol bytes → 8 spread-LUT transposes → 128 DMA bytes. But for Wave8 encoding, there's an algebraic identity hidden inbuildWave8ExpansionLUT:where W0/W1 are the bit-0/bit-1 waveform patterns, M0_p = (W0 >> (7-p)) & 1, D_p = M0_p XOR M1_p. The 256-entry byte_lut is encoding redundant information — every byte's expansion is just bit-wise selection between W0 and W1.
The bit-transpose of the 16 input bytes (giving the per-symbol column bytes) is exactly what
spread_transpose16_symbolcomputes when applied to the input bytes directly. So we call the existing primitive ONCE per byte-position instead of 8 times.W0/W1 are extracted from
byte_lut[0x00 / 0xFF].symbols[0]at the API boundary, so BF1 works for any Wave8 chipset/timing — not WS2812B-specific.Measured (ESP32-P4 v1.3, 16-lane × 256 LEDs, 12 000 byte-positions)
Captured live via the
perf/parlio-l1l2l3boot-time bench:Encode is now 4.4× FASTER than the DMA drain. Started this session 26 % over budget; ended 77 % under. ISR-chunked streaming is now trivial; the CPU has massive idle time for other work.
Engine dispatch (16-lane Wave8 path)
Simpler than the prior 3-way ladder — BF1 single is already 1.71× faster than pipe2, so pipe2 is no longer needed.
Test plan
tests/fl/channels/wave8.cpptest cases:bf1 == byte_lut path(1 000 random seeds × 128 bytes, WS2812B Wave8)bf1 == byte_lut across 5 chipset timings(200 seeds each — generalizes the proof)bf1+pipe4 == 4 sequential single calls(500 seeds × 4 positions × 128 bytes)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 BF1-specific cases compile cleanly.wave8Transpose_16x4_bf1_pipe4symbol linked fromlibfastledand reports 1 754 µs/frame — exactly matches bench-branch (1 757 µs).bash lint --cppcleanFiles
Why none of the prior 9 prototypes found this
L1 / L3 / L4-byte / L4-nibble / L7 / fused_v2 / pipe-N all preserved the
byte_lut → 8 transposechain and optimized within that structure. BF1 replaces the structure. The algebraic identity was hiding in plain sight inbuildWave8ExpansionLUT— the byte_lut is justfor each input bit, pick W0 or W1— but no prior variant exploited it at the inner-loop level.This is the orthogonal axis the user's
/goaldirective ("macro and micro opts to significantly reduce computation") asked for. Pipe-N filled pipeline bubbles (same instructions, fewer wasted cycles). BF1 removes instructions — going from ~752 ops per byte-position down to ~216, then pipe4 layers ILP on top.Refs #2548. Builds on #2553 (L2), #2555 (pipe2), #2557 (pipe4) — all already on master.
Session-total speed delta
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests