code wiki / _hdl_build / nx_jit_ra_probe.nx
nx_jit_ra_probe.nx source
↩ module page · 29 lines · 2555 B
1// nx_jit_ra_probe.nx -- PROBE: dump the register-allocated JIT's emitted x86 bytes WITHOUT executing (isolate
2// compile vs execute for the hang). expect_exit:0
3import "nx_syscalls.nx"
4import "nx_rv64_asm.nx"
5import "nx_rv64_fast.nx"
6import "nx_rv64_jit.nx"
7
8func p_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
9func p_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 }
10func p_hx2(v: i64) -> i64 { let b: *u8=sys_mmap(4); let n0: i64=(v>>4)&15; let n1: i64=v&15; if n0<10 { b[0]=(48+n0) as u8 } else { b[0]=(87+n0) as u8 } if n1<10 { b[1]=(48+n1) as u8 } else { b[1]=(87+n1) as u8 } b[2]=32 as u8; sys_write(1,b,3); return 0 }
11
12func main() -> i64 {
13 p_puts("nx_jit_ra_probe: compile P1 count loop with the reg-alloc JIT, dump bytes (no execute)\n" as *u8)
14 let code: *u8=sys_mmap(4096)
15 let opk: *i64=sys_mmap(64*8) as *i64; let rd: *i64=sys_mmap(64*8) as *i64; let rs1: *i64=sys_mmap(64*8) as *i64; let rs2: *i64=sys_mmap(64*8) as *i64; let imm: *i64=sys_mmap(64*8) as *i64
16 let nb: i64 = rvasm_assemble_str(" li t0, 0\n lui t1, 0x800\nloop:\n addi t0, t0, 1\n blt t0, t1, loop\n" as *u8, code, 4096)
17 let nc: i64 = fk_predecode(code, nb, opk, rd, rs1, rs2, imm)
18 p_puts(" predecoded "); p_pn(nc); p_puts(" ops. per-op (kind,rd,rs1,rs2,imm):\n" as *u8)
19 var i: i64=0; while i<nc { p_puts(" ["); p_pn(i); p_puts("] k="); p_pn(opk[i]); p_puts(" rd="); p_pn(rd[i]); p_puts(" rs1="); p_pn(rs1[i]); p_puts(" rs2="); p_pn(rs2[i]); p_puts(" imm="); p_pn(imm[i]); p_puts("\n" as *u8); i=i+1 }
20 let x86: *u8=sys_mmap(4096); let x86off: *i64=sys_mmap(nc*8) as *i64; let rvmap: *i64=sys_mmap(32*8) as *i64
21 let xlen: i64 = jit_compile_ra(opk, rd, rs1, rs2, imm, nc, x86, x86off, rvmap)
22 p_puts(" jit_compile_ra xlen="); p_pn(xlen); p_puts("\n" as *u8)
23 if xlen<0 { p_puts(" (ineligible)\n" as *u8); sys_exit(0); return 0 }
24 p_puts(" rvmap: t0(x5)->"); p_pn(rvmap[5]); p_puts(" t1(x6)->"); p_pn(rvmap[6]); p_puts("\n" as *u8)
25 p_puts(" x86off: "); i=0; while i<nc { p_pn(x86off[i]); p_puts(" " as *u8); i=i+1 } p_puts("\n" as *u8)
26 p_puts(" bytes: "); i=0; while i<xlen { p_hx2(x86[i] as i64); i=i+1 } p_puts("\n" as *u8)
27 p_puts("verdict=GREEN (compile dumped; inspect the bytes)\n" as *u8)
28 sys_exit(0); return 0
29}