nx_wasm.nx
buildroot/runtime/nx_wasm.nx
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
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
| 43 | func wat_push_operand(f: *Function, o: *OutBuf, ind: i64, v: i64) -> i64 |
| 58 | func wat_store_result(o: *OutBuf, ind: i64, v: i64) -> i64 |
| 68 | func wat_binop_mnem(op: i64, o: *OutBuf) -> i64 |
| 83 | func wat_cmp_mnem(op: i64, o: *OutBuf) -> i64 |
| 95 | func wat_emit_binop(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_instr calls 5: wat_push_operandout_indentwat_binop_mnemout_charwat_store_result |
| 105 | func wat_emit_cmp(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_instr calls 6: wat_push_operandout_indentwat_cmp_mnemout_charout_strwat_store_result |
| 120 | func wat_nameq(name: *u8, kw: *u8) -> i64 called by 1: wat_call_is_sad16 |
| 129 | func wat_call_is_sad16(i: *Instr) -> i64 |
| 139 | func wat_emit_v128sad(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 2: wat_emit_callwat_emit_tail_call calls 4: wat_push_operandout_indentout_strwat_store_result |
| 177 | func wat_emit_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_instr calls 7: wat_call_is_sad16wat_emit_v128sadwat_push_operandout_indentout_strout_char+1 |
| 214 | func wat_emit_return(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 |
| 225 | func wat_emit_branch(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 |
| 268 | func wat_emit_f32(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 |
| 310 | func wat_is_alloca(f: *Function, vid: i64) -> i64 |
| 318 | func wat_emit_load(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_instr calls 7: wat_is_allocaout_indentout_strout_i64out_charwat_store_result+1 |
| 342 | func wat_emit_store(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 |
| 362 | func wat_emit_gep(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 |
| 370 | func wat_emit_tail_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_instr calls 7: wat_call_is_sad16wat_emit_v128sadout_indentout_strout_i64out_char+1 |
| 411 | func wat_emit_instr(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 called by 1: wat_emit_function calls 17: wat_emit_binopwat_emit_f32wat_emit_cmpwat_emit_callwat_emit_tail_callwat_emit_return+11 |
| 509 | func wat_emit_function(f: *Function, o: *OutBuf) -> i64 |
| 669 | func wat_emit_module(m: *Module, o: *OutBuf) -> i64 |