code wiki / _hdl_build / nx_emu_exceed.nx

nx_emu_exceed.nx source

↩ module page · 85 lines · 3556 B

1// nx_emu_exceed.nx -- R0.5 MEASURED exceed census for the sovereign emulator vs the incumbent (Emscripten 2// em-dosbox / js-dos). Data-driven (emu_exceed_panel.tsv), graded MECHANICALLY not self-scored: the audit 3// MEASURES the real wasm artifact size and REFUSES any EXCEED grade that lacks evidence (the liar-kill). 4// Honest by construction -- the panel carries PARITY (accuracy, verified subset only) and BEHIND 5// (breadth/maturity) rows, so the census can never read as "we beat everything". license_tier: ORIGINAL 6// 7// emu_exceed_panel.tsv columns (TAB-separated): axis <TAB> verdict <TAB> nishi <TAB> incumbent <TAB> evidence 8// verdict: EXCEED | PARITY | BEHIND evidence: gate:<name> | file:<path> | emit:<path> | - 9// LAW: a row with verdict==EXCEED MUST carry evidence (non "-"); otherwise it is a LIAR -> flagged. 10import "nx_syscalls.nx" 11 12const EMU_WASM: *u8 = "web_assets/ch8.wasm" 13 14func ex_field(buf: *u8, ls: i64, le: i64, idx: i64, fs: *i64, fl: *i64) -> i64 { 15 var cur: i64 = ls 16 var f: i64 = 0 17 while f < idx { 18 while cur < le { if buf[cur] == (9 as u8) { break } cur = cur + 1 } 19 if cur >= le { return 0 } 20 cur = cur + 1 21 f = f + 1 22 } 23 var e: i64 = cur 24 while e < le { if buf[e] == (9 as u8) { break } e = e + 1 } 25 fs[0] = cur 26 fl[0] = e - cur 27 return 1 28} 29func ex_streq(buf: *u8, start: i64, len: i64, s: *u8) -> i64 { 30 var slen: i64 = 0 31 while s[slen] != (0 as u8) { slen = slen + 1 } 32 if slen != len { return 0 } 33 var i: i64 = 0 34 while i < len { if buf[start + i] != s[i] { return 0 } i = i + 1 } 35 return 1 36} 37func ex_absent(buf: *u8, start: i64, len: i64) -> i64 { 38 if len == 0 { return 1 } 39 if len == 1 { if buf[start] == (45 as u8) { return 1 } } 40 return 0 41} 42 43// the MEASURED anchor: the real byte size of the shipped sovereign wasm (0 if missing). 44func ex_wasm_size() -> i64 { 45 let box: *i64 = sys_mmap(16) as *i64 46 let d: *u8 = sys_read_file(EMU_WASM, box) 47 if (d as i64) == 0 { return 0 } 48 return box[0] 49} 50 51// audit a panel buffer: out[0]=#EXCEED, out[1]=#PARITY, out[2]=#BEHIND. RETURNS the number of LIAR rows 52// (verdict==EXCEED with no evidence) -- 0 means the census is honest (no unevidenced exceed claim). 53func nx_emu_audit(panel: *u8, plen: i64, out: *i64) -> i64 { 54 out[0] = 0; out[1] = 0; out[2] = 0 55 var liars: i64 = 0 56 let fs: *i64 = sys_mmap(8) as *i64 57 let fl: *i64 = sys_mmap(8) as *i64 58 let es: *i64 = sys_mmap(8) as *i64 59 let el: *i64 = sys_mmap(8) as *i64 60 var i: i64 = 0 61 var ls: i64 = 0 62 while i <= plen { 63 var nl: i64 = 0 64 if i == plen { nl = 1 } else { if panel[i] == (10 as u8) { nl = 1 } } 65 if nl == 1 { 66 let le: i64 = i 67 if le > ls { 68 if ex_field(panel, ls, le, 1, fs, fl) == 1 { 69 var isE: i64 = 0 70 if ex_streq(panel, fs[0], fl[0], "EXCEED" as *u8) == 1 { isE = 1; out[0] = out[0] + 1 } 71 if ex_streq(panel, fs[0], fl[0], "PARITY" as *u8) == 1 { out[1] = out[1] + 1 } 72 if ex_streq(panel, fs[0], fl[0], "BEHIND" as *u8) == 1 { out[2] = out[2] + 1 } 73 if isE == 1 { 74 var hasEv: i64 = 0 75 if ex_field(panel, ls, le, 4, es, el) == 1 { if ex_absent(panel, es[0], el[0]) == 0 { hasEv = 1 } } 76 if hasEv == 0 { liars = liars + 1 } 77 } 78 } 79 } 80 ls = i + 1 81 } 82 i = i + 1 83 } 84 return liars 85}