Skip to content

perf(parlio): #2548 extend BF1 chipset-aware encode to 2/4/8-lane Wave8 - #2568

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-bf1-2-4-8-lane
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-bf1-2-4-8-lane

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Generalizes the 16-lane BF1 win from #2559 to all PARLIO Wave8 lane counts (2, 4, 8, 16). Same algebraic identity:

output_bit(s, p, lane) = M0_p XOR (input_bit_(7-s)_of_lane AND D_p)

…adapted to each lane count's output packing format.

Output packing per lane count

lanes output per symbol layout
16 16 bytes 8 pulses × 2 bytes (low lanes 0-7, high lanes 8-15) (#2559)
8 8 bytes 8 pulses × 1 byte (8 lanes per pulse byte) (this PR)
4 4 bytes 2 pulses/byte (4 lanes in each nibble) (this PR)
2 2 bytes 4 pulses/byte (lane 1 even bits, lane 0 odd bits) (this PR)

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 — chipset-agnostic).
  2. Bit-transposes input lane bytes to per-symbol "column" bytes:
    • 16, 8 lane: reuses existing spread_transpose{16,8}_symbol primitives (single call per byte-position).
    • 4 lane: uses spreadA/spreadB with shifted-OR across 4 lanes (8 ops total).
    • 2 lane: direct bit extraction (16 ops — tiny workload).
  3. Emits the output bytes via 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 observations
2 9 994 2 559 7 434 encode ≪ TX → frame TX-bound; BF1 = CPU cycles saved
4 10 244 2 917 7 326 same
8 12 243 4 701 7 541 encode < TX → frame TX-bound; BF1 = CPU cycles saved
16 12 312 10 677 1 635 eager-queue → TX overlaps with show() (from #2565)

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.

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

  • 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 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. BF1-specific cases compile cleanly.
  • Device (ESP32-P4 v1.3): boot-time validation cycles each lane count through 5 back-to-back show() calls. All pass cleanly with the numbers shown above.
  • bash lint --cpp clean.

Files

 src/fl/channels/detail/wave8.hpp                                +110
 src/fl/channels/wave8.h                                         +18
 src/fl/channels/wave8.cpp.hpp                                   +27
 src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp       +9 / −6
 tests/fl/channels/wave8.cpp                                     +104

Refs #2548, #2559.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Enhanced Wave8 data transposition with BF1 chipset variant support, optimizing DMA buffer encoding for improved performance across multiple lane configurations.
  • Tests

    • Added comprehensive unit tests validating BF1 transposition implementations, including chipset timing compatibility checks across multiple configurations.

Review Change Stack

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]>
@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: 7835ca41-4544-489e-9188-2b08d295641d

📥 Commits

Reviewing files that changed from the base of the PR and between 49f46c9 and 7a3ce18.

📒 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 chipset-aware BF1 transposition algorithms for Wave8 LED encoding across three lane widths (8, 4, 2), wraps them in public entry points that extract timing constants from a lookup table, integrates them into the ParlIO DMA hot path to replace existing transpose calls, and validates functional equivalence with randomized and multi-timing unit tests.

Changes

Wave8 BF1 Transposition

Layer / File(s) Summary
Detail BF1 transposition implementations
src/fl/channels/detail/wave8.hpp
wave8_transpose_8_bf1, wave8_transpose_4_bf1, and wave8_transpose_2_bf1 compute BF1-algebraic masked column transposes for their respective lane widths, using precomputed masks and bit-spread helpers to generate DMA-formatted output bytes.
Public API wrappers and LUT dispatch
src/fl/channels/wave8.h, src/fl/channels/wave8.cpp.hpp
Public wave8Transpose_{8,4,2}_bf1 functions extract chipset constants W0 and W1 from the provided Wave8ByteExpansionLut at fixed nibble indices and forward the lanes and constants to the corresponding detail implementation.
Hot-path integration and equivalence validation
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp, tests/fl/channels/wave8.cpp
ParlIO's populateDmaBuffer() now dispatches to BF1 variants for Wave8 DMA encoding at data widths 2, 4, and 8. Unit tests assert byte-for-byte equivalence of BF1 outputs to non-BF1 implementations across 1000 randomized lane inputs per lane width and multiple chipset timing configurations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Possibly related issues

  • FastLED/FastLED#2548: Modifies the same Wave8 transpose implementations and parlio_engine hot path that this PR updates with BF1-specific variants.
  • FastLED/FastLED#2523: Proposes generalizing Wave8 transpose to a WaveN framework; this PR's BF1 additions directly modify the Wave8 transpose path.
  • FastLED/FastLED#2522: Investigates performance of the populateDmaBuffer() hot path that this PR updates with new BF1 dispatch.

Possibly related PRs

  • FastLED/FastLED#2553: Modifies the same ParlioEngine::populateDmaBuffer() Wave8 encode dispatch sites (mDataWidth 2, 4, 8) where this PR swaps in BF1 variants.
  • FastLED/FastLED#2534: Introduces the spread_transpose8_symbol and spread helper utilities that this PR's BF1 detail implementations depend on.

Poem

🐰 Eight lanes, four lanes, two lanes too,
BF1 transposes swift and true,
Chipset-wise with masks so bright,
DMA bytes packed fast and tight! ✨

✨ 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-bf1-2-4-8-lane

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.

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