code wiki / _hdl_build / nx_pcb_autoroute_gate.nx

nx_pcb_autoroute_gate.nx source

↩ module page · 83 lines · 5517 B

1// nx_pcb_autoroute_gate.nx -- GATE for the SOVEREIGN PCB autorouter (reuses the silicon router = shared resource). 2// T1 CLEAN BOARD -- 2 non-conflicting nets route node-disjoint, 0 shorts, copper length>0. 3// T2 CROSS+DETOUR -- 2 nets that would cross at one node; node-keepout forces the 2nd to DETOUR, still routed, 0 shorts. 4// T3 NEVER-BRICK -- deterministic (re-run identical), bounded, pure memory. 5// T4 LIAR-KILL -- same crossing board WITHOUT keepout -> the traces SHORT (shorts>0); proves DRC keepout is load-bearing. 6// T5 CONGESTION -- a full-width trace blocks every vertical crossing -> the 2nd net is UNROUTABLE (not fabricated). 7// GREEN iff all pass. Sovereign nx_cc->nxasm (no gcc, no KiCad/Freerouting). expect_exit: 0 license_tier: ORIGINAL 8import "nx_pcb_autoroute.nx" 9import "nx_syscalls.nx" 10 11func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 13func fill(a: *i64, n: i64, v: i64) -> i64 { var i: i64=0; while i<n { a[i]=v; i=i+1 } return 0 } 14 15func main() -> i64 { 16 w("=== nx_pcb_autoroute_gate: SOVEREIGN PCB autorouter (reuses the silicon Lee/BFS router = shared resource) ===\n" as *u8) 17 var pass: i64 = 0; var total: i64 = 0 18 let W: i64 = 4; let H: i64 = 4 19 let CAP: i64 = 8 20 let nh: i64 = H*(W-1) 21 let nv: i64 = (H-1)*W 22 23 let ax: *i64 = sys_mmap(8*4) as *i64 24 let ay: *i64 = sys_mmap(8*4) as *i64 25 let bx: *i64 = sys_mmap(8*4) as *i64 26 let by: *i64 = sys_mmap(8*4) as *i64 27 let cap_h: *i64 = sys_mmap(8*64) as *i64 28 let cap_v: *i64 = sys_mmap(8*64) as *i64 29 let block: *i64 = sys_mmap(8*64) as *i64 30 let usedby: *i64 = sys_mmap(8*64) as *i64 31 let vis: *i64 = sys_mmap(8*64) as *i64 32 let came: *i64 = sys_mmap(8*64) as *i64 33 let q: *i64 = sys_mmap(8*64) as *i64 34 let pathbuf: *i64 = sys_mmap(8*64) as *i64 35 let sh: *i64 = sys_mmap(8*2) as *i64 36 let ok: *i64 = sys_mmap(8*2) as *i64 37 38 // ---------- T1: clean board, 2 non-conflicting nets ---------- 39 ax[0]=0; ay[0]=0; bx[0]=3; by[0]=0 40 ax[1]=0; ay[1]=3; bx[1]=3; by[1]=3 41 fill(cap_h, nh, CAP); fill(cap_v, nv, CAP) 42 let t1: i64 = pa_route_board(2, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 1, sh, ok) 43 total=total+1 44 if ok[0]==1 { if sh[0]==0 { if t1>0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) } 45 w("T1 clean board: routed=" as *u8); wn(ok[0]); w(" shorts=" as *u8); wn(sh[0]); w(" copper=" as *u8); wn(t1); w("\n" as *u8) 46 47 // ---------- T2: crossing nets, keepout forces detour ---------- 48 ax[0]=0; ay[0]=1; bx[0]=2; by[0]=1 49 ax[1]=1; ay[1]=0; bx[1]=1; by[1]=2 50 fill(cap_h, nh, CAP); fill(cap_v, nv, CAP) 51 let t2: i64 = pa_route_board(2, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 1, sh, ok) 52 total=total+1 53 if ok[0]==1 { if sh[0]==0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) } 54 w("T2 cross+detour (keepout): routed=" as *u8); wn(ok[0]); w(" shorts=" as *u8); wn(sh[0]); w(" copper=" as *u8); wn(t2); w(" (2nd net detoured node-disjoint)\n" as *u8) 55 56 // ---------- T3: never-brick determinism ---------- 57 fill(cap_h, nh, CAP); fill(cap_v, nv, CAP) 58 let t3: i64 = pa_route_board(2, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 1, sh, ok) 59 var t3ok: i64 = 1 60 if t3 != t2 { t3ok = 0 } 61 total=total+1; if t3ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 62 w("T3 never-brick: deterministic (copper " as *u8); wn(t2); w("==" as *u8); wn(t3); w("), bounded, pure memory\n" as *u8) 63 64 // ---------- T4: liar-kill -- same crossing board WITHOUT keepout -> SHORT ---------- 65 ax[0]=0; ay[0]=1; bx[0]=2; by[0]=1 66 ax[1]=1; ay[1]=0; bx[1]=1; by[1]=2 67 fill(cap_h, nh, CAP); fill(cap_v, nv, CAP) 68 pa_route_board(2, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 0, sh, ok) 69 total=total+1; if sh[0]>0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 70 w("T4 liar-kill: WITHOUT keepout the traces short at shared node(s) shorts=" as *u8); wn(sh[0]); w(" (DRC keepout is load-bearing)\n" as *u8) 71 72 // ---------- T5: congestion -- full-width trace blocks all vertical crossings -> UNROUTABLE ---------- 73 ax[0]=0; ay[0]=1; bx[0]=3; by[0]=1 74 ax[1]=1; ay[1]=0; bx[1]=1; by[1]=3 75 fill(cap_h, nh, CAP); fill(cap_v, nv, CAP) 76 pa_route_board(2, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 1, sh, ok) 77 total=total+1; if ok[0]==0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } 78 w("T5 congestion: a full-width trace blocks every crossing -> 2nd net UNROUTABLE routed=" as *u8); wn(ok[0]); w(" (no fabricated success)\n" as *u8) 79 80 w("\n=== nx_pcb_autoroute_gate " as *u8); wn(pass); w("/" as *u8); wn(total) 81 if pass == total { w(" GREEN (sovereign PCB autorouter on the SHARED silicon router: node-disjoint DRC-clean routing, detour, liar-kill, congestion; never-brick; no KiCad/Freerouting)\n" as *u8); sys_exit(0); return 0 } 82 w(" RED\n" as *u8); sys_exit(1); return 1 83}