Repository navigation
JIT remaining S/D floating-point families and zlib NEON shuffles - #8
Merged
Merged
Conversation
losfair
marked this pull request as ready for review
October 25, 2026 10:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
96271afversus 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.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 addedtests/bench/fp.candzlib.cand 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.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:
1dd7eb0, including the existing randomized FP, vector-cache, integer, and crypto suites.