Repository navigation
perf(wave): spread-LUT bit transpose — ~2x transpose / ~1.24x encode on ESP32-P4 - #2534
Conversation
…P32-P4 (#2533) Replace the unrolled-naive wave8/wave3 8- and 16-lane bit transposes with a u32 "spread LUT": acc = OR over 8 lanes of spread(laneByte) << lane, where spread() pre-positions a byte's pulse bits into 8 separate bytes via a 16-entry literal table (C++11-valid, ~64 B, cache-resident). All native u32, independent ops, no dependency chain / no emulated u64 — the shape the in-order RV32 schedules best. Measured on ESP32-P4 (RV32), bit-exact vs naive (host equivalence tests + on-device mismatch=0): isolated transpose: 16-lane 6649->3353 us (1.98x), 8-lane 3356->1764 us (1.90x) full encode_us: 16-lane 14611->11744 us (1.24x), 8-lane 7208->5879 us (1.23x) Beats every prior candidate (u64 SWAR, Hacker's-Delight u32, two-pass, u64-pack) which all lost to the naive; the spread-LUT is the first to beat it. Shared helper: src/fl/channels/detail/bit_spread_lut.hpp. Refs #2533
|
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 (3)
📝 WalkthroughWalkthroughThis PR introduces a shared LUT-based bit-transpose primitive module and refactors Wave3 and Wave8 channel implementations to use it, replacing previous fully-unrolled bitwise macro implementations with calls to compact spread-and-extract helpers backed by a 16-entry nibble lookup table. ChangesBit-matrix transpose refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes The refactoring touches critical bit-manipulation transpose logic across three files, requires understanding the nibble-to-pulse LUT mapping and the 32-bit shift-based byte extraction, and involves verification that the new compact implementations produce identical output to the previous unrolled versions across multiple lane widths and channels. 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 |
Summary
Replace the unrolled-naive wave8/wave3 8- and 16-lane bit transposes with a u32 spread-LUT:
acc = OR over 8 lanes of spread(laneByte) << lane, wherespread()pre-positions a byte's pulse bits into 8 separate bytes via a 16-entry literal table. All native u32, independent ops, no dependency chain / no emulated u64 — the op shape the in-order RV32 schedules best. New shared helper:src/fl/channels/detail/bit_spread_lut.hpp.Measured on a real ESP32-P4 (RV32), bit-exact vs naive
encode_us(256 LEDs)Correctness: bit-identical to the naive across the host equivalence + known-answer + round-trip tests, and on-device
mismatch=0. The naive was the proven-correct production transpose, so the WS2812 output is byte-for-byte unchanged.Why this beats everything else
Every prior candidate lost to the naive on the in-order P4 — u64 SWAR (0.41×), Hacker's-Delight u32 8×8 (0.71×), two-pass (0.63×), u64-pack template. The spread-LUT is the first to beat the naive because it's independent table-lookup + shift + OR-reduce (no dependency chain). Full investigation + on-device benchmark harness (
bash autoresearch --transpose 16) in #2533.Test plan
bash test wave8/bash test wave3/bash test parlio_driver(bit-exact vs naive) — passbash lint --cpp— cleanmeasureParlioencode_us before/after (P4)Refs #2533
Summary by CodeRabbit