code wiki / _hdl_build / nx_recycler_bench_compile.nx
nx_recycler_bench_compile.nx source
↩ module page · 78 lines · 4639 B
1// nx_recycler_bench_compile.nx -- MEASURE Nishi compile speed to turn the benchmark's "compile-speed" axis from
2// PROVABLE into PROVEN (the operator's "keep growing the provable evidence"). Times nx_cc_sovereign compiling the
3// minimal program (nx_min, self-contained -- no imports, so nx_cc DIRECT is valid per CC-EXPIMP) to a .s, over N
4// runs, with the monotonic-us clock. HONEST: Nishi's number is MEASURED here; the competitor baseline (Rust's
5// slow compile times) is a DOCUMENTED criticism grounded in recyc_lang_rust.raw, NOT run by us. Self-gating. ORIGINAL
6import "nx_syscalls.nx"
7const K_MAGIC_1000000: i64 = 1000000
8
9func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func gn(v0: i64) -> i64 { var v: i64=v0; if v<0{sys_write(1,"-" as *u8,1);v=0-v} let b: *u8=sys_mmap(24); var k: i64=0; if v==0{b[0]=48 as u8;k=1} while v>0{b[k]=(48+(v%10)) as u8;v=v/10;k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k{o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 }
11func lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
12func ground(file: *u8, kw: *u8) -> i64 {
13 let lp: *i64 = sys_mmap(16) as *i64; lp[0]=0
14 let buf: *u8 = sys_read_file(file, lp)
15 if (buf as i64)==0 { return 0 }
16 let n: i64 = lp[0]
17 var kl: i64=0; while kw[kl]!=(0 as u8){kl=kl+1}
18 var i: i64=0
19 while i+kl<=n { var k: i64=0; var m: i64=1; while k<kl { if lc(buf[i+k] as i64)!=lc(kw[k] as i64){m=0;k=kl} else {k=k+1} } if m==1 { return 1 } i=i+1 }
20 return 0
21}
22// fork nx_cc_sovereign on nx_min: stdout -> /tmp/_bc_min.s, stderr -> /dev/null. returns child exit code.
23func compile_once() -> i64 {
24 let sf: i64 = sys_openat_wr("/tmp/_bc_min.s" as *u8, 0x1a4)
25 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
26 let pid: i64 = sys_fork()
27 if pid == 0 {
28 if sf >= 0 { sys_dup3(sf, 1, 0) }
29 if dn >= 0 { sys_dup3(dn, 2, 0) }
30 let a: *i64 = sys_mmap(32) as *i64
31 a[0] = "_offc/nx_cc_sovereign.elf" as *u8 as i64; a[1] = "runtime/_hdl_build/nx_min.nx" as *u8 as i64; a[2] = 0
32 let e: *i64 = sys_mmap(16) as *i64; e[0] = "PATH=/usr/bin:/bin" as *u8 as i64; e[1] = 0
33 sys_execve("_offc/nx_cc_sovereign.elf" as *u8, a, e)
34 sys_exit(127)
35 }
36 if sf >= 0 { sys_close(sf) }
37 if dn >= 0 { sys_close(dn) }
38 let st: *i64 = sys_mmap(16) as *i64
39 sys_wait4(pid, st, 0)
40 let sig: i64 = st[0] & 0x7f
41 if sig != 0 { return 128 + sig }
42 return (st[0] >> 8) & 0xff
43}
44
45func main() -> i64 {
46 gp("=== nx_recycler_bench_compile: MEASURED Nishi compile speed (vs documented Rust slow-compile critique) ===\n" as *u8)
47 var bad: i64 = 0
48 if compile_once() != 0 { bad = bad + 1 } // warm up
49 let N: i64 = 20
50 let t0: i64 = sys_now_us()
51 var i: i64 = 0
52 while i < N { if compile_once() != 0 { bad = bad + 1 } i = i + 1 }
53 let t1: i64 = sys_now_us()
54 let total: i64 = t1 - t0
55 var avg: i64 = 0
56 if N > 0 { avg = total / N }
57
58 // confirm a non-empty .s was produced
59 let lp: *i64 = sys_mmap(16) as *i64; lp[0]=0
60 let sbuf: *u8 = sys_read_file("/tmp/_bc_min.s" as *u8, lp)
61 var ssize: i64 = 0
62 if (sbuf as i64)!=0 { ssize = lp[0] }
63 let grounded: i64 = ground("knowledge/fetched/recyc_lang_rust.raw" as *u8, "compile" as *u8)
64
65 gp(" MEASURED: nx_cc compiles nx_min in avg=" as *u8); gn(avg); gp(" us (" as *u8); gn(avg/1000); gp(" ms) over " as *u8); gn(N); gp(" runs -> " as *u8); gn(ssize); gp(" bytes of .s\n" as *u8)
66 gp(" DOCUMENTED (grounded in recyc_lang_rust.raw, NOT run by us): slow compile times are a well-known Rust criticism; rustc+LLVM carries high fixed cost even for tiny programs\n" as *u8)
67
68 var pass: i64=0; var fail: i64=0
69 if avg > 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-timing\n" as *u8) }
70 if avg < K_MAGIC_1000000 { pass=pass+1 } else { fail=fail+1; gp(" FAIL compile-not-sub-second\n" as *u8) }
71 if ssize > 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-asm-produced (compile failed)\n" as *u8) }
72 if bad == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL some-compiles-nonzero=" as *u8); gn(bad); gp("\n" as *u8) }
73 if grounded == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL rust-compile-critique-not-grounded\n" as *u8) }
74
75 gp("RECYCLER-BENCH-COMPILE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail)
76 if fail==0 { gp(" verdict=GREEN (MEASURED sub-second single-pass nx_cc compile; Rust slow-compile baseline cited not faked -- compile-speed is now a PROVEN axis)\n" as *u8); sys_exit(0); return 0 }
77 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1
78}