Skip to content

perf(wave): fastest unrolled-naive 8/16-lane transpose + equivalence tests - #2532

Merged
zackees merged 1 commit into
masterfrom
perf/wave-transpose-fastest
May 29, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/wave-transpose-fastest

Conversation

@zackees

@zackees zackees commented May 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Make the wave3/wave8 8-lane and 16-lane bit transposes use the empirically-fastest variant on ESP32-P4 (RV32): the fully-unrolled naive bit-by-bit transpose. No SIMD.
  • transpose_8: switched from the u32 Hacker's-Delight 8×8 primitive to the unrolled naive (~1.4× faster on RV32).
  • transpose_16: kept the unrolled naive (a two-pass "two 8×8 via u32" decomposition was implemented + bit-verified but ran 1.6× slower on RV32, so it was rejected).
  • Adds host unit tests asserting the production transposes are bit-identical to a ground-truth naive across edge + 400 random rounds (wave8 + wave3, 8- and 16-lane).

Why

Fair same-build A/B on ESP32-P4 (RV32), all FORCE_INLINE + O3, 768 calls/frame:

Lanes unrolled naive structured result
16 6595 µs two-pass (u32 8×8) 10524 µs naive 1.6×
8 3336 µs Hacker's-Delight u32 8×8 4680 µs naive 1.4×

The naive's bit-extracts are independent (compiler/pipeline parallelizes them); the HD/two-pass delta-swap is a latency-bound dependency chain that stalls on an in-order core. Same conclusion on x86. Investigation + data: #2524.

Test plan

  • bash test wave8 (known-answer + round-trip + new equivalence tests) — pass
  • bash test wave3 (new equivalence test) — pass
  • bash test parlio_driver (wave3 transpose coverage) — pass
  • bash lint --cpp — clean

Refs #2524

Summary by CodeRabbit

  • Refactor

    • Refactored internal signal processing channel implementations with revised computation approaches and optimized operation logic.
  • Tests

    • Added comprehensive test coverage for signal processing components, featuring randomized input validation scenarios and known-answer testing across hundreds of test configurations to verify implementation correctness.

Review Change Stack

…ivalence tests (#2524)

Goal: fastest possible wave3/wave8 8-lane and 16-lane bit transposes, no SIMD.

Empirically benchmarked candidates on the ESP32-P4 (RV32) with a fair same-build
A/B (all FORCE_INLINE + O3), 768 calls/frame:
  - 16-lane: unrolled naive 6595us  vs  two-pass (two 8x8 via u32) 10524us  -> naive 1.6x faster
  -  8-lane: unrolled naive 3336us  vs  Hacker's-Delight u32 8x8   4680us  -> naive 1.4x faster

So the fully-unrolled naive bit-by-bit transpose is fastest for BOTH on the
in-order RV32 (and on x86): the compiler schedules the independent shift/or ops
better than a latency-bound delta-swap chain. The two-pass 4->8->16
decomposition was implemented and proven bit-correct but regressed, so it was
not adopted (third time a structured bit-trick lost to the naive; cf u64 SWAR).

Changes:
  - wave8/wave3 transpose_8: switch from the u32 HD primitive to the unrolled
    naive (~1.4x faster on RV32).
  - wave8/wave3 transpose_16: keep the unrolled naive (the two-pass regressed).
  - Add host unit tests (tests/fl/channels/wave3.cpp + wave8.cpp) asserting the
    production transposes are bit-identical to a ground-truth naive across edge
    + random inputs.

Refs #2524
@zackees
zackees merged commit 5cc4967 into master May 29, 2026
5 of 7 checks passed
@coderabbitai

coderabbitai Bot commented May 29, 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: 1c9e931b-0559-4a9b-adf3-320841424c13

📥 Commits

Reviewing files that changed from the base of the PR and between ef12f45 and f64db15.

📒 Files selected for processing (4)
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.hpp
  • tests/fl/channels/wave3.cpp
  • tests/fl/channels/wave8.cpp

📝 Walkthrough

Walkthrough

Wave3 and Wave8 bit-matrix transpose functions were reimplemented from Hacker's Delight and SWAR-style approaches to fully-unrolled, macro-driven bit-by-bit construction. Output semantics remain unchanged. Comprehensive randomized test coverage validates correctness against naive reference implementations.

Changes

Wave Transpose Optimization

Layer / File(s) Summary
Wave3 transpose 8 and 16 reimplementation
src/fl/channels/detail/wave3.hpp
wave3_transpose_8 and wave3_transpose_16 replaced Hacker's Delight + isr::memcpy_32 and explicit bit extraction with fully-unrolled macro-driven construction using per-symbol lane byte captures and FL_W3_LO/FL_W3_HI macros for output pulse byte assembly.
Wave8 transpose 8 and 16 reimplementation
src/fl/channels/detail/wave8.hpp
wave8_transpose_8 moved from Hacker's Delight 8x8 matrix transpose with byte-order reversal to fully-unrolled FL_W8_PULSE(b) macro construction; wave8_transpose_16 shifted from explicit shift/or chains to FL_W8_LO(b)/FL_W8_HI(b) macro-based per-pulse byte derivation with sequential output writes.
Wave3 transpose validation tests
tests/fl/channels/wave3.cpp
New test file validating wave3_transpose_8 and wave3_transpose_16 against naive reference implementations across 400 deterministic randomized rounds of Wave3Byte[16] lane data with explicit edge-case patterns in early rounds.
Wave8 transpose validation tests
tests/fl/channels/wave8.cpp
Added randomized "known-answer" test for wave8_transpose_8 and wave8_transpose_16 using inline naive helpers to verify bit-identical outputs across 400 pseudo-random Wave8Byte input rounds.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Poem

🐰 Eight lanes transpose with grace and care,
No Hacker's Delight, just bits laid bare,
Macros dance where shifts once flew,
Sixteen pulses, crisp and true.
Tests confirm the path we take,
Each transpose pulse for pixel's sake! ✨

✨ 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/wave-transpose-fastest

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