code wiki / _hdl_build / nx_voxchunk_gate.nx

nx_voxchunk_gate.nx source

↩ module page · 265 lines · 11060 B

1// nx_voxchunk_gate.nx -- CERTIFICATION of nx_voxchunk (gamebench gap-queue rank 1: voxel-world-chunked). 2// The craft world is a FIXED volume; the capability's bar is Minecraft-class STREAMING: unbounded land 3// through a bounded resident set. Each tooth is one way real chunked engines die: 4// T1 DETERMINISTIC REGEN -- load->evict->reload of virgin land is bit-identical; two worlds same seed agree 5// T2 EDITS SURVIVE EVICTION -- a dirty chunk is flushed (nx_gamesave) before slot reuse and reloaded 6// from disk, not regenerated; losing edits on eviction is THE chunk-corruption class 7// T3 BOUNDED RESIDENCY -- a 200-chunk walk never exceeds `cap` resident chunks; memory is bounded 8// BY CONSTRUCTION, and evictions actually happened (the bound was exercised, not idle) 9// T4 SEAM + GEN CONSISTENCY -- world-coordinate access at chunk borders matches the pure height 10// function on both sides of the seam, resident or not 11// T5 WHOLE-WALK DETERMINISM -- two worlds, same seed, same 300-op edit/read script with eviction 12// churn -> identical probes and identical live checksum 13// T6 SESSION DURABILITY -- flush + whole-arena gs_save -> load into a ZEROED arena -> identical 14// continued behaviour; knowledge/nx_voxchunk_world.sav is the board evidence 15// T7 ANTI-VACUITY -- distinct chunks genuinely differ, edits genuinely change blocks, the disk 16// path was genuinely taken (flushes>0, disk_loads>0) 17// T8 BOUNDED + LOUD -- out-of-range y / block value refuse with a DISTINCT code and change nothing 18// license_tier: ORIGINAL expect_exit: 0 19import "nx_syscalls.nx" 20import "nx_voxchunk.nx" 21const K_MAGIC_6364136223: i64 = 6364136223 22const K_MAGIC_1442695041: i64 = 1442695041 23const K_MAGIC_20260730: i64 = 20260730 24const K_MAGIC_4242: i64 = 4242 25const K_MAGIC_31337: i64 = 31337 26const K_MAGIC_60631: i64 = 60631 27const K_MAGIC_1785430000: i64 = 1785430000 28 29func vlcg(s: *i64) -> i64 { s[0] = ((s[0]*K_MAGIC_6364136223)+K_MAGIC_1442695041) & 0x7FFFFFFFFFFF; return s[0] } 30// fold a chunk's full content via world reads (world-coordinate truth, not slot peeking) 31func chunksig(a: *i64, cx: i64, cz: i64) -> i64 { 32 var h: i64 = 7 33 var y: i64 = 0 34 while y < 32 { 35 var z: i64 = 0 36 while z < 16 { 37 var x: i64 = 0 38 while x < 16 { 39 h = ((h * 131) + vxc_get(a, cx*16+x, y, cz*16+z)) & 0x7FFFFFFFFFFFFFFF 40 x = x + 4 41 } 42 z = z + 4 43 } 44 y = y + 2 45 } 46 return h 47} 48// churn the resident set: touch n distinct far-away chunks 49func churn(a: *i64, base: i64, n: i64) -> i64 { 50 var i: i64 = 0 51 while i < n { vxc_get(a, (base+i)*16, 5, 0); i = i + 1 } 52 return 0 53} 54 55func main() -> i64 { 56 gw("=== nx_voxchunk_gate: is the chunked voxel world safe to build unbounded land on? ===\n\n") 57 var pass: i64 = 0 58 var checks: i64 = 0 59 let CAP: i64 = 8 60 let W: i64 = vxc_words(CAP) 61 let AP: *u8 = "knowledge/nx_voxchunk_world.sav" as *u8 62 // start clean: session artifact + every chunk save this gate can create (cx 0..44, cz 0..8) 63 sys_unlinkat(AP) 64 let pb: *u8 = sys_mmap(96) 65 var ccx: i64 = 0 66 while ccx < 45 { 67 var ccz: i64 = 0 68 while ccz < 9 { 69 vxc_path(pb, ccx, ccz) 70 sys_unlinkat(pb) 71 ccz = ccz + 1 72 } 73 ccx = ccx + 1 74 } 75 76 // ---------- T1 deterministic regeneration ---------- 77 checks = checks + 1 78 let A: *i64 = sys_mmap(W*8) as *i64 79 vxc_init(A, CAP, K_MAGIC_20260730) 80 let sig1: i64 = chunksig(A, 5, 7) 81 churn(A, 100, 12) 82 let sig2: i64 = chunksig(A, 5, 7) 83 let B: *i64 = sys_mmap(W*8) as *i64 84 vxc_init(B, CAP, K_MAGIC_20260730) 85 let sigB: i64 = chunksig(B, 5, 7) 86 var t1: i64 = 0 87 if sig1 == sig2 { if sig1 == sigB { t1 = 1 } } 88 if t1==1 { 89 gw("T1 GREEN deterministic regen: chunk(5,7) load->evict->reload bit-identical AND a second world agrees (sig="); gn(sig1); gw(")\n"); pass=pass+1 90 } else { gw("T1 RED regen diverged: "); gn(sig1); gw(" / "); gn(sig2); gw(" / "); gn(sigB); gw("\n") } 91 92 // ---------- T2 edits survive eviction ---------- 93 checks = checks + 1 94 let C: *i64 = sys_mmap(W*8) as *i64 95 vxc_init(C, CAP, K_MAGIC_4242) 96 vxc_set(C, 2*16+3, 20, 3*16+5, 7) 97 vxc_set(C, 2*16+4, 21, 3*16+6, 9) 98 churn(C, 200, 12) 99 let e1: i64 = vxc_get(C, 2*16+3, 20, 3*16+5) 100 let e2: i64 = vxc_get(C, 2*16+4, 21, 3*16+6) 101 var t2: i64 = 0 102 if e1 == 7 { if e2 == 9 { if vxc_flushes(C) >= 1 { if vxc_diskloads(C) >= 1 { t2 = 1 } } } } 103 if t2==1 { 104 gw("T2 GREEN edits survive eviction: dirty chunk flushed through nx_gamesave ("); gn(vxc_flushes(C)) 105 gw(" flushes) and reloaded FROM DISK ("); gn(vxc_diskloads(C)); gw(" disk loads) with both edits intact\n"); pass=pass+1 106 } else { 107 gw("T2 RED edit lost on eviction: got "); gn(e1); gw("/"); gn(e2) 108 gw(" flushes="); gn(vxc_flushes(C)); gw(" diskloads="); gn(vxc_diskloads(C)); gw("\n") 109 } 110 111 // ---------- T3 bounded residency ---------- 112 checks = checks + 1 113 let D: *i64 = sys_mmap(W*8) as *i64 114 vxc_init(D, CAP, 999) 115 var over: i64 = 0 116 var i: i64 = 0 117 while i < 200 { 118 vxc_get(D, i*16+8, 10, (i % 4)*16+8) 119 if vxc_resident(D) > CAP { over = over + 1 } 120 i = i + 1 121 } 122 var t3: i64 = 0 123 if over == 0 { if vxc_evictions(D) >= 150 { if vxc_resident(D) <= CAP { t3 = 1 } } } 124 if t3==1 { 125 gw("T3 GREEN bounded: 200-chunk walk, resident never exceeded "); gn(CAP) 126 gw(" ("); gn(vxc_evictions(D)); gw(" evictions -- the bound was exercised)\n"); pass=pass+1 127 } else { gw("T3 RED over="); gn(over); gw(" evictions="); gn(vxc_evictions(D)); gw("\n") } 128 129 // ---------- T4 seam + gen consistency ---------- 130 checks = checks + 1 131 let E: *i64 = sys_mmap(W*8) as *i64 132 vxc_init(E, CAP, K_MAGIC_31337) 133 var seam_ok: i64 = 1 134 var col: i64 = 0 135 while col < 8 { 136 let wz: i64 = col*3 + 2 137 var side: i64 = 0 138 while side < 2 { 139 let wx: i64 = 15 + side 140 let want: i64 = vxc_height(wx, wz, K_MAGIC_31337) 141 var found: i64 = 0-1 142 var y: i64 = 0 143 while y < 32 { 144 if found < 0 { if vxc_get(E, wx, y, wz) == 1 { found = y } } 145 y = y + 1 146 } 147 if found != want { seam_ok = 0 } 148 side = side + 1 149 } 150 churn(E, 300+col*4, 3) 151 col = col + 1 152 } 153 if seam_ok==1 { 154 gw("T4 GREEN seam-consistent: surface at border columns (15|16) matches the pure height function on both sides, through eviction churn\n"); pass=pass+1 155 } else { gw("T4 RED seam mismatch between world access and the generator\n") } 156 157 // ---------- T5 whole-walk determinism ---------- 158 checks = checks + 1 159 let F1: *i64 = sys_mmap(W*8) as *i64 160 let F2: *i64 = sys_mmap(W*8) as *i64 161 vxc_init(F1, CAP, 555) 162 vxc_init(F2, CAP, 555) 163 let r1: *i64 = sys_mmap(8) as *i64 164 let r2: *i64 = sys_mmap(8) as *i64 165 r1[0] = 77 166 r2[0] = 77 167 var mism: i64 = 0 168 i = 0 169 while i < 300 { 170 let opa: i64 = vlcg(r1) % 3 171 let wxa: i64 = vlcg(r1) % 640 172 let wya: i64 = vlcg(r1) % 32 173 let wza: i64 = vlcg(r1) % 64 174 let ba: i64 = 1 + (vlcg(r1) % 5) 175 let opb: i64 = vlcg(r2) % 3 176 let wxb: i64 = vlcg(r2) % 640 177 let wyb: i64 = vlcg(r2) % 32 178 let wzb: i64 = vlcg(r2) % 64 179 let bb: i64 = 1 + (vlcg(r2) % 5) 180 if opa == 1 { 181 vxc_set(F1, wxa, wya, wza, ba) 182 vxc_set(F2, wxb, wyb, wzb, bb) 183 } else { 184 let ga: i64 = vxc_get(F1, wxa, wya, wza) 185 let gb: i64 = vxc_get(F2, wxb, wyb, wzb) 186 if ga != gb { mism = mism + 1 } 187 } 188 i = i + 1 189 } 190 var t5: i64 = 0 191 if mism == 0 { if vxc_checksum(F1) == vxc_checksum(F2) { if vxc_evictions(F1) > 0 { t5 = 1 } } } 192 if t5==1 { 193 gw("T5 GREEN whole-walk deterministic: 300 mixed ops with eviction churn -> every probe equal, live checksum equal ("); gn(vxc_checksum(F1)); gw(")\n"); pass=pass+1 194 } else { 195 gw("T5 RED mismatches="); gn(mism); gw(" ck "); gn(vxc_checksum(F1)); gw(" vs "); gn(vxc_checksum(F2)); gw("\n") 196 } 197 198 // ---------- T6 session durability (artifact) ---------- 199 checks = checks + 1 200 let fl: i64 = vxc_flush_all(F1) 201 let aw: i64 = gs_save(AP, K_MAGIC_60631, F1, W, K_MAGIC_1785430000) 202 let G: *i64 = sys_mmap(W*8) as *i64 203 let ar: i64 = gs_load(AP, G, W, 0 as *i64) 204 var t6: i64 = 0 205 if fl >= 0 { if aw > 0 { if ar == W { 206 var same: i64 = 1 207 vxc_set(F1, 100, 15, 100, 8) 208 vxc_set(G, 100, 15, 100, 8) 209 if vxc_get(F1, 100, 15, 100) != vxc_get(G, 100, 15, 100) { same = 0 } 210 churn(F1, 400, 10) 211 churn(G, 400, 10) 212 if vxc_checksum(F1) != vxc_checksum(G) { same = 0 } 213 if same == 1 { t6 = 1 } 214 } } } 215 if t6==1 { 216 gw("T6 GREEN session durable: "); gn(W); gw("-word world ("); gn(aw) 217 gw("B) flushed, saved, reloaded into a ZEROED arena, and CONTINUED identically (edit + churn)\n"); pass=pass+1 218 } else { gw("T6 RED fl="); gn(fl); gw(" aw="); gn(aw); gw(" ar="); gn(ar); gw("\n") } 219 220 // ---------- T7 anti-vacuity ---------- 221 checks = checks + 1 222 let H: *i64 = sys_mmap(W*8) as *i64 223 vxc_init(H, CAP, K_MAGIC_20260730) 224 var sigs: *i64 = sys_mmap(10*8) as *i64 225 i = 0 226 while i < 10 { sigs[i] = chunksig(H, i*3, (i*7) % 9); i = i + 1 } 227 var distinct: i64 = 0 228 i = 0 229 while i < 10 { 230 var uniq: i64 = 1 231 var j: i64 = 0 232 while j < i { 233 if sigs[j] == sigs[i] { uniq = 0 } 234 j = j + 1 235 } 236 if uniq == 1 { distinct = distinct + 1 } 237 i = i + 1 238 } 239 vxc_set(H, 8, 25, 8, 6) 240 let editok: i64 = vxc_get(H, 8, 25, 8) 241 var t7: i64 = 0 242 if distinct >= 8 { if editok == 6 { if vxc_evictions(H) > 0 { t7 = 1 } } } 243 if t7==1 { 244 gw("T7 GREEN anti-vacuity: "); gn(distinct) 245 gw("/10 chunks distinct, an edit genuinely lands, evictions genuinely occurred -- the world is not one chunk in a costume\n"); pass=pass+1 246 } else { gw("T7 RED distinct="); gn(distinct); gw(" edit="); gn(editok); gw(" ev="); gn(vxc_evictions(H)); gw("\n") } 247 248 // ---------- T8 bounded + loud ---------- 249 checks = checks + 1 250 let ck8: i64 = vxc_checksum(H) 251 let x1: i64 = vxc_get(H, 5, 0-1, 5) 252 let x2: i64 = vxc_get(H, 5, 32, 5) 253 let x3: i64 = vxc_set(H, 5, 5, 5, 999) 254 var t8: i64 = 0 255 if x1==VXC_E_RANGE { if x2==VXC_E_RANGE { if x3==VXC_E_RANGE { if vxc_checksum(H)==ck8 { t8=1 } } } } 256 if t8==1 { 257 gw("T8 GREEN bounded+loud: y-range and block-value refusals distinct ("); gn(x1) 258 gw("), state untouched\n"); pass=pass+1 259 } else { gw("T8 RED x1="); gn(x1); gw(" x2="); gn(x2); gw(" x3="); gn(x3); gw("\n") } 260 261 gw("\n=== nx_voxchunk_gate "); gn(pass); gw("/"); gn(checks) 262 if pass == checks { gw(" GREEN ===\n"); return 0 } 263 gw(" RED ===\n") 264 return 1 265}