omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / helix / helix_jit.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/helix/helix_jit.om: In-Process Proof-Carrying SM121 Evolutionary JIT + Strand A Monk Proof Gate. |
| 3 | note Pure seeded OM-2 (zero C, zero Python, zero CUDA). |
| 4 | note Compose after: |
| 5 | note gpu/nvidia/om/codegen/bw_hazard.om (with local `rb` non-colliding when composed with bw_enc_sm121.om) |
| 6 | note om/gpu/q36/emit_fast.om |
| 7 | note |
| 8 | note Intercepts every SM121 kernel emitted into q36Buf[0..cnt*4) (and optionally qhBuf[0..cnt*4)) |
| 9 | note BEFORE upload to GB10 VRAM: |
| 10 | note 1. Runs a 3-mutant negative self-test against Strand A's in-process Monk verifier (hxMonkVerify) |
| 11 | note on first init (opcode smuggle, wait-barrier strip, illegal RAW stall shave -> 3/3 MUST be KILLED). |
| 12 | note 2. Reads active Arboris genome (0..6) from `/tmp/helix_genome.cfg` (default 0 = Monk Reference): |
| 13 | note G0: Monk Reference (untouched baseline) |
| 14 | note G1: Predator (Antibody #13 basic-block leaders + Antibody #14 rawFloor=6 swaps + ALU/wait-NOP compaction) |
| 15 | note G2: Mitosis Hybrid Champion (G1 + G6 warp-yield hiding + Antibody #15 never shave I2F fixed-latency stalls) |
| 16 | note G3: Mitosis 2-Pass Champion (2-pass RAW-safe interleaving + G2) |
| 17 | note G5: Strand 3 Trickster (reverse-order chaos swaps + hostile yield/stall jitter, rawFloor=6) |
| 18 | note G6: Strand 4 Ascetic (zero-swap minimal footprint + rawFloor=6 compaction + yield=1 power/warp pacing) |
| 19 | note 3. Mechanically proves EVERY evolved kernel in-memory via Strand A Monk BEFORE VRAM upload: |
| 20 | note - 128-bit functional equality outside 17-bit SM121 control word w3[9..25] |
| 21 | note - Exact bijection permutation (Antibodies 2 & 7) |
| 22 | note - Full anchor pinning: flow!=0, guard!=7, nm<=8, ISETP(16), FSETP(25), nm>=33 (Antibody 4) |
| 23 | note - Full RAW/WAR/WAW dependency preservation (Antibody 5) |
| 24 | note - Full CFG worklist fixed-point dataflow scoreboard check: hazards == 0 (Antibody 6a) |
| 25 | note - Fixed-latency ALU RAW cycle floor >= min(ref_cycles, rawFloor) including anchor |
| 26 | note consumers AND live writes reaching a BRA/EXIT boundary (Antibody 6b / Attack 8) |
| 27 | note If ANY check fails by a single bit, the candidate dies on the spot and original q36Buf is kept! |
| 28 | |
| 29 | global hxInitDone ulong 1 |
| 30 | global hxActive ulong 1 |
| 31 | global hxGenome ulong 1 |
| 32 | global hxRawFloor ulong 1 |
| 33 | global hxStats ulong 8 |
| 34 | note hxStats: 0=kernels_seen, 1=proved, 2=rejected, 3=skipped, 4=stalls_ref, 5=stalls_cand, 6=swaps, 7=yields_tuned |
| 35 | |
| 36 | global hxRef ulong 8192 |
| 37 | global hxCand ulong 8192 |
| 38 | global hxRefRec ulong 49152 |
| 39 | global hxCndRec ulong 49152 |
| 40 | global hxPerm ulong 2048 |
| 41 | global hxInv ulong 2048 |
| 42 | global hxSeen ulong 2048 |
| 43 | global hxTarget uchar 2048 |
| 44 | global hxWbar uchar 512 |
| 45 | global hxRbar uchar 512 |
| 46 | global hxInW uchar 1048576 |
| 47 | global hxInR uchar 1048576 |
| 48 | global hxHzSeen ulong 2048 |
| 49 | global hxHzQu ulong 2048 |
| 50 | global hxHzWk ulong 2048 |
| 51 | |
| 52 | text hxCfgPath "/tmp/helix_genome.cfg" |
| 53 | text hxLogA "HELIX_JIT_SUMMARY genome=" |
| 54 | text hxLogB " kernels=" |
| 55 | text hxLogC " proved=" |
| 56 | text hxLogD " rejected=" |
| 57 | text hxLogE " skipped=" |
| 58 | text hxLogF " swaps=" |
| 59 | text hxLogG " stalls_ref=" |
| 60 | text hxLogH " stalls_evolved=" |
| 61 | text hxLogI " yields_tuned=" |
| 62 | text hxLogJ " mutants_killed=3/3\n" |
| 63 | text hxMutFail "HELIX_JIT FATAL: Monk self-test mutant survived!\n" |
| 64 | |
| 65 | fn hxWrt s view uchar * to void |
| 66 | r = write 1 s 0 len s |
| 67 | end |
| 68 | |
| 69 | fn hxNum v ulong to void |
| 70 | b = new uchar 24 0 |
| 71 | p = ulong 24 |
| 72 | x = v |
| 73 | while true bound 24 |
| 74 | p = sub p 1 |
| 75 | put b p uchar add 48 rem x 10 |
| 76 | x = div x 10 |
| 77 | if eq x 0 |
| 78 | break |
| 79 | end |
| 80 | end |
| 81 | r = write 1 b p sub 24 p |
| 82 | end |
| 83 | |
| 84 | fn hxLoadGenomeCfg to ulong |
| 85 | fd = fopen hxCfgPath 0 len hxCfgPath 0 0 |
| 86 | if lt fd 0 |
| 87 | ret 0 |
| 88 | end |
| 89 | buf = new uchar 16 0 |
| 90 | r = read int fd buf 0 15 |
| 91 | z = fclose int fd |
| 92 | if lt r 1 |
| 93 | ret 0 |
| 94 | end |
| 95 | c = ulong get buf 0 |
| 96 | if and ge c 48 le c 54 |
| 97 | ret sub c 48 |
| 98 | end |
| 99 | ret 0 |
| 100 | end |
| 101 | |
| 102 | fn hxDecodeBuf isCand bool cnt ulong to bool |
| 103 | ins = new uchar 16 0 |
| 104 | rec = new ulong 24 0 |
| 105 | for pc ulong cnt bound 2048 |
| 106 | base = mul pc 4 |
| 107 | for k ulong 4 |
| 108 | w = ulong 0 |
| 109 | if isCand |
| 110 | w = get hxCand add base k |
| 111 | else |
| 112 | w = get hxRef add base k |
| 113 | end |
| 114 | put ins mul k 4 uchar and w 255 |
| 115 | put ins add mul k 4 1 uchar and shr w 8 255 |
| 116 | put ins add mul k 4 2 uchar and shr w 16 255 |
| 117 | put ins add mul k 4 3 uchar and shr w 24 255 |
| 118 | end |
| 119 | if ne hz_dec1 ins rec 0 |
| 120 | ret false |
| 121 | end |
| 122 | db = mul pc 24 |
| 123 | for j ulong 24 |
| 124 | if isCand |
| 125 | put hxCndRec add db j get rec j |
| 126 | else |
| 127 | put hxRefRec add db j get rec j |
| 128 | end |
| 129 | end |
| 130 | end |
| 131 | ret true |
| 132 | end |
| 133 | |
| 134 | fn hxMarkTargets cnt ulong to void |
| 135 | for i ulong cnt bound 2048 |
| 136 | put hxTarget i 0 |
| 137 | end |
| 138 | if gt cnt 0 |
| 139 | put hxTarget 0 1 |
| 140 | end |
| 141 | for pc ulong cnt bound 2048 |
| 142 | db = mul pc 24 |
| 143 | fl = get hxRefRec add db 17 |
| 144 | if eq fl 2 |
| 145 | tg = hz_u2l get hxRefRec add db 18 |
| 146 | dst = add long pc tg |
| 147 | if and ge dst 0 lt dst long cnt |
| 148 | put hxTarget ulong dst 1 |
| 149 | end |
| 150 | if lt add pc 1 cnt |
| 151 | put hxTarget add pc 1 1 |
| 152 | end |
| 153 | end |
| 154 | end |
| 155 | end |
| 156 | |
| 157 | fn hxIsMonkAnchor pc ulong to bool |
| 158 | if ne get hxTarget pc 0 |
| 159 | ret true |
| 160 | end |
| 161 | db = mul pc 24 |
| 162 | if ne get hxRefRec add db 17 0 |
| 163 | ret true |
| 164 | end |
| 165 | if ne get hxRefRec add db 1 7 |
| 166 | ret true |
| 167 | end |
| 168 | nm = get hxRefRec add db 19 |
| 169 | if or le nm 8 ge nm 33 |
| 170 | ret true |
| 171 | end |
| 172 | if or eq nm 16 eq nm 25 |
| 173 | ret true |
| 174 | end |
| 175 | ret false |
| 176 | end |
| 177 | |
| 178 | fn hxIsSwapAnchor pc ulong to bool |
| 179 | if hxIsMonkAnchor pc |
| 180 | ret true |
| 181 | end |
| 182 | db = mul pc 24 |
| 183 | if ne get hxRefRec add db 6 0 |
| 184 | ret true |
| 185 | end |
| 186 | if ne get hxRefRec add db 4 7 |
| 187 | ret true |
| 188 | end |
| 189 | ret ne get hxRefRec add db 5 7 |
| 190 | end |
| 191 | |
| 192 | fn hxRegOverlap a ulong b ulong to bool |
| 193 | if or eq a 0 eq b 0 |
| 194 | ret false |
| 195 | end |
| 196 | ra = and a 255 |
| 197 | na = and shr a 8 255 |
| 198 | ua = and shr a 16 1 |
| 199 | rb2 = and b 255 |
| 200 | nb = and shr b 8 255 |
| 201 | ub = and shr b 16 1 |
| 202 | if ne ua ub |
| 203 | ret false |
| 204 | end |
| 205 | if or eq ra 255 eq rb2 255 |
| 206 | ret false |
| 207 | end |
| 208 | if or le add ra na rb2 le add rb2 nb ra |
| 209 | ret false |
| 210 | end |
| 211 | ret true |
| 212 | end |
| 213 | |
| 214 | fn hxHasRaw u ulong v ulong to bool |
| 215 | du = mul u 24 |
| 216 | dv = mul v 24 |
| 217 | if eq get hxRefRec add du 10 0 |
| 218 | ret false |
| 219 | end |
| 220 | wu = get hxRefRec add du 16 |
| 221 | for j ulong get hxRefRec add dv 9 bound 5 |
| 222 | if hxRegOverlap wu get hxRefRec add add dv 11 j |
| 223 | ret true |
| 224 | end |
| 225 | end |
| 226 | ret false |
| 227 | end |
| 228 | |
| 229 | fn hxHasWaw u ulong v ulong to bool |
| 230 | du = mul u 24 |
| 231 | dv = mul v 24 |
| 232 | if or eq get hxRefRec add du 10 0 eq get hxRefRec add dv 10 0 |
| 233 | ret false |
| 234 | end |
| 235 | ret hxRegOverlap get hxRefRec add du 16 get hxRefRec add dv 16 |
| 236 | end |
| 237 | |
| 238 | fn hxHasDep u ulong v ulong to bool |
| 239 | if hxHasWaw u v |
| 240 | ret true |
| 241 | end |
| 242 | if hxHasRaw u v |
| 243 | ret true |
| 244 | end |
| 245 | du = mul u 24 |
| 246 | dv = mul v 24 |
| 247 | if ne get hxRefRec add dv 10 0 |
| 248 | wv = get hxRefRec add dv 16 |
| 249 | for j ulong get hxRefRec add du 9 bound 5 |
| 250 | if hxRegOverlap get hxRefRec add add du 11 j wv |
| 251 | ret true |
| 252 | end |
| 253 | end |
| 254 | end |
| 255 | ret false |
| 256 | end |
| 257 | |
| 258 | fn hxCndStall pc ulong to ulong |
| 259 | w3 = get hxCand add mul pc 4 3 |
| 260 | ret and shr w3 9 15 |
| 261 | end |
| 262 | |
| 263 | fn hxSetCndStall pc ulong nst ulong to void |
| 264 | idx = add mul pc 4 3 |
| 265 | w3 = get hxCand idx |
| 266 | nw3 = or and w3 not shl ulong 15 9 shl nst 9 |
| 267 | put hxCand idx nw3 |
| 268 | end |
| 269 | |
| 270 | fn hxSumRefStall lo ulong hi ulong to ulong |
| 271 | tot = ulong 0 |
| 272 | k = lo |
| 273 | while lt k hi bound 2048 |
| 274 | tot = add tot get hxRefRec add mul k 24 2 |
| 275 | k = add k 1 |
| 276 | end |
| 277 | ret tot |
| 278 | end |
| 279 | |
| 280 | fn hxSumCndStall lo ulong hi ulong to ulong |
| 281 | tot = ulong 0 |
| 282 | k = lo |
| 283 | while lt k hi bound 2048 |
| 284 | tot = add tot hxCndStall k |
| 285 | k = add k 1 |
| 286 | end |
| 287 | ret tot |
| 288 | end |
| 289 | |
| 290 | note ==================== STRAND A IN-PROCESS MONK PROOF VERIFIER ==================== |
| 291 | fn hxChkOpnd opnd ulong chkR bool to bool |
| 292 | reg = and opnd 255 |
| 293 | cnt = and shr opnd 8 255 |
| 294 | uni = and shr opnd 16 1 |
| 295 | base = add mul uni 256 reg |
| 296 | for k ulong cnt bound 4 |
| 297 | idx = add base k |
| 298 | if lt idx 512 |
| 299 | if ne get hxWbar idx 0 |
| 300 | ret false |
| 301 | end |
| 302 | if chkR |
| 303 | if ne get hxRbar idx 0 |
| 304 | ret false |
| 305 | end |
| 306 | end |
| 307 | end |
| 308 | end |
| 309 | ret true |
| 310 | end |
| 311 | |
| 312 | fn hxMarkOpnd opnd ulong bit ulong isR bool to void |
| 313 | reg = and opnd 255 |
| 314 | cnt = and shr opnd 8 255 |
| 315 | uni = and shr opnd 16 1 |
| 316 | base = add mul uni 256 reg |
| 317 | b8 = uchar bit |
| 318 | for k ulong cnt bound 4 |
| 319 | idx = add base k |
| 320 | if lt idx 512 |
| 321 | if isR |
| 322 | put hxRbar idx or get hxRbar idx b8 |
| 323 | else |
| 324 | put hxWbar idx or get hxWbar idx b8 |
| 325 | end |
| 326 | end |
| 327 | end |
| 328 | end |
| 329 | |
| 330 | fn hxStepHazard pc ulong check bool to bool |
| 331 | db = mul pc 24 |
| 332 | wt = get hxCndRec add db 6 |
| 333 | if ne wt 0 |
| 334 | clr = uchar and not wt 255 |
| 335 | w8 = uchar and wt 255 |
| 336 | for i ulong 512 |
| 337 | put hxWbar i and get hxWbar i clr |
| 338 | if ne and get hxRbar i w8 0 |
| 339 | put hxRbar i 0 |
| 340 | end |
| 341 | end |
| 342 | end |
| 343 | nr = get hxCndRec add db 9 |
| 344 | nw = get hxCndRec add db 10 |
| 345 | if check |
| 346 | for j ulong nr bound 5 |
| 347 | if not hxChkOpnd get hxCndRec add add db 11 j false |
| 348 | ret false |
| 349 | end |
| 350 | end |
| 351 | if ne nw 0 |
| 352 | if not hxChkOpnd get hxCndRec add db 16 true |
| 353 | ret false |
| 354 | end |
| 355 | end |
| 356 | end |
| 357 | if and ne get hxCndRec add db 7 0 ne nw 0 |
| 358 | wb = get hxCndRec add db 4 |
| 359 | if lt wb 6 |
| 360 | hxMarkOpnd get hxCndRec add db 16 shl ulong 1 wb false |
| 361 | end |
| 362 | end |
| 363 | if ne get hxCndRec add db 8 0 |
| 364 | rb2 = get hxCndRec add db 5 |
| 365 | wb2 = get hxCndRec add db 4 |
| 366 | lm = ulong 0 |
| 367 | if lt rb2 6 |
| 368 | lm = or lm shl ulong 1 rb2 |
| 369 | end |
| 370 | if lt wb2 6 |
| 371 | lm = or lm shl ulong 1 wb2 |
| 372 | end |
| 373 | if ne lm 0 |
| 374 | for j ulong nr bound 5 |
| 375 | hxMarkOpnd get hxCndRec add add db 11 j lm true |
| 376 | end |
| 377 | end |
| 378 | end |
| 379 | ret true |
| 380 | end |
| 381 | |
| 382 | fn hxLoadIn pc ulong to void |
| 383 | off = mul pc 512 |
| 384 | for i ulong 512 |
| 385 | put hxWbar i get hxInW add off i |
| 386 | put hxRbar i get hxInR add off i |
| 387 | end |
| 388 | end |
| 389 | |
| 390 | fn hxJoinTo tgt ulong to bool |
| 391 | off = mul tgt 512 |
| 392 | ch = false |
| 393 | for i ulong 512 |
| 394 | ow = get hxInW add off i |
| 395 | nw = or ow get hxWbar i |
| 396 | if ne nw ow |
| 397 | put hxInW add off i nw |
| 398 | ch = true |
| 399 | end |
| 400 | orv = get hxInR add off i |
| 401 | nrv = or orv get hxRbar i |
| 402 | if ne nrv orv |
| 403 | put hxInR add off i nrv |
| 404 | ch = true |
| 405 | end |
| 406 | end |
| 407 | ret ch |
| 408 | end |
| 409 | |
| 410 | fn hxReachPush n ulong tgt long top ulong to ulong |
| 411 | if or lt tgt 0 ge tgt long n |
| 412 | ret top |
| 413 | end |
| 414 | u = ulong tgt |
| 415 | if eq get hxHzSeen u 0 |
| 416 | put hxHzSeen u 1 |
| 417 | put hxHzWk top u |
| 418 | ret add top 1 |
| 419 | end |
| 420 | ret top |
| 421 | end |
| 422 | |
| 423 | fn hxEdge n ulong tgt long top ulong to ulong |
| 424 | if or lt tgt 0 ge tgt long n |
| 425 | ret top |
| 426 | end |
| 427 | u = ulong tgt |
| 428 | ch = hxJoinTo u |
| 429 | sv = get hxHzSeen u |
| 430 | qv = get hxHzQu u |
| 431 | if and or ch eq sv 1 eq qv 0 |
| 432 | put hxHzQu u 1 |
| 433 | put hxHzWk top u |
| 434 | ret add top 1 |
| 435 | end |
| 436 | ret top |
| 437 | end |
| 438 | |
| 439 | fn hxZeroHz n ulong to void |
| 440 | for i ulong n bound 2048 |
| 441 | put hxHzSeen i 0 |
| 442 | put hxHzQu i 0 |
| 443 | off = mul i 512 |
| 444 | for r ulong 512 |
| 445 | put hxInW add off r 0 |
| 446 | put hxInR add off r 0 |
| 447 | end |
| 448 | end |
| 449 | end |
| 450 | |
| 451 | fn hxDoReach n ulong to void |
| 452 | put hxHzSeen 0 1 |
| 453 | put hxHzWk 0 0 |
| 454 | top = ulong 1 |
| 455 | while gt top 0 bound 4096 |
| 456 | top = sub top 1 |
| 457 | pc = get hxHzWk top |
| 458 | db = mul pc 24 |
| 459 | fl = get hxCndRec add db 17 |
| 460 | gd = get hxCndRec add db 1 |
| 461 | if or eq fl 0 ne gd 7 |
| 462 | top = hxReachPush n add long pc 1 top |
| 463 | end |
| 464 | if eq fl 2 |
| 465 | tg = hz_u2l get hxCndRec add db 18 |
| 466 | top = hxReachPush n add long pc tg top |
| 467 | end |
| 468 | end |
| 469 | end |
| 470 | |
| 471 | fn hxCheckCfgHazards n ulong to bool |
| 472 | hxZeroHz n |
| 473 | hxDoReach n |
| 474 | put hxHzWk 0 0 |
| 475 | put hxHzQu 0 1 |
| 476 | top = ulong 1 |
| 477 | while gt top 0 bound 65536 |
| 478 | top = sub top 1 |
| 479 | pc = get hxHzWk top |
| 480 | put hxHzQu pc 0 |
| 481 | put hxHzSeen pc 2 |
| 482 | hxLoadIn pc |
| 483 | z = hxStepHazard pc false |
| 484 | db = mul pc 24 |
| 485 | fl = get hxCndRec add db 17 |
| 486 | gd = get hxCndRec add db 1 |
| 487 | if or eq fl 0 ne gd 7 |
| 488 | top = hxEdge n add long pc 1 top |
| 489 | end |
| 490 | if eq fl 2 |
| 491 | tg = hz_u2l get hxCndRec add db 18 |
| 492 | top = hxEdge n add long pc tg top |
| 493 | end |
| 494 | end |
| 495 | for pc ulong n bound 2048 |
| 496 | if ne get hxHzSeen pc 0 |
| 497 | hxLoadIn pc |
| 498 | if not hxStepHazard pc true |
| 499 | ret false |
| 500 | end |
| 501 | end |
| 502 | end |
| 503 | ret true |
| 504 | end |
| 505 | |
| 506 | fn hxRawSpanOk u ulong v ulong inclV bool flr ulong to bool |
| 507 | hiRef = v |
| 508 | hiCnd = get hxInv v |
| 509 | if inclV |
| 510 | hiRef = add v 1 |
| 511 | hiCnd = add hiCnd 1 |
| 512 | end |
| 513 | rcyc = hxSumRefStall u hiRef |
| 514 | eff = flr |
| 515 | note SM121 IMAD.WIDE (nm==14) and I2FP/I2F (nm==29) are 6-cycle pipes; never drop below 6! |
| 516 | nm = get hxRefRec add mul u 24 19 |
| 517 | if or eq nm 14 eq nm 29 |
| 518 | if lt eff 6 |
| 519 | eff = ulong 6 |
| 520 | end |
| 521 | end |
| 522 | req = rcyc |
| 523 | if gt req eff |
| 524 | req = eff |
| 525 | end |
| 526 | ret ge hxSumCndStall get hxInv u hiCnd req |
| 527 | end |
| 528 | |
| 529 | note Fixed-latency RAW stall verification (up to distance 16, including anchor consumers & BRA/EXIT!) |
| 530 | fn hxCheckRawOne u ulong n ulong flr ulong to bool |
| 531 | du = mul u 24 |
| 532 | if or eq get hxRefRec add du 10 0 ne get hxRefRec add du 7 0 |
| 533 | ret true |
| 534 | end |
| 535 | note Antibody #15: I2FP/I2F (op 581, nm==29, var=0) stall must never be shaved below min(ref_stall, flr)! |
| 536 | if eq get hxRefRec add du 19 29 |
| 537 | rst = get hxRefRec add du 2 |
| 538 | if gt rst flr |
| 539 | rst = flr |
| 540 | end |
| 541 | if lt hxCndStall get hxInv u rst |
| 542 | ret false |
| 543 | end |
| 544 | end |
| 545 | lim = add u 16 |
| 546 | if gt lim n |
| 547 | lim = n |
| 548 | end |
| 549 | v = add u 1 |
| 550 | while lt v lim bound 16 |
| 551 | if hxHasRaw u v |
| 552 | ret hxRawSpanOk u v false flr |
| 553 | end |
| 554 | if hxHasWaw u v |
| 555 | ret true |
| 556 | end |
| 557 | dbv = mul v 24 |
| 558 | flv = get hxRefRec add dbv 17 |
| 559 | if ne flv 0 |
| 560 | ret hxRawSpanOk u v true flr |
| 561 | end |
| 562 | if hxIsMonkAnchor v |
| 563 | ret hxRawSpanOk u v true flr |
| 564 | end |
| 565 | v = add v 1 |
| 566 | end |
| 567 | ret true |
| 568 | end |
| 569 | |
| 570 | fn hxCheckRawStalls n ulong flr ulong to bool |
| 571 | for u ulong n bound 2048 |
| 572 | if not hxCheckRawOne u n flr |
| 573 | ret false |
| 574 | end |
| 575 | end |
| 576 | ret true |
| 577 | end |
| 578 | |
| 579 | fn hxCheckFunc n ulong to bool |
| 580 | for i ulong n bound 2048 |
| 581 | ri = get hxPerm i |
| 582 | cb = mul i 4 |
| 583 | rb3 = mul ri 4 |
| 584 | if ne get hxCand cb get hxRef rb3 |
| 585 | ret false |
| 586 | end |
| 587 | if ne get hxCand add cb 1 get hxRef add rb3 1 |
| 588 | ret false |
| 589 | end |
| 590 | if ne get hxCand add cb 2 get hxRef add rb3 2 |
| 591 | ret false |
| 592 | end |
| 593 | cw = and get hxCand add cb 3 ulong 4227858943 |
| 594 | rw = and get hxRef add rb3 3 ulong 4227858943 |
| 595 | if ne cw rw |
| 596 | ret false |
| 597 | end |
| 598 | end |
| 599 | ret true |
| 600 | end |
| 601 | |
| 602 | fn hxCheckPermAnchors n ulong to bool |
| 603 | for i ulong n bound 2048 |
| 604 | put hxSeen i 0 |
| 605 | end |
| 606 | for i ulong n bound 2048 |
| 607 | r = get hxPerm i |
| 608 | if ge r n |
| 609 | ret false |
| 610 | end |
| 611 | if ne get hxSeen r 0 |
| 612 | ret false |
| 613 | end |
| 614 | put hxSeen r 1 |
| 615 | put hxInv r i |
| 616 | if hxIsMonkAnchor i |
| 617 | if ne r i |
| 618 | ret false |
| 619 | end |
| 620 | end |
| 621 | end |
| 622 | ret true |
| 623 | end |
| 624 | |
| 625 | fn hxCheckDeps n ulong to bool |
| 626 | for u ulong n bound 2048 |
| 627 | pu = get hxInv u |
| 628 | v = add u 1 |
| 629 | while lt v n bound 2048 |
| 630 | if hxHasDep u v |
| 631 | if ge pu get hxInv v |
| 632 | ret false |
| 633 | end |
| 634 | end |
| 635 | v = add v 1 |
| 636 | end |
| 637 | end |
| 638 | ret true |
| 639 | end |
| 640 | |
| 641 | note Complete Strand A Monk Proof Gate: returns 0 PASS, or antibody error code (13/14/15/16/17). |
| 642 | fn hxMonkVerify n ulong flr ulong to ulong |
| 643 | if not hxCheckPermAnchors n |
| 644 | ret 13 |
| 645 | end |
| 646 | if not hxCheckFunc n |
| 647 | ret 14 |
| 648 | end |
| 649 | if not hxDecodeBuf true n |
| 650 | ret 17 |
| 651 | end |
| 652 | if not hxCheckDeps n |
| 653 | ret 16 |
| 654 | end |
| 655 | if not hxCheckCfgHazards n |
| 656 | ret 17 |
| 657 | end |
| 658 | if not hxCheckRawStalls n flr |
| 659 | ret 17 |
| 660 | end |
| 661 | ret 0 |
| 662 | end |
| 663 | |
| 664 | note ==================== STRAND B PREDATOR EVOLUTION PASSES ==================== |
| 665 | fn hxSwapCand i ulong j ulong to void |
| 666 | bi = mul i 4 |
| 667 | bj = mul j 4 |
| 668 | for k ulong 4 |
| 669 | t = get hxCand add bi k |
| 670 | put hxCand add bi k get hxCand add bj k |
| 671 | put hxCand add bj k t |
| 672 | end |
| 673 | tp = get hxPerm i |
| 674 | put hxPerm i get hxPerm j |
| 675 | put hxPerm j tp |
| 676 | put hxInv get hxPerm i i |
| 677 | put hxInv get hxPerm j j |
| 678 | end |
| 679 | |
| 680 | fn hxWindowRawOk lo ulong hi ulong n ulong flr ulong to bool |
| 681 | k = lo |
| 682 | while lt k hi bound 24 |
| 683 | u = get hxPerm k |
| 684 | if not hxCheckRawOne u n flr |
| 685 | ret false |
| 686 | end |
| 687 | k = add k 1 |
| 688 | end |
| 689 | ret true |
| 690 | end |
| 691 | |
| 692 | fn hxDoSwapsRevPass n ulong flr ulong to ulong |
| 693 | note Trickster (G5): reverse-order adversarial interleaving from back to front! |
| 694 | sw = ulong 0 |
| 695 | if lt n 2 |
| 696 | ret 0 |
| 697 | end |
| 698 | i = sub n 2 |
| 699 | while true bound 2048 |
| 700 | j = add i 1 |
| 701 | if and not hxIsSwapAnchor i not hxIsSwapAnchor j |
| 702 | if not hxHasDep get hxPerm i get hxPerm j |
| 703 | hxSwapCand i j |
| 704 | lo = ulong 0 |
| 705 | if gt i 16 |
| 706 | lo = sub i 16 |
| 707 | end |
| 708 | hi = add i 2 |
| 709 | if gt hi n |
| 710 | hi = n |
| 711 | end |
| 712 | if hxWindowRawOk lo hi n flr |
| 713 | sw = add sw 1 |
| 714 | if lt i 2 |
| 715 | break |
| 716 | end |
| 717 | i = sub i 2 |
| 718 | continue |
| 719 | end |
| 720 | hxSwapCand i j |
| 721 | end |
| 722 | end |
| 723 | if eq i 0 |
| 724 | break |
| 725 | end |
| 726 | i = sub i 1 |
| 727 | end |
| 728 | ret sw |
| 729 | end |
| 730 | |
| 731 | fn hxTricksterChaos n ulong flr ulong to ulong |
| 732 | note Trickster (G5): inject adversarial yield=1 jitter + asymmetric non-RAW stall perturbations! |
| 733 | cnt = ulong 0 |
| 734 | for pc ulong n bound 2048 |
| 735 | orig = get hxPerm pc |
| 736 | if not hxIsSwapAnchor orig |
| 737 | idx = add mul pc 4 3 |
| 738 | w3 = get hxCand idx |
| 739 | if eq rem pc 2 0 |
| 740 | put hxCand idx or w3 ulong 8192 |
| 741 | cnt = add cnt 1 |
| 742 | end |
| 743 | st = hxCndStall pc |
| 744 | if and eq rem pc 3 1 lt st 8 |
| 745 | hxSetCndStall pc add st 1 |
| 746 | end |
| 747 | end |
| 748 | end |
| 749 | ret cnt |
| 750 | end |
| 751 | |
| 752 | fn hxAsceticPace n ulong to ulong |
| 753 | note Ascetic (G6): energy & thermal pacing -- enable yield=1 on FFMA(24)/I2FP(29)/F2I(30)/MUFU(31) transitions |
| 754 | note to maximize warp power-gating and minimize peak thermal bursts while keeping exact semantics! |
| 755 | cnt = ulong 0 |
| 756 | for pc ulong n bound 2048 |
| 757 | orig = get hxPerm pc |
| 758 | db = mul orig 24 |
| 759 | nm = get hxRefRec add db 19 |
| 760 | if or eq nm 24 or eq nm 29 or eq nm 30 eq nm 31 |
| 761 | idx = add mul pc 4 3 |
| 762 | w3 = get hxCand idx |
| 763 | if eq and w3 8192 0 |
| 764 | put hxCand idx or w3 ulong 8192 |
| 765 | cnt = add cnt 1 |
| 766 | end |
| 767 | end |
| 768 | end |
| 769 | ret cnt |
| 770 | end |
| 771 | |
| 772 | fn hxDoSwapsPass n ulong flr ulong to ulong |
| 773 | sw = ulong 0 |
| 774 | i = ulong 0 |
| 775 | while lt add i 1 n bound 2048 |
| 776 | j = add i 1 |
| 777 | if and not hxIsSwapAnchor i not hxIsSwapAnchor j |
| 778 | if not hxHasDep get hxPerm i get hxPerm j |
| 779 | hxSwapCand i j |
| 780 | lo = ulong 0 |
| 781 | if gt i 16 |
| 782 | lo = sub i 16 |
| 783 | end |
| 784 | hi = add i 2 |
| 785 | if gt hi n |
| 786 | hi = n |
| 787 | end |
| 788 | if hxWindowRawOk lo hi n flr |
| 789 | sw = add sw 1 |
| 790 | i = add i 2 |
| 791 | continue |
| 792 | end |
| 793 | hxSwapCand i j |
| 794 | end |
| 795 | end |
| 796 | i = add i 1 |
| 797 | end |
| 798 | ret sw |
| 799 | end |
| 800 | |
| 801 | note Can we compact stall on candidate pc? |
| 802 | note Safe targets (Antibodies #13, #14, #15 crystallized from live GB10 silicon): |
| 803 | note 1. Non-anchor fixed-latency ALU (rawFloor >= 6) |
| 804 | note 2. Wait-barrier NOP (nm==1 && wait!=0, e.g. qW0/qW1/qWall: hardware wait already stalls!) |
| 805 | note NEVER compact I2FP/I2F (nm==29) / LDC / ULDC / S2R / LDG / LDS / F2I (nm==30) / MUFU (nm==31)! |
| 806 | fn hxCanCompactPc pc ulong gen ulong to bool |
| 807 | orig = get hxPerm pc |
| 808 | db = mul orig 24 |
| 809 | nm = get hxRefRec add db 19 |
| 810 | if eq nm 1 |
| 811 | wt = get hxRefRec add db 6 |
| 812 | if ne wt 0 |
| 813 | ret ge gen 1 |
| 814 | end |
| 815 | ret false |
| 816 | end |
| 817 | if eq nm 29 |
| 818 | ret false |
| 819 | end |
| 820 | if hxIsSwapAnchor orig |
| 821 | ret false |
| 822 | end |
| 823 | if ne get hxRefRec add db 7 0 |
| 824 | ret false |
| 825 | end |
| 826 | ret eq get hxRefRec add db 8 0 |
| 827 | end |
| 828 | |
| 829 | fn hxShaveSafe pc ulong n ulong flr ulong to bool |
| 830 | lo = ulong 0 |
| 831 | if gt pc 17 |
| 832 | lo = sub pc 17 |
| 833 | end |
| 834 | hi = add pc 1 |
| 835 | ret hxWindowRawOk lo hi n flr |
| 836 | end |
| 837 | |
| 838 | fn hxCompactStalls n ulong gen ulong flr ulong to void |
| 839 | for pc ulong n bound 2048 |
| 840 | if hxCanCompactPc pc gen |
| 841 | for s ulong 15 |
| 842 | st = hxCndStall pc |
| 843 | if le st 1 |
| 844 | break |
| 845 | end |
| 846 | hxSetCndStall pc sub st 1 |
| 847 | if not hxShaveSafe pc n flr |
| 848 | hxSetCndStall pc st |
| 849 | break |
| 850 | end |
| 851 | end |
| 852 | end |
| 853 | end |
| 854 | end |
| 855 | |
| 856 | note SM121 yield-hint burst tuning (G3/G4): clear redundant yield=1 on non-memory I2FP(29)/F2I(30)/MUFU(31) issue bursts |
| 857 | fn hxTuneYields n ulong to ulong |
| 858 | cnt = ulong 0 |
| 859 | for pc ulong n bound 2048 |
| 860 | orig = get hxPerm pc |
| 861 | db = mul orig 24 |
| 862 | nm = get hxRefRec add db 19 |
| 863 | if or eq nm 29 or eq nm 30 eq nm 31 |
| 864 | idx = add mul pc 4 3 |
| 865 | w3 = get hxCand idx |
| 866 | if ne and w3 8192 0 |
| 867 | put hxCand idx and w3 not ulong 8192 |
| 868 | cnt = add cnt 1 |
| 869 | end |
| 870 | end |
| 871 | end |
| 872 | ret cnt |
| 873 | end |
| 874 | |
| 875 | note ==================== 3-MUTANT MONK SELF-TEST ==================== |
| 876 | fn hxMut1 n ulong flr ulong to bool |
| 877 | w0 = get hxCand 0 |
| 878 | put hxCand 0 xor w0 1 |
| 879 | rc1 = hxMonkVerify n flr |
| 880 | put hxCand 0 w0 |
| 881 | ret eq rc1 14 |
| 882 | end |
| 883 | |
| 884 | fn hxMut2 n ulong flr ulong to bool |
| 885 | hasWt = false |
| 886 | clr = not shl ulong 63 20 |
| 887 | for pc ulong n bound 2048 |
| 888 | if ne get hxRefRec add mul pc 24 6 0 |
| 889 | hasWt = true |
| 890 | idx = add mul pc 4 3 |
| 891 | w = get hxCand idx |
| 892 | put hxCand idx and w clr |
| 893 | end |
| 894 | end |
| 895 | if not hasWt |
| 896 | ret true |
| 897 | end |
| 898 | rc2 = hxMonkVerify n flr |
| 899 | for pc ulong n bound 2048 |
| 900 | idx = add mul pc 4 3 |
| 901 | put hxCand idx get hxRef idx |
| 902 | end |
| 903 | ret eq rc2 17 |
| 904 | end |
| 905 | |
| 906 | fn hxFindRawMut n ulong to ulong |
| 907 | for u ulong n bound 2048 |
| 908 | du = mul u 24 |
| 909 | if ne get hxRefRec add du 10 0 |
| 910 | if eq get hxRefRec add du 7 0 |
| 911 | if lt add u 1 n |
| 912 | if gt get hxRefRec add du 2 0 |
| 913 | if hxHasRaw u add u 1 |
| 914 | ret u |
| 915 | end |
| 916 | end |
| 917 | end |
| 918 | end |
| 919 | end |
| 920 | end |
| 921 | ret 99999 |
| 922 | end |
| 923 | |
| 924 | fn hxMut3 n ulong flr ulong to bool |
| 925 | sPc = hxFindRawMut n |
| 926 | if eq sPc 99999 |
| 927 | ret true |
| 928 | end |
| 929 | hxSetCndStall sPc 0 |
| 930 | rc3 = hxMonkVerify n flr |
| 931 | put hxCand add mul sPc 4 3 get hxRef add mul sPc 4 3 |
| 932 | ret eq rc3 17 |
| 933 | end |
| 934 | |
| 935 | fn hxTest3Mutants n ulong flr ulong to bool |
| 936 | if not hxMut1 n flr |
| 937 | ret false |
| 938 | end |
| 939 | if not hxMut2 n flr |
| 940 | ret false |
| 941 | end |
| 942 | ret hxMut3 n flr |
| 943 | end |
| 944 | |
| 945 | fn hxPrintSummary to void |
| 946 | hxWrt hxLogA |
| 947 | hxNum get hxGenome 0 |
| 948 | hxWrt hxLogB |
| 949 | hxNum get hxStats 0 |
| 950 | hxWrt hxLogC |
| 951 | hxNum get hxStats 1 |
| 952 | hxWrt hxLogD |
| 953 | hxNum get hxStats 2 |
| 954 | hxWrt hxLogE |
| 955 | hxNum get hxStats 3 |
| 956 | hxWrt hxLogF |
| 957 | hxNum get hxStats 6 |
| 958 | hxWrt hxLogG |
| 959 | hxNum get hxStats 4 |
| 960 | hxWrt hxLogH |
| 961 | hxNum get hxStats 5 |
| 962 | hxWrt hxLogI |
| 963 | hxNum get hxStats 7 |
| 964 | hxWrt hxLogJ |
| 965 | end |
| 966 | |
| 967 | fn hxEnsureInit to void |
| 968 | if eq get hxInitDone 0 0 |
| 969 | g = hxLoadGenomeCfg |
| 970 | put hxGenome 0 g |
| 971 | note Antibody #14 (crystallized from live GB10 silicon): SM121 fixed-latency ALU pipe floor is ALWAYS 6 cycles! |
| 972 | put hxRawFloor 0 6 |
| 973 | for i ulong 8 |
| 974 | put hxStats i 0 |
| 975 | end |
| 976 | put hxInitDone 0 1 |
| 977 | end |
| 978 | end |
| 979 | |
| 980 | fn hxRunCore cnt ulong to bool |
| 981 | for i ulong cnt bound 2048 |
| 982 | put hxPerm i i |
| 983 | put hxInv i i |
| 984 | end |
| 985 | if not hxDecodeBuf false cnt |
| 986 | put hxStats 3 add get hxStats 3 1 |
| 987 | ret false |
| 988 | end |
| 989 | hxMarkTargets cnt |
| 990 | flr = get hxRawFloor 0 |
| 991 | if eq get hxInitDone 0 1 |
| 992 | if not hxTest3Mutants cnt flr |
| 993 | hxWrt hxMutFail |
| 994 | exit 88 |
| 995 | end |
| 996 | put hxInitDone 0 2 |
| 997 | end |
| 998 | gen = get hxGenome 0 |
| 999 | sRef = hxSumRefStall 0 cnt |
| 1000 | sw = ulong 0 |
| 1001 | yt = ulong 0 |
| 1002 | if eq gen 5 |
| 1003 | sw = hxDoSwapsRevPass cnt flr |
| 1004 | yt = hxTricksterChaos cnt flr |
| 1005 | else |
| 1006 | if eq gen 6 |
| 1007 | hxCompactStalls cnt 1 flr |
| 1008 | yt = hxAsceticPace cnt |
| 1009 | else |
| 1010 | sw = hxDoSwapsPass cnt flr |
| 1011 | if eq gen 3 |
| 1012 | sw = add sw hxDoSwapsPass cnt flr |
| 1013 | end |
| 1014 | hxCompactStalls cnt gen flr |
| 1015 | if or eq gen 2 eq gen 3 |
| 1016 | yt = hxAsceticPace cnt |
| 1017 | end |
| 1018 | end |
| 1019 | end |
| 1020 | mrc = hxMonkVerify cnt flr |
| 1021 | if ne mrc 0 |
| 1022 | put hxStats 2 add get hxStats 2 1 |
| 1023 | ret false |
| 1024 | end |
| 1025 | sCnd = hxSumCndStall 0 cnt |
| 1026 | put hxStats 1 add get hxStats 1 1 |
| 1027 | put hxStats 4 add get hxStats 4 sRef |
| 1028 | put hxStats 5 add get hxStats 5 sCnd |
| 1029 | put hxStats 6 add get hxStats 6 sw |
| 1030 | put hxStats 7 add get hxStats 7 yt |
| 1031 | ret true |
| 1032 | end |
| 1033 | |
| 1034 | fn hxEvolveQ36Buf cnt ulong to void |
| 1035 | if eq get hxActive 0 0 |
| 1036 | ret |
| 1037 | end |
| 1038 | hxEnsureInit |
| 1039 | if eq get hxGenome 0 0 |
| 1040 | ret |
| 1041 | end |
| 1042 | if or eq cnt 0 gt cnt 2048 |
| 1043 | put hxStats 3 add get hxStats 3 1 |
| 1044 | ret |
| 1045 | end |
| 1046 | put hxStats 0 add get hxStats 0 1 |
| 1047 | for i ulong mul cnt 4 bound 8192 |
| 1048 | v = get q36Buf i |
| 1049 | put hxRef i v |
| 1050 | put hxCand i v |
| 1051 | end |
| 1052 | if hxRunCore cnt |
| 1053 | for i ulong mul cnt 4 bound 8192 |
| 1054 | put q36Buf i get hxCand i |
| 1055 | end |
| 1056 | end |
| 1057 | end |