code wiki / _hdl_build / nx_train_int_vs_softfloat_gate.nx

nx_train_int_vs_softfloat_gate.nx

buildroot/runtime/_hdl_build/nx_train_int_vs_softfloat_gate.nx

8477 B121 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind gate/prooftopic train
docsdependenciesstructsconstsfunctions

about

nx_train_int_vs_softfloat_gate.nx -- THE PAYOFF measurement: does INTEGER training actually run FASTER than our SOFTWARE-FLOAT tape on IDENTICAL work? Trains the SAME 2-layer MLP (W1->ReLU->W2, L=sum(y-t)^2) for the same number of steps, TWO ways -- (A) software-float via nx_f32_mul/add (what nx_f32_qwen2_train uses), (B) integer Q16 -- times both with sys_now_us, and reports the speedup. Same algorithm, same MAC count; only the arithmetic differs, so the ratio IS the software-float tax paid in a real training loop. This is the internal h2h that justifies porting the trainer to integer (the sovereign path to beat PyTorch CPU). Measured-not-asserted. ReLU + sign checks read the IEEE sign bit directly ((raw>>31)&1) to avoid nx_int-typed comparisons. license_tier: ORIGINAL

dependencies 4 imports · 0 importers

nx_f32.nx nx_f32_cvt.nx nx_f32_div.nx nx_syscalls.nx nx_train_int_vs_softfloat_gate

imports: nx_f32.nxnx_f32_cvt.nxnx_f32_div.nxnx_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 wn sys_write ↻ sys_mmap sys_mmap ↻ nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_i32_to_f32 step_int sys_mmap ↻ sys_now_us sys_mmap ↻ sys_clock_gettime_mono step_sf nx_i32_to_f32 ↻ sys_mmap ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ fneg nx_f32_sub nx_f32_add ↻ nx_f32_neg nx_f32_sub ↻ nx_f32_mul ↻ fneg ↻

structs

none

consts

17const S: i64 = 65536
18const K: i64 = 3
19const H: i64 = 8
20const O: i64 = 2
21const NEX: i64 = 3
22const STEPS: i64 = 1500

functions

13func 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
14func 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
15func fneg(raw: i64) -> i64 { return (raw/2147483648)%2 } // IEEE sign bit (1 => negative)
called by 2: step_sfmain
25func step_int(W1: *i64, X: *i64, W2: *i64, T: *i64, gW1: *i64, gW2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64
called by 1: main calls 1: sys_mmap
43func step_sf(W1: *i64, X: *i64, W2: *i64, T: *i64, gW1: *i64, gW2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64
61func main() -> i64