code wiki / _hdl_build / nx_pcb_twin_gate.nx
nx_pcb_twin_gate.nx source
↩ module page · 82 lines · 5709 B
1// nx_pcb_twin_gate.nx -- GATE for the PCB electrical DIGITAL TWIN. Proves the model behaves like a REAL board EXACTLY:
2// T1 TEXTBOOK PIN -- a 10-mil-wide, 1-oz, 1-inch (1000-mil) trace == 49100 uOhm (49.1 mOhm), the standard real value.
3// This pins the twin to REALITY (a wrong formula misses it) -- the liar-kill.
4// T2 SCALING LAWS -- 2 oz copper halves R; 2x width halves R; 2x length doubles R. Exact integer relationships.
5// T3 V & P -- 500 mA through 49.1 mOhm => 24550 uV drop, 12275 uW dissipated (V=IR, P=I^2R), exact.
6// T4 NEVER-BRICK -- deterministic re-run; invalid geometry (width 0) returns -1 (guarded, no divide-by-zero).
7// T5 ROUTED TWIN -- route a real net on the shared router, take its ACTUAL length, compute its real resistance
8// -> the electrical twin reflects the routed geometry (topology + physics = a full twin).
9// GREEN iff all exact. Sovereign no-float nx_cc->nxasm. This is the EXACT engineering core; games/movies loosen it later.
10// expect_exit: 0 license_tier: ORIGINAL
11import "nx_pcb_twin.nx"
12import "nx_pcb_autoroute.nx"
13import "nx_syscalls.nx"
14
15func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func 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 }
17func fill(a: *i64, n: i64, v: i64) -> i64 { var i: i64=0; while i<n { a[i]=v; i=i+1 } return 0 }
18
19func main() -> i64 {
20 w("=== nx_pcb_twin_gate: PCB electrical DIGITAL TWIN (real copper physics, exact no-float, S-class) ===\n" as *u8)
21 var pass: i64 = 0; var total: i64 = 0
22
23 // ---------- T1: textbook pin ----------
24 let r_ref: i64 = twin_resistance_uohm(10, 100, 10, 1) // 10 hops x 100 mil = 1000 mil (1"), 10 mil wide, 1 oz
25 total=total+1; if r_ref == 49100 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
26 w("T1 textbook pin: 1-oz 10-mil 1-inch trace R=" as *u8); wn(r_ref); w(" uOhm (=49100 = 49.1 mOhm, the real value)\n" as *u8)
27
28 // ---------- T2: scaling laws ----------
29 let r_2oz: i64 = twin_resistance_uohm(10, 100, 10, 2)
30 let r_2w: i64 = twin_resistance_uohm(10, 100, 20, 1)
31 let r_2l: i64 = twin_resistance_uohm(20, 100, 10, 1)
32 var t2ok: i64 = 1
33 if r_2oz != 24550 { t2ok = 0 } // 2 oz -> half
34 if r_2w != 24550 { t2ok = 0 } // 2x width -> half
35 if r_2l != 98200 { t2ok = 0 } // 2x length -> double
36 total=total+1; if t2ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
37 w("T2 scaling: 2oz=" as *u8); wn(r_2oz); w(" 2xWidth=" as *u8); wn(r_2w); w(" 2xLen=" as *u8); wn(r_2l); w(" uOhm (half/half/double, exact)\n" as *u8)
38
39 // ---------- T3: voltage drop + power ----------
40 let vd: i64 = twin_vdrop_uv(49100, 500)
41 let pw: i64 = twin_power_uw(49100, 500)
42 var t3ok: i64 = 1
43 if vd != 24550 { t3ok = 0 }
44 if pw != 12275 { t3ok = 0 }
45 total=total+1; if t3ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
46 w("T3 V&P @ 500mA: Vdrop=" as *u8); wn(vd); w(" uV (24.55 mV) Power=" as *u8); wn(pw); w(" uW (12.275 mW), exact\n" as *u8)
47
48 // ---------- T4: never-brick ----------
49 let d1: i64 = twin_resistance_uohm(10, 100, 10, 1)
50 let d2: i64 = twin_resistance_uohm(10, 100, 10, 1)
51 let bad: i64 = twin_resistance_uohm(10, 100, 0, 1) // width 0 -> guarded -1
52 var t4ok: i64 = 1
53 if d1 != d2 { t4ok = 0 }
54 if bad != (0 - 1) { t4ok = 0 }
55 total=total+1; if t4ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
56 w("T4 never-brick: deterministic (" as *u8); wn(d1); w("==" as *u8); wn(d2); w("), invalid width->" as *u8); wn(bad); w(" (guarded, no div-by-zero)\n" as *u8)
57
58 // ---------- T5: routed twin (topology + physics) ----------
59 let W: i64 = 4; let H: i64 = 4
60 let nh: i64 = H*(W-1); let nv: i64 = (H-1)*W
61 let ax: *i64=sys_mmap(8*4) as *i64; let ay: *i64=sys_mmap(8*4) as *i64
62 let bx: *i64=sys_mmap(8*4) as *i64; let by: *i64=sys_mmap(8*4) as *i64
63 let cap_h: *i64=sys_mmap(8*64) as *i64; let cap_v: *i64=sys_mmap(8*64) as *i64
64 let block: *i64=sys_mmap(8*64) as *i64; let usedby: *i64=sys_mmap(8*64) as *i64
65 let vis: *i64=sys_mmap(8*64) as *i64; let came: *i64=sys_mmap(8*64) as *i64
66 let q: *i64=sys_mmap(8*64) as *i64; let pathbuf: *i64=sys_mmap(8*64) as *i64
67 let sh: *i64=sys_mmap(8*2) as *i64; let ok: *i64=sys_mmap(8*2) as *i64
68 ax[0]=0; ay[0]=0; bx[0]=3; by[0]=0
69 fill(cap_h, nh, 8); fill(cap_v, nv, 8)
70 let routed_hops: i64 = pa_route_board(1, ax, ay, bx, by, W, H, cap_h, cap_v, block, usedby, vis, came, q, pathbuf, 1, sh, ok)
71 let r_routed: i64 = twin_resistance_uohm(routed_hops, 100, 10, 1)
72 var t5ok: i64 = 1
73 if ok[0] != 1 { t5ok = 0 }
74 if routed_hops <= 0 { t5ok = 0 }
75 if r_routed <= 0 { t5ok = 0 }
76 total=total+1; if t5ok==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
77 w("T5 routed twin: real trace hops=" as *u8); wn(routed_hops); w(" -> length=" as *u8); wn(routed_hops*100); w(" mil -> R=" as *u8); wn(r_routed); w(" uOhm (the ACTUAL routed copper, as a real board)\n" as *u8)
78
79 w("\n=== nx_pcb_twin_gate " as *u8); wn(pass); w("/" as *u8); wn(total)
80 if pass == total { w(" GREEN (PCB electrical digital twin: exact real-copper physics pinned to the textbook value + routed-geometry-driven; deterministic no-float; the exact engineering core)\n" as *u8); sys_exit(0); return 0 }
81 w(" RED\n" as *u8); sys_exit(1); return 1
82}