code wiki / _hdl_build / nx_netquant_gate.nx
nx_netquant_gate.nx source
↩ module page · 126 lines · 6777 B
1// nx_netquant_gate.nx -- proves + MEASURES the sovereign bit-packed/delta state codec
2// (nx_netquant) that keeps a bad-mobile-network player smooth. Shows the real bit budget.
3// 1) FULL keyframe round-trips EXACTLY (lossless for in-range values) -- measured 88 bits/11 B
4// 2) BIT BUDGET: full < raw 28-byte frame (measured compression)
5// 3) DELTA stationary -> tiny (~mask only); round-trips exact
6// 4) DELTA small move < FULL (the low-bandwidth win) + round-trips exact
7// 5) WALK PATH: 16 frames delta-coded -> measured avg bytes/snapshot vs full vs raw
8// 6) anti-tautology (neg): a delta on the WRONG baseline gives a WRONG result
9// (proves it is genuinely baseline-relative, not secretly absolute)
10// Built nx_cc_sovereign -> nxasm_x86 (no gcc, no .sh). license_tier: ORIGINAL
11import "nx_syscalls.nx"
12import "nx_gate_emit_lib.nx"
13import "nx_netquant.nx"
14import "nx_gate_verdict.nx"
15
16func setf(f: *i64, x: i64, y: i64, z: i64, yaw: i64, pitch: i64, sp: i64, ct: i64, act: i64, anim: i64, fl: i64) -> i64 {
17 f[0]=x; f[1]=y; f[2]=z; f[3]=yaw; f[4]=pitch; f[5]=sp; f[6]=ct; f[7]=act; f[8]=anim; f[9]=fl
18 return 0
19}
20func fcopy(dst: *i64, src: *i64) -> i64 { var i: i64=0; while i<10 { dst[i]=src[i]; i=i+1 } return 0 }
21// equality with the codec's lossy-but-defined fields normalized (yaw mod360, anim low6)
22func feq_full(a: *i64, b: *i64) -> i64 {
23 var i: i64=0
24 while i<10 {
25 var av: i64 = a[i]; var bv: i64 = b[i]
26 if i==3 { av = nq_yawn(av); bv = nq_yawn(bv) }
27 if i==8 { av = av & 63; bv = bv & 63 }
28 if av != bv { return 0 }
29 i=i+1
30 }
31 return 1
32}
33func feq_exact(a: *i64, b: *i64) -> i64 { var i: i64=0; while i<10 { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
34
35func main() -> i64 {
36 g_puts("nx_netquant gate (sovereign bit-packed/delta state codec for adverse networks)\n" as *u8)
37 var pass: i64 = 0; var total: i64 = 0
38
39 let buf: *u8 = sys_mmap(256)
40 let f: *i64 = sys_mmap(10*8) as *i64
41 let g: *i64 = sys_mmap(10*8) as *i64
42 let base:*i64 = sys_mmap(10*8) as *i64
43 let cur: *i64 = sys_mmap(10*8) as *i64
44 let out: *i64 = sys_mmap(10*8) as *i64
45
46 // a representative player snapshot (z negative -> west of origin)
47 setf(f, 1500, 9, 0-820, 725, 0-37, 2, 6, 4, 41, 1)
48
49 // 1) FULL round-trip + bit measure
50 let fbits: i64 = nq_pack_full(buf, f)
51 nq_unpack_full(buf, g)
52 var r1: i64 = feq_full(f, g)
53 g_puts(" [measure] FULL keyframe = " as *u8); g_pn(fbits); g_puts(" bits = " as *u8); g_pn(nx_bits_bytes(fbits)); g_puts(" bytes (raw frame = 28 bytes)\n" as *u8)
54 pass = pass + g_check("FULL keyframe round-trips exactly" as *u8, r1); total=total+1
55
56 // 2) BIT BUDGET: full < raw
57 pass = pass + g_check("BIT BUDGET: full keyframe < 28-byte raw frame" as *u8, nx_bits_bytes(fbits) < 28); total=total+1
58
59 // 3) DELTA stationary
60 setf(base, 1500, 9, 0-820, 725, 0-37, 2, 6, 4, 41, 1)
61 fcopy(cur, base) // no change
62 let dbits0: i64 = nq_pack_delta(buf, base, cur)
63 nq_unpack_delta(buf, base, out)
64 var r3: i64 = 1
65 if feq_exact(out, cur) != 1 { r3 = 0 }
66 g_puts(" [measure] DELTA stationary = " as *u8); g_pn(dbits0); g_puts(" bits = " as *u8); g_pn(nx_bits_bytes(dbits0)); g_puts(" bytes\n" as *u8)
67 if nx_bits_bytes(dbits0) > 2 { r3 = 0 } // mask-only must be tiny
68 pass = pass + g_check("DELTA stationary tiny + exact" as *u8, r3); total=total+1
69
70 // 4) DELTA small move < FULL, exact
71 fcopy(cur, base); cur[0]=cur[0]+2; cur[2]=cur[2]+1; cur[3]=cur[3]+3 // walk a couple voxels, turn 3deg
72 let dbits1: i64 = nq_pack_delta(buf, base, cur)
73 nq_unpack_delta(buf, base, out)
74 var r4: i64 = 1
75 if feq_exact(out, cur) != 1 { r4 = 0 }
76 if dbits1 >= fbits { r4 = 0 } // delta must beat full for a small move
77 g_puts(" [measure] DELTA small-move = " as *u8); g_pn(dbits1); g_puts(" bits = " as *u8); g_pn(nx_bits_bytes(dbits1)); g_puts(" bytes (< full " as *u8); g_pn(nx_bits_bytes(fbits)); g_puts(")\n" as *u8)
78 pass = pass + g_check("DELTA small-move beats FULL + exact" as *u8, r4); total=total+1
79
80 // 5) WALK PATH: 16 frames, delta-coded vs previous -> avg bytes/snapshot
81 fcopy(base, f)
82 fcopy(cur, f)
83 var totbits: i64 = 0
84 var frame: i64 = 0
85 var walkok: i64 = 1
86 while frame < 16 {
87 cur[0] = cur[0] + 1 // drift east 1 voxel/frame
88 if (frame % 3) == 0 { cur[2] = cur[2] + 1 } // occasional z step
89 cur[3] = cur[3] + 2 // slow turn
90 if (frame % 8) == 0 { cur[8] = cur[8] + 1 } // anim tick
91 let db: i64 = nq_pack_delta(buf, base, cur)
92 nq_unpack_delta(buf, base, out)
93 if feq_exact(out, cur) != 1 { walkok = 0 }
94 totbits = totbits + db
95 fcopy(base, cur) // baseline advances to the just-sent frame
96 frame = frame + 1
97 }
98 let avgbytes: i64 = nx_bits_bytes(totbits) / 16
99 g_puts(" [measure] WALK 16 frames: total " as *u8); g_pn(nx_bits_bytes(totbits)); g_puts(" bytes, avg " as *u8); g_pn(avgbytes); g_puts(" B/snapshot vs full 11 B vs raw 28 B\n" as *u8)
100 if walkok != 1 { }
101 if avgbytes >= 11 { walkok = 0 } // delta walk must beat full keyframes
102 pass = pass + g_check("WALK delta-coded round-trips + beats full keyframes" as *u8, walkok); total=total+1
103
104 // 6) anti-tautology (neg): wrong baseline -> wrong result (delta IS baseline-relative)
105 fcopy(base, f)
106 fcopy(cur, f); cur[0]=cur[0]+5
107 nq_pack_delta(buf, base, cur)
108 let wrong: *i64 = sys_mmap(10*8) as *i64
109 setf(wrong, 999, 9, 0-820, 725, 0-37, 2, 6, 4, 41, 1) // different x baseline
110 nq_unpack_delta(buf, wrong, out)
111 var r6: i64 = 1
112 if feq_exact(out, cur) == 1 { r6 = 0 } // must NOT equal cur (it was decoded vs the wrong base)
113 if out[0] != 999 + 5 { r6 = 0 } // it applied the +5 delta to the wrong base, as expected
114 pass = pass + g_check("anti-tautology: delta is baseline-relative (wrong base -> wrong result)" as *u8, r6); total=total+1
115
116 g_puts("---- netquant gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
117 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
118 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
119 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
120 let ctr__dry: *i64 = gv_ctr()
121 ctr__dry[0] = pass
122 ctr__dry[1] = total
123 let rc__dry: i64 = gv_verdict("NETQUANT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
124 sys_exit(rc__dry)
125 return rc__dry
126}