code wiki / _hdl_build / nx_isa_equiv_sov.nx

nx_isa_equiv_sov.nx

buildroot/runtime/_hdl_build/nx_isa_equiv_sov.nx

18319 B358 linesdepth 5pulls 17 transitivereach 0 importersview sourcekind tooltopic isa
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_itoa_lib.nx nishi_hdl_primitives.nx rv64im_min_decoder.nx rv64im_min_alu.nx rv64im_min_regfile.nx rv64im_min_csr.nx rv64im_min_clint.nx rv64im_min_uart.nx rv64im_min_sim.nx nx_isa_equiv_sov.nx

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

main ie_p sys_write ie_faithful sys_mmap ie_run_prog sys_mmap ↻ nx_rv64im_rf_init nx_rv64im_csr_init nx_clint_init nx_uart_init nx_rv64im_sim_init ie_emit rv_w32 rv_addi rv_rtype ie_f7 ie_f3 rv_lui rv_store_imm nx_rv64im_sim_run nx_rv64im_sim_step nx_clint_tick nx_clint_update_mtip nx_rv64im_csr_tick_mcycle nx_clint_mtip_get nx_rv64im_csr_read nx_csr_addr_to_slot nx_rv64im_sim_take_trap nx_rv64im_csr_read ↻ nx_rv64im_csr_write nx_rv64im_xlate nx_rv64im_csr_read ↻ nx_rv64im_is_device sys_mmap ↻ nx_sv39_walk nx_mmu_inrange nx_mmu_rd64 nx_mmu_wr64 nx_rv64im_csr_write ↻

structs

none

consts

30const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757
31const EVO_MAGIC_3037000493: i64 = 3037000493
32const EVO_MAGIC_1000000000000: i64 = 1000000000000
33const EVO_MAGIC_10000000000000: i64 = 10000000000000
34const EVO_MAGIC_1000000000: i64 = 1000000000
35const EVO_MAGIC_2654435761: i64 = 2654435761
36const EVO_MAGIC_12345: i64 = 12345
38const NINSTR: i64 = 3
39const GLEN: i64 = 9 // NINSTR * 3 (op, rs1, rs2); rd = x3 fixed
40const EVO_P: i64 = 320
41const EVO_G: i64 = 1400
42const EVO_T: i64 = 5
43const NTRAIN: i64 = 6
44const NHELD: i64 = 12
46const IR_MEM_BASE: i64 = 0x80000000
47const IR_MEM_SIZE: i64 = 8192
48const IR_TX_CAP: i64 = 256
49const RES_OFF: i64 = 0x700 // scratch result slot (positive S-imm, past the ~52-byte code)

functions

52func ie_rand(s: *i64) -> i64 { s[0] = s[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (s[0] >> 17) & 0x3fffffff }
53func ie_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 1: ie_fit
56func 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
57func 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
58func 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 }
59func 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 }
62func ie_op(op: i64, x: i64, y: i64) -> i64
called by 2: ie_evalie_faithful
71func 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
72func 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
74func ie_reg(idx: i64, a: i64, b: i64, acc: i64) -> i64
called by 1: ie_eval
81func ie_eval(gen: *i64, base: i64, a: i64, b: i64) -> i64
97func rv_addi(rd: i64, rs1: i64, imm: i64) -> i64 { return ((imm & 0xFFF) << 20) | (rs1 << 15) | (rd << 7) | 0x13 }
called by 1: ie_emit
98func rv_lui(rd: i64, imm20: i64) -> i64 { return ((imm20 & 0xFFFFF) << 12) | (rd << 7) | 0x37 }
called by 1: ie_emit
99func 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
100func rv_store_imm(rs2: i64, rs1: i64, f3: i64, imm: i64) -> i64
called by 1: ie_emit
105func rv_w32(buf: *u8, off: i64, w: i64) -> i64
called by 1: ie_emit
113func ie_emit(mem: *u8, gen: *i64, base: i64, a: i64, b: i64) -> i64
136func ie_read_i64(mem: *u8, off: i64) -> i64
called by 1: ie_run_prog
143func ie_run_prog(gen: *i64, base: i64, a: i64, b: i64) -> i64
166func ie_setinstr(gen: *i64, j: i64, state: *i64) -> i64
called by 2: ie_composeie_derive calls 1: ie_rand
173func ie_compose(state: *i64, T: *i64) -> i64
called by 2: ie_seedie_negctl calls 2: ie_setinstrie_eval
186func ie_fit(pop: *i64, base: i64, T: *i64) -> i64
called by 1: ie_derive calls 4: ie_paie_pbie_evalie_abs
199func ie_tourney(fit: *i64, state: *i64) -> i64
called by 1: ie_derive calls 1: ie_rand
204func ie_mut(gen: *i64, base: i64, state: *i64) -> i64
called by 1: ie_derive calls 1: ie_rand
211func ie_derive(T: *i64, state: *i64, G: *i64) -> i64
244func 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 }
249func ie_pn(v: i64) -> i64 { nxi_out(v); return 0 }
253func ie_faithful() -> i64
271func ie_hw_agree(A: *i64, B: *i64) -> i64
281func ie_hw_faithful(T: *i64) -> i64
292func ie_seed(seed: i64) -> i64
317func ie_negctl(seed: i64) -> i64
341func main() -> i64