nx_race_board.nx source
↩ module page · 83 lines · 4288 B
1// nx_race_board.nx -- the RACING BOARD: every car RACED vs its named incumbent,
2// as standing teamwork (the racing-crew's racing line, not "does the car turn
3// on"). Sovereign NishiLang, no .sh. Data-driven: a registry of "race-car" .nx
4// programs, each of which MEASURES ours vs the incumbent/research baseline and
5// prints its racing line (+ verdict). The board compiles + runs each and shows
6// the line -- run it every cycle (the Conductor ticks it, like nx_gate_runner
7// does for correctness gates). Adding a car = adding a registry row, not a
8// one-off. This is stage 6 (measure vs incumbent) of the autonomous-build
9// pipeline, made concrete + always-on.
10//
11// Race-car contract: a .nx that measures + prints "ours vs incumbent/frontier"
12// and a RACE-VERDICT line; exits 0 when the measurement ran. (Correctness is the
13// gate runner's job; this is purely the speed/competitiveness line.)
14// Build oracles as/ld (-> nxasm/nxld). license_tier: ORIGINAL
15
16import "nx_run_timeout.nx"
17
18const RB_CC: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/_offc/nx_cc_known_good.elf"
19const RB_AS: *u8 = "/usr/bin/as"
20const RB_LD: *u8 = "/usr/bin/ld"
21const RB_S: *u8 = "/tmp/nx_rb.s"
22const RB_O: *u8 = "/tmp/nx_rb.o"
23const RB_ELF: *u8 = "/tmp/nx_rb.elf"
24const RB_MODE: i64 = 420
25
26func rb_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 }
27
28// fork+exec; out_path != 0 => child stdout -> that file; out_path == 0 => stdout
29// INHERITED (shown, so the race line prints to the board). stderr -> /dev/null.
30func rb_run(path: *u8, argv: *i64, envp: *i64, out_path: *u8) -> i64 {
31 let pid: i64 = sys_fork()
32 if pid == 0 {
33 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0)
34 if (out_path as i64) != 0 { let ofd: i64 = sys_openat_wr(out_path, RB_MODE); if ofd >= 0 { sys_dup3(ofd, 1, 0) } }
35 if dn >= 0 { sys_dup3(dn, 2, 0) }
36 sys_execve(path, argv, envp)
37 sys_exit(127)
38 }
39 let st: *i64 = sys_mmap(16) as *i64
40 sys_wait4(pid, st, 0)
41 return wait_exit_code(st[0])
42}
43
44// compile + run a race-car .nx, SHOWING its racing line. returns the run exit
45// code, or a negative stage code on a build-oracle failure.
46func rb_race(racenx: *u8) -> i64 {
47 let envp: *i64 = sys_mmap(8) as *i64; envp[0] = 0
48 let a1: *i64 = sys_mmap(32) as *i64; a1[0] = RB_CC as i64; a1[1] = racenx as i64; a1[2] = 0
49 if rb_run(RB_CC, a1, envp, RB_S) != 0 { return 0 - 1 }
50 let a2: *i64 = sys_mmap(40) as *i64; a2[0] = RB_AS as i64; a2[1] = RB_S as i64; a2[2] = ("-o" as *u8) as i64; a2[3] = RB_O as i64; a2[4] = 0
51 if rb_run(RB_AS, a2, envp, 0 as *u8) != 0 { return 0 - 2 }
52 let a3: *i64 = sys_mmap(40) as *i64; a3[0] = RB_LD as i64; a3[1] = ("-o" as *u8) as i64; a3[2] = RB_ELF as i64; a3[3] = RB_O as i64; a3[4] = 0
53 if rb_run(RB_LD, a3, envp, 0 as *u8) != 0 { return 0 - 3 }
54 let a4: *i64 = sys_mmap(16) as *i64; a4[0] = RB_ELF as i64; a4[1] = 0
55 return rb_run(RB_ELF, a4, envp, 0 as *u8) // stdout INHERITED -> the race line shows
56}
57
58func main() -> i64 {
59 rb_puts("NISHI RACING BOARD -- every car raced vs its named incumbent (the racing LINE, not 'does it turn on')\n")
60 rb_puts("===================================================================================================\n")
61
62 let N: i64 = 1
63 let names: *i64 = sys_mmap(N * 8) as *i64
64 let cars: *i64 = sys_mmap(N * 8) as *i64
65 names[0] = ("divider-latency vs the division ladder" as *u8) as i64
66 cars[0] = ("/mnt/c/Users/elder/nishi-core/nxc2/runtime/_hdl_build/nx_alu_divider_race_test.nx" as *u8) as i64
67
68 var ran: i64 = 0
69 var i: i64 = 0
70 while i < N {
71 rb_puts("\n[race] "); rb_puts(names[i] as *u8); rb_puts("\n")
72 let rc: i64 = rb_race(cars[i] as *u8)
73 if rc >= 0 { ran = ran + 1 } else { rb_puts(" (race build failed)\n") }
74 i = i + 1
75 }
76
77 rb_puts("\nracing board ran ");
78 let z: *u8 = sys_mmap(2); z[0] = (0x30 + ran) as u8; sys_write(1, z, 1)
79 rb_puts(" race-car(s). TO WIRE (each has measured incumbents on the pitwall board): crypto vs OpenSSL,\n")
80 rb_puts(" codec vs Opus, search vs Elasticsearch, NX-EMU vs qemu, nxasm vs as+ld. Racing = standing teamwork.\n")
81 if ran != N { sys_exit(1); return 1 }
82 sys_exit(0); return 0
83}