code wiki / (root) / nx_wasm_vm.nx

nx_wasm_vm.nx

buildroot/runtime/nx_wasm_vm.nx

38033 B640 linesdepth 2pulls 3 transitivereach 36 importersview sourcekind librarytopic wasm
docsdependenciesstructsconstsfunctions

about

nx_wasm_vm.nx F618 wasm-SIMD FLIP (2026-07-21, landed from the proven rung-1 twin). Adds interpretation of the 0xFD-prefixed wasm-SIMD subset the nx_wasm_v128 emitter produces (v128.load, i8x16.sub_sat_u, v128.or, i16x8.extadd_pairwise_i8x16_u/_s, i32x4.extadd_pairwise_i16x8_u, i32x4.extract_lane), byte-level-exact per the spec, so the faithdiff-class differential can prove SIMD == scalar == native. v128 VALUES ride the untyped i64 stack as POINTERS into a 4096-slot x 16B ring arena (values are consumed within an op sequence; the SAD kernel holds <=3 live). wm_skip_imm ALSO learns 0xFD -- without that the structured-control forward scanners desync on any function containing SIMD. FLIPPED into the shared VM 2026-07-21 (F618); nx_v128_gate T2/T3 + faithdiff hold it GREEN. nx_wasm_vm.nx -- a SOVEREIGN WebAssembly virtual machine: parses a .wasm BINARY and executes its exported functions over a linear memory, pure NishiLang, no third-party runtime (no node/wasmtime/wasmer). Purpose: close the last verification gap for shipped wasm -- run the COMPILED nx_vcodec.wasm offline and prove it computes bit-exact to the gate-proven NATIVE codec (a functional gate on the actual shipped bytes, which most toolchains never do; they trust the compiler). This is R0+R1: the parser (sections -> module) + a stack-machine executor for the opcode subset our nx_wat_compiler emits (i32/i64 const/arith/shift/compare, local.get/set/tee, i64/i32 load/store(+8/16), call, block/loop/if/else/end/br/br_if/br_table/return/drop/select, memory.size/grow, wrap/extend). license_tier: ORIGINAL

dependencies 2 imports · 36 importers

nx_syscalls.nx nx_f32_hw.nx nx_wasm_vm.nx nx_ballistics_wasm_vm_gate.nx nx_charlab_wasm_vet.nx nx_chip8_wasm_gate.nx nx_connect_keyx_vm_gate.nx nx_emu_probe_wasm_gate.nx nx_explodelab_wasm_vet.nx nx_faithdiff.nx nx_gassim_wasm_vm_gate.nx nx_kinetics_wasm_vm_gate.nx nx_media_crypt_wasm_gate.nx

diagram shows first 10 each side; +0 more imports, +26 more importers in the complete lists below.

imports: nx_syscalls.nxnx_f32_hw.nx

imported by: nx_ballistics_wasm_vm_gate.nxnx_charlab_wasm_vet.nxnx_chip8_wasm_gate.nxnx_connect_keyx_vm_gate.nxnx_emu_probe_wasm_gate.nxnx_explodelab_wasm_vet.nxnx_faithdiff.nxnx_gassim_wasm_vm_gate.nxnx_kinetics_wasm_vm_gate.nxnx_media_crypt_wasm_gate.nxnx_meshview_vm_probe.nxnx_meshview_wasm_gate.nxnx_mineworld_autotest.nxnx_mineworld_wasm_vet.nxnx_pendulum_wasm_vm_gate.nxnx_physlab_wasm_vet.nxnx_scratch_wasm_gate.nxnx_sext_wasm_kat_gate.nxnx_sha256_wasm_vm_gate.nxnx_simlab_wasm_vm_gate.nxnx_skincube_anim_gate.nxnx_solarsim_wasm_vm_gate.nxnx_v128_gate.nxnx_vcodec_color_gop_vm_gate.nxnx_vcodec_color_wasm_vm_gate.nxnx_vcodec_gop_vm_gate.nxnx_vcodec_inter_vm_gate.nxnx_vcodec_luma32_vm_gate.nxnx_video_client_live_verify.nxnx_video_client_wasm_vm_gate.nxnx_vmleak_gate.nxnx_vmtest_vm_gate.nxnx_wasm_vm_exec_gate.nxnx_wasm_vm_gate.nxnx_x25519_wasm_vm_gate.nxnx_x86_wasm_gate.nx

structs

40struct WasmMod

consts

18const K_MAGIC_65536: i64 = 65536
19const K_MAGIC_1024: i64 = 1024
20const K_MAGIC_2048: i64 = 2048
21const K_MAGIC_262144: i64 = 262144
22const K_MAGIC_4096: i64 = 4096
23const K_MAGIC_131072: i64 = 131072
24const K_MAGIC_2654435761: i64 = 2654435761
25const K_MAGIC_4000000: i64 = 4000000
26const K_MAGIC_32768: i64 = 32768
27const K_MAGIC_2147483648: i64 = 2147483648
28const K_MAGIC_4294967296: i64 = 4294967296
29const K_MAGIC_4090: i64 = 4090
30const K_MAGIC_65530: i64 = 65530
31const K_MAGIC_262140: i64 = 262140
32const K_MAGIC_999999: i64 = 999999

functions

72func wv_u8(b: *u8, pos: *i64) -> i64 { let p: i64 = pos[0]; pos[0] = p + 1; return b[p] as i64 }
73func wv_uleb(b: *u8, pos: *i64) -> i64
83func wv_sleb(b: *u8, pos: *i64) -> i64
called by 2: wm_skip_immwm_call
98func wm_parse(mod: *WasmMod) -> i64
210func wm_name_eq(b: *u8, off: i64, len: i64, needle: *u8) -> i64
called by 1: wm_find_export
217func wm_find_export(mod: *WasmMod, needle: *u8) -> i64
called by 25: mainmainmainmainmainmain+19 calls 1: wm_name_eq
228func wm_new(bytes: *u8, len: i64) -> *WasmMod
called by 36: mainmainmainmainmainmain+30 calls 1: sys_mmap
252func wm_memo_get(mod: *WasmMod, key: i64) -> i64
called by 1: wm_call
265func wm_memo_put(mod: *WasmMod, key: i64, val: i64) -> i64
called by 1: wm_call
281func wm_ld64(m: *u8, a: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v = v | ((m[a+i] as i64) << (i*8)); i=i+1 } return v }
282func wm_st64(m: *u8, a: i64, v: i64) -> i64 { var i: i64=0; while i<8 { m[a+i] = ((v >> (i*8)) & 0xFF) as u8; i=i+1 } return 0 }
called by 2: mainwm_call
285func wm_skip_imm(b: *u8, op: i64, pos: *i64) -> i64
309func wm_match_end(b: *u8, startpos: i64) -> i64
335func wm_match_else(b: *u8, startpos: i64) -> i64
355func wm_do_br(mod: *WasmMod, pos: *i64, lbl: i64) -> i64
called by 1: wm_call
364func wm_phexf(v: i64, fd: i64) -> i64
called by 2: wm_phexwm_trap1 calls 2: sys_mmapsys_write
370func wm_pn2f(v: i64, fd: i64) -> i64
called by 2: wm_pn2wm_trap1 calls 2: sys_mmapsys_write
380func wm_pn2(v: i64) -> i64 { return wm_pn2f(v, 2) }
calls 1: wm_pn2f
381func wm_phex(v: i64) -> i64 { return wm_phexf(v, 2) }
calls 1: wm_phexf
382func wm_trap1(code: i64, op: i64, a: i64, bb: i64, fd: i64) -> i64
called by 1: wm_trap calls 3: sys_writewm_pn2fwm_phexf
390func wm_trap(code: i64, op: i64, a: i64, bb: i64) -> i64
called by 1: wm_call calls 2: wm_trap1sys_exit
396func wm_call(mod: *WasmMod, fidx: i64, args: *i64, nargs: i64) -> i64
634func wm_run(mod: *WasmMod, name: *u8, a0: i64, a1: i64, a2: i64, a3: i64, a4: i64, na: i64) -> i64