code wiki / _hdl_build / nx_js_octane_richards.nx

nx_js_octane_richards.nx source

↩ module page · 85 lines · 3924 B

1// nx_js_octane_richards.nx -- MILESTONE: run the REAL Octane Richards benchmark (unmodified Google source, 2// harness stubbed) on our sovereign VM/JIT. Richards self-validates against V8's exact internal counts 3// (queueCount==2322, holdCount==928) and THROWS on mismatch -> a clean "RICHARDS_OK" return means we ran a 4// real Octane test AND matched V8's semantics. This proves the prototype-OOP + growable-array work is enough 5// to enter the feature-vs-feature competition. V8 (node v22, parse+20 runs, best-of-5) = 10983us on this box. 6// expect_exit: 0 license_tier: ORIGINAL 7import "nx_js_vm.nx" 8const K_MAGIC_262144: i64 = 262144 9const K_MAGIC_1204: i64 = 1204 10func ow(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func on(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 x: i64=0; while q>=0 { o[x]=t[q]; x=x+1; q=q-1 } sys_write(1,o,x); return 0 } 12 13func main(argc: i64, argv: *i64) -> i64 { 14 ow("=== nx_js_octane_richards: real Octane Richards on our sovereign VM/JIT ===\n" as *u8) 15 let fd: i64 = sys_openat_rd("knowledge/octane/richards_eng.js\x00" as *u8) 16 if fd < 0 { ow(" RED: cannot open knowledge/octane/richards_eng.js\n" as *u8); return 1 } 17 let cap: i64 = K_MAGIC_262144 18 let buf: *u8 = sys_mmap(cap + 8) 19 var total: i64 = 0 20 var done: i64 = 0 21 while done == 0 { 22 let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, cap - total) 23 if n <= 0 { done = 1 } else { total = total + n } 24 } 25 sys_close(fd) 26 buf[total] = 0 as u8 27 ow(" loaded richards_eng.js: ") 28 on(total) 29 ow(" bytes\n" as *u8) 30 31 // PARSE-ONLY check first: distinguish a syntax gap from a runtime feature gap. 32 let ctxbox: *i64 = sys_mmap(16) as *i64 33 let prog: i64 = jp_parse_source(buf, total, ctxbox) 34 let pctx: *i64 = (ctxbox[0]) as *i64 35 let pst: *i64 = jp_pst(pctx) 36 if pst[PST_ERR] == 1 { ow(" PARSE ERROR (a syntax feature is missing)\n" as *u8) } else { ow(" PARSE OK -> failure is a RUNTIME feature\n" as *u8) } 37 38 let out: *i64 = sys_mmap(16) as *i64 39 var best: i64 = 0 40 var rc: i64 = 0 41 var r: i64 = 0 42 while r < 3 { 43 let t0: i64 = sys_now_us() 44 rc = compile_run(buf, out) 45 let t1: i64 = sys_now_us() 46 var us: i64 = t1 - t0 47 if us < 1 { us = 1 } 48 if r == 0 { best = us } 49 if us < best { best = us } 50 r = r + 1 51 } 52 ow(" compile_run rc=") 53 on(rc) 54 ow(" result tag=") 55 on(out[0]) 56 if out[0] == VAL_STR { 57 ow(" '") 58 sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)) 59 ow("'") 60 } 61 ow("\n" as *u8) 62 // verify: rc==0 AND result == "RICHARDS_OK" (the self-validation passed = matched V8 counts) 63 var okr: i64 = 0 64 if rc == 0 { if out[0] == VAL_STR { 65 let rb: *u8 = ev_str_bytes((out[1]) as *i64) 66 let rl: i64 = ev_str_len((out[1]) as *i64) 67 if rl == 11 { okr = 1; var i: i64 = 0; let exp: *u8 = "RICHARDS_OK" as *u8; while i < 11 { if (rb[i] & 0xff) != (exp[i] & 0xff) { okr = 0; i = 11 } else { i = i + 1 } } } 68 } } 69 if okr == 0 { ow("=== RED: Richards did not run correctly (feature gap or wrong counts) ===\n" as *u8); return 1 } 70 let v8: i64 = K_MAGIC_1204 71 ow(" ours(parse+1 run)=") 72 on(best) 73 ow("us V8=") 74 on(v8) 75 ow("us => ") 76 let ratio: i64 = best * 100 / v8 77 on(ratio / 100) 78 ow(".") 79 let fr: i64 = ratio - (ratio / 100) * 100 80 if fr < 10 { ow("0" as *u8) } 81 on(fr) 82 ow("x slower than V8 on REAL Octane Richards\n" as *u8) 83 ow("=== GREEN: we RAN real Octane Richards, matched V8's internal counts (queueCount 2322/holdCount 928) ===\n" as *u8) 84 return 0 85}