code wiki / (root) / nx_wasm.nx

nx_wasm.nx

buildroot/runtime/nx_wasm.nx

30376 B722 linesdepth 4pulls 6 transitivereach 3 importersview sourcekind librarytopic wasm
docsdependenciesstructsconstsfunctions

about

nx_wasm.nx F618 wasm-SIMD FLIP (2026-07-21, landed from the proven rung-1 twin nx_wasm_v128.nx). The fused v128 SAD intercept fires ONLY on calls to v128_sad16 (nx_vmotion.nx); any function without one emits byte-identical wasm. THE INTERCEPT: a call to the scalar reference fn `v128_sad16(a,b)` (nx_vmotion.nx) is emitted as an INLINE wasm-SIMD sequence (v128.load x2, sub_sat_u both ways, or -> bytewise |a-b|, extadd_pairwise u8->u16->u32, 4x extract_lane+extend+add) instead of a call. Native + stock-wat builds keep the scalar body = the bit-exact reference; this backend swaps ONLY the call sites. Exact-integer equivalence: sub_sat_u(a,b)|sub_sat_u(b,a) == |a-b| per byte (one side is 0); extadds are exact (max 16*255=4080 << u16/u32); the lane sum is the same integer as the scalar loop. The inliner is OFF by default (opt_inline_module gate) so call sites always reach this emitter. wasm.nx -- NishiLang port of wasm.c (WAT backend). Lowers our SSA IR to WebAssembly Text format. The core challenge WAT imposes is structured control flow: there are no arbitrary branches, only block/loop/if scopes with break-to-label. Our IR has free-form CFG edges, so we use the universal block-dispatch pattern (`br_table` driven by a `$target` local) that encodes any CFG at small constant cost. Per-op semantics match wasm.c exactly; every Value gets a $vN local, comparisons extend to i64 after the i32 WASM result, and constants materialize inline as i64.const. Functions are prefixed `wat_` so they don't collide with riscv.nx's asm-side `rv_*` / `emit_*` naming when both libraries are imported into a driver.

dependencies 4 imports · 3 importers

nx_syscalls.nx nx_types.nx nx_ir.nx nx_outbuf.nx nx_wasm.nx nx_compile_wat.nx nx_vcc_color_wat.nx nx_vcc_probe_wat.nx

imports: nx_syscalls.nxnx_types.nxnx_ir.nxnx_outbuf.nx

imported by: nx_compile_wat.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nx

structs

none

consts

none

functions

43func wat_push_operand(f: *Function, o: *OutBuf, ind: i64, v: i64) -> i64
58func wat_store_result(o: *OutBuf, ind: i64, v: i64) -> i64
68func wat_binop_mnem(op: i64, o: *OutBuf) -> i64
called by 1: wat_emit_binop calls 1: out_str
83func wat_cmp_mnem(op: i64, o: *OutBuf) -> i64
called by 1: wat_emit_cmp calls 1: out_str
95func wat_emit_binop(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
105func wat_emit_cmp(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
120func wat_nameq(name: *u8, kw: *u8) -> i64
called by 1: wat_call_is_sad16
129func wat_call_is_sad16(i: *Instr) -> i64
139func wat_emit_v128sad(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
177func wat_emit_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
214func wat_emit_return(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
225func wat_emit_branch(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
268func wat_emit_f32(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
310func wat_is_alloca(f: *Function, vid: i64) -> i64
called by 2: wat_emit_loadwat_emit_store calls 1: val_at
318func wat_emit_load(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
342func wat_emit_store(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
362func wat_emit_gep(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
370func wat_emit_tail_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
411func wat_emit_instr(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64
509func wat_emit_function(f: *Function, o: *OutBuf) -> i64
669func wat_emit_module(m: *Module, o: *OutBuf) -> i64