code wiki / _hdl_build / nx_rv64_run_bin_tier.nx

nx_rv64_run_bin_tier.nx source

↩ module page · 27 lines · 2132 B

1// nx_rv64_run_bin_tier.nx -- runs knowledge/hw/runbin.bin on tier_run_c (C-capable tiered engine WITH the compressed- 2// region JIT) + UART capture, printing "TIERUART: <hex> jit=<loops>". Broad validation of the compressed JIT on diverse 3// real programs vs QEMU. expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_rv64_fast.nx" 6import "nx_rv64_jit.nx" 7import "nx_rv64_tier.nx" 8 9func 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 } 10func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; 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 } 11func g_h2(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 } sys_write(1,b,2); return 0 } 12const MEMSZ: i64 = 262144 13 14func main() -> i64 { 15 let lenbox: *i64=sys_mmap(16) as *i64 16 let code: *u8=sys_read_file("knowledge/hw/runbin.bin" as *u8, lenbox) 17 if (code as i64)==0 { g_puts("TIERUART: NOFILE\n" as *u8); sys_exit(1); return 1 } 18 let nb: i64=lenbox[0]; let nslot: i64=nb/2 + 16 19 let opk: *i64=sys_mmap(nslot*8) as *i64; let rd: *i64=sys_mmap(nslot*8) as *i64; let rs1: *i64=sys_mmap(nslot*8) as *i64; let rs2: *i64=sys_mmap(nslot*8) as *i64; let imm: *i64=sys_mmap(nslot*8) as *i64 20 let nc: i64=fk_predecode_c(code, nb, opk, rd, rs1, rs2, imm) 21 let reg: *i64=sys_mmap(32*8) as *i64; let mem: *u8=sys_mmap(MEMSZ); var z: i64=0; while z<32 { reg[z]=0; z=z+1 } var m: i64=0; while m<nb { mem[m]=code[m]; m=m+1 } 22 let txbuf: *u8=sys_mmap(512); fk_tx_reset(txbuf); let stats: *i64=sys_mmap(64) as *i64 23 tier_run_c(opk, rd, rs1, rs2, imm, nc, reg, mem, MEMSZ, 500000000, (0 as i64) as *NxVirtioMmio, 3, stats) 24 let n: i64=fk_tx_count() 25 g_puts("TIERUART: " as *u8); var i: i64=0; while i<n { g_h2(txbuf[i] as i64); i=i+1 } g_puts(" jit=" as *u8); g_pn(stats[1]); g_puts("\n" as *u8) 26 sys_exit(0); return 0 27}