Repository navigation
Description
Summary
Add an ESP32-P4 PIE (xesppie) backend to fl::simd. The P4 has the same 128-bit DSP/SIMD coprocessor lineage as the ESP32-S3, but today P4 falls through to the scalar simd_riscv.hpp, leaving its vector unit unused. We already ship a working Xtensa PIE backend for the S3 (src/platforms/esp/32/simd_xtensa.hpp, ee.* mnemonics) — this issue is to mirror that backend for the P4's RISC-V xesppie ISA (esp.* mnemonics, GCC-only).
This is orthogonal to #2535: the PARLIO bit-transpose does not call fl::simd, and PIE has no movemask, so this integration does not accelerate the transpose. It targets the existing fl::simd consumers (blur, scaling) instead.
Current state
- Dispatch:
src/platforms/simd.h->src/platforms/esp/32/simd_esp32.hpp-> for__riscv+FL_IS_ESP_32P4includessimd_riscv.hpp, which is scalar loops (FASTLED_ESP32_RISCV_HAS_RVV 0, "RVV-ready" placeholders). P4 gets zero SIMD acceleration. - Precedent:
simd_xtensa.hppgates onFL_XTENSA_HAS_PIEand implements a subset of ops via PIE inline asm, scalar-fallback for the rest. This is the exact template — the P4 backend differs only in assembler dialect (esp.vsee.), the GCC-only constraint, and revision sensitivity. - Type model is fixed: 128-bit registers exposed as
simd_u8x16/simd_u16x8/simd_u32x4/simd_f32x4(+ 256-bitu8x32/u16x16composed of two 128-bit halves). Public API does not change. - On-device probe (Reverse-engineer ESP32-P4 PIE (xesppie) instruction set by experimentation (for a PIE transpose) #2535) on the attached P4 (eco2):
esp.vld.128.ip/esp.vst.128.ip/esp.andq/orq/xorq/notq/esp.movi.32.q/esp.zero.qassemble and execute (pie_smoke=1).
What PIE can express — operation mapping
Tiered by confidence. Tier 1 is probed-working on the attached P4; Tiers 2-3 exist in the S3 PIE backend and need on-device confirmation on P4; Tier 4 has no PIE hardware.
Tier 1 — confirmed PIE on this P4 (LCD, revision-stable)
fl::simd op |
PIE instruction(s) |
|---|---|
load_u8_16 / load_u32_4 / load_f32_4 (+aligned) |
esp.vld.128.ip |
store_u8_16 / store_u32_4 / store_f32_4 (+aligned) |
esp.vst.128.ip |
and_u8_16 / and_u32_4 |
esp.andq |
or_u8_16 / or_u32_4 |
esp.orq |
xor_u8_16 / xor_u32_4 |
esp.xorq |
andnot_u8_16 |
esp.notq + esp.andq |
set1_u32_4 / set1_u16_8 / set1_f32_4 |
esp.movi.32.q (or broadcast-load) |
Tier 2 — in S3 PIE backend; verify mnemonic/semantics on P4
fl::simd op |
S3 used | P4 risk |
|---|---|---|
min_u8_16 / max_u8_16 |
ee.vmin.u8 / ee.vmax.u8 |
mnemonic likely esp.vmin.u8; unprobed |
srl_u32_4 / sll_u32_4 |
scalar on S3 | P4 has esp.vsr.u32 / esp.vsl.32 (per-32-lane); note fl::simd shifts are immediate, PIE is by-amount -> set amount via movi.32.q |
add_u16_8 / mullo_u16_8 |
scalar on S3 | P4 has 16-bit SIMD multiply; expressible but unverified |
Tier 3 — saturation / rounding / QACC — revision-variable (v3.x changed these)
fl::simd op |
S3 used | P4 risk |
|---|---|---|
add_sat_u8_16 / sub_sat_u8_16 |
ee.vadds.u8 / ee.vsubs.u8 |
saturating-arith semantics changed in PIE v3.x — high variant risk |
scale_u8_16 |
ee.vmulas.u8.qacc + ee.srcmb.s8.qacc |
QACC accumulator + SAR rounding — highest variant risk |
blend_u8_16 / avg_round_u8_16 |
scalar on S3 | depends on the same MAC/round path |
Tier 4 — NOT expressible by PIE (always scalar)
- All
f32x4ops (add/sub/mul/div/sqrt/min/max_f32_4) — PIE is integer DSP; P4 float is the scalar FPU, not SIMD. (S3 backend already keeps these scalar.) mulhi_i32_4/mulhi_u32_4/mulhi_su32_4/mulhi32_i32_4(32x32->64 hi, Q16.16/Q31) — PIE MAC is 16-bit-oriented; no 32x32->64 path. (S3 keeps these scalar.)min_i32_4/max_i32_4— kept scalar on S3.- Comparisons / movemask —
fl::simdexposes none, and PIE has no movemask (see Reverse-engineer ESP32-P4 PIE (xesppie) instruction set by experimentation (for a PIE transpose) #2535).
Integration steps
- New backend file
src/platforms/esp/32/simd_riscv_pie.hpp(mirrorsimd_xtensa.hpp):- Same
simd_u8x16/u16x8/u32x4/f32x4FL_ALIGNAS(16)structs + 256-bit composition. - Per-op dual path:
#if FL_RISCV_HAS_PIE->esp.*inline asm;#else-> scalar (identical tosimd_noop.hpp). - Implement Tier 1 first; Tier 2/3 behind their own guards as they're verified.
- Same
- Feature gate at top of that file:
(PIE asm is GCC-only;
#if defined(__riscv_xesppie) && !defined(__clang__) # define FL_RISCV_HAS_PIE 1 #else # define FL_RISCV_HAS_PIE 0 // clang/host -> scalar #endif
SOC_CPU_HAS_PIEis a secondary signal — see Reverse-engineer ESP32-P4 PIE (xesppie) instruction set by experimentation (for a PIE transpose) #2535.) - Dispatch in
simd_riscv.hpp(orsimd_esp32.hpp): forFL_IS_ESP_32P4, includesimd_riscv_pie.hppwhenFL_RISCV_HAS_PIE, else keep scalar. Leave C2/C3/C5/C6/H2 on scalar (no PIE). - Register/clobber translation from the S3 asm:
ee.->esp., keepq0..q7clobbers +"memory". The QACC/SAR sequences (Tier 3) need P4-specific accumulator mnemonics — port last. FL_IRAMon all ops (already the convention) so they're safe in ISR/DMA paths.
Variants to be mindful of
- Compiler: PIE asm only compiles under GCC (xtensa/riscv esp toolchain). clang + host build -> scalar. Hard-gate with
!defined(__clang__). - Silicon revision: only the Tier-1 LCD (load/store/bitwise/broadcast) is guaranteed across P4 revisions. PIE v3.x changed saturation/rounding ops (Tier 3) — those may trap/differ on some silicon. Attached chip is eco2. Either keep Tier 3 scalar or guard behind a verified-revision macro. (esphome reported "Illegal instruction" on a v1.3 PIE sample — real risk.)
- Float: never route
f32x4through PIE; it's scalar-FPU only. - Shift semantics:
fl::simdshifts take a compile-time immediate; PIE shifts are by register amount and per-32-bit-lane. Bridging needs amovi.32.qof the amount — measure whether it beats scalar before shipping. - 256-bit types (
u8x32/u16x16) compose two 128-bit halves -> they inherit PIE automatically once the 128-bit ops are PIE; no extra work. - Other RISC-V ESP32s (C-series, H2) have no PIE — must stay scalar; don't widen the gate.
Testing strategy
- Host gap: the 49 cross-backend tests in
tests/fl/math/simd.cppvalidate scalar/SSE/NEON on the host, but the PIE path never compiles on host (x86/clang). So host tests guarantee the scalar fallback only. - On-device equivalence: add a P4 RPC (extend
examples/AutoResearch/AutoResearchRemote.cpp, run viabash autoresearch esp32p4) that, for every PIE-backed op, asserts PIE result == scalar result across randomized inputs (mismatch must be 0), plus an A/B microsecond timing. Gate any op's PIE path on passing this on the actual target before enabling by default. - Illegal-instruction safety: keep the conservative gate; a failed op should fall back to scalar, not trap.
Realistic benefit (blast radius)
fl::simd consumers: blur (src/fl/gfx/blur.cpp.hpp — u8 load/scale/avg -> real PIE win), noise/animartrix (f32-heavy -> no PIE benefit, Tier 4), fixed-point (s16x16x4/s0x32x4 via mulhi_* -> no PIE benefit, Tier 4). Net: the clear beneficiary is the u8 graphics path (blur/scale/blend); the float and 32-bit-fixed-point consumers stay scalar. Worth scoping Phase 1 to the u8x16 bitwise + load/store + scale ops that blur actually uses.
Recommended scope (phased)
- Phase 1: Tier 1 ops (load/store, bitwise, broadcast) + on-device equivalence RPC. Low risk, immediately exercised by blur.
- Phase 2: Tier 2 (
min/max_u8, u16 add/mul, shifts) after on-device verification. - Phase 3: Tier 3 (saturating add/sub,
scale/blend) only with a revision guard + device equivalence — or leave scalar if the variance is unmanageable.
Activity
feat(esp32-p4): add PIE (xesppie) SIMD backend Tier-1 ops (#2536) (#2538
zackees commentedon May 29, 2026
Phase 1 landed via #2538: the ESP32-P4 PIE (xesppie) backend now exists in
simd_riscv.hppfor the revision-stable Tier-1 ops (aligned load/store + bitwise and/or/xor/andnot, u8x16+u32x4), gated on__riscv_xesppie && !FL_IS_CLANG. Closing as the backend is in place. Remaining optional follow-ups (not blocking): Tier-2/3 ops (min/max, saturating, scale/blend) and the on-device bit-equivalence readout via--simd, which is gated on the P4 serial/RPC infra fix (testSimd RPC currently blocked by a UART0-vs-USB-JTAG routing mismatch). Note: PIE does NOT accelerate the LED transpose (see #2535) — it targets fl::simd consumers like blur/scale.perf(wave8): byte-indexed expansion LUT (#2526) — 1.66x on ESP32-P4 (#…