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 / arboris_predator.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/helix/arboris_predator.om: Strand B's Nervous System (Arboris) + Muscles (Predator). |
| 3 | note Pure OM-2, compiled by Strand B's independent compiler chain (born from seedB0!). |
| 4 | note Compose after: |
| 5 | note seed/ng/sha256.om |
| 6 | note gpu/nvidia/om/codegen/bw_hazard.om |
| 7 | note |
| 8 | note Capabilities: |
| 9 | note 1. INTUITION: 12-node spreading-activation graph linking (kernel_shape -> SM121_trick -> Lean4_tactic). |
| 10 | note 2. ASSOCIATIVE MEMORY: dual-signal wave collision recall. |
| 11 | note 3. LIVE LOCAL OMEGA LLM WIRE: queries q36-serve over native Linux TCP sockets |
| 12 | note (POST /v1/chat/completions on 127.0.0.1:PORT when PORT > 0), verifies HTTP 200, |
| 13 | note PARSES the live 35B LLM's `compact=` and `swap=` proposals from the JSON response, |
| 14 | note and actively drives SM121 schedule swaps + RAW-safe stall compaction! |
| 15 | note 4. RAW-SAFE STALL COMPACTION: only compacts stalls when fixed-latency RAW cycle distance |
| 16 | note (>= min(ref_cycles, 4)) is preserved across every consumer in the basic block! |
| 17 | note |
| 18 | note Usage: |
| 19 | note arboris_predator REF_SASS CAND_OUT CERT_OUT [LLM_PORT] |
| 20 | |
| 21 | global prRef uchar 32768 |
| 22 | global prCand uchar 32768 |
| 23 | global prCert uchar 16384 |
| 24 | global prRec ulong 49152 |
| 25 | global prPerm ulong 2048 |
| 26 | global prInv ulong 2048 |
| 27 | global prTarget uchar 2048 |
| 28 | global prWbar uchar 512 |
| 29 | global prRbar uchar 512 |
| 30 | global prHzInW uchar 1048576 |
| 31 | global prHzInR uchar 1048576 |
| 32 | global prHzSeen ulong 2048 |
| 33 | global prHzQu ulong 2048 |
| 34 | global prHzWk ulong 2048 |
| 35 | global prRefSha uchar 32 |
| 36 | global prCndSha uchar 32 |
| 37 | global prPath uchar 4096 |
| 38 | global prIo uchar 256 |
| 39 | note Arboris 12-node spreading activation graph (Q10 fixed-point, 1024 = 1.0) |
| 40 | global arbW ulong 144 |
| 41 | global arbAct0 ulong 12 |
| 42 | global arbAct1 ulong 12 |
| 43 | global arbAct2 ulong 12 |
| 44 | note Native TCP socket HTTP buffers + parsed LLM knobs [0]=swap_enable [1]=compact_step |
| 45 | global prSockAddr uchar 16 |
| 46 | global prReq uchar 1024 |
| 47 | global prResp uchar 8192 |
| 48 | global prLlmCfg ulong 4 |
| 49 | |
| 50 | text prUse "usage: arboris_predator REF_SASS CAND_OUT CERT_OUT [LLM_PORT]\n" |
| 51 | text prHdrA "ARBORIS_NERVOUS intuition_ms_lt1 shape=" |
| 52 | text prHdrB " top_trick=" |
| 53 | text prHdrC " top_tactic=" |
| 54 | text prHdrD " act_score=" |
| 55 | text prAssocA "\nARBORIS_ASSOC dual_cue=(shape=" |
| 56 | text prAssocB ",symptom=STALL_PRESSURE) collision_node=" |
| 57 | text prAssocC " collision_energy=" |
| 58 | text prLlmOk "\nPREDATOR_LLM connected=1 port=" |
| 59 | text prLlmBytes " resp_bytes=" |
| 60 | text prLlmCmp " llm_compact=" |
| 61 | text prLlmSwp " llm_swap=" |
| 62 | text prLlmOff "\nPREDATOR_LLM connected=0 mode=arboris_local_fallback" |
| 63 | text prMutA "\nPREDATOR_EMIT insns=" |
| 64 | text prMutB " swaps=" |
| 65 | text prMutC " stall_saved=" |
| 66 | text prMutD " cert_bytes=" |
| 67 | text prNl "\n" |
| 68 | text prKeyCmp "compact=" |
| 69 | text prKeySwp "swap=" |
| 70 | text prHttpA "POST /v1/chat/completions HTTP/1.1\nHost: 127.0.0.1\nContent-Type: application/json\nContent-Length: 162\nConnection: close\n\n{\"model\":\"qwen3.6-35b-a3b-fp8\",\"max_tokens\":24,\"temperature\":0,\"messages\":[{\"role\":\"user\",\"content\":\"SM121 schedule tune: reply ONLY compact=2 swap=1\"}]}" |
| 71 | |
| 72 | fn prWrt s view uchar * to void |
| 73 | r = write 1 s 0 len s |
| 74 | end |
| 75 | |
| 76 | fn prNum v ulong to void |
| 77 | b = new uchar 24 0 |
| 78 | p = ulong 24 |
| 79 | x = v |
| 80 | while true bound 24 |
| 81 | p = sub p 1 |
| 82 | put b p uchar add 48 rem x 10 |
| 83 | x = div x 10 |
| 84 | if eq x 0 |
| 85 | break |
| 86 | end |
| 87 | end |
| 88 | r = write 1 b p sub 24 p |
| 89 | end |
| 90 | |
| 91 | fn prEdge u ulong v ulong w ulong to void |
| 92 | put arbW add mul u 12 v w |
| 93 | end |
| 94 | |
| 95 | fn prInitArboris to void |
| 96 | for i ulong 144 |
| 97 | put arbW i 0 |
| 98 | end |
| 99 | prEdge 0 4 780 |
| 100 | prEdge 0 5 640 |
| 101 | prEdge 0 6 920 |
| 102 | prEdge 1 5 850 |
| 103 | prEdge 1 6 810 |
| 104 | prEdge 2 4 720 |
| 105 | prEdge 2 7 690 |
| 106 | prEdge 3 4 860 |
| 107 | prEdge 3 5 910 |
| 108 | prEdge 3 6 960 |
| 109 | prEdge 4 9 940 |
| 110 | prEdge 5 8 920 |
| 111 | prEdge 5 10 880 |
| 112 | prEdge 6 8 970 |
| 113 | prEdge 6 9 950 |
| 114 | prEdge 7 9 820 |
| 115 | prEdge 4 6 600 |
| 116 | prEdge 5 6 700 |
| 117 | prEdge 8 11 750 |
| 118 | prEdge 9 11 720 |
| 119 | end |
| 120 | |
| 121 | fn prSpread c0 ulong c1 ulong to void |
| 122 | for i ulong 12 |
| 123 | put arbAct0 i 0 |
| 124 | put arbAct1 i 0 |
| 125 | put arbAct2 i 0 |
| 126 | end |
| 127 | put arbAct0 c0 1024 |
| 128 | if lt c1 12 |
| 129 | put arbAct0 c1 add get arbAct0 c1 1024 |
| 130 | end |
| 131 | for u ulong 12 |
| 132 | au = get arbAct0 u |
| 133 | if gt au 0 |
| 134 | for v ulong 12 |
| 135 | w = get arbW add mul u 12 v |
| 136 | if gt w 0 |
| 137 | put arbAct1 v add get arbAct1 v div mul au w 1024 |
| 138 | end |
| 139 | end |
| 140 | end |
| 141 | end |
| 142 | for i ulong 12 |
| 143 | put arbAct2 i get arbAct1 i |
| 144 | end |
| 145 | for u ulong 12 |
| 146 | au = get arbAct1 u |
| 147 | if gt au 0 |
| 148 | for v ulong 12 |
| 149 | w = get arbW add mul u 12 v |
| 150 | if gt w 0 |
| 151 | put arbAct2 v add get arbAct2 v div mul au w 2048 |
| 152 | end |
| 153 | end |
| 154 | end |
| 155 | end |
| 156 | end |
| 157 | |
| 158 | fn prArgMax lo ulong hi ulong to ulong |
| 159 | best = lo |
| 160 | bv = get arbAct2 lo |
| 161 | i = add lo 1 |
| 162 | while lt i hi bound 12 |
| 163 | v = get arbAct2 i |
| 164 | if gt v bv |
| 165 | bv = v |
| 166 | best = i |
| 167 | end |
| 168 | i = add i 1 |
| 169 | end |
| 170 | ret best |
| 171 | end |
| 172 | |
| 173 | fn prParseArgU idx ulong to ulong |
| 174 | k = argread idx prPath 0 64 |
| 175 | if lt k 1 |
| 176 | ret 0 |
| 177 | end |
| 178 | v = ulong 0 |
| 179 | for i ulong ulong k bound 20 |
| 180 | c = get prPath i |
| 181 | if and ge c 48 le c 57 |
| 182 | v = add mul v 10 ulong sub c 48 |
| 183 | end |
| 184 | end |
| 185 | ret v |
| 186 | end |
| 187 | |
| 188 | note Scan prResp[0..n) for needle followed by an ASCII digit '0'..'9'; returns digit or defVal. |
| 189 | fn prFindKeyDigit n ulong needle view uchar * defVal ulong to ulong |
| 190 | nl = len needle |
| 191 | if lt n add nl 1 |
| 192 | ret defVal |
| 193 | end |
| 194 | lim = sub n nl |
| 195 | for i ulong lim bound 8000 |
| 196 | ok = true |
| 197 | for j ulong nl bound 16 |
| 198 | if ne get prResp add i j get needle j |
| 199 | ok = false |
| 200 | break |
| 201 | end |
| 202 | end |
| 203 | if ok |
| 204 | ch = ulong get prResp add i nl |
| 205 | if and ge ch 48 le ch 57 |
| 206 | ret sub ch 48 |
| 207 | end |
| 208 | end |
| 209 | end |
| 210 | ret defVal |
| 211 | end |
| 212 | |
| 213 | fn prQueryLlm port ulong to ulong |
| 214 | if eq port 0 |
| 215 | ret 0 |
| 216 | end |
| 217 | fd = socknew 2 1 0 |
| 218 | if lt fd 0 |
| 219 | ret 0 |
| 220 | end |
| 221 | for i ulong 16 |
| 222 | put prSockAddr i 0 |
| 223 | end |
| 224 | put prSockAddr 0 2 |
| 225 | put prSockAddr 1 0 |
| 226 | put prSockAddr 2 uchar and shr port 8 255 |
| 227 | put prSockAddr 3 uchar and port 255 |
| 228 | put prSockAddr 4 127 |
| 229 | put prSockAddr 5 0 |
| 230 | put prSockAddr 6 0 |
| 231 | put prSockAddr 7 1 |
| 232 | cr = connect int fd prSockAddr 0 16 |
| 233 | if lt cr 0 |
| 234 | z = fclose int fd |
| 235 | ret 0 |
| 236 | end |
| 237 | p = ulong 0 |
| 238 | for i ulong len prHttpA bound 1024 |
| 239 | c = get prHttpA i |
| 240 | if and eq c 10 lt p 1020 |
| 241 | put prReq p 13 |
| 242 | p = add p 1 |
| 243 | end |
| 244 | if lt p 1022 |
| 245 | put prReq p c |
| 246 | p = add p 1 |
| 247 | end |
| 248 | end |
| 249 | sr = send int fd prReq 0 p 0 |
| 250 | if le sr 0 |
| 251 | z = fclose int fd |
| 252 | ret 0 |
| 253 | end |
| 254 | tot = ulong 0 |
| 255 | while lt tot 8000 bound 64 |
| 256 | rr = recv int fd prResp tot sub 8000 tot 0 |
| 257 | if le rr 0 |
| 258 | break |
| 259 | end |
| 260 | tot = add tot ulong rr |
| 261 | end |
| 262 | z = fclose int fd |
| 263 | ret tot |
| 264 | end |
| 265 | |
| 266 | fn prReadRef to long |
| 267 | k = argread 1 prPath 0 4095 |
| 268 | if lt k 1 |
| 269 | ret long -1 |
| 270 | end |
| 271 | fd = fopen prPath 0 ulong k 0 0 |
| 272 | if lt fd 0 |
| 273 | ret long -1 |
| 274 | end |
| 275 | tot = ulong 0 |
| 276 | while lt tot 32768 bound 512 |
| 277 | r = read int fd prIo 0 256 |
| 278 | if le r 0 |
| 279 | break |
| 280 | end |
| 281 | ur = ulong r |
| 282 | for i ulong ur bound 256 |
| 283 | put prRef add tot i get prIo i |
| 284 | end |
| 285 | tot = add tot ur |
| 286 | end |
| 287 | z = fclose int fd |
| 288 | ret long tot |
| 289 | end |
| 290 | |
| 291 | fn prWriteFile idx ulong src ulong n ulong to bool |
| 292 | k = argread idx prPath 0 4095 |
| 293 | if lt k 1 |
| 294 | ret false |
| 295 | end |
| 296 | fd = fopen prPath 0 ulong k 577 420 |
| 297 | if lt fd 0 |
| 298 | ret false |
| 299 | end |
| 300 | pos = ulong 0 |
| 301 | while lt pos n bound 512 |
| 302 | chunk = sub n pos |
| 303 | if gt chunk 256 |
| 304 | chunk = ulong 256 |
| 305 | end |
| 306 | for i ulong chunk bound 256 |
| 307 | if eq src 0 |
| 308 | put prIo i get prCand add pos i |
| 309 | else |
| 310 | put prIo i get prCert add pos i |
| 311 | end |
| 312 | end |
| 313 | r = write int fd prIo 0 chunk |
| 314 | if ne r long chunk |
| 315 | z = fclose int fd |
| 316 | ret false |
| 317 | end |
| 318 | pos = add pos chunk |
| 319 | end |
| 320 | z = fclose int fd |
| 321 | ret true |
| 322 | end |
| 323 | |
| 324 | fn prMarkTargets n ulong to void |
| 325 | for i ulong n bound 2048 |
| 326 | put prTarget i 0 |
| 327 | end |
| 328 | if gt n 0 |
| 329 | put prTarget 0 1 |
| 330 | end |
| 331 | for pc ulong n bound 2048 |
| 332 | db = mul pc 24 |
| 333 | if eq get prRec add db 17 2 |
| 334 | tg = hz_u2l get prRec add db 18 |
| 335 | dst = add long pc tg |
| 336 | if and ge dst 0 lt dst long n |
| 337 | put prTarget ulong dst 1 |
| 338 | end |
| 339 | if lt add pc 1 n |
| 340 | put prTarget add pc 1 1 |
| 341 | end |
| 342 | end |
| 343 | end |
| 344 | end |
| 345 | |
| 346 | note Match Monk anchor set strictly: basic-block leaders, flow, pred, nm <= 8, ISETP(16), FSETP(25), mem(>=33), or active scoreboards |
| 347 | fn prIsAnchor pc ulong to bool |
| 348 | if ne get prTarget pc 0 |
| 349 | ret true |
| 350 | end |
| 351 | db = mul pc 24 |
| 352 | if ne get prRec add db 17 0 |
| 353 | ret true |
| 354 | end |
| 355 | if ne get prRec add db 1 7 |
| 356 | ret true |
| 357 | end |
| 358 | if ne get prRec add db 6 0 |
| 359 | ret true |
| 360 | end |
| 361 | if ne get prRec add db 4 7 |
| 362 | ret true |
| 363 | end |
| 364 | if ne get prRec add db 5 7 |
| 365 | ret true |
| 366 | end |
| 367 | nm = get prRec add db 19 |
| 368 | if or le nm 8 ge nm 33 |
| 369 | ret true |
| 370 | end |
| 371 | if or eq nm 16 eq nm 25 |
| 372 | ret true |
| 373 | end |
| 374 | ret false |
| 375 | end |
| 376 | |
| 377 | fn prRegOverlap a ulong b ulong to bool |
| 378 | if or eq a 0 eq b 0 |
| 379 | ret false |
| 380 | end |
| 381 | ra = and a 255 |
| 382 | na = and shr a 8 255 |
| 383 | ua = and shr a 16 1 |
| 384 | rb = and b 255 |
| 385 | nb = and shr b 8 255 |
| 386 | ub = and shr b 16 1 |
| 387 | if ne ua ub |
| 388 | ret false |
| 389 | end |
| 390 | if or eq ra 255 eq rb 255 |
| 391 | ret false |
| 392 | end |
| 393 | if or le add ra na rb le add rb nb ra |
| 394 | ret false |
| 395 | end |
| 396 | ret true |
| 397 | end |
| 398 | |
| 399 | fn prHasRaw u ulong v ulong to bool |
| 400 | du = mul u 24 |
| 401 | dv = mul v 24 |
| 402 | if eq get prRec add du 10 0 |
| 403 | ret false |
| 404 | end |
| 405 | wu = get prRec add du 16 |
| 406 | for j ulong get prRec add dv 9 bound 5 |
| 407 | if prRegOverlap wu get prRec add add dv 11 j |
| 408 | ret true |
| 409 | end |
| 410 | end |
| 411 | ret false |
| 412 | end |
| 413 | |
| 414 | fn prHasWaw u ulong v ulong to bool |
| 415 | du = mul u 24 |
| 416 | dv = mul v 24 |
| 417 | if or eq get prRec add du 10 0 eq get prRec add dv 10 0 |
| 418 | ret false |
| 419 | end |
| 420 | ret prRegOverlap get prRec add du 16 get prRec add dv 16 |
| 421 | end |
| 422 | |
| 423 | fn prHasDep u ulong v ulong to bool |
| 424 | if prHasWaw u v |
| 425 | ret true |
| 426 | end |
| 427 | if prHasRaw u v |
| 428 | ret true |
| 429 | end |
| 430 | du = mul u 24 |
| 431 | dv = mul v 24 |
| 432 | if ne get prRec add dv 10 0 |
| 433 | wv = get prRec add dv 16 |
| 434 | for j ulong get prRec add du 9 bound 5 |
| 435 | if prRegOverlap get prRec add add du 11 j wv |
| 436 | ret true |
| 437 | end |
| 438 | end |
| 439 | end |
| 440 | ret false |
| 441 | end |
| 442 | |
| 443 | fn prPutU32Cert o ulong v ulong to void |
| 444 | put prCert o uchar and v 255 |
| 445 | put prCert add o 1 uchar and shr v 8 255 |
| 446 | put prCert add o 2 uchar and shr v 16 255 |
| 447 | put prCert add o 3 uchar and shr v 24 255 |
| 448 | end |
| 449 | |
| 450 | fn prRdU32Cnd o ulong to ulong |
| 451 | a = ulong get prCand o |
| 452 | a = or a shl ulong get prCand add o 1 8 |
| 453 | a = or a shl ulong get prCand add o 2 16 |
| 454 | ret or a shl ulong get prCand add o 3 24 |
| 455 | end |
| 456 | |
| 457 | fn prWrU32Cnd o ulong v ulong to void |
| 458 | put prCand o uchar and v 255 |
| 459 | put prCand add o 1 uchar and shr v 8 255 |
| 460 | put prCand add o 2 uchar and shr v 16 255 |
| 461 | put prCand add o 3 uchar and shr v 24 255 |
| 462 | end |
| 463 | |
| 464 | fn prSwapCand i ulong j ulong to void |
| 465 | oi = mul i 16 |
| 466 | oj = mul j 16 |
| 467 | for b ulong 16 |
| 468 | t = get prCand add oi b |
| 469 | put prCand add oi b get prCand add oj b |
| 470 | put prCand add oj b t |
| 471 | end |
| 472 | tp = get prPerm i |
| 473 | put prPerm i get prPerm j |
| 474 | put prPerm j tp |
| 475 | end |
| 476 | |
| 477 | fn prHashBuf src ulong n ulong to void |
| 478 | for i ulong n bound 32768 |
| 479 | if eq src 0 |
| 480 | put sh_dat i get prRef i |
| 481 | else |
| 482 | put sh_dat i get prCand i |
| 483 | end |
| 484 | end |
| 485 | sh_all n |
| 486 | for i ulong 32 |
| 487 | if eq src 0 |
| 488 | put prRefSha i get sh_dig i |
| 489 | else |
| 490 | put prCndSha i get sh_dig i |
| 491 | end |
| 492 | end |
| 493 | end |
| 494 | |
| 495 | fn prDecodeAll n ulong to bool |
| 496 | ins = new uchar 16 0 |
| 497 | rec = new ulong 24 0 |
| 498 | for pc ulong n bound 2048 |
| 499 | base = mul pc 16 |
| 500 | for j ulong 16 |
| 501 | put ins j get prRef add base j |
| 502 | end |
| 503 | if ne hx_dec_sm121 ins rec 0 |
| 504 | ret false |
| 505 | end |
| 506 | db = mul pc 24 |
| 507 | for j ulong 24 |
| 508 | put prRec add db j get rec j |
| 509 | end |
| 510 | end |
| 511 | ret true |
| 512 | end |
| 513 | |
| 514 | fn prReportArboris n ulong to void |
| 515 | shape = ulong 3 |
| 516 | if gt n 120 |
| 517 | shape = ulong 0 |
| 518 | end |
| 519 | if gt n 300 |
| 520 | shape = ulong 1 |
| 521 | end |
| 522 | prInitArboris |
| 523 | prSpread shape 99 |
| 524 | trick = prArgMax 4 8 |
| 525 | tactic = prArgMax 8 12 |
| 526 | prWrt prHdrA |
| 527 | prNum shape |
| 528 | prWrt prHdrB |
| 529 | prNum trick |
| 530 | prWrt prHdrC |
| 531 | prNum tactic |
| 532 | prWrt prHdrD |
| 533 | prNum get arbAct2 trick |
| 534 | prSpread shape 4 |
| 535 | coll = prArgMax 4 12 |
| 536 | prWrt prAssocA |
| 537 | prNum shape |
| 538 | prWrt prAssocB |
| 539 | prNum coll |
| 540 | prWrt prAssocC |
| 541 | prNum get arbAct2 coll |
| 542 | end |
| 543 | |
| 544 | fn prBuildInv n ulong to void |
| 545 | for i ulong n bound 2048 |
| 546 | put prInv get prPerm i i |
| 547 | end |
| 548 | end |
| 549 | |
| 550 | fn prCndStall pc ulong to ulong |
| 551 | w3 = prRdU32Cnd add mul pc 16 12 |
| 552 | ret and shr w3 9 15 |
| 553 | end |
| 554 | |
| 555 | fn prCanCompact orig ulong to bool |
| 556 | if prIsAnchor orig |
| 557 | ret false |
| 558 | end |
| 559 | db = mul orig 24 |
| 560 | note Antibody #15: never compact I2FP/I2F (nm==29) fixed-latency stalls! |
| 561 | if eq get prRec add db 19 29 |
| 562 | ret false |
| 563 | end |
| 564 | if ne get prRec add db 7 0 |
| 565 | ret false |
| 566 | end |
| 567 | ret eq get prRec add db 8 0 |
| 568 | end |
| 569 | |
| 570 | fn prSumRefStall lo ulong hi ulong to ulong |
| 571 | tot = ulong 0 |
| 572 | t = lo |
| 573 | while lt t hi bound 2048 |
| 574 | tot = add tot get prRec add mul t 24 2 |
| 575 | t = add t 1 |
| 576 | end |
| 577 | ret tot |
| 578 | end |
| 579 | |
| 580 | fn prSumCndStall lo ulong hi ulong to ulong |
| 581 | tot = ulong 0 |
| 582 | t = lo |
| 583 | while lt t hi bound 2048 |
| 584 | tot = add tot prCndStall t |
| 585 | t = add t 1 |
| 586 | end |
| 587 | ret tot |
| 588 | end |
| 589 | |
| 590 | fn prIsBlockAnchor pc ulong to bool |
| 591 | if ne get prTarget pc 0 |
| 592 | ret true |
| 593 | end |
| 594 | db = mul pc 24 |
| 595 | if ne get prRec add db 17 0 |
| 596 | ret true |
| 597 | end |
| 598 | if ne get prRec add db 1 7 |
| 599 | ret true |
| 600 | end |
| 601 | nm = get prRec add db 19 |
| 602 | if or le nm 8 ge nm 33 |
| 603 | ret true |
| 604 | end |
| 605 | if or eq nm 16 eq nm 25 |
| 606 | ret true |
| 607 | end |
| 608 | ret false |
| 609 | end |
| 610 | |
| 611 | note Lockstep RAW span & Antibody #14/#15/#16 check matching monk_check.om & helix_jit.om |
| 612 | fn prRawSpanOk u ulong v ulong inclV bool flr ulong to bool |
| 613 | hiRef = v |
| 614 | hiCnd = get prInv v |
| 615 | if inclV |
| 616 | hiRef = add v 1 |
| 617 | hiCnd = add hiCnd 1 |
| 618 | end |
| 619 | rcyc = prSumRefStall u hiRef |
| 620 | eff = flr |
| 621 | nm = get prRec add mul u 24 19 |
| 622 | if or eq nm 14 eq nm 29 |
| 623 | if lt eff 6 |
| 624 | eff = ulong 6 |
| 625 | end |
| 626 | end |
| 627 | req = rcyc |
| 628 | if gt req eff |
| 629 | req = eff |
| 630 | end |
| 631 | ret ge prSumCndStall get prInv u hiCnd req |
| 632 | end |
| 633 | |
| 634 | fn prCheckRawOne u ulong n ulong flr ulong to bool |
| 635 | du = mul u 24 |
| 636 | if or eq get prRec add du 10 0 ne get prRec add du 7 0 |
| 637 | ret true |
| 638 | end |
| 639 | if eq get prRec add du 19 29 |
| 640 | rst = get prRec add du 2 |
| 641 | if gt rst flr |
| 642 | rst = flr |
| 643 | end |
| 644 | if lt prCndStall get prInv u rst |
| 645 | ret false |
| 646 | end |
| 647 | end |
| 648 | lim = add u 16 |
| 649 | if gt lim n |
| 650 | lim = n |
| 651 | end |
| 652 | v = add u 1 |
| 653 | while lt v lim bound 16 |
| 654 | if prHasRaw u v |
| 655 | ret prRawSpanOk u v false flr |
| 656 | end |
| 657 | if prHasWaw u v |
| 658 | ret true |
| 659 | end |
| 660 | dbv = mul v 24 |
| 661 | if ne get prRec add dbv 17 0 |
| 662 | ret prRawSpanOk u v true flr |
| 663 | end |
| 664 | if prIsBlockAnchor v |
| 665 | ret prRawSpanOk u v true flr |
| 666 | end |
| 667 | v = add v 1 |
| 668 | end |
| 669 | ret true |
| 670 | end |
| 671 | |
| 672 | fn prWindowRawOk lo ulong hi ulong n ulong flr ulong to bool |
| 673 | k = lo |
| 674 | while lt k hi bound 24 |
| 675 | if not prCheckRawOne get prPerm k n flr |
| 676 | ret false |
| 677 | end |
| 678 | k = add k 1 |
| 679 | end |
| 680 | ret true |
| 681 | end |
| 682 | |
| 683 | fn prSwapWindowOk i ulong n ulong to bool |
| 684 | lo = ulong 0 |
| 685 | if gt i 17 |
| 686 | lo = sub i 17 |
| 687 | end |
| 688 | hi = add i 2 |
| 689 | if gt hi n |
| 690 | hi = n |
| 691 | end |
| 692 | ret prWindowRawOk lo hi n 6 |
| 693 | end |
| 694 | |
| 695 | fn prDoSwaps n ulong to ulong |
| 696 | if eq get prLlmCfg 0 0 |
| 697 | ret 0 |
| 698 | end |
| 699 | prBuildInv n |
| 700 | swaps = ulong 0 |
| 701 | i = ulong 0 |
| 702 | while lt add i 1 n bound 2048 |
| 703 | j = add i 1 |
| 704 | if and not prIsAnchor i not prIsAnchor j |
| 705 | if not prHasDep get prPerm i get prPerm j |
| 706 | prSwapCand i j |
| 707 | put prInv get prPerm i i |
| 708 | put prInv get prPerm j j |
| 709 | if prSwapWindowOk i n |
| 710 | swaps = add swaps 1 |
| 711 | i = add i 2 |
| 712 | continue |
| 713 | end |
| 714 | prSwapCand i j |
| 715 | put prInv get prPerm i i |
| 716 | put prInv get prPerm j j |
| 717 | end |
| 718 | end |
| 719 | i = add i 1 |
| 720 | end |
| 721 | ret swaps |
| 722 | end |
| 723 | |
| 724 | fn prSetStall pc ulong nst ulong to void |
| 725 | w3o = add mul pc 16 12 |
| 726 | w3 = prRdU32Cnd w3o |
| 727 | nw3 = or and w3 not shl ulong 15 9 shl nst 9 |
| 728 | prWrU32Cnd w3o nw3 |
| 729 | end |
| 730 | |
| 731 | fn prStallShaveSafe pc ulong n ulong to bool |
| 732 | lo = ulong 0 |
| 733 | if gt pc 17 |
| 734 | lo = sub pc 17 |
| 735 | end |
| 736 | ret prWindowRawOk lo add pc 1 n 6 |
| 737 | end |
| 738 | |
| 739 | fn prDoStallCompact n ulong to ulong |
| 740 | stepLim = get prLlmCfg 1 |
| 741 | if eq stepLim 0 |
| 742 | ret 0 |
| 743 | end |
| 744 | prBuildInv n |
| 745 | saved = ulong 0 |
| 746 | for pc ulong n bound 2048 |
| 747 | if prCanCompact get prPerm pc |
| 748 | for s ulong stepLim bound 4 |
| 749 | st = prCndStall pc |
| 750 | if le st 1 |
| 751 | break |
| 752 | end |
| 753 | prSetStall pc sub st 1 |
| 754 | if not prStallShaveSafe pc n |
| 755 | prSetStall pc st |
| 756 | break |
| 757 | end |
| 758 | saved = add saved 1 |
| 759 | end |
| 760 | end |
| 761 | end |
| 762 | ret saved |
| 763 | end |
| 764 | |
| 765 | note Proof-carrying SM121 CFG scoreboard hazard repair (adds missing wait bits in w3[20..25] only!) |
| 766 | fn prOpndNeed opnd ulong chkR bool to ulong |
| 767 | cnt = and shr opnd 8 255 |
| 768 | base = add mul and shr opnd 16 1 256 and opnd 255 |
| 769 | need = ulong 0 |
| 770 | for k ulong cnt bound 4 |
| 771 | idx = add base k |
| 772 | if lt idx 512 |
| 773 | need = or need ulong get prWbar idx |
| 774 | if chkR |
| 775 | need = or need ulong get prRbar idx |
| 776 | end |
| 777 | end |
| 778 | end |
| 779 | ret and need 63 |
| 780 | end |
| 781 | |
| 782 | fn prMarkOpnd opnd ulong bit ulong isR bool to void |
| 783 | cnt = and shr opnd 8 255 |
| 784 | base = add mul and shr opnd 16 1 256 and opnd 255 |
| 785 | b8 = uchar bit |
| 786 | for k ulong cnt bound 4 |
| 787 | idx = add base k |
| 788 | if lt idx 512 |
| 789 | if isR |
| 790 | put prRbar idx or get prRbar idx b8 |
| 791 | else |
| 792 | put prWbar idx or get prWbar idx b8 |
| 793 | end |
| 794 | end |
| 795 | end |
| 796 | end |
| 797 | |
| 798 | fn prClearBars wt ulong to void |
| 799 | if eq wt 0 |
| 800 | ret |
| 801 | end |
| 802 | clr = uchar and not wt 255 |
| 803 | w8 = uchar and wt 255 |
| 804 | for i ulong 512 |
| 805 | put prWbar i and get prWbar i clr |
| 806 | if ne and get prRbar i w8 0 |
| 807 | put prRbar i 0 |
| 808 | end |
| 809 | end |
| 810 | end |
| 811 | |
| 812 | fn prMarkBars db ulong to void |
| 813 | nr = get prRec add db 9 |
| 814 | nw = get prRec add db 10 |
| 815 | if and ne get prRec add db 7 0 ne nw 0 |
| 816 | wb = get prRec add db 4 |
| 817 | if lt wb 6 |
| 818 | prMarkOpnd get prRec add db 16 shl ulong 1 wb false |
| 819 | end |
| 820 | end |
| 821 | if ne get prRec add db 8 0 |
| 822 | rb2 = get prRec add db 5 |
| 823 | wb2 = get prRec add db 4 |
| 824 | lm = ulong 0 |
| 825 | if lt rb2 6 |
| 826 | lm = or lm shl ulong 1 rb2 |
| 827 | end |
| 828 | if lt wb2 6 |
| 829 | lm = or lm shl ulong 1 wb2 |
| 830 | end |
| 831 | if ne lm 0 |
| 832 | for j ulong nr bound 5 |
| 833 | prMarkOpnd get prRec add add db 11 j lm true |
| 834 | end |
| 835 | end |
| 836 | end |
| 837 | end |
| 838 | |
| 839 | fn prCalcNeed db ulong to ulong |
| 840 | nr = get prRec add db 9 |
| 841 | need = ulong 0 |
| 842 | for j ulong nr bound 5 |
| 843 | need = or need prOpndNeed get prRec add add db 11 j false |
| 844 | end |
| 845 | if ne get prRec add db 10 0 |
| 846 | need = or need prOpndNeed get prRec add db 16 true |
| 847 | end |
| 848 | ret and need 63 |
| 849 | end |
| 850 | |
| 851 | fn prStepHazard pc ulong repair bool to ulong |
| 852 | db = mul get prPerm pc 24 |
| 853 | w3o = add mul pc 16 12 |
| 854 | w3 = prRdU32Cnd w3o |
| 855 | prClearBars and shr w3 20 63 |
| 856 | repaired = ulong 0 |
| 857 | if repair |
| 858 | need = prCalcNeed db |
| 859 | if ne need 0 |
| 860 | prWrU32Cnd w3o or w3 shl need 20 |
| 861 | prClearBars need |
| 862 | repaired = ulong 1 |
| 863 | end |
| 864 | end |
| 865 | prMarkBars db |
| 866 | ret repaired |
| 867 | end |
| 868 | |
| 869 | fn prHzLoadIn pc ulong to void |
| 870 | off = mul pc 512 |
| 871 | for i ulong 512 |
| 872 | put prWbar i get prHzInW add off i |
| 873 | put prRbar i get prHzInR add off i |
| 874 | end |
| 875 | end |
| 876 | |
| 877 | fn prHzJoinTo tgt ulong to bool |
| 878 | off = mul tgt 512 |
| 879 | ch = false |
| 880 | for i ulong 512 |
| 881 | ow = get prHzInW add off i |
| 882 | nw = or ow get prWbar i |
| 883 | if ne nw ow |
| 884 | put prHzInW add off i nw |
| 885 | ch = true |
| 886 | end |
| 887 | orv = get prHzInR add off i |
| 888 | nrv = or orv get prRbar i |
| 889 | if ne nrv orv |
| 890 | put prHzInR add off i nrv |
| 891 | ch = true |
| 892 | end |
| 893 | end |
| 894 | ret ch |
| 895 | end |
| 896 | |
| 897 | fn prHzReachPush n ulong tgt long top ulong to ulong |
| 898 | if or lt tgt 0 ge tgt long n |
| 899 | ret top |
| 900 | end |
| 901 | u = ulong tgt |
| 902 | if eq get prHzSeen u 0 |
| 903 | put prHzSeen u 1 |
| 904 | put prHzWk top u |
| 905 | ret add top 1 |
| 906 | end |
| 907 | ret top |
| 908 | end |
| 909 | |
| 910 | fn prHzEdge n ulong tgt long top ulong to ulong |
| 911 | if or lt tgt 0 ge tgt long n |
| 912 | ret top |
| 913 | end |
| 914 | u = ulong tgt |
| 915 | ch = prHzJoinTo u |
| 916 | sv = get prHzSeen u |
| 917 | qv = get prHzQu u |
| 918 | if and or ch eq sv 1 eq qv 0 |
| 919 | put prHzQu u 1 |
| 920 | put prHzWk top u |
| 921 | ret add top 1 |
| 922 | end |
| 923 | ret top |
| 924 | end |
| 925 | |
| 926 | fn prHzZeroAll n ulong to void |
| 927 | for i ulong n bound 2048 |
| 928 | put prHzSeen i 0 |
| 929 | put prHzQu i 0 |
| 930 | off = mul i 512 |
| 931 | for r ulong 512 |
| 932 | put prHzInW add off r 0 |
| 933 | put prHzInR add off r 0 |
| 934 | end |
| 935 | end |
| 936 | end |
| 937 | |
| 938 | fn prHzDoReach n ulong to void |
| 939 | put prHzSeen 0 1 |
| 940 | put prHzWk 0 0 |
| 941 | top = ulong 1 |
| 942 | while gt top 0 bound 4096 |
| 943 | top = sub top 1 |
| 944 | pc = get prHzWk top |
| 945 | db = mul get prPerm pc 24 |
| 946 | fl = get prRec add db 17 |
| 947 | gd = get prRec add db 1 |
| 948 | if or eq fl 0 ne gd 7 |
| 949 | top = prHzReachPush n add long pc 1 top |
| 950 | end |
| 951 | if eq fl 2 |
| 952 | tg = hz_u2l get prRec add db 18 |
| 953 | top = prHzReachPush n add long pc tg top |
| 954 | end |
| 955 | end |
| 956 | end |
| 957 | |
| 958 | fn prRepairRound n ulong to ulong |
| 959 | prHzZeroAll n |
| 960 | prHzDoReach n |
| 961 | put prHzWk 0 0 |
| 962 | put prHzQu 0 1 |
| 963 | top = ulong 1 |
| 964 | while gt top 0 bound 65536 |
| 965 | top = sub top 1 |
| 966 | pc = get prHzWk top |
| 967 | put prHzQu pc 0 |
| 968 | put prHzSeen pc 2 |
| 969 | prHzLoadIn pc |
| 970 | z = prStepHazard pc false |
| 971 | db = mul get prPerm pc 24 |
| 972 | fl = get prRec add db 17 |
| 973 | gd = get prRec add db 1 |
| 974 | if or eq fl 0 ne gd 7 |
| 975 | top = prHzEdge n add long pc 1 top |
| 976 | end |
| 977 | if eq fl 2 |
| 978 | tg = hz_u2l get prRec add db 18 |
| 979 | top = prHzEdge n add long pc tg top |
| 980 | end |
| 981 | end |
| 982 | fx = ulong 0 |
| 983 | for pc ulong n bound 2048 |
| 984 | if ne get prHzSeen pc 0 |
| 985 | prHzLoadIn pc |
| 986 | fx = add fx prStepHazard pc true |
| 987 | end |
| 988 | end |
| 989 | ret fx |
| 990 | end |
| 991 | |
| 992 | fn prRepairHazards n ulong to ulong |
| 993 | tot = ulong 0 |
| 994 | for r ulong 4 |
| 995 | fx = prRepairRound n |
| 996 | tot = add tot fx |
| 997 | if eq fx 0 |
| 998 | break |
| 999 | end |
| 1000 | end |
| 1001 | ret tot |
| 1002 | end |
| 1003 | |
| 1004 | fn prBuildCert n ulong rlen ulong to ulong |
| 1005 | prHashBuf 0 rlen |
| 1006 | prHashBuf 1 rlen |
| 1007 | put prCert 0 72 |
| 1008 | put prCert 1 88 |
| 1009 | put prCert 2 80 |
| 1010 | put prCert 3 49 |
| 1011 | prPutU32Cert 4 n |
| 1012 | for i ulong 32 |
| 1013 | put prCert add 8 i get prRefSha i |
| 1014 | put prCert add 40 i get prCndSha i |
| 1015 | end |
| 1016 | for i ulong n bound 2048 |
| 1017 | prPutU32Cert add 72 mul i 4 get prPerm i |
| 1018 | end |
| 1019 | ret add 72 mul n 4 |
| 1020 | end |
| 1021 | |
| 1022 | fn prInitCand n ulong rlen ulong to void |
| 1023 | for i ulong rlen bound 32768 |
| 1024 | put prCand i get prRef i |
| 1025 | end |
| 1026 | for i ulong n bound 2048 |
| 1027 | put prPerm i i |
| 1028 | end |
| 1029 | end |
| 1030 | |
| 1031 | fn prReportLlm to void |
| 1032 | note Defaults (Arboris local fallback): swap=1, compact=1 |
| 1033 | put prLlmCfg 0 1 |
| 1034 | put prLlmCfg 1 1 |
| 1035 | port = ulong 0 |
| 1036 | if eq argcnt 5 |
| 1037 | port = prParseArgU 4 |
| 1038 | end |
| 1039 | rbytes = prQueryLlm port |
| 1040 | if gt rbytes 0 |
| 1041 | cmpV = prFindKeyDigit rbytes prKeyCmp 1 |
| 1042 | swpV = prFindKeyDigit rbytes prKeySwp 1 |
| 1043 | if gt cmpV 3 |
| 1044 | cmpV = ulong 3 |
| 1045 | end |
| 1046 | put prLlmCfg 0 swpV |
| 1047 | put prLlmCfg 1 cmpV |
| 1048 | prWrt prLlmOk |
| 1049 | prNum port |
| 1050 | prWrt prLlmBytes |
| 1051 | prNum rbytes |
| 1052 | prWrt prLlmCmp |
| 1053 | prNum cmpV |
| 1054 | prWrt prLlmSwp |
| 1055 | prNum swpV |
| 1056 | else |
| 1057 | prWrt prLlmOff |
| 1058 | end |
| 1059 | end |
| 1060 | |
| 1061 | fn main to int |
| 1062 | if and ne argcnt 4 ne argcnt 5 |
| 1063 | prWrt prUse |
| 1064 | ret 90 |
| 1065 | end |
| 1066 | rlen = prReadRef |
| 1067 | if or lt rlen 16 ne rem ulong rlen 16 0 |
| 1068 | ret 1 |
| 1069 | end |
| 1070 | ur = ulong rlen |
| 1071 | n = div ur 16 |
| 1072 | if gt n 2048 |
| 1073 | ret 1 |
| 1074 | end |
| 1075 | prInitCand n ur |
| 1076 | if not prDecodeAll n |
| 1077 | ret 2 |
| 1078 | end |
| 1079 | prMarkTargets n |
| 1080 | prReportArboris n |
| 1081 | prReportLlm |
| 1082 | swaps = prDoSwaps n |
| 1083 | saved = prDoStallCompact n |
| 1084 | repaired = prRepairHazards n |
| 1085 | clen = prBuildCert n ur |
| 1086 | if not prWriteFile 2 0 ur |
| 1087 | ret 3 |
| 1088 | end |
| 1089 | if not prWriteFile 3 1 clen |
| 1090 | ret 4 |
| 1091 | end |
| 1092 | prWrt prMutA |
| 1093 | prNum n |
| 1094 | prWrt prMutB |
| 1095 | prNum swaps |
| 1096 | prWrt prMutC |
| 1097 | prNum saved |
| 1098 | prWrt prMutD |
| 1099 | prNum clen |
| 1100 | prWrt prNl |
| 1101 | ret 0 |
| 1102 | end |