Skip to content

jit: accelerate libm, SHA-256 and compiler hot paths - #9

Merged
losfair merged 1 commit into
mainfrom
perf/report-bottlenecks
Oct 25, 2026
Merged

losfair merged 1 commit into
mainfrom
perf/report-bottlenecks

Conversation

@losfair

@losfair losfair commented Oct 25, 2026

Copy link
Copy Markdown
Owner

glibc's sin, cos and atan still entered helpers for FPCR reads and NEON bit selection. GCC also hit hundreds of thousands of integer/SIMD helpers and flushed its code cache during a small compilation. SHA-256 used an AVX2 expansion even on hosts with SHA-NI.

This adds the missing hot instruction paths, optional SHA-NI lowering, and cheaper shared-cache validation.

  • Lower FPCR/FPSR access, bit selects, RBIT, population counts, integer comparisons, reductions, and the indexed multiplies and shifts used by libc/GCC. FP register writes update live MXCSR with recovery metadata that completes an interrupted write atomically.
  • Use SHA-NI for SHA256H/H2/SU0/SU1. Reserve XMM0 in blocks containing rounds, and clear upper YMM halves before legacy SHA instructions to avoid AVX/SSE transition assists after DC ZVA. Retain the AVX2 path when the host lacks SHA.
  • Batch up to 16 adjacent shared-cache dependency reads within an executable page while still checking every word and fault dependency. Raise the on-demand per-process code-cache ceiling from 64 to 128 MiB so the measured GCC working set fits.
  • Correct libc syscall() errno conversion in kemu-user, needed to profile GCC's include search. Add a libm benchmark, SHA-256 to the crypto benchmark, a 195-form differential catalog, and CI coverage.

Measurements against merged main b4d3b1e, using identical AArch64 binaries in a local 2-vCPU l4h guest on an i7-13700H host. Libm and OpenSSL numbers are medians of three trials; the compiler rows separate the first compilation from the two subsequent runs. The host is shared, so timings vary.

Workload Main This PR Improvement
sin 4,675.7 ns/call 32.7 ns/call 143×
cos 4,708.8 ns/call 47.5 ns/call 99×
atan 4,652.5 ns/call 42.6 ns/call 109×
SHA-256 EVP, 8 KiB 54.8 MB/s 350.0 MB/s 6.4×
GCC, cold 14.45 s 12.20 s 1.18×
GCC, warm 8.91–10.66 s 4.62–5.04 s about 2×

The libm repro uses GCC 14.2, -O2 -static, without fast-math. SHA uses OpenSSL 3.5.7 with speed -elapsed -seconds 2 -bytes 8192 -evp sha256. GCC 14.2 compiles and links the report's cbench.c with -O2 -static -pthread -lm; its guest gets 1 GiB RAM. Native reference binaries run in the same guests.

SHA now beats the ARM software path (117 MB/s); the native SHA reference is 897 MB/s. Trig remains about 4–5× native. GCC's cc1 helpers fall from 409,558 to 1,804 and its cache flushes from one to zero, but cold translation and code installation remain substantial: warm GCC is still roughly 9× native here.

Validation completed:

  • 36 core unit tests and 2 userspace syscall tests.
  • 300,000 final randomized differential cases with asynchronous interruption and relocation, including vector-cache-disabled and SHA-NI-disabled configurations; exact FPCR/FPSR checks and helper-count assertions for the new catalog.
  • Crypto checksums and libm results compared with QEMU.
  • l4h kernel build and ABI/vector/syscall/FP-status smoke tests, with vector caching enabled and disabled.
  • Rebuilt with the CI Rust toolchain, 1.88.0; standard Linux kernel boot tests are in progress.

Lower FP control/status access and the remaining hot integer/SIMD helpers in glibc and GCC. Preserve atomic FP register writes during signal recovery. Add optional SHA-NI lowering with AVX2 fallback and clear upper YMM state before legacy SHA instructions. Batch shared-cache dependency reads and let code chunks grow on demand to 128 MiB to avoid GCC cache flushes. Add differential coverage and reproducible libm/SHA benchmarks, and fix errno translation in the userspace profiling harness.
@losfair
losfair merged commit 7e8de37 into main Oct 25, 2026
2 checks passed
@losfair
losfair deleted the perf/report-bottlenecks branch October 25, 2026 11:32
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