Skip to content

JIT remaining S/D floating-point families and zlib NEON shuffles - #8

Merged
losfair merged 3 commits into
mainfrom
perf/floating-point-jit
Oct 25, 2026
Merged

losfair merged 3 commits into
mainfrom
perf/floating-point-jit

Conversation

@losfair

@losfair losfair commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

FP algorithms and zlib compression spend their hot loops in per-instruction interpreter helpers. Lower the remaining decoded scalar/SIMD S/D floating-point families and the NEON shuffles used by zlib to native x86/AVX2/FMA:

  • Scalar/vector FP MIN/MAX and MINNM/MAXNM, with exact signed-zero handling.
  • Scalar/vector indexed FMUL/FMLA/FMLS, including aliased operands and inactive-lane clearing.
  • Scalar/vector rounding, comparisons and conditional comparisons, pairwise/across-lane reductions, FABD and FMULX (including indexed forms).
  • Signed/unsigned integer and fixed-point conversions, FJCVTZS, S/D precision conversions, FCVTXN round-to-odd, and half-precision storage conversions. No FP16 arithmetic. Common signed int32 vector conversions stay packed.
  • FRECPE/FRSQRTE using exact ARM lookup tables embedded once per block, FRECPX, and fused FRECPS/FRSQRTS refinement.
  • TBL/TBX over 1–4 registers, including register-list wraparound and out-of-range indices.
  • Byte/halfword ZIP1/ZIP2/UZP1/UZP2, with table operands included in vector-cache allocation.

The new paths retain exact softfloat fallbacks where host semantics differ: NaN propagation, FPCR.FZ/AHP, saturation/modulo cases, underflow/overflow boundaries, and FCVTXN outside its normal-result fast range. Basic FP arithmetic was already JITted. The underflow boundary guard handles ARM's tininess-before-rounding rule when x86 rounds up to the smallest normal without setting underflow.

Performance

Measured inside an l4h guest, default JIT enabled, baseline kemu 96271af versus the initial hot-path changes (5ffa0cb). The full FP expansion is measured separately below. Medians of three runs; times below are normalized per invocation. FP and compression warm up before timing. Baseline used 20 FP iterations and 2 compression iterations per run; the much faster patched/native runs used 5,000 and 100 respectively.

Workload Baseline kemu Patched kemu Native x86-64 Speedup
Float 48×48 matrix multiply 42.035 ms 0.03345 ms 0.006604 ms 1,257×
Clamp 4,096 floats 5.933 ms 0.002923 ms 0.008187 ms 2,030×
zlib level-6 compression, 128 KiB 314.611 ms 2.517 ms 1.761 ms 125×

Matrix multiplication remains about 5.1× slower than native; compression is about 1.43× slower. Clamping benefits from GCC vectorizing the AArch64 implementation while using scalar libm calls on x86-64. These are workload-specific results, not a claim that all FP or zlib operations improve by these factors. Decompression and checksums were also exercised but their hot loops were already translated.

Host: i7-13700H, KVM, 4-vCPU l4h guest based on 2072e45. Both benchmark sources compiled with GCC 14 at -O3; native uses -march=x86-64-v3. Both zlib builds are Debian 1.3.1 (1:1.3.dfsg+really1.3.1-1+b1). Baseline/patched AArch64, native, and QEMU checksums agree. The added tests/bench/fp.c and zlib.c and README commands reproduce the workloads. Separate userspace profiling of the 1 MiB zlib workload drops from about 3.8 million helper calls to 206; profiling is disabled for timings.

Remaining FP families: additional measurements

Comparison of the previous PR version (5ffa0cb) with the completed FP expansion (1dd7eb0), in the same l4h guest. Each kernel processes 4,096 floats. Medians of three warmed runs, normalized per call; previous version uses 30 iterations and patched/native use 10,000. Compile both targets with GCC 14 -O3 -fno-math-errno (native also -march=x86-64-v3). ARM/native/QEMU checksums agree.

Workload Previous PR Completed FP JIT Native x86-64 Speedup Relative to native
Square roots 5,366.9 µs 2.253 µs 1.585 µs 2,382× 1.42×
Float/int quantization 5,761.3 µs 4.264 µs 0.543 µs 1,351× 7.85×
Rounding 3,071.1 µs 2.359 µs 0.385 µs 1,302× 6.13×

These ratios describe these kernels, not all FP code. Quantization and rounding still have translation/semantic-check overhead and use 128-bit guest vectors versus the native compiler's 256-bit AVX2 loops. Square roots are much closer to native. The signed-int32 truncation path uses packed CVTTPS2DQ directly, with a pre-scaling range check for fixed-point conversions; x86 supplies IOC/IXC without a separate rounding/inexact pass.

Correctness and integration

Exact-FPSR interruption tests exposed a pre-existing recovery bug: live MXCSR exception flags were lost when returning through the dispatcher. Capture MXCSR alongside XMM state; in page-state stub ranges use the saved image, since live state may precede a reload or signal return. The new kernel test loses flags in 98/100 baseline samples and passes 100/100 after the fix, with vector caching both enabled and disabled.

Architecture ports must replace the XMM-only hook with u32 kemu_arch_read_fpu(u64 xmm[8][2]), returning MXCSR. The tested l4h adaptation stays in l4h and is prepared for its subsequent pin update.

The userspace runner also needs a private guest brk heap: forwarding brk into the host allocator corrupts the runner during zlib's allocations. Reserve a separate range and test growth, shrinking/zeroing, and bounds. This harness fix does not affect the kernel timings.

Validation:

  • 34 core unit tests and the guest-heap test pass.
  • The new FP catalog covers 429 instruction forms plus two deterministic underflow regressions. 350,000 strict differential cases pass across vector caching enabled/disabled, exact FPCR/FPSR/NZCV, all rounding modes, aliases, asynchronous interruptions and code relocation. Ordinary-input cases must execute without helpers.
  • QEMU independently agrees on every catalog entry: 431 entries × 100 random states, zero mismatches.
  • 40,000 earlier targeted differential cases pass with asynchronous interruption, relocation, and vector caching enabled/disabled; checks include exact FPCR/FPSR and prohibit unexpected hot-path fallbacks.
  • GitHub's userspace CI passes on final head 1dd7eb0, including the existing randomized FP, vector-cache, integer, and crypto suites.
  • QEMU checksum and signal/FPSR oracle checks pass.
  • Patched l4h passes FP/zlib workloads, ABI, vector-state/fault recovery, syscall-state stress, and the new FP-status test. The completed expansion also passes all those tests in l4h (126 vector-state signals plus a fault, 7,995 syscall-state signals, and 100/100 FP-status samples). Native-kernel CI remains pending.

@losfair
losfair marked this pull request as ready for review October 25, 2026 10:10
@losfair losfair changed the title JIT FP hot paths and NEON shuffles used by zlib JIT remaining S/D floating-point families and zlib NEON shuffles Oct 25, 2026
@losfair
losfair merged commit b4d3b1e into main Oct 25, 2026
2 checks passed
@losfair
losfair deleted the perf/floating-point-jit branch October 25, 2026 10:36
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