Skip to content

feat(esp32-p4): PIE (xesppie) SIMD backend Tier-1 ops (#2536) - #2538

Merged
zackees merged 1 commit into
masterfrom
feat/esp32p4-pie-simd
May 29, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/esp32p4-pie-simd

Conversation

@zackees

@zackees zackees commented May 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements Phase 1 of #2536: an ESP32-P4 PIE (xesppie) backend for fl::simd. The revision-stable Tier-1 ops now route through PIE inline asm on the P4 (RISC-V), mirroring the existing Xtensa-S3 PIE backend (simd_xtensa.hpp); everything else keeps the scalar fallback. Public API unchanged.

PIE-backed ops (in src/platforms/esp/32/simd_riscv.hpp):

  • bitwise and/or/xor/andnot for u8x16 and u32x4 (esp.andq/orq/xorq/notq)
  • aligned load/store (esp.vld.128.ip / esp.vst.128.ip)

Gated on defined(__riscv_xesppie) && !defined(FL_IS_CLANG) (PIE asm is GCC-only).

Key fix: RVC register constraint

esp.vld.128.ip / esp.vst.128.ip require their base address register to be in the RVC compressed set (x8–x15). A plain "r" inline-asm constraint lets GCC pick an illegal register (a6/a7/t0/...), and the assembler rejects it:

Error: illegal operands `esp.vld.128.ip q1,a7,0'

The asm is centralized in pie_and_128/pie_or_128/pie_xor_128/pie_andnot_128/pie_copy_128, each pinning pointers to a0/a1/a2 via local register variables. Verified against the ESP32-P4 binutils (only s0,s1,a0–a5 accepted as the base register).

Validation

  • ✅ Assembles + links under the ESP32-P4 GCC toolchain (PlatformIO build).
  • ✅ Device boots and setup() completes with the AutoResearch PIE SIMD self-tests running (runSimdTests at boot) — the ops execute without faulting on a v1.3 chip.
  • ✅ Host scalar tests (tests/fl/math/simd.cpp) + bash lint pass.
  • ⏳ On-device bit-equivalence readout (bash autoresearch esp32p4 --simd) is pending the P4 serial/RPC infra fix: the testSimd RPC is currently blocked by a UART0-vs-USB-JTAG routing mismatch (CDC On Boot: 0), a transport-layer issue unrelated to the SIMD ops. fbuild also currently produces non-booting P4 images (use --no-fbuild / PlatformIO).

Notes

  • Tiers 2–4 from feat(esp32-p4): add PIE (xesppie) SIMD backend to fl::simd #2536 (min/max, saturating, scale/blend, float, mulhi) remain scalar — float and 32×32→64 have no PIE path; saturation/rounding are revision-variable.
  • Adds a CLAUDE.md note to route on-device tests through AutoResearch.ino rather than new example sketches.

Refs #2536 #2535

Summary by CodeRabbit

  • Documentation

    • Added hardware testing guidelines recommending standardized validation practices.
  • Performance

    • Accelerated SIMD bitwise and memory operations on ESP32-P4 through hardware-level optimizations.

Review Change Stack

Route the revision-stable load/store + bitwise ops in fl::simd through
ESP32-P4 PIE inline asm (esp.vld/vst.128.ip, esp.andq/orq/xorq/notq) on
RISC-V, mirroring the existing Xtensa-S3 PIE backend; everything else
keeps the scalar fallback. Gated on __riscv_xesppie && !FL_IS_CLANG.

esp.vld/vst.128.ip require their base address register to be in the RVC
compressed set (x8-x15), so pointers are pinned to a0/a1/a2 via local
register variables. A plain "r" constraint lets GCC pick an illegal
register (a6/a7/t0/...) and the assembler rejects it ("illegal
operands"); the asm is centralized in pie_*_128 primitives.

Also: CLAUDE.md note to route on-device tests through AutoResearch.ino
rather than new example sketches.

Validated: assembles under the ESP32-P4 GCC toolchain (PlatformIO build),
device boots and setup() completes with the PIE SIMD self-tests running
(ops execute without faulting on a v1.3 chip); host scalar tests + lint
pass. On-device bit-equivalence readout is pending the P4 serial/RPC
infra fix (testSimd RPC currently blocked by a UART0-vs-USB-JTAG routing
mismatch, unrelated to the SIMD ops).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 58512032-4da1-4f39-8ce3-40d409006eea

📥 Commits

Reviewing files that changed from the base of the PR and between 5ba7e6b and 051e7f8.

📒 Files selected for processing (2)
  • CLAUDE.md
  • src/platforms/esp/32/simd_riscv.hpp

📝 Walkthrough

Walkthrough

This PR adds test execution guidelines and implements PIE (packed in-element) acceleration for ESP32-P4 SIMD operations. A new compile-time feature gate enables 128-bit inline-assembly helper primitives that optimize bitwise and aligned copy operations for u8x16 and u32x4 SIMD types.

Changes

Test Execution Guideline

Layer / File(s) Summary
Test execution guideline
CLAUDE.md
Added workflow directive requiring on-device/hardware tests to reuse the AutoResearch sketch harness and discouraging new standalone .ino sketches due to CI matrix impact.

ESP32-P4 PIE SIMD Optimization

Layer / File(s) Summary
Platform detection and feature gating
src/platforms/esp/32/simd_riscv.hpp
Added platforms/is_platform.h header and introduced FL_RISCV_HAS_PIE compile-time macro to detect ESP32-P4 PIE support when __riscv_xesppie is defined and clang is not in use.
PIE 128-bit helper primitives
src/platforms/esp/32/simd_riscv.hpp
Implemented five inline-assembly helper functions (pie_and_128, pie_or_128, pie_xor_128, pie_andnot_128, pie_copy_128) for 128-bit bitwise and copy operations, conditionally compiled under FL_RISCV_HAS_PIE.
u8x16 bitwise operation integration
src/platforms/esp/32/simd_riscv.hpp
Updated simd_u8x16::and_u8_16, or_u8_16, xor_u8_16, and andnot_u8_16 to dispatch to PIE helpers when available, falling back to scalar per-byte loops otherwise.
u32x4 bitwise and load/store integration
src/platforms/esp/32/simd_riscv.hpp
Updated simd_u32x4::xor_u32_4, and_u32_4, or_u32_4, and aligned load/store pair to use corresponding PIE helpers with scalar fallback paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

  • #2535: Directly addresses ESP32-P4 PIE support by enumerating and implementing 128-bit PIE instructions (bitwise ops and aligned load/store) for PIE-accelerated SIMD kernels with compile-time gating and fallback logic.
  • #2536: Implements the same FL_RISCV_HAS_PIE gate and integrates the 128-bit PIE inline-assembly helpers into the same simd_u8x16 and simd_u32x4 bitwise/load-store code paths.
  • #2531: Related to ESP32-P4 PIE/SIMD support in the RISC-V implementation by adding PIE 128-bit primitives and switching SIMD operations to conditionally use them.

Poem

🐰 Whiskers twitch with glee,
ESP32-P4 now runs free,
PIE helpers dance in assembly verse,
SIMD speeds that tease and immerse!
Tests reuse, no sketches abound,
Optimization wisdom profound! 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding PIE (xesppie) SIMD backend support for ESP32-P4 Tier-1 operations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/esp32p4-pie-simd

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.

@zackees
zackees merged commit 1211c98 into master May 29, 2026
6 of 7 checks passed
@zackees
zackees deleted the feat/esp32p4-pie-simd branch May 29, 2026 19:50
zackees added a commit that referenced this pull request May 29, 2026
…2539)

* perf(wave8): byte-indexed expansion LUT (#2526) — 1.66x on ESP32-P4

Adds a 256x8 byte-indexed expansion LUT (Wave8ByteExpansionLut, 2 KB) and a
single-lookup expansion primitive (wave8_expand_byte) that replaces the two
nibble lookups in the hot PARLIO encode path. Same bit-exact output, ~half the
per-byte index work — which is the bottleneck because expansion is
instruction-issue-bound on the in-order RV32 core, not memory-bandwidth-bound.

Integration:
- New Wave8ByteExpansionLut type and buildWave8ByteExpansionLUT(nibble) builder.
- detail::wave8_expand_byte(b, byteLut, *out): one indexed 8-byte copy.
- Byte-LUT overloads of wave8Transpose_2/4/8/16; the PARLIO engine now holds
  mWave8ByteLut alongside mWave8Lut and routes all 5 hot expansion call sites
  through it (single-lane + 2/4/8/16-lane multi-lane).
- Host test buildWave8ByteExpansionLUT_matches_nibble_path verifies bit-exact
  equivalence across all 256 input bytes.

Measured on a real ESP32-P4 (revision v1.3) via a boot-time micro-bench in
AutoResearch.ino (output via esp_rom_printf -> USB-Serial-JTAG console to
sidestep the testSimd RPC's UART0 routing block; see #2536/#2538):

  iters=30000 (= 480,000 expansions per measurement)
  nibble_us=350170  byte_us=210419  batched_us=198682
  frame_equiv (768 byte-positions): nibble=8964us byte=5386us batched=5086us
  speedup vs nibble: byte=1.66x  batched=1.76x

At expansion ~55% of encode, the 1.66x expansion speedup predicts ~1.28x on
full encode_us — matching the prediction posted on #2526.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* refactor(autoresearch): wave8 expansion bench is RPC-driven + adds transpose16 timing

Addresses review feedback on PR #2539:
- Boot-time call removed by default; behind -DFL_BENCH_WAVE8_AT_BOOT=1 only.
- Registers wave8ExpandBenchmark RPC handler (returns JSON via the RPC server).
- Split into a pure measureWave8Expand() compute function + an optional
  esp_rom_printf print helper; the RPC path serializes the struct directly.
- Adds full per-byte-position production timing (wave8Transpose_16 with both
  LUTs), not just isolated expansion — this is what the engine actually pays
  in the hot loop x 768 byte-positions/frame.

Measured on ESP32-P4 v1.3 (boot-time bridge until #2541 routing fix):
  expand_only_us         nibble=350142  byte=210155  batched=206528
  transpose16_us         nibble=530115  byte=344128
  frame_equiv_us (768)   expand_nibble=8963  expand_byte=5379
                         t16_nibble=13570    t16_byte=8809
  speedup_x100           expand=166  batched=169  transpose16=154

So the **production per-byte-position hot loop is 1.54x faster** with the
byte-LUT (4761 us/frame saved), and **isolated expansion is 1.66x faster**.
Real encode-side measurement, not the prior 1.28x extrapolation.

Follow-ups filed: #2540 (FL_PRINT vs esp_rom_printf), #2541 (testSimd RPC
routing root cause).

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
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