code wiki / _hdl_build / nx_rv64_difftest.nx
nx_rv64_difftest.nx
buildroot/runtime/_hdl_build/nx_rv64_difftest.nx
about
nx_rv64_difftest.nx -- DIFFERENTIAL FUZZER for the RV64 emulator stack (the SOTA way to validate a JIT: V8/QEMU do
exactly this). Generates hundreds of RANDOM, terminating-by-construction RV64 programs (random arithmetic/shift/
memory ops + a bounded counting loop) with a FIXED SEED (reproducible), and asserts the GOLDEN INTERPRETER, the JIT
(whole-program compile+run), and the TIERED ENGINE all produce BIT-IDENTICAL final state (registers XOR memory).
This turns "equivalence-validated" from a handful of hand-written KATs into broad evidence -- and any divergence is
a real bug (reproducible from the seed). expect_exit: 0
dependencies 4 imports · 0 importers
imports: nx_syscalls.nxnx_rv64_fast.nxnx_rv64_jit.nxnx_rv64_tier.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
| 16 | const MEMSZ: i64 = 4096 |
| 17 | const NPROG: i64 = 500 |
| 18 | const BIGSTEPS: i64 = 4000000 |
functions
| 12 | func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 13 | func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 } |
| 14 | func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c } |
| 21 | func rnd(st: *i64) -> i64 { st[0]=st[0]*6364136223846793005 + 1442695040888963407; return (st[0]>>16)&0xFFFFFF } called by 1: rndn |
| 22 | func rndn(st: *i64, n: i64) -> i64 { return rnd(st)%n } |
| 26 | func gen_op(st: *i64, opk: *i64, rd: *i64, rs1: *i64, rs2: *i64, imm: *i64, idx: i64) -> i64 |
| 47 | func gen_program(st: *i64, opk: *i64, rd: *i64, rs1: *i64, rs2: *i64, imm: *i64) -> i64 |
| 59 | func ck_reg(reg: *i64) -> i64 { var h: i64=1469598103934665603; var i: i64=1; while i<32 { h=(h^reg[i])*1099511628211; i=i+1 } return h } called by 1: main |
| 60 | func ck_mem(mem: *u8, n: i64) -> i64 { var h: i64=1469598103934665603; var i: i64=0; while i<n { h=(h^(mem[i] as i64))*1099511628211; i=i+1 } return h } called by 1: main |
| 61 | func zero32(r: *i64) -> i64 { var i: i64=0; while i<32 { r[i]=0; i=i+1 } return 0 } called by 1: main |
| 63 | func main() -> i64 |