code wiki / _hdl_build / nx_isa_equiv_sov.nx
nx_isa_equiv_sov.nx
buildroot/runtime/_hdl_build/nx_isa_equiv_sov.nx
about
nx_isa_equiv_sov.nx -- THE DIFFERENTIAL-REPLACEMENT TEST, ON THE HARDWARE.
The operator's own method ("comp a working child, turn it off, emit ours, see if they
function the same") performed at the genesis-hardware level, with NO Claude crutch left:
(1) the team COMPOSES its own random non-trivial target program T (over the REAL RV64IM
ALU ops that rv64im_min_sim executes -- ADD/SUB/MUL/AND/OR/SLT on a register machine),
(2) the team DERIVES a program G by evolutionary search that matches T's TRAIN examples
(search sees only (a,b)->T(a,b) points, never T's source),
(3) we ENCODE BOTH T and G to real RV64 machine code, run BOTH on rv64im_min_sim (god)
over 12 HELD-OUT inputs, and verify sim(T) == sim(G) as FULL 64-bit values.
The equivalence verdict reads the hardware -- the interpreter only GUIDES the search, it is
NOT in the proof. Two controls keep it honest: a FAITHFUL-ENCODE control (all 6 ops
encode->run->match the ALU) and a NEGATIVE control (a perturbed G the differential MUST
catch -- proving the test discriminates, not rubber-stamps).
Full 64-bit read-back: each program does `sd x3, RES_OFF(x5)` to scratch RAM; store64 writes
through to mem_buf (verified rv64im_min_sim.nx:415), which we read back directly. license_tier: ORIGINAL
dependencies 10 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnishi_hdl_primitives.nxrv64im_min_decoder.nxrv64im_min_alu.nxrv64im_min_regfile.nxrv64im_min_csr.nxrv64im_min_clint.nxrv64im_min_uart.nxrv64im_min_sim.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757 |
| 31 | const EVO_MAGIC_3037000493: i64 = 3037000493 |
| 32 | const EVO_MAGIC_1000000000000: i64 = 1000000000000 |
| 33 | const EVO_MAGIC_10000000000000: i64 = 10000000000000 |
| 34 | const EVO_MAGIC_1000000000: i64 = 1000000000 |
| 35 | const EVO_MAGIC_2654435761: i64 = 2654435761 |
| 36 | const EVO_MAGIC_12345: i64 = 12345 |
| 38 | const NINSTR: i64 = 3 |
| 39 | const GLEN: i64 = 9 // NINSTR * 3 (op, rs1, rs2); rd = x3 fixed |
| 40 | const EVO_P: i64 = 320 |
| 41 | const EVO_G: i64 = 1400 |
| 42 | const EVO_T: i64 = 5 |
| 43 | const NTRAIN: i64 = 6 |
| 44 | const NHELD: i64 = 12 |
| 46 | const IR_MEM_BASE: i64 = 0x80000000 |
| 47 | const IR_MEM_SIZE: i64 = 8192 |
| 48 | const IR_TX_CAP: i64 = 256 |
| 49 | const RES_OFF: i64 = 0x700 // scratch result slot (positive S-imm, past the ~52-byte code) |
functions
| 52 | func ie_rand(s: *i64) -> i64 { s[0] = s[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (s[0] >> 17) & 0x3fffffff } |
| 53 | func ie_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } called by 1: ie_fit |
| 56 | func ie_pa(i: i64) -> i64 { if i==0 {return 6} if i==1 {return 4} if i==2 {return 9} if i==3 {return 5} if i==4 {return 7} return 2 } called by 1: ie_fit |
| 57 | func ie_pb(i: i64) -> i64 { if i==0 {return 4} if i==1 {return 7} if i==2 {return 2} if i==3 {return 9} if i==4 {return 3} return 5 } called by 1: ie_fit |
| 58 | func ie_ha(i: i64) -> i64 { if i==0 {return 3} if i==1 {return 8} if i==2 {return 11} if i==3 {return 2} if i==4 {return 10} if i==5 {return 13} if i==6 {return 7} if i==7 {return 4} if i==8 {return 12} if i==9 {return 6} if i==10 {return 9} return 5 } |
| 59 | func ie_hb(i: i64) -> i64 { if i==0 {return 5} if i==1 {return 2} if i==2 {return 7} if i==3 {return 11} if i==4 {return 4} if i==5 {return 3} if i==6 {return 9} if i==7 {return 8} if i==8 {return 2} if i==9 {return 13} if i==10 {return 6} return 10 } |
| 62 | func ie_op(op: i64, x: i64, y: i64) -> i64 |
| 71 | func ie_f3(op: i64) -> i64 { if op==3 {return 7} if op==4 {return 6} if op==5 {return 2} return 0 } // AND=7 OR=6 SLT=2 else 0 called by 1: ie_emit |
| 72 | func ie_f7(op: i64) -> i64 { if op==1 {return 0x20} if op==2 {return 0x01} return 0x00 } // SUB=0x20 MUL=0x01 else 0 called by 1: ie_emit |
| 74 | func ie_reg(idx: i64, a: i64, b: i64, acc: i64) -> i64 called by 1: ie_eval |
| 81 | func ie_eval(gen: *i64, base: i64, a: i64, b: i64) -> i64 |
| 97 | func rv_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 } called by 1: ie_emit |
| 98 | func rv_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 } called by 1: ie_emit |
| 99 | func rv_rtype(f7: i64, rs2: i64, rs1: i64, f3: i64, rd: i64) -> i64 { return (f7 << 25) | (rs2 << 20) | (rs1 << 15) | (f3 << 12) | (rd << 7) | 0x33 } called by 1: ie_emit |
| 100 | func rv_store_imm(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64 called by 1: ie_emit |
| 105 | func rv_w32(buf: *u8, off: i64, w: i64) -> i64 called by 1: ie_emit |
| 113 | func ie_emit(mem: *u8, gen: *i64, base: i64, a: i64, b: i64) -> i64 |
| 136 | func ie_read_i64(mem: *u8, off: i64) -> i64 called by 1: ie_run_prog |
| 143 | func ie_run_prog(gen: *i64, base: i64, a: i64, b: i64) -> i64 |
| 166 | func ie_setinstr(gen: *i64, j: i64, state: *i64) -> i64 |
| 173 | func ie_compose(state: *i64, T: *i64) -> i64 |
| 186 | func ie_fit(pop: *i64, base: i64, T: *i64) -> i64 |
| 199 | func ie_tourney(fit: *i64, state: *i64) -> i64 |
| 204 | func ie_mut(gen: *i64, base: i64, state: *i64) -> i64 |
| 211 | func ie_derive(T: *i64, state: *i64, G: *i64) -> i64 |
| 244 | func ie_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 249 | func ie_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 253 | func ie_faithful() -> i64 |
| 271 | func ie_hw_agree(A: *i64, B: *i64) -> i64 |
| 281 | func ie_hw_faithful(T: *i64) -> i64 |
| 292 | func ie_seed(seed: i64) -> i64 |
| 317 | func ie_negctl(seed: i64) -> i64 |
| 341 | func main() -> i64 |