code wiki / _hdl_build / nx_simd_lever_gate.nx

nx_simd_lever_gate.nx

buildroot/runtime/_hdl_build/nx_simd_lever_gate.nx

3945 B49 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic simd
docsdependenciesstructsconstsfunctions

about

nx_simd_lever_gate.nx -- PROVE the SIMD lever that WINS the PyTorch h2h, using the REAL supported intrinsic __i16x16_madd (vpmaddwd) exactly as nx_nofloat_llm's mm_pool_i8 does. The trainer's matmul inner dot (len 64) scalar ~= 358 MMAC/s (=> 4x slower than PyTorch). Here: same dot (a) scalar i64 full-precision vs (b) SIMD __i16x16_madd with i8-quantized operands packed as i16 lanes. Measures speedup + i8-quant accuracy. If SIMD is several-x faster AND accurate, wiring it into the trainer flips 15.2ms/step to beat PyTorch's 3.7ms/step. ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_simd_lever_gate.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main w sys_write sys_mmap nf_pack2 sys_now_us sys_mmap ↻ sys_clock_gettime_mono scalar_dot hsum8 wn sys_write ↻ sys_mmap ↻

structs

none

consts

13const NN: i64 = 64
14const REPS: i64 = 300000

functions

8func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
9func wn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var q: i64=k-1; var i: i64=0; while q>=0{o[i]=t[q];i=i+1;q=q-1} sys_write(1,o,i); return 0 }
called by 1: main calls 2: sys_writesys_mmap
10func nf_pack2(buf: *u8, idx: i64, val: i64) -> i64 { buf[idx*2]=(val) as u8; buf[idx*2+1]=(val>>8) as u8; return 0 }
called by 1: main
11func hsum8(acc: *u8) -> i64 { let pp: *i32=acc as *i32; var s: i64=0; var i: i64=0; while i<8 { s=s+(pp[i] as i64); i=i+1 } return s }
called by 1: main
16func scalar_dot(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { s=s+a[i]*b[i]; i=i+1 } return s }
called by 1: main
18func main() -> i64