code wiki / _hdl_build / nx_vskip_gate.nx

nx_vskip_gate.nx source

↩ module page · 53 lines · 2734 B

1// nx_vskip_gate.nx -- proves + MEASURES sovereign skip-block coding (nx_vskip). Native, fast. 2// 1) static block (sad 0, mv 0) -> skip ; 2) moved/changed block -> not skip ; 3) measured static-frame saving 3import "nx_syscalls.nx" 4import "nx_vskip.nx" 5import "nx_gate_verdict.nx" 6 7func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 8func g_pn(v: i64) -> i64 { 9 let b: *u8 = sys_mmap(28); var x: i64 = v 10 if x == 0 { b[0]=48; sys_write(1,b,1); return 0 } 11 var d: i64=0; var y: i64=x 12 while y>0 { d=d+1; y=y/10 } 13 var i: i64=d-1; y=x 14 while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 } 15 sys_write(1,b,d); return 0 16} 17func g_check(name: *u8, cond: i64) -> i64 { 18 if cond==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } 19 g_puts(name); g_puts("\n" as *u8); return cond 20} 21 22func main() -> i64 { 23 g_puts("nx_vskip gate (skip-block coding, MEASURED)\n" as *u8) 24 var pass: i64 = 0; var total: i64 = 0 25 let TH: i64 = 16 26 27 var r1: i64 = 1 28 if vs_skip(0, 0, 0, TH) != 1 { r1 = 0 } // perfectly static -> skip 29 if vs_skip(10, 0, 0, TH) != 1 { r1 = 0 } // tiny residual under threshold -> skip 30 pass = pass + g_check("static / near-static block -> SKIP (1 bit)" as *u8, r1); total=total+1 31 32 var r2: i64 = 1 33 if vs_skip(200, 0, 0, TH) != 0 { r2 = 0 } // big residual -> not skip 34 if vs_skip(0, 2, 0, TH) != 0 { r2 = 0 } // moved (mv!=0) -> not skip 35 pass = pass + g_check("changed / moved block -> NOT skip (coded normally, neg)" as *u8, r2); total=total+1 36 37 // 3) measured: a near-static frame of 16 blocks, 15 skip + 1 coded (~50 bits) vs all-coded 38 let with_skip: i64 = vs_frame_bits(16, 15, 50) 39 let no_skip: i64 = vs_frame_bits(16, 0, 50) 40 g_puts(" [measure] near-static frame: skip-coded=" as *u8); g_pn(with_skip); g_puts(" bits vs no-skip=" as *u8); g_pn(no_skip); g_puts(" bits\n" as *u8) 41 pass = pass + g_check("skip cuts the near-static frame sharply" as *u8, with_skip * 5 < no_skip); total=total+1 42 43 g_puts("---- vskip gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 44 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 45 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 46 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 47 let ctr__dry: *i64 = gv_ctr() 48 ctr__dry[0] = pass 49 ctr__dry[1] = total 50 let rc__dry: i64 = gv_verdict("VSKIP-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 51 sys_exit(rc__dry) 52 return rc__dry 53}