code wiki / _hdl_build / nx_boolhunt_test.nx
nx_boolhunt_test.nx source
↩ module page · 65 lines · 3729 B
1// nx_boolhunt_test.nx -- the TEAM finds its own opportunities. It sweeps EVERY 3-input
2// boolean function (all 256), finds each minimal circuit, races the best of {gcc, clang},
3// and reports what IT discovered: where its exhaustive-minimal op-count is below the
4// compiler's instruction count (candidate exceeds), where it ties, and where it is behind
5// (the behind cases name ops the team should next AUTHOR -- e.g. andn/lea the compiler has).
6// No human picks the functions. Honest: team size = minimal OP COUNT (the floor); a confirmed
7// exceed also needs the team's emitted insn count, but op-count<compiler-insns is the signal.
8
9import "nx_boolhunt.nx"
10
11func bh_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func bh_num(v: i64) -> i64 {
13 let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m }
14 let t: *u8 = sys_mmap(28); var k: i64 = 0
15 if m == 0 { t[0] = 48; k = 1 }
16 while m > 0 { t[k] = 48 + (m % 10); m = m / 10; k = k + 1 }
17 if v < 0 { bh_puts("-" as *u8) }
18 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
19 sys_write(1, bb, k); return 0
20}
21
22// sweep all 256; c[0]=wins c[1]=ties c[2]=behind c[3]=swept; record up to 8 win/behind examples.
23func bh_sweep(gcc: *u8, c: *i64, ex: *i64) -> i64 {
24 let res: *i64 = sys_mmap(8 * 4) as *i64
25 c[0]=0; c[1]=0; c[2]=0; c[3]=0
26 var nex: i64 = 0
27 var nbe: i64 = 0
28 var tt: i64 = 0
29 while tt < 256 {
30 bool_hunt_one(tt, gcc, res)
31 if res[3] == 1 { // only count VERIFIED-correct emits
32 if res[2] == 1 { c[0] = c[0] + 1; if nex < 8 { ex[nex*3+0]=tt; ex[nex*3+1]=res[0]; ex[nex*3+2]=res[1]; nex = nex + 1 } }
33 if res[2] == 0 { c[1] = c[1] + 1 }
34 if res[2] == 0 - 1 { c[2] = c[2] + 1; if nbe < 4 { ex[24 + nbe*3+0]=tt; ex[24 + nbe*3+1]=res[0]; ex[24 + nbe*3+2]=res[1]; nbe = nbe + 1 } }
35 }
36 c[3] = c[3] + 1
37 tt = tt + 1
38 }
39 return 0
40}
41
42func bh_main() -> i64 {
43 bh_puts("=== TEAM HUNTS ITS OWN SEARCH SPACE: sweep ALL 256 boolean functions, discover wins (no human picks) ===\n" as *u8)
44 let gcc: *u8 = gr_newest_gcc()
45 let c: *i64 = sys_mmap(8 * 8) as *i64
46 let ex: *i64 = sys_mmap(8 * 64) as *i64
47 bh_sweep(gcc, c, ex)
48 bh_puts(" swept " as *u8); bh_num(c[3]); bh_puts(" functions vs best of {gcc-14,clang-18}, team code EMITTED+VERIFIED by execution.\n team-insns < compiler-insns (genuine EXCEED) on " as *u8)
49 bh_num(c[0]); bh_puts(", equal " as *u8); bh_num(c[1]); bh_puts(", behind " as *u8); bh_num(c[2]); bh_puts("\n" as *u8)
50 bh_puts(" -- EXCEEDS the team DISCOVERED itself (truth-table: team insns vs compiler insns; compiler races the SOP form) --\n" as *u8)
51 var i: i64 = 0
52 while i < 8 { if ex[i*3+1] > 0 { if ex[i*3+1] <= 9 { bh_puts(" tt=" as *u8); bh_num(ex[i*3+0]); bh_puts(": team " as *u8); bh_num(ex[i*3+1]); bh_puts(" ops vs compiler " as *u8); bh_num(ex[i*3+2]); bh_puts(" insns\n" as *u8) } } i = i + 1 }
53 bh_puts(" -- where the team is BEHIND (names ops to AUTHOR next, e.g. andn the compiler has) --\n" as *u8)
54 i = 0
55 while i < 4 { if ex[24+i*3+1] > 0 { if ex[24+i*3+1] <= 9 { bh_puts(" tt=" as *u8); bh_num(ex[24+i*3+0]); bh_puts(": team " as *u8); bh_num(ex[24+i*3+1]); bh_puts(" ops vs compiler " as *u8); bh_num(ex[24+i*3+2]); bh_puts(" insns\n" as *u8) } } i = i + 1 }
56 bh_puts("----------------------------------------------------------------\n" as *u8)
57 bh_puts(" the team mapped the WHOLE space and surfaced its own wins + gaps -- it finds opportunities, not me.\n" as *u8)
58 return 0
59}
60
61func main() -> i64 {
62 bh_main()
63 sys_exit(0)
64 return 0
65}