13 Commits

Author SHA1 Message Date
Pooya Parsa
75694e278f kernel: optimize the lowered kernel with Binaryen -O2 (about 4% smaller, Debian shell commands about 3.5% faster in Node) and build kwemu with bulk memory, sign-ext, nontrapping-fptoint and mutable globals, which the kernel's C objects already need 2026-11-24 22:09:38 +00:00
Pooya Parsa
c46e019741 kwemu: a region takes the blocks of its page that have counted a quarter of the compile threshold (pageWarm), and exit growth waits for 32768 exits per KiB of module instead of 8192: a test/app-bench.mjs boot compiles about 4900 modules instead of 6500, 21% less compile time, and Node, Bun and Claude Code run 2-9% faster or unchanged on 1 and 2 CPUs; record the 2026-11-21 measurements and the rejected variants in the agent docs 2026-11-21 19:01:57 +00:00
Pooya Parsa
c087d31856 Move the kwemu test guests from guest/ to test/guest/ 2026-11-19 07:37:16 +00:00
Pooya Parsa
a1acf312e0 Remove the riscv64 CPU, reset the kwemu ABI to 2
The riscv64 interpreter, its JIT emitter, test guests and drivers are
gone; kwemu keeps the ISA-neutral core (MMU, TLBs, code marking, block
cache, JIT core) and the A64 CPU. The arm64 user ABI is one kernel
patch, the last of the series, and the contract between the kernel and
kwemu starts again at KW_ABI_VERSION 2.
2026-11-19 00:12:39 +00:00
Pooya Parsa
3414200e47 a64: translate AdvSIMD, AES, PMULL and SHA with wasm SIMD
With a host that compiles wasm SIMD (a JIT host capability; the scalar
form remains as the fallback), V registers live in v128 locals and the
integer AdvSIMD ops, AES rounds, PMULL and the SHA families are
translated inline. The image's libcrypto picks its code paths from
HWCAP again, and SHA512 is advertised by default.
2026-11-19 00:12:38 +00:00
Pooya Parsa
0169bdbb57 a64: call the interpreter from compiled code, translate the frequent generic ops
Ops the JIT does not translate no longer end a compiled block: compiled
code calls the reference interpreter for them through the kernel's
function table (a JIT host capability). FMOV, UMOV/INS/DUP, MOVI, vector
logic, MRS of FPCR/FPSR/NZCV/DCZID and FCMP are translated inline.
2026-11-19 00:12:38 +00:00
Pooya Parsa
1153cea626 a64: LSE atomics, SHA-512 and SHA-3
FEAT_LSE, FEAT_SHA512 and FEAT_SHA3 in the interpreter and the tier,
with their HWCAP bits and ID register fields in the kernel and checks in
kwtest.
2026-11-19 00:12:38 +00:00
Pooya Parsa
0573a18e47 a64: compile hot code to wasm in the JIT
The JIT's ISA-neutral core (regions, thresholds, entry, growth) is
factored out behind ISA hooks, and the A64 emitter sits on it with one
file per op family: ALU, bitfield, multiply and divide kinds with lazy
NZCV, every load and store kind, and every branch kind with side exits.
2026-11-19 00:12:38 +00:00
Pooya Parsa
e43aaddca2 a64: run user code through a decoded-op tier
The decoded-block cache is generic over an ISA's block hooks. A64 code
is decoded once into ops (one instruction, one op) that runOps executes,
with coherence on SMP through a shared code epoch. The tier is tested
against the reference interpreter.
2026-11-19 00:12:38 +00:00
Pooya Parsa
783c48c76e Switch the guest CPU to AArch64
User space is now unmodified aarch64 Linux ELF. kwemu gets an A64
interpreter (src/a64): integer, scalar and vector floating point,
AdvSIMD, exclusives and load-acquire/store-release, the EL0 system
registers, AES, PMULL, SHA1, SHA256 and CRC32. The kernel runs arm64
user space (signal frames, HWCAP, ptrace regsets, the arm64 syscall ABI),
and the guest image, the bundle, kwtest and the page's texts are built
for aarch64.
2026-11-19 00:12:38 +00:00
Pooya Parsa
55095f50bf Boot an SMP kernel on several CPUs in Node (SMP step 2)
A second kernel build (kw_smp.config) runs one instance of the module
per CPU, each in a worker thread on a shared memory. The host's Kernel
is CPU 0 with every device; wasm_cpu_start starts the others through
Platform.spawnCpu (js/node/cpu.ts), which run js/core/cpu.ts: their own
JSPI task switching, the clocks on CPU 0's time base, and console and
exit forwarded to CPU 0's host. The host sets IRQ bits atomically and
ends CPU 0's idle on Atomics.waitAsync of its word, which other CPUs'
IPIs notify. createKernel's cpus option and the CLI's --smp N (which
implies --worker) ask for CPUs; a UP kernel ignores them with a log
line, and more than one CPU runs the interpreter only.

kwemu built with -Dkwemu-atomics makes AMOs atomic, SC a
compare-and-swap against the value LR read, and FENCE a barrier (ABI
7). kwtest gains an smp check (threads on several CPUs counting
through AMOs, LR/SC and a mutex) and skips the park check on an SMP
kernel, which has no parking. The kernel side is in five new patches.
2026-11-16 16:07:40 +00:00
Pooya Parsa
fccde8ff93 Build kwemu with atomics and boot a shared-memory kernel (SMP step 1, WIP)
-Dkwemu-atomics adds the wasm atomics and bulk-memory features to the
wasm64 objects, so wasm-ld can link them into a kernel built with
--shared-memory. The JIT declares its env.memory import shared when the
host reports caps bit 3, the host creates a shared WebAssembly.Memory
when the module's import is shared (found by retrying the instantiation
on a LinkError that says so), and the WASI imports and the JIT host copy
out of the memory where browsers refuse shared views.
2026-11-16 13:12:22 +00:00
Pooya Parsa
26d08730cc Initial commit 2026-11-15 23:27:04 +00:00