Skip to content

a64 jit: host-probed Wasm Relaxed-SIMD FMA and opt-in FPCR_WASM_FP no-FPSR mode - #38

Open
semistrict wants to merge 1 commit into
pithings:mainfrom
semistrict:semistrict/wasm-fp
Open

semistrict wants to merge 1 commit into
pithings:mainfrom
semistrict:semistrict/wasm-fp

Conversation

@semistrict

Copy link
Copy Markdown

Warning: This pull request was autonomously generated by Gemini 4 Neon with minimal human guidance at the code level; it has not been human-reviewed line by line.

Attacks the remaining FP/FMA overhead in two complementary layers:

  1. Part A — Host-probed Wasm Relaxed-SIMD FMA (100% strict bit-exact ARM64, zero guest changes):
    • Adds cap_relaxed_fma (bit 6 = 64) in src/emu/jitcore.zig and a startup probe jitRelaxedFma() in test/kwemu-jit-host.mjs and js/core/jit.ts that both validates f32x4/f64x2.relaxed_{madd,nmadd} (0x105..0x108) AND verifies true single-rounded hardware FMA (fma(1+2^-52, 1+2^-52, -1-2^-51) === 2^-104).
    • Lowers scalar FMADD/FMSUB/FNMADD/FNMSUB (generic.zig) and vector/by-element 2S/4S/2D FMLA/FMLS (vec.zig) to a single Wasm Relaxed-SIMD FMA instruction while keeping strict inRange + FPSR.IXC checks.
  2. Part B — Opt-in Wasm-FP / no-FPSR mode (FPCR_WASM_FP = 1 << 16):
    • Allows MSR/MRS FPCR to preserve bit 16 (src/a64/common.zig).
    • When FPCR & (FZ | RMode | WASM_FP) == WASM_FP, skips FPSR updates in both interpreter (fp.zig, simd_fp.zig) and JIT (generic.zig, vec.zig), emitting bare Wasm FP/SIMD instructions with no per-op exponent/NaN/FPSR guards.

Benchmarks (Apple Silicon, Node v26.13.1, median of 3)

Part A (strict ARM64, unmodified binaries):

Benchmark No-RFMA Part A RFMA Speedup JIT / Wasm
fp_daxpy_2d 598.53 ms 40.76 ms 14.68x 7.6x
fp_daxpy_scalar 601.04 ms 55.33 ms 10.86x 9.2x
fp_matmul 175.44 ms 61.20 ms 2.87x 10.5x
fp_saxpy_4s 28.42 ms 21.99 ms 1.29x 10.9x

Part B (opt-in msr fpcr, #(1<<16) vs FPCR=0):

  • subnormal_audio_f32: 239.96 ms -> 11.62 ms (20.7x, 9.1x Wasm)
  • fp_subnormal: 57.69 ms -> 23.18 ms (2.49x, 8.9x Wasm)
  • fp_daxpy_2d: 47.31 ms -> 36.84 ms (1.28x, 6.9x Wasm)
  • fp_nan_scan: 72.70 ms -> 38.47 ms (1.89x, 6.8x Wasm)

Verification

  • zig build test passes 100% across SIMD+RFMA, KWEMU_JIT_RELAXED_FMA=0, and KWEMU_JIT_SIMD=0.
  • include/kw_emu.h and KW_CPU_SIZE unchanged.

…P mode

Probe Wasm Relaxed-SIMD FMA (f32x4/f64x2 relaxed_madd 0x105/0x107 and
relaxed_nmadd 0x106/0x108) for both validation and exact single-rounded FMA
in test/kwemu-jit-host.mjs and js/core/jit.ts, exposing cap_relaxed_fma
(bit 6) and relaxed_fma_ok in jitcore.zig.

Use Relaxed-SIMD FMA in strict bit-exact ARM64 mode for scalar FMADD/FMSUB/
FNMADD/FNMSUB (generic.zig) and AdvSIMD vector/by-element 2S/4S/2D FMLA/FMLS
(vec.zig), including enabling 2D FMLA/FMLS in vec.zig.

Add opt-in FPCR_WASM_FP (bit 16 in FPCR_MASK): when active with RMode=RNE
and FZ=0, FP instructions skip FPSR updates and JIT paths execute bare Wasm
scalar/SIMD FP instructions (including inline unordered FCMP, trunc_sat
FCVTZ[SU], subnormals, and FMA) directly.
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