Repository navigation
a64/jit: use Wasm wide multiply for UMULH and SMULH - #97
Open
SukharevAndrey wants to merge 1 commit into
Open
SukharevAndrey wants to merge 1 commit into
SukharevAndrey wants to merge 1 commit into
Conversation
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.
Summary
UMULHandSMULHreturn the upper 64 bits of a 64 × 64-bit product. The JIT computes those bits from 32-bit partial products. On engines with Wasm wide arithmetic, emiti64.mul_wide_uori64.mul_wide_sand keep the high word.The SDK probes both opcodes once per JIT host with
WebAssembly.validate. Capability bit 6 enables the new lowering. When either opcode is unavailable, or an older host omits the bit, the JIT emits the partial products. The probe is shared with the Zig test host, so the Zig package includesjs/core/jit.ts. This change does not alterKW_ABI_VERSION.Benchmarks
2026-11-29, Apple M1 Max, AArch64 ELF harness. Each pair used the same kwemu build with Wasm wide multiply disabled or enabled. Each timing was the median of three warmed passes. The time columns show separate medians. The last column gives the median change within pairs (negative is faster).
GMP 6.3.0 made 16,384
mpz_mulcalls per pass on 128 deterministic operand pairs of 512–4,096 bits, checking one word from each product. GMP finished sooner in all nine pairs on each host. It executed 11.15 millionUMULHinstructions per pass (9.15% of guest instructions). Generated Wasm fell from 241,044 to 230,319 bytes in Firefox and from 245,379 to 234,654 bytes in Bun. GMP exercised the unsigned form only. The two instruction loops each chained about 20 million multiplications, feeding the high word into the next iteration. They isolate the cost of each signedness. The sorting control executed neither wide multiply instruction and emitted the same number of bytes with either setting. Five A/A pairs in Bun (fallback on both sides) gave a median GMP timing change of −0.31%. The Firefox series compared fallback with wide multiply only.Verification
The high-multiply regression runs signed and unsigned compiled blocks with boundary operands and a destination that overlaps a source. It checks the result, emitted opcode, entry count and hand-backs. The Zig suite also feeds signed and unsigned operations through the emitter with the wide capability forced on and checks the opcode and the order in which it consumes the two result words. This check runs under Node 24.21.0, where the engine rejects wide arithmetic and the execution test takes the fallback. A separate AArch64 ELF checked 768 operand pairs against exact Python arithmetic, including overlapping registers and XZR. It ran in Firefox with wide multiply enabled and disabled. In Firefox 161 the high-multiply regression also passed through both the SDK and the test host. Each host validated the feature once. The SDK checks below exercised both paths in Bun.
zig build testcompleted all 55 build steps and matched 77 guest results against QEMU 11.0.3. The Wasm JIT tests ran with SIMD enabled and disabled.kernel/build.sh kernelbuilt the UP kernel. Both the default and--no-jitboots rankwtestwith zero failures.