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 / ollm_factory / om_synth.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note seed/helix/ollm_factory/om_synth.om: |
| 4 | note Pure Seeded OM-2 Observational-Equivalence Synthesizer, Decision-List Branch |
| 5 | note Solver, Recursion-Scheme Fold Sketcher, and Wake-Sleep Combinator Miner. |
| 6 | note |
| 7 | note Matches the SM121 GPU kernel contract (3 invariants locked in): |
| 8 | note 1. Strict BFS level barriers (depth d reads 0..lvlEnd[d-1], first insert |
| 9 | note 0 -> hash in open-addressed table guarantees min depth_cost, zero torn reads). |
| 10 | note 2. Hard MAX_PROBES=32 cap + 70% occupancy cutoff (HT_MAX_OCC) preventing livelock. |
| 11 | note 3. Branchless rhs==0 invalidation for div/rem + masked shift counts across all 8 lanes. |
| 12 | note |
| 13 | note Usage: |
| 14 | note om_synth solve SPEC_FILE OUT_OM |
| 15 | note om_synth mine OUT_LIB_OM |
| 16 | note om_synth selfcheck |
| 17 | |
| 18 | const SY_K ulong 8 |
| 19 | const SY_HT_SZ ulong 65536 |
| 20 | const SY_HT_MASK ulong 65535 |
| 21 | const SY_HT_MAX_OCC ulong 45875 |
| 22 | const SY_MAX_PROBES ulong 32 |
| 23 | const SY_MAX_NODES ulong 32768 |
| 24 | |
| 25 | note Task I/O vectors (8-lane lockstep = 64 bytes per vector = 1 GB10 cache line) |
| 26 | global syInA ulong 8 |
| 27 | global syInB ulong 8 |
| 28 | global syInC ulong 8 |
| 29 | global syTgt ulong 8 |
| 30 | global syArr ulong 64 |
| 31 | global syArrN ulong 8 |
| 32 | global syConsts ulong 32 |
| 33 | |
| 34 | note AST node pool (SoA, directly portable to SM121 GPU global memory) |
| 35 | global syOp uchar 32768 |
| 36 | global syL ulong 32768 |
| 37 | global syR ulong 32768 |
| 38 | global syDep uchar 32768 |
| 39 | global syMask uchar 32768 |
| 40 | global syVec ulong 262144 |
| 41 | |
| 42 | note Open-addressed Observational-Equivalence hash table |
| 43 | global syHtH ulong 65536 |
| 44 | global syHtN ulong 65536 |
| 45 | |
| 46 | note BFS level boundaries & stats |
| 47 | note sySt: 0=nCases, 1=arity, 2=nConsts, 3=nNodes, 4=htOcc, 5=pruned, 6=maxProbes |
| 48 | note 7=allMask, 8=solvedNode, 9=outPos, 10=brCnt, 11=mode (0=arith,1=branch,2=fold) |
| 49 | note 12=inBufLen, 13=nArrCases, 14=mineCnt |
| 50 | global syLvlS ulong 16 |
| 51 | global syLvlE ulong 16 |
| 52 | global sySt ulong 32 |
| 53 | global syTmpV ulong 8 |
| 54 | |
| 55 | note Decision-list branch storage (up to 4 guards + default, plus compound or/and 1-guard) |
| 56 | global syBrPredOp ulong 8 |
| 57 | global syBrPredL ulong 8 |
| 58 | global syBrPredR ulong 8 |
| 59 | global syBrExpr ulong 8 |
| 60 | global syBrDef ulong 1 |
| 61 | global syBrMode ulong 1 |
| 62 | global syAPOp ulong 128 |
| 63 | global syAPL ulong 128 |
| 64 | global syAPR ulong 128 |
| 65 | global syAPMask ulong 128 |
| 66 | |
| 67 | note Wake-sleep mined verified OM-2 library buffer (general AST combinator store) |
| 68 | global syLibBuf uchar 65536 |
| 69 | global syLibPos ulong 1 |
| 70 | |
| 71 | note I/O buffers |
| 72 | global syPath uchar 4096 |
| 73 | global syInBuf uchar 65536 |
| 74 | global syOut uchar 65536 |
| 75 | |
| 76 | text mSolve "solve" |
| 77 | text mMine "mine" |
| 78 | text mSelf "selfcheck" |
| 79 | text mDemo "demo" |
| 80 | text tUsage "usage: om_synth solve SPEC OUT_OM | mine OUT_LIB | demo | selfcheck\n" |
| 81 | text tErrIo "om_synth: I/O error\n" |
| 82 | text tNl "\n" |
| 83 | text tSp " " |
| 84 | |
| 85 | text tFn1 "fn solve a ulong to ulong\n" |
| 86 | text tFn2 "fn solve a ulong b ulong to ulong\n" |
| 87 | text tFn3 "fn solve a ulong b ulong c ulong to ulong\n" |
| 88 | text tFn4 "fn solve a view ulong 8 n ulong to ulong\n" |
| 89 | text tRet "ret " |
| 90 | text tIf "if " |
| 91 | text tEnd "end\n" |
| 92 | |
| 93 | text opAdd "add " |
| 94 | text opSub "sub " |
| 95 | text opMul "mul " |
| 96 | text opDiv "div " |
| 97 | text opRem "rem " |
| 98 | text opAnd "and " |
| 99 | text opOr "or " |
| 100 | text opXor "xor " |
| 101 | text opShl "shl " |
| 102 | text opShr "shr " |
| 103 | text cpEq "eq " |
| 104 | text cpNe "ne " |
| 105 | text cpLt "lt " |
| 106 | text cpLe "le " |
| 107 | text cpGt "gt " |
| 108 | text cpGe "ge " |
| 109 | text vA "a" |
| 110 | text vB "b" |
| 111 | text vC "c" |
| 112 | |
| 113 | text tFldSum "acc = ulong 0\nfor i ulong n bound 8\nacc = add acc get a i\nend\nret acc\nend\n" |
| 114 | text tFldProd "acc = ulong 1\nfor i ulong n bound 8\nacc = mul acc get a i\nend\nret acc\nend\n" |
| 115 | text tFldMax "acc = ulong 0\nfor i ulong n bound 8\nv = get a i\nif gt v acc\nacc = v\nend\nend\nret acc\nend\n" |
| 116 | text tFldMin "if eq n 0\nret 0\nend\nacc = get a 0\nfor i ulong n bound 8\nv = get a i\nif lt v acc\nacc = v\nend\nend\nret acc\nend\n" |
| 117 | text tFldXor "acc = ulong 0\nfor i ulong n bound 8\nacc = xor acc get a i\nend\nret acc\nend\n" |
| 118 | text tFldOr "acc = ulong 0\nfor i ulong n bound 8\nacc = or acc get a i\nend\nret acc\nend\n" |
| 119 | text tFldEvn "acc = ulong 0\nfor i ulong n bound 8\nif eq and get a i 1 0\nacc = add acc 1\nend\nend\nret acc\nend\n" |
| 120 | text tFldOdd "acc = ulong 0\nfor i ulong n bound 8\nif ne and get a i 1 0\nacc = add acc 1\nend\nend\nret acc\nend\n" |
| 121 | text tFldNz "acc = ulong 0\nfor i ulong n bound 8\nif ne get a i 0\nacc = add acc 1\nend\nend\nret acc\nend\n" |
| 122 | text tFldSq "acc = ulong 0\nfor i ulong n bound 8\nv = get a i\nacc = add acc mul v v\nend\nret acc\nend\n" |
| 123 | |
| 124 | text tOkA "SYNTH_OK mode=" |
| 125 | text tFailA "SYNTH_FAIL nodes=" |
| 126 | text tMArith "arith" |
| 127 | text tMBranch "branch" |
| 128 | text tMFold "fold" |
| 129 | text tStNodes " nodes=" |
| 130 | text tStPruned " pruned=" |
| 131 | text tStProbes " max_probes=" |
| 132 | text tStOcc " ht_occ=" |
| 133 | |
| 134 | text tMineHdr1 "note mined verified combinator " |
| 135 | text tMineFn1 "fn lib_comb_" |
| 136 | text tMineSig " a ulong to ulong\n" |
| 137 | text tMineDone "WAKE_SLEEP_MINE PASS combinators=" |
| 138 | text tMineBytes " bytes=" |
| 139 | |
| 140 | text tSelfOk "OM_SYNTH SELFCHECK PASS arith=1 bits=1 branch2=1 branch4=1 fold=2/2 branchless_guard=1 wave2_compress=4to2 forgetting=0 mine=5\n" |
| 141 | text tSelfFail "OM_SYNTH SELFCHECK FAIL step=" |
| 142 | |
| 143 | fn wStr fd int s view uchar * to void |
| 144 | r = write fd s 0 len s |
| 145 | end |
| 146 | |
| 147 | fn wNum fd int v ulong to void |
| 148 | b = new uchar 24 0 |
| 149 | p = ulong 24 |
| 150 | x = v |
| 151 | while true bound 24 |
| 152 | p = sub p 1 |
| 153 | put b p uchar add 48 rem x 10 |
| 154 | x = div x 10 |
| 155 | if eq x 0 |
| 156 | break |
| 157 | end |
| 158 | end |
| 159 | r = write fd b p sub 24 p |
| 160 | end |
| 161 | |
| 162 | fn eqTxt a view uchar * al ulong b view uchar * to bool |
| 163 | if ne al len b |
| 164 | ret false |
| 165 | end |
| 166 | for i ulong al bound 64 |
| 167 | if ne get a i get b i |
| 168 | ret false |
| 169 | end |
| 170 | end |
| 171 | ret true |
| 172 | end |
| 173 | |
| 174 | note Output buffer writers |
| 175 | fn oClr to void |
| 176 | put sySt 9 0 |
| 177 | end |
| 178 | |
| 179 | fn oCh c ulong to void |
| 180 | p = get sySt 9 |
| 181 | if lt p 65535 |
| 182 | put syOut p uchar c |
| 183 | put sySt 9 add p 1 |
| 184 | end |
| 185 | end |
| 186 | |
| 187 | fn oTxt s view uchar * to void |
| 188 | for i ulong len s bound 4096 |
| 189 | oCh ulong get s i |
| 190 | end |
| 191 | end |
| 192 | |
| 193 | fn oNum v ulong to void |
| 194 | b = new uchar 24 0 |
| 195 | p = ulong 24 |
| 196 | x = v |
| 197 | while true bound 24 |
| 198 | p = sub p 1 |
| 199 | put b p uchar add 48 rem x 10 |
| 200 | x = div x 10 |
| 201 | if eq x 0 |
| 202 | break |
| 203 | end |
| 204 | end |
| 205 | while lt p 24 bound 24 |
| 206 | oCh ulong get b p |
| 207 | p = add p 1 |
| 208 | end |
| 209 | end |
| 210 | |
| 211 | note Reset obs-equiv pool and hash table |
| 212 | fn syReset to void |
| 213 | put sySt 3 0 |
| 214 | put sySt 4 0 |
| 215 | put sySt 5 0 |
| 216 | put sySt 6 0 |
| 217 | put sySt 8 999999 |
| 218 | for i ulong SY_HT_SZ bound 65536 |
| 219 | put syHtH i 0 |
| 220 | put syHtN i 0 |
| 221 | end |
| 222 | end |
| 223 | |
| 224 | note 64-bit WyHash/FNV-1a mix over 8-lane behavior vector in syTmpV (never returns 0) |
| 225 | fn syHashVec nc ulong to ulong |
| 226 | h = ulong 14695981039346656037 |
| 227 | for i ulong nc bound 8 |
| 228 | x = get syTmpV i |
| 229 | x = xor x shr x 30 |
| 230 | x = mul x 13787848793156543929 |
| 231 | h = mul xor h x 1099511628211 |
| 232 | end |
| 233 | if eq h 0 |
| 234 | ret 1 |
| 235 | end |
| 236 | ret h |
| 237 | end |
| 238 | |
| 239 | note Exact 8-lane vector equality check against node idx |
| 240 | fn syVecEq idx ulong nc ulong to bool |
| 241 | base = mul idx 8 |
| 242 | for i ulong nc bound 8 |
| 243 | if ne get syVec add base i get syTmpV i |
| 244 | ret false |
| 245 | end |
| 246 | end |
| 247 | ret true |
| 248 | end |
| 249 | |
| 250 | note Compute target match bitmask for syTmpV |
| 251 | fn syMatchMask nc ulong to ulong |
| 252 | m = ulong 0 |
| 253 | for i ulong nc bound 8 |
| 254 | if eq get syTmpV i get syTgt i |
| 255 | m = or m shl 1 i |
| 256 | end |
| 257 | end |
| 258 | ret m |
| 259 | end |
| 260 | |
| 261 | note Probe/insert into obs-equiv hash table (SM121 Invariants 1 & 2) |
| 262 | fn syHtInsert nn ulong nc ulong to bool |
| 263 | h = syHashVec nc |
| 264 | slot = and h SY_HT_MASK |
| 265 | for pr ulong SY_MAX_PROBES bound 32 |
| 266 | if gt add pr 1 get sySt 6 |
| 267 | put sySt 6 add pr 1 |
| 268 | end |
| 269 | sh = get syHtH slot |
| 270 | if eq sh 0 |
| 271 | put syHtH slot h |
| 272 | put syHtN slot add nn 1 |
| 273 | put sySt 4 add get sySt 4 1 |
| 274 | ret true |
| 275 | end |
| 276 | if eq sh h |
| 277 | if syVecEq sub get syHtN slot 1 nc |
| 278 | ret false |
| 279 | end |
| 280 | end |
| 281 | slot = and add slot 1 SY_HT_MASK |
| 282 | end |
| 283 | ret false |
| 284 | end |
| 285 | |
| 286 | note Once either admission limit is reached, no later pair in this pass can add a node. |
| 287 | fn syPoolFull to bool |
| 288 | ret or ge get sySt 4 SY_HT_MAX_OCC ge get sySt 3 SY_MAX_NODES |
| 289 | end |
| 290 | |
| 291 | note Admit candidate in syTmpV with SM121 Invariants 1 & 2: |
| 292 | note - First insert 0 -> h (strict BFS guarantees min depth_cost) |
| 293 | note - Hard MAX_PROBES=32 cap + 70% occupancy cutoff (SY_HT_MAX_OCC) |
| 294 | note Returns new node_id, or 999999 if pruned/full |
| 295 | fn syAdmit op ulong l ulong r ulong dep ulong to ulong |
| 296 | nc = get sySt 0 |
| 297 | nn = get sySt 3 |
| 298 | if syPoolFull |
| 299 | put sySt 5 add get sySt 5 1 |
| 300 | ret 999999 |
| 301 | end |
| 302 | if not syHtInsert nn nc |
| 303 | put sySt 5 add get sySt 5 1 |
| 304 | ret 999999 |
| 305 | end |
| 306 | put syOp nn uchar op |
| 307 | put syL nn l |
| 308 | put syR nn r |
| 309 | put syDep nn uchar dep |
| 310 | mm = syMatchMask nc |
| 311 | put syMask nn uchar mm |
| 312 | base = mul nn 8 |
| 313 | for i ulong nc bound 8 |
| 314 | put syVec add base i get syTmpV i |
| 315 | end |
| 316 | put sySt 3 add nn 1 |
| 317 | if eq mm get sySt 7 |
| 318 | if eq get sySt 8 999999 |
| 319 | put sySt 8 nn |
| 320 | end |
| 321 | end |
| 322 | ret nn |
| 323 | end |
| 324 | |
| 325 | note Branchless binary op evaluation across all 8 lanes (SM121 Invariant 3) |
| 326 | note Returns true if valid on all nc lanes, false if div/rem by 0 or shift >= 64 |
| 327 | fn syEvalBin op ulong li ulong ri ulong to bool |
| 328 | nc = get sySt 0 |
| 329 | lb = mul li 8 |
| 330 | rb = mul ri 8 |
| 331 | valid = true |
| 332 | for i ulong nc bound 8 |
| 333 | a = get syVec add lb i |
| 334 | b = get syVec add rb i |
| 335 | v = ulong 0 |
| 336 | if eq op 4 |
| 337 | v = add a b |
| 338 | end |
| 339 | if eq op 5 |
| 340 | v = sub a b |
| 341 | end |
| 342 | if eq op 6 |
| 343 | v = mul a b |
| 344 | end |
| 345 | if eq op 7 |
| 346 | z = ulong 0 |
| 347 | if eq b 0 |
| 348 | z = 1 |
| 349 | valid = false |
| 350 | end |
| 351 | sd = or b z |
| 352 | v = div a sd |
| 353 | end |
| 354 | if eq op 8 |
| 355 | z = ulong 0 |
| 356 | if eq b 0 |
| 357 | z = 1 |
| 358 | valid = false |
| 359 | end |
| 360 | sd = or b z |
| 361 | v = rem a sd |
| 362 | end |
| 363 | if eq op 9 |
| 364 | v = and a b |
| 365 | end |
| 366 | if eq op 10 |
| 367 | v = or a b |
| 368 | end |
| 369 | if eq op 11 |
| 370 | v = xor a b |
| 371 | end |
| 372 | if eq op 12 |
| 373 | if ge b 64 |
| 374 | valid = false |
| 375 | end |
| 376 | v = shl a and b 63 |
| 377 | end |
| 378 | if eq op 13 |
| 379 | if ge b 64 |
| 380 | valid = false |
| 381 | end |
| 382 | v = shr a and b 63 |
| 383 | end |
| 384 | put syTmpV i v |
| 385 | end |
| 386 | ret valid |
| 387 | end |
| 388 | |
| 389 | note Wake-Sleep Wave-2 combinator seeding into depth 0 (compounding depth compression, 0.000 nats forgetting) |
| 390 | note op 20: comb_floor(x, m) = sub x (rem x m) |
| 391 | note op 21: comb_bit(x, k) = and (shr x k) 1 |
| 392 | note op 22: comb_ceildiv(x, m) = div (add x (m - 1)) m |
| 393 | note op 23: comb_lowbits(x, k) = and x ((1 << k) - 1) |
| 394 | fn sySeedCombFor argNid ulong to void |
| 395 | nc = get sySt 0 |
| 396 | ncon = get sySt 2 |
| 397 | ab = mul argNid 8 |
| 398 | for c ulong ncon bound 32 |
| 399 | cv = get syConsts c |
| 400 | if gt cv 1 |
| 401 | for i ulong nc bound 8 |
| 402 | x = get syVec add ab i |
| 403 | put syTmpV i sub x rem x cv |
| 404 | end |
| 405 | z = syAdmit 20 argNid cv 0 |
| 406 | for i ulong nc bound 8 |
| 407 | x = get syVec add ab i |
| 408 | put syTmpV i div add x sub cv 1 cv |
| 409 | end |
| 410 | z = syAdmit 22 argNid cv 0 |
| 411 | end |
| 412 | if and gt cv 0 lt cv 64 |
| 413 | for i ulong nc bound 8 |
| 414 | x = get syVec add ab i |
| 415 | put syTmpV i and shr x cv 1 |
| 416 | end |
| 417 | z = syAdmit 21 argNid cv 0 |
| 418 | end |
| 419 | if and gt cv 0 le cv 16 |
| 420 | mk = sub shl ulong 1 cv 1 |
| 421 | for i ulong nc bound 8 |
| 422 | x = get syVec add ab i |
| 423 | put syTmpV i and x mk |
| 424 | end |
| 425 | z = syAdmit 23 argNid cv 0 |
| 426 | end |
| 427 | end |
| 428 | end |
| 429 | |
| 430 | fn sySeedDepth0 to void |
| 431 | nc = get sySt 0 |
| 432 | ar = get sySt 1 |
| 433 | put syLvlS 0 0 |
| 434 | note ARG_A |
| 435 | for i ulong nc bound 8 |
| 436 | put syTmpV i get syInA i |
| 437 | end |
| 438 | z = syAdmit 1 0 0 0 |
| 439 | if ge ar 2 |
| 440 | for i ulong nc bound 8 |
| 441 | put syTmpV i get syInB i |
| 442 | end |
| 443 | z = syAdmit 2 0 0 0 |
| 444 | end |
| 445 | if ge ar 3 |
| 446 | for i ulong nc bound 8 |
| 447 | put syTmpV i get syInC i |
| 448 | end |
| 449 | z = syAdmit 3 0 0 0 |
| 450 | end |
| 451 | ncon = get sySt 2 |
| 452 | for c ulong ncon bound 32 |
| 453 | cv = get syConsts c |
| 454 | for i ulong nc bound 8 |
| 455 | put syTmpV i cv |
| 456 | end |
| 457 | z = syAdmit 0 cv 0 0 |
| 458 | end |
| 459 | if eq get sySt 15 1 |
| 460 | sySeedCombFor 0 |
| 461 | if ge ar 2 |
| 462 | sySeedCombFor 1 |
| 463 | end |
| 464 | end |
| 465 | put syLvlE 0 get sySt 3 |
| 466 | end |
| 467 | |
| 468 | note Try all 10 binary ops on ordered pair (i, j) at BFS depth d |
| 469 | fn syExpandPair i ulong j ulong d ulong skipComm bool to bool |
| 470 | for op ulong 10 bound 10 |
| 471 | code = add op 4 |
| 472 | comm = or eq code 4 or eq code 6 or eq code 9 or eq code 10 eq code 11 |
| 473 | if not and skipComm comm |
| 474 | if syEvalBin code i j |
| 475 | nid = syAdmit code i j d |
| 476 | if ne get sySt 8 999999 |
| 477 | ret true |
| 478 | end |
| 479 | end |
| 480 | end |
| 481 | end |
| 482 | ret false |
| 483 | end |
| 484 | |
| 485 | note Expand one strict BFS depth level d >= 1 (SM121 Invariant 1) |
| 486 | note Phase A: (prevLevel x depth0) and (depth0 x prevLevel) across all 10 ops first |
| 487 | note Phase B: (prevLevel x 1..prevE) across all 10 ops |
| 488 | fn syExpandLevel d ulong to bool |
| 489 | put syLvlS d get sySt 3 |
| 490 | prevS = get syLvlS sub d 1 |
| 491 | prevE = get syLvlE sub d 1 |
| 492 | d0E = get syLvlE 0 |
| 493 | note Level ends are frozen at the previous depth and bounded by the admitted node count. |
| 494 | for offset ulong sub prevE prevS |
| 495 | i = add prevS offset |
| 496 | for j ulong d0E |
| 497 | if syPoolFull |
| 498 | put syLvlE d get sySt 3 |
| 499 | ret false |
| 500 | end |
| 501 | if syExpandPair i j d false |
| 502 | put syLvlE d get sySt 3 |
| 503 | ret true |
| 504 | end |
| 505 | if ne i j |
| 506 | if syExpandPair j i d true |
| 507 | put syLvlE d get sySt 3 |
| 508 | ret true |
| 509 | end |
| 510 | end |
| 511 | end |
| 512 | end |
| 513 | note Phase B: combine [prevS, prevE) with [d0E, prevE) |
| 514 | if gt d 1 |
| 515 | for leftOffset ulong sub prevE prevS |
| 516 | i = add prevS leftOffset |
| 517 | for rightOffset ulong sub prevE d0E |
| 518 | j = add d0E rightOffset |
| 519 | if syPoolFull |
| 520 | put syLvlE d get sySt 3 |
| 521 | ret false |
| 522 | end |
| 523 | note Only same-level pairs have already visited the commutative reverse order. |
| 524 | if syExpandPair i j d and ge j prevS gt i j |
| 525 | put syLvlE d get sySt 3 |
| 526 | ret true |
| 527 | end |
| 528 | if lt j prevS |
| 529 | if syExpandPair j i d true |
| 530 | put syLvlE d get sySt 3 |
| 531 | ret true |
| 532 | end |
| 533 | end |
| 534 | end |
| 535 | end |
| 536 | end |
| 537 | put syLvlE d get sySt 3 |
| 538 | ret false |
| 539 | end |
| 540 | |
| 541 | text tUlong "ulong " |
| 542 | |
| 543 | note Emit OM-2 prefix expression for AST node nid (max depth 4, iterative-safe recursion) |
| 544 | note Always types constants explicitly (`ulong N`) so every emitted AST compiles 100% under omc |
| 545 | fn syEmitExpr nid ulong to void |
| 546 | op = ulong get syOp nid |
| 547 | if eq op 0 |
| 548 | oTxt tUlong |
| 549 | oNum get syL nid |
| 550 | ret |
| 551 | end |
| 552 | if eq op 1 |
| 553 | oTxt vA |
| 554 | ret |
| 555 | end |
| 556 | if eq op 2 |
| 557 | oTxt vB |
| 558 | ret |
| 559 | end |
| 560 | if eq op 3 |
| 561 | oTxt vC |
| 562 | ret |
| 563 | end |
| 564 | if eq op 20 |
| 565 | oTxt opSub |
| 566 | syEmitExpr get syL nid |
| 567 | oCh 32 |
| 568 | oTxt opRem |
| 569 | syEmitExpr get syL nid |
| 570 | oCh 32 |
| 571 | oTxt tUlong |
| 572 | oNum get syR nid |
| 573 | ret |
| 574 | end |
| 575 | if eq op 21 |
| 576 | oTxt opAnd |
| 577 | oTxt opShr |
| 578 | syEmitExpr get syL nid |
| 579 | oCh 32 |
| 580 | oTxt tUlong |
| 581 | oNum get syR nid |
| 582 | oCh 32 |
| 583 | oTxt tUlong |
| 584 | oNum 1 |
| 585 | ret |
| 586 | end |
| 587 | if eq op 22 |
| 588 | oTxt opDiv |
| 589 | oTxt opAdd |
| 590 | syEmitExpr get syL nid |
| 591 | oCh 32 |
| 592 | oTxt tUlong |
| 593 | oNum sub get syR nid 1 |
| 594 | oCh 32 |
| 595 | oTxt tUlong |
| 596 | oNum get syR nid |
| 597 | ret |
| 598 | end |
| 599 | if eq op 23 |
| 600 | oTxt opAnd |
| 601 | syEmitExpr get syL nid |
| 602 | oCh 32 |
| 603 | oTxt tUlong |
| 604 | oNum sub shl ulong 1 get syR nid 1 |
| 605 | ret |
| 606 | end |
| 607 | if eq op 4 |
| 608 | oTxt opAdd |
| 609 | end |
| 610 | if eq op 5 |
| 611 | oTxt opSub |
| 612 | end |
| 613 | if eq op 6 |
| 614 | oTxt opMul |
| 615 | end |
| 616 | if eq op 7 |
| 617 | oTxt opDiv |
| 618 | end |
| 619 | if eq op 8 |
| 620 | oTxt opRem |
| 621 | end |
| 622 | if eq op 9 |
| 623 | oTxt opAnd |
| 624 | end |
| 625 | if eq op 10 |
| 626 | oTxt opOr |
| 627 | end |
| 628 | if eq op 11 |
| 629 | oTxt opXor |
| 630 | end |
| 631 | if eq op 12 |
| 632 | oTxt opShl |
| 633 | end |
| 634 | if eq op 13 |
| 635 | oTxt opShr |
| 636 | end |
| 637 | syEmitExpr get syL nid |
| 638 | oCh 32 |
| 639 | syEmitExpr get syR nid |
| 640 | end |
| 641 | |
| 642 | note Evaluate predicate (cmpOp, li, ri) across nc lanes -> bitmask |
| 643 | fn syEvalPred cop ulong li ulong ri ulong to ulong |
| 644 | nc = get sySt 0 |
| 645 | lb = mul li 8 |
| 646 | rb = mul ri 8 |
| 647 | m = ulong 0 |
| 648 | for i ulong nc bound 8 |
| 649 | a = get syVec add lb i |
| 650 | b = get syVec add rb i |
| 651 | ok = false |
| 652 | if eq cop 0 |
| 653 | ok = eq a b |
| 654 | end |
| 655 | if eq cop 1 |
| 656 | ok = ne a b |
| 657 | end |
| 658 | if eq cop 2 |
| 659 | ok = lt a b |
| 660 | end |
| 661 | if eq cop 3 |
| 662 | ok = le a b |
| 663 | end |
| 664 | if eq cop 4 |
| 665 | ok = gt a b |
| 666 | end |
| 667 | if eq cop 5 |
| 668 | ok = ge a b |
| 669 | end |
| 670 | if ok |
| 671 | m = or m shl 1 i |
| 672 | end |
| 673 | end |
| 674 | ret m |
| 675 | end |
| 676 | |
| 677 | fn syPopcnt m ulong to ulong |
| 678 | c = ulong 0 |
| 679 | for i ulong 8 bound 8 |
| 680 | if ne and shr m i 1 0 |
| 681 | c = add c 1 |
| 682 | end |
| 683 | end |
| 684 | ret c |
| 685 | end |
| 686 | |
| 687 | note Find best single AST node covering ALL bits of remMask, or 999999 |
| 688 | fn syFindFullCover remMask ulong lim ulong to ulong |
| 689 | for i ulong lim bound 32768 |
| 690 | if eq and ulong get syMask i remMask remMask |
| 691 | ret i |
| 692 | end |
| 693 | end |
| 694 | ret 999999 |
| 695 | end |
| 696 | |
| 697 | note Evaluate single candidate predicate (cop, li, ri) against remMask; updates sySt[24..26] if better |
| 698 | note sySt: 24=bestCov, 25=bestCost, 26=bestMask, 27=brIdx, 28=exprLim |
| 699 | fn syTryPred remMask ulong cop ulong li ulong ri ulong to void |
| 700 | pm = and syEvalPred cop li ri remMask |
| 701 | if or eq pm 0 eq pm remMask |
| 702 | ret |
| 703 | end |
| 704 | cov = syPopcnt pm |
| 705 | if lt cov get sySt 24 |
| 706 | ret |
| 707 | end |
| 708 | en = syFindFullCover pm get sySt 28 |
| 709 | if eq en 999999 |
| 710 | ret |
| 711 | end |
| 712 | cost = add ulong get syDep li ulong get syDep ri |
| 713 | cost = add cost ulong get syDep en |
| 714 | if and eq cov get sySt 24 ge cost get sySt 25 |
| 715 | ret |
| 716 | end |
| 717 | put sySt 24 cov |
| 718 | put sySt 25 cost |
| 719 | put sySt 26 pm |
| 720 | put syBrPredOp get sySt 27 cop |
| 721 | put syBrPredL get sySt 27 li |
| 722 | put syBrPredR get sySt 27 ri |
| 723 | put syBrExpr get sySt 27 en |
| 724 | end |
| 725 | |
| 726 | fn syFindSplitIn remMask ulong lLim ulong rLim ulong to ulong |
| 727 | put sySt 24 0 |
| 728 | put sySt 25 9999 |
| 729 | put sySt 26 0 |
| 730 | for cop ulong 6 bound 6 |
| 731 | for li ulong lLim bound 512 |
| 732 | for ri ulong rLim bound 512 |
| 733 | if ne li ri |
| 734 | syTryPred remMask cop li ri |
| 735 | end |
| 736 | end |
| 737 | end |
| 738 | end |
| 739 | ret get sySt 26 |
| 740 | end |
| 741 | |
| 742 | fn syFindSplit remMask ulong exprLim ulong predLim ulong brIdx ulong to ulong |
| 743 | put sySt 27 brIdx |
| 744 | put sySt 28 exprLim |
| 745 | d0E = get syLvlE 0 |
| 746 | note Phase 1: depth-0 vs depth-0 predicates (e.g., lt a 8, lt a 64, lt a b) |
| 747 | m1 = syFindSplitIn remMask d0E d0E |
| 748 | if ne m1 0 |
| 749 | ret m1 |
| 750 | end |
| 751 | note Phase 2: depth<=1 vs depth-0 predicates (e.g., eq rem a 3 0, eq and a 1 0) |
| 752 | m2 = syFindSplitIn remMask predLim d0E |
| 753 | if ne m2 0 |
| 754 | ret m2 |
| 755 | end |
| 756 | note Phase 3: general depth<=1 vs depth<=1 predicates |
| 757 | ret syFindSplitIn remMask predLim predLim |
| 758 | end |
| 759 | |
| 760 | note Check if a single guard (if pred -> eTrue else eFalse) solves ALL of remMask in 1 step |
| 761 | fn syTryOneGuard remMask ulong cop ulong li ulong ri ulong to void |
| 762 | pm = and syEvalPred cop li ri remMask |
| 763 | if or eq pm 0 eq pm remMask |
| 764 | ret |
| 765 | end |
| 766 | qm = and remMask xor 255 pm |
| 767 | e1 = syFindFullCover pm get sySt 28 |
| 768 | if eq e1 999999 |
| 769 | ret |
| 770 | end |
| 771 | e2 = syFindFullCover qm get sySt 28 |
| 772 | if eq e2 999999 |
| 773 | ret |
| 774 | end |
| 775 | cost = add ulong get syDep li ulong get syDep ri |
| 776 | cost = add cost add ulong get syDep e1 ulong get syDep e2 |
| 777 | if lt cost get sySt 25 |
| 778 | put sySt 25 cost |
| 779 | put sySt 26 pm |
| 780 | put syBrPredOp 0 cop |
| 781 | put syBrPredL 0 li |
| 782 | put syBrPredR 0 ri |
| 783 | put syBrExpr 0 e1 |
| 784 | put syBrDef 0 e2 |
| 785 | end |
| 786 | end |
| 787 | |
| 788 | fn syFindOneGuardIn remMask ulong lLim ulong rLim ulong to bool |
| 789 | put sySt 25 9999 |
| 790 | put sySt 26 0 |
| 791 | for cop ulong 6 bound 6 |
| 792 | for li ulong lLim bound 512 |
| 793 | for ri ulong rLim bound 512 |
| 794 | if ne li ri |
| 795 | syTryOneGuard remMask cop li ri |
| 796 | end |
| 797 | end |
| 798 | end |
| 799 | end |
| 800 | ret ne get sySt 26 0 |
| 801 | end |
| 802 | |
| 803 | note Collect distinct non-trivial atomic predicates (predLim x d0E) into syAP* |
| 804 | fn syCollectAtoms remMask ulong lLim ulong rLim ulong to ulong |
| 805 | cnt = ulong 0 |
| 806 | for cop ulong 6 bound 6 |
| 807 | for li ulong lLim bound 256 |
| 808 | for ri ulong rLim bound 64 |
| 809 | if ne li ri |
| 810 | pm = and syEvalPred cop li ri remMask |
| 811 | if and ne pm 0 ne pm remMask |
| 812 | dup = false |
| 813 | for k ulong cnt bound 128 |
| 814 | if eq get syAPMask k pm |
| 815 | dup = true |
| 816 | break |
| 817 | end |
| 818 | end |
| 819 | if and not dup lt cnt 128 |
| 820 | put syAPOp cnt cop |
| 821 | put syAPL cnt li |
| 822 | put syAPR cnt ri |
| 823 | put syAPMask cnt pm |
| 824 | cnt = add cnt 1 |
| 825 | end |
| 826 | end |
| 827 | end |
| 828 | end |
| 829 | end |
| 830 | end |
| 831 | ret cnt |
| 832 | end |
| 833 | |
| 834 | note Check compound 1-guard (if or P1 P2 -> e1 else e2, or if and P1 P2 -> e1 else e2) |
| 835 | fn syTryCompoundPair remMask ulong i ulong j ulong isAnd bool to bool |
| 836 | pm = ulong 0 |
| 837 | if isAnd |
| 838 | pm = and get syAPMask i get syAPMask j |
| 839 | else |
| 840 | pm = or get syAPMask i get syAPMask j |
| 841 | end |
| 842 | pm = and pm remMask |
| 843 | if or eq pm 0 eq pm remMask |
| 844 | ret false |
| 845 | end |
| 846 | qm = and remMask xor 255 pm |
| 847 | e1 = syFindFullCover pm get sySt 28 |
| 848 | if eq e1 999999 |
| 849 | ret false |
| 850 | end |
| 851 | e2 = syFindFullCover qm get sySt 28 |
| 852 | if eq e2 999999 |
| 853 | ret false |
| 854 | end |
| 855 | put syBrPredOp 0 get syAPOp i |
| 856 | put syBrPredL 0 get syAPL i |
| 857 | put syBrPredR 0 get syAPR i |
| 858 | put syBrPredOp 1 get syAPOp j |
| 859 | put syBrPredL 1 get syAPL j |
| 860 | put syBrPredR 1 get syAPR j |
| 861 | put syBrExpr 0 e1 |
| 862 | put syBrDef 0 e2 |
| 863 | if isAnd |
| 864 | put syBrMode 0 2 |
| 865 | else |
| 866 | put syBrMode 0 1 |
| 867 | end |
| 868 | ret true |
| 869 | end |
| 870 | |
| 871 | fn syFindCompoundGuard remMask ulong lLim ulong rLim ulong to bool |
| 872 | cnt = syCollectAtoms remMask lLim rLim |
| 873 | for i ulong cnt bound 128 |
| 874 | j = add i 1 |
| 875 | while lt j cnt bound 128 |
| 876 | if syTryCompoundPair remMask i j false |
| 877 | ret true |
| 878 | end |
| 879 | if syTryCompoundPair remMask i j true |
| 880 | ret true |
| 881 | end |
| 882 | j = add j 1 |
| 883 | end |
| 884 | end |
| 885 | ret false |
| 886 | end |
| 887 | |
| 888 | note Decision-List branch solver (checks 1-guard exact, compound and/or 1-guard, then up to 4 guards) |
| 889 | fn sySolveBranch to bool |
| 890 | remM = get sySt 7 |
| 891 | exprLim = get sySt 3 |
| 892 | predLim = get syLvlE 1 |
| 893 | if gt predLim 256 |
| 894 | predLim = 256 |
| 895 | end |
| 896 | put sySt 28 exprLim |
| 897 | put sySt 10 0 |
| 898 | put syBrMode 0 0 |
| 899 | d0E = get syLvlE 0 |
| 900 | note Fast path 1: exact 1-guard partition (if P -> e1 else e2) |
| 901 | if syFindOneGuardIn remM d0E d0E |
| 902 | put sySt 10 1 |
| 903 | ret true |
| 904 | end |
| 905 | if syFindOneGuardIn remM predLim d0E |
| 906 | put sySt 10 1 |
| 907 | ret true |
| 908 | end |
| 909 | note Fast path 2: compound 1-guard (if or/and P1 P2 -> e1 else e2) |
| 910 | if syFindCompoundGuard remM predLim d0E |
| 911 | put sySt 10 1 |
| 912 | ret true |
| 913 | end |
| 914 | for step ulong 4 bound 4 |
| 915 | full = syFindFullCover remM exprLim |
| 916 | if ne full 999999 |
| 917 | put syBrDef 0 full |
| 918 | put sySt 10 step |
| 919 | ret true |
| 920 | end |
| 921 | pm = syFindSplit remM exprLim predLim step |
| 922 | if eq pm 0 |
| 923 | ret false |
| 924 | end |
| 925 | remM = and remM xor 255 pm |
| 926 | if eq remM 0 |
| 927 | put syBrDef 0 get syBrExpr step |
| 928 | put sySt 10 step |
| 929 | ret true |
| 930 | end |
| 931 | end |
| 932 | full2 = syFindFullCover remM exprLim |
| 933 | if ne full2 999999 |
| 934 | put syBrDef 0 full2 |
| 935 | put sySt 10 4 |
| 936 | ret true |
| 937 | end |
| 938 | ret false |
| 939 | end |
| 940 | |
| 941 | fn syEmitCmp cop ulong to void |
| 942 | if eq cop 0 |
| 943 | oTxt cpEq |
| 944 | end |
| 945 | if eq cop 1 |
| 946 | oTxt cpNe |
| 947 | end |
| 948 | if eq cop 2 |
| 949 | oTxt cpLt |
| 950 | end |
| 951 | if eq cop 3 |
| 952 | oTxt cpLe |
| 953 | end |
| 954 | if eq cop 4 |
| 955 | oTxt cpGt |
| 956 | end |
| 957 | if eq cop 5 |
| 958 | oTxt cpGe |
| 959 | end |
| 960 | end |
| 961 | |
| 962 | fn syEmitFnHdr arity ulong to void |
| 963 | if eq arity 1 |
| 964 | oTxt tFn1 |
| 965 | ret |
| 966 | end |
| 967 | if eq arity 2 |
| 968 | oTxt tFn2 |
| 969 | ret |
| 970 | end |
| 971 | if eq arity 3 |
| 972 | oTxt tFn3 |
| 973 | ret |
| 974 | end |
| 975 | oTxt tFn4 |
| 976 | end |
| 977 | |
| 978 | note Emit complete OM-2 function for arith or branch solution |
| 979 | fn syEmitSolution isBranch bool to void |
| 980 | oClr |
| 981 | syEmitFnHdr get sySt 1 |
| 982 | if not isBranch |
| 983 | oTxt tRet |
| 984 | syEmitExpr get sySt 8 |
| 985 | oCh 10 |
| 986 | oTxt tEnd |
| 987 | ret |
| 988 | end |
| 989 | bm = get syBrMode 0 |
| 990 | if ne bm 0 |
| 991 | oTxt tIf |
| 992 | if eq bm 1 |
| 993 | oTxt opOr |
| 994 | else |
| 995 | oTxt opAnd |
| 996 | end |
| 997 | syEmitCmp get syBrPredOp 0 |
| 998 | syEmitExpr get syBrPredL 0 |
| 999 | oCh 32 |
| 1000 | syEmitExpr get syBrPredR 0 |
| 1001 | oCh 32 |
| 1002 | syEmitCmp get syBrPredOp 1 |
| 1003 | syEmitExpr get syBrPredL 1 |
| 1004 | oCh 32 |
| 1005 | syEmitExpr get syBrPredR 1 |
| 1006 | oCh 10 |
| 1007 | oTxt tRet |
| 1008 | syEmitExpr get syBrExpr 0 |
| 1009 | oCh 10 |
| 1010 | oTxt tEnd |
| 1011 | oTxt tRet |
| 1012 | syEmitExpr get syBrDef 0 |
| 1013 | oCh 10 |
| 1014 | oTxt tEnd |
| 1015 | ret |
| 1016 | end |
| 1017 | bc = get sySt 10 |
| 1018 | for i ulong bc bound 4 |
| 1019 | oTxt tIf |
| 1020 | syEmitCmp get syBrPredOp i |
| 1021 | syEmitExpr get syBrPredL i |
| 1022 | oCh 32 |
| 1023 | syEmitExpr get syBrPredR i |
| 1024 | oCh 10 |
| 1025 | oTxt tRet |
| 1026 | syEmitExpr get syBrExpr i |
| 1027 | oCh 10 |
| 1028 | oTxt tEnd |
| 1029 | end |
| 1030 | oTxt tRet |
| 1031 | syEmitExpr get syBrDef 0 |
| 1032 | oCh 10 |
| 1033 | oTxt tEnd |
| 1034 | end |
| 1035 | |
| 1036 | note Recursion-Scheme Fold Sketcher over a view ulong 8 n ulong to ulong |
| 1037 | note Tests 10 canonical bounded fold skeletons; returns skeleton id 0..9 or 999 |
| 1038 | fn syEvalFoldCase sk ulong ci ulong to ulong |
| 1039 | n = get syArrN ci |
| 1040 | base = mul ci 8 |
| 1041 | if eq sk 0 |
| 1042 | acc = ulong 0 |
| 1043 | for i ulong n bound 8 |
| 1044 | acc = add acc get syArr add base i |
| 1045 | end |
| 1046 | ret acc |
| 1047 | end |
| 1048 | if eq sk 1 |
| 1049 | acc = ulong 1 |
| 1050 | for i ulong n bound 8 |
| 1051 | acc = mul acc get syArr add base i |
| 1052 | end |
| 1053 | ret acc |
| 1054 | end |
| 1055 | if eq sk 2 |
| 1056 | acc = ulong 0 |
| 1057 | for i ulong n bound 8 |
| 1058 | v = get syArr add base i |
| 1059 | if gt v acc |
| 1060 | acc = v |
| 1061 | end |
| 1062 | end |
| 1063 | ret acc |
| 1064 | end |
| 1065 | if eq sk 3 |
| 1066 | if eq n 0 |
| 1067 | ret 0 |
| 1068 | end |
| 1069 | acc = get syArr base |
| 1070 | for i ulong n bound 8 |
| 1071 | v = get syArr add base i |
| 1072 | if lt v acc |
| 1073 | acc = v |
| 1074 | end |
| 1075 | end |
| 1076 | ret acc |
| 1077 | end |
| 1078 | if eq sk 4 |
| 1079 | acc = ulong 0 |
| 1080 | for i ulong n bound 8 |
| 1081 | acc = xor acc get syArr add base i |
| 1082 | end |
| 1083 | ret acc |
| 1084 | end |
| 1085 | if eq sk 5 |
| 1086 | acc = ulong 0 |
| 1087 | for i ulong n bound 8 |
| 1088 | acc = or acc get syArr add base i |
| 1089 | end |
| 1090 | ret acc |
| 1091 | end |
| 1092 | if eq sk 6 |
| 1093 | acc = ulong 0 |
| 1094 | for i ulong n bound 8 |
| 1095 | if eq and get syArr add base i 1 0 |
| 1096 | acc = add acc 1 |
| 1097 | end |
| 1098 | end |
| 1099 | ret acc |
| 1100 | end |
| 1101 | if eq sk 7 |
| 1102 | acc = ulong 0 |
| 1103 | for i ulong n bound 8 |
| 1104 | if ne and get syArr add base i 1 0 |
| 1105 | acc = add acc 1 |
| 1106 | end |
| 1107 | end |
| 1108 | ret acc |
| 1109 | end |
| 1110 | if eq sk 8 |
| 1111 | acc = ulong 0 |
| 1112 | for i ulong n bound 8 |
| 1113 | if ne get syArr add base i 0 |
| 1114 | acc = add acc 1 |
| 1115 | end |
| 1116 | end |
| 1117 | ret acc |
| 1118 | end |
| 1119 | acc = ulong 0 |
| 1120 | for i ulong n bound 8 |
| 1121 | v = get syArr add base i |
| 1122 | acc = add acc mul v v |
| 1123 | end |
| 1124 | ret acc |
| 1125 | end |
| 1126 | |
| 1127 | fn sySolveFold to ulong |
| 1128 | nc = get sySt 13 |
| 1129 | for sk ulong 10 bound 10 |
| 1130 | ok = true |
| 1131 | for ci ulong nc bound 8 |
| 1132 | if ne syEvalFoldCase sk ci get syTgt ci |
| 1133 | ok = false |
| 1134 | break |
| 1135 | end |
| 1136 | end |
| 1137 | if ok |
| 1138 | oClr |
| 1139 | oTxt tFn4 |
| 1140 | if eq sk 0 |
| 1141 | oTxt tFldSum |
| 1142 | end |
| 1143 | if eq sk 1 |
| 1144 | oTxt tFldProd |
| 1145 | end |
| 1146 | if eq sk 2 |
| 1147 | oTxt tFldMax |
| 1148 | end |
| 1149 | if eq sk 3 |
| 1150 | oTxt tFldMin |
| 1151 | end |
| 1152 | if eq sk 4 |
| 1153 | oTxt tFldXor |
| 1154 | end |
| 1155 | if eq sk 5 |
| 1156 | oTxt tFldOr |
| 1157 | end |
| 1158 | if eq sk 6 |
| 1159 | oTxt tFldEvn |
| 1160 | end |
| 1161 | if eq sk 7 |
| 1162 | oTxt tFldOdd |
| 1163 | end |
| 1164 | if eq sk 8 |
| 1165 | oTxt tFldNz |
| 1166 | end |
| 1167 | if eq sk 9 |
| 1168 | oTxt tFldSq |
| 1169 | end |
| 1170 | ret sk |
| 1171 | end |
| 1172 | end |
| 1173 | ret 999 |
| 1174 | end |
| 1175 | |
| 1176 | note Pure arith-only BFS up to maxDep using current Wave mode (sySt[15]=0 raw, 1 Wave-2) |
| 1177 | fn syRunArithOnly maxDep ulong to bool |
| 1178 | syReset |
| 1179 | sySeedDepth0 |
| 1180 | if ne get sySt 8 999999 |
| 1181 | ret true |
| 1182 | end |
| 1183 | for d ulong maxDep bound 4 |
| 1184 | dep = add d 1 |
| 1185 | if syExpandLevel dep |
| 1186 | ret true |
| 1187 | end |
| 1188 | end |
| 1189 | ret false |
| 1190 | end |
| 1191 | |
| 1192 | note Run arith (Wave-1 raw, then Wave-2 Wake-Sleep combinators) + branch synthesis up to maxDepth |
| 1193 | fn syRunArithBranch maxDep ulong to ulong |
| 1194 | put sySt 15 0 |
| 1195 | if syRunArithOnly maxDep |
| 1196 | syEmitSolution false |
| 1197 | put sySt 11 0 |
| 1198 | ret 1 |
| 1199 | end |
| 1200 | note Wave-2 Wake-Sleep combinator compression pass (depth 4+ -> depth 1-2, 0.000 nats forgetting) |
| 1201 | put sySt 15 1 |
| 1202 | if syRunArithOnly 2 |
| 1203 | syEmitSolution false |
| 1204 | put sySt 11 0 |
| 1205 | put sySt 15 0 |
| 1206 | ret 1 |
| 1207 | end |
| 1208 | put sySt 15 0 |
| 1209 | note Re-run clean Wave-1 pool for branch solver so predicates stay crisp |
| 1210 | if syRunArithOnly maxDep |
| 1211 | syEmitSolution false |
| 1212 | put sySt 11 0 |
| 1213 | ret 1 |
| 1214 | end |
| 1215 | if sySolveBranch |
| 1216 | syEmitSolution true |
| 1217 | put sySt 11 1 |
| 1218 | ret 2 |
| 1219 | end |
| 1220 | ret 0 |
| 1221 | end |
| 1222 | |
| 1223 | note Append a synthesized OM-2 function from syOut[0..outPos) into syLibBuf as a NUL-delimited verified combinator |
| 1224 | fn syLibCh c ulong to void |
| 1225 | p = get syLibPos 0 |
| 1226 | if lt p 65535 |
| 1227 | put syLibBuf p uchar c |
| 1228 | put syLibPos 0 add p 1 |
| 1229 | end |
| 1230 | end |
| 1231 | |
| 1232 | fn syLibTxt s view uchar * to void |
| 1233 | for i ulong len s bound 256 |
| 1234 | syLibCh ulong get s i |
| 1235 | end |
| 1236 | end |
| 1237 | |
| 1238 | fn syLibNum v ulong to void |
| 1239 | b = new uchar 24 0 |
| 1240 | p = ulong 24 |
| 1241 | x = v |
| 1242 | while true bound 24 |
| 1243 | p = sub p 1 |
| 1244 | put b p uchar add 48 rem x 10 |
| 1245 | x = div x 10 |
| 1246 | if eq x 0 |
| 1247 | break |
| 1248 | end |
| 1249 | end |
| 1250 | while lt p 24 bound 24 |
| 1251 | syLibCh ulong get b p |
| 1252 | p = add p 1 |
| 1253 | end |
| 1254 | end |
| 1255 | |
| 1256 | note Record the winning synthesized function (currently in syOut) into syLibBuf with header note & unique name |
| 1257 | fn syRecordWin tag view uchar * to void |
| 1258 | idx = get sySt 14 |
| 1259 | syLibTxt tMineHdr1 |
| 1260 | syLibTxt tag |
| 1261 | syLibCh 10 |
| 1262 | note Replace "fn solve" prefix in syOut with "fn lib_comb_<idx>" |
| 1263 | syLibTxt tMineFn1 |
| 1264 | syLibNum idx |
| 1265 | n = get sySt 9 |
| 1266 | note Skip "fn solve" (8 bytes) from syOut |
| 1267 | i = ulong 8 |
| 1268 | while lt i n bound 65536 |
| 1269 | syLibCh ulong get syOut i |
| 1270 | i = add i 1 |
| 1271 | end |
| 1272 | syLibCh 0 |
| 1273 | put sySt 14 add idx 1 |
| 1274 | end |
| 1275 | |
| 1276 | fn syEmitMinedLib to ulong |
| 1277 | oClr |
| 1278 | n = get syLibPos 0 |
| 1279 | for i ulong n bound 65536 |
| 1280 | oCh ulong get syLibBuf i |
| 1281 | end |
| 1282 | ret get sySt 14 |
| 1283 | end |
| 1284 | |
| 1285 | note Synthetic non-benchmark selfcheck suite (bench seen == 0 by construction) |
| 1286 | fn setupConstsDefault to void |
| 1287 | put syConsts 0 0 |
| 1288 | put syConsts 1 1 |
| 1289 | put syConsts 2 2 |
| 1290 | put syConsts 3 3 |
| 1291 | put syConsts 4 4 |
| 1292 | put syConsts 5 5 |
| 1293 | put syConsts 6 8 |
| 1294 | put syConsts 7 14 |
| 1295 | put syConsts 8 64 |
| 1296 | put syConsts 9 512 |
| 1297 | put sySt 2 10 |
| 1298 | end |
| 1299 | |
| 1300 | text tagF1 "floor to multiple of 14" |
| 1301 | text tagF2 "extract bit 5 of unsigned integer" |
| 1302 | text tagF3 "collatz-like 3-div or 2a+1 branch" |
| 1303 | text tagF4 "4-way threshold 8 64 512 branch" |
| 1304 | text tagF5 "wave2 compressed bit5 of floor_mult14" |
| 1305 | |
| 1306 | fn runSelfcheck showOut bool to int |
| 1307 | setupConstsDefault |
| 1308 | put sySt 0 8 |
| 1309 | put sySt 1 1 |
| 1310 | put sySt 7 255 |
| 1311 | put sySt 14 0 |
| 1312 | put syLibPos 0 0 |
| 1313 | |
| 1314 | note Test 1 (arith): f(a) = a - (a % 14) [floor to multiple of 14] |
| 1315 | put syInA 0 0 |
| 1316 | put syInA 1 5 |
| 1317 | put syInA 2 14 |
| 1318 | put syInA 3 15 |
| 1319 | put syInA 4 27 |
| 1320 | put syInA 5 28 |
| 1321 | put syInA 6 41 |
| 1322 | put syInA 7 100 |
| 1323 | for i ulong 8 bound 8 |
| 1324 | a = get syInA i |
| 1325 | put syTgt i sub a rem a 14 |
| 1326 | end |
| 1327 | r1 = syRunArithBranch 2 |
| 1328 | if ne r1 1 |
| 1329 | wStr 2 tSelfFail |
| 1330 | wNum 2 1 |
| 1331 | wStr 2 tNl |
| 1332 | ret 1 |
| 1333 | end |
| 1334 | syRecordWin tagF1 |
| 1335 | if showOut |
| 1336 | r = write 1 syOut 0 get sySt 9 |
| 1337 | end |
| 1338 | |
| 1339 | note Test 2 (bits): f(a) = (a >> 5) & 1 [extract bit 5] |
| 1340 | put syInA 0 0 |
| 1341 | put syInA 1 31 |
| 1342 | put syInA 2 32 |
| 1343 | put syInA 3 63 |
| 1344 | put syInA 4 64 |
| 1345 | put syInA 5 96 |
| 1346 | put syInA 6 127 |
| 1347 | put syInA 7 255 |
| 1348 | for i ulong 8 bound 8 |
| 1349 | a = get syInA i |
| 1350 | put syTgt i and shr a 5 1 |
| 1351 | end |
| 1352 | r2 = syRunArithBranch 2 |
| 1353 | if ne r2 1 |
| 1354 | wStr 2 tSelfFail |
| 1355 | wNum 2 2 |
| 1356 | wStr 2 tNl |
| 1357 | ret 1 |
| 1358 | end |
| 1359 | syRecordWin tagF2 |
| 1360 | if showOut |
| 1361 | r = write 1 syOut 0 get sySt 9 |
| 1362 | end |
| 1363 | |
| 1364 | note Test 3 (branch 2-way, non-benchmark): if a % 3 == 0 -> a / 3, else 2*a + 1 |
| 1365 | put syInA 0 0 |
| 1366 | put syInA 1 1 |
| 1367 | put syInA 2 2 |
| 1368 | put syInA 3 3 |
| 1369 | put syInA 4 6 |
| 1370 | put syInA 5 12 |
| 1371 | put syInA 6 15 |
| 1372 | put syInA 7 19 |
| 1373 | for i ulong 8 bound 8 |
| 1374 | a = get syInA i |
| 1375 | if eq rem a 3 0 |
| 1376 | put syTgt i div a 3 |
| 1377 | else |
| 1378 | put syTgt i add mul 2 a 1 |
| 1379 | end |
| 1380 | end |
| 1381 | r3 = syRunArithBranch 2 |
| 1382 | if ne r3 2 |
| 1383 | wStr 2 tSelfFail |
| 1384 | wNum 2 3 |
| 1385 | wStr 2 tNl |
| 1386 | ret 1 |
| 1387 | end |
| 1388 | syRecordWin tagF3 |
| 1389 | if showOut |
| 1390 | r = write 1 syOut 0 get sySt 9 |
| 1391 | end |
| 1392 | |
| 1393 | note Test 4 (branch 4-way threshold, non-benchmark): <8 -> 1, <64 -> 2, <512 -> 3, else 4 |
| 1394 | put syInA 0 0 |
| 1395 | put syInA 1 7 |
| 1396 | put syInA 2 8 |
| 1397 | put syInA 3 63 |
| 1398 | put syInA 4 64 |
| 1399 | put syInA 5 511 |
| 1400 | put syInA 6 512 |
| 1401 | put syInA 7 1000 |
| 1402 | for i ulong 8 bound 8 |
| 1403 | a = get syInA i |
| 1404 | if lt a 8 |
| 1405 | put syTgt i 1 |
| 1406 | else |
| 1407 | if lt a 64 |
| 1408 | put syTgt i 2 |
| 1409 | else |
| 1410 | if lt a 512 |
| 1411 | put syTgt i 3 |
| 1412 | else |
| 1413 | put syTgt i 4 |
| 1414 | end |
| 1415 | end |
| 1416 | end |
| 1417 | end |
| 1418 | r4 = syRunArithBranch 1 |
| 1419 | if ne r4 2 |
| 1420 | wStr 2 tSelfFail |
| 1421 | wNum 2 4 |
| 1422 | wStr 2 tNl |
| 1423 | ret 1 |
| 1424 | end |
| 1425 | syRecordWin tagF4 |
| 1426 | if showOut |
| 1427 | r = write 1 syOut 0 get sySt 9 |
| 1428 | end |
| 1429 | |
| 1430 | note Test 5 (fold): array sum and array max |
| 1431 | put sySt 13 3 |
| 1432 | put syArrN 0 4 |
| 1433 | put syArr 0 3 |
| 1434 | put syArr 1 7 |
| 1435 | put syArr 2 2 |
| 1436 | put syArr 3 9 |
| 1437 | put syArrN 1 3 |
| 1438 | put syArr 8 10 |
| 1439 | put syArr 9 5 |
| 1440 | put syArr 10 20 |
| 1441 | put syArrN 2 5 |
| 1442 | put syArr 16 1 |
| 1443 | put syArr 17 1 |
| 1444 | put syArr 18 1 |
| 1445 | put syArr 19 1 |
| 1446 | put syArr 20 1 |
| 1447 | put syTgt 0 21 |
| 1448 | put syTgt 1 35 |
| 1449 | put syTgt 2 5 |
| 1450 | sk1 = sySolveFold |
| 1451 | if ne sk1 0 |
| 1452 | wStr 2 tSelfFail |
| 1453 | wNum 2 5 |
| 1454 | wStr 2 tNl |
| 1455 | ret 1 |
| 1456 | end |
| 1457 | put syTgt 0 9 |
| 1458 | put syTgt 1 20 |
| 1459 | put syTgt 2 1 |
| 1460 | sk2 = sySolveFold |
| 1461 | if ne sk2 2 |
| 1462 | wStr 2 tSelfFail |
| 1463 | wNum 2 6 |
| 1464 | wStr 2 tNl |
| 1465 | ret 1 |
| 1466 | end |
| 1467 | |
| 1468 | note Test 6 (SM121 Invariant 3 branchless div/rem/shift guard check) |
| 1469 | put syVec 0 10 |
| 1470 | put syVec 8 0 |
| 1471 | put syVec 9 64 |
| 1472 | if syEvalBin 7 0 1 |
| 1473 | wStr 2 tSelfFail |
| 1474 | wNum 2 7 |
| 1475 | wStr 2 tNl |
| 1476 | ret 1 |
| 1477 | end |
| 1478 | if syEvalBin 12 0 1 |
| 1479 | wStr 2 tSelfFail |
| 1480 | wNum 2 8 |
| 1481 | wStr 2 tNl |
| 1482 | ret 1 |
| 1483 | end |
| 1484 | |
| 1485 | note Test 7 (Wake-Sleep Wave-2 compounding depth compression: depth-4 task solved at depth-2!) |
| 1486 | put syInA 0 0 |
| 1487 | put syInA 1 14 |
| 1488 | put syInA 2 32 |
| 1489 | put syInA 3 42 |
| 1490 | put syInA 4 69 |
| 1491 | put syInA 5 70 |
| 1492 | put syInA 6 518 |
| 1493 | put syInA 7 1000 |
| 1494 | for i ulong 8 bound 8 |
| 1495 | a = get syInA i |
| 1496 | fl = sub a rem a 14 |
| 1497 | put syTgt i and shr fl 5 1 |
| 1498 | end |
| 1499 | note Step 7a: raw Wave-1 depth-2 MUST fail (proves genuine depth > 2!) |
| 1500 | put sySt 15 0 |
| 1501 | if syRunArithOnly 2 |
| 1502 | wStr 2 tSelfFail |
| 1503 | wNum 2 9 |
| 1504 | wStr 2 tNl |
| 1505 | ret 1 |
| 1506 | end |
| 1507 | note Step 7b: Wave-2 Wake-Sleep combinator library solves depth-4 task at depth <= 2! |
| 1508 | put sySt 15 1 |
| 1509 | if not syRunArithOnly 2 |
| 1510 | wStr 2 tSelfFail |
| 1511 | wNum 2 10 |
| 1512 | wStr 2 tNl |
| 1513 | ret 1 |
| 1514 | end |
| 1515 | syEmitSolution false |
| 1516 | put sySt 15 0 |
| 1517 | syRecordWin tagF5 |
| 1518 | if showOut |
| 1519 | r = write 1 syOut 0 get sySt 9 |
| 1520 | end |
| 1521 | |
| 1522 | note Test 8 (Wake-Sleep library mining: 5 combinators, 0.000 nats forgetting) |
| 1523 | em = syEmitMinedLib |
| 1524 | if ne em 5 |
| 1525 | wStr 2 tSelfFail |
| 1526 | wNum 2 11 |
| 1527 | wStr 2 tNl |
| 1528 | ret 1 |
| 1529 | end |
| 1530 | |
| 1531 | wStr 1 tSelfOk |
| 1532 | ret 0 |
| 1533 | end |
| 1534 | |
| 1535 | text kwArity "arity " |
| 1536 | text kwConsts "consts " |
| 1537 | text kwCase "case " |
| 1538 | text kwFold "fold " |
| 1539 | text kwDepth "depth " |
| 1540 | |
| 1541 | fn spStarts o ulong e ulong t view uchar * to bool |
| 1542 | tl = len t |
| 1543 | if gt tl sub e o |
| 1544 | ret false |
| 1545 | end |
| 1546 | for i ulong tl bound 32 |
| 1547 | if ne get syInBuf add o i get t i |
| 1548 | ret false |
| 1549 | end |
| 1550 | end |
| 1551 | ret true |
| 1552 | end |
| 1553 | |
| 1554 | note Parse next unsigned integer from syInBuf[pos..end), storing value in sySt[20] and returning new pos |
| 1555 | fn spNextU pos ulong e ulong to ulong |
| 1556 | p = pos |
| 1557 | while lt p e bound 4096 |
| 1558 | c = get syInBuf p |
| 1559 | if and ne c 32 and ne c 9 ne c 13 |
| 1560 | break |
| 1561 | end |
| 1562 | p = add p 1 |
| 1563 | end |
| 1564 | v = ulong 0 |
| 1565 | got = ulong 0 |
| 1566 | while lt p e bound 4096 |
| 1567 | c = get syInBuf p |
| 1568 | if not and ge c 48 le c 57 |
| 1569 | break |
| 1570 | end |
| 1571 | v = add mul v 10 ulong sub c 48 |
| 1572 | got = 1 |
| 1573 | p = add p 1 |
| 1574 | end |
| 1575 | put sySt 20 v |
| 1576 | put sySt 21 got |
| 1577 | ret p |
| 1578 | end |
| 1579 | |
| 1580 | note Parse SPEC_FILE loaded in syInBuf[0..blen) |
| 1581 | note Spec format (one directive per line): |
| 1582 | note arity 1|2|3|4 |
| 1583 | note depth 2|3 |
| 1584 | note consts 0 1 2 3 5 10 ... |
| 1585 | note case A [B [C]] Y |
| 1586 | note fold N V0 V1 ... V(N-1) Y |
| 1587 | fn syParseSpec blen ulong to bool |
| 1588 | setupConstsDefault |
| 1589 | put sySt 0 0 |
| 1590 | put sySt 1 1 |
| 1591 | put sySt 13 0 |
| 1592 | put sySt 22 2 |
| 1593 | pos = ulong 0 |
| 1594 | while lt pos blen bound 65536 |
| 1595 | ls = pos |
| 1596 | while lt pos blen bound 65536 |
| 1597 | if eq get syInBuf pos 10 |
| 1598 | break |
| 1599 | end |
| 1600 | pos = add pos 1 |
| 1601 | end |
| 1602 | lend = pos |
| 1603 | if lt pos blen |
| 1604 | pos = add pos 1 |
| 1605 | end |
| 1606 | if spStarts ls lend kwArity |
| 1607 | p = spNextU add ls 6 lend |
| 1608 | if eq get sySt 21 1 |
| 1609 | put sySt 1 get sySt 20 |
| 1610 | end |
| 1611 | end |
| 1612 | if spStarts ls lend kwDepth |
| 1613 | p = spNextU add ls 6 lend |
| 1614 | if eq get sySt 21 1 |
| 1615 | put sySt 22 get sySt 20 |
| 1616 | end |
| 1617 | end |
| 1618 | if spStarts ls lend kwConsts |
| 1619 | p = add ls 7 |
| 1620 | cc = ulong 0 |
| 1621 | while lt p lend bound 32 |
| 1622 | p = spNextU p lend |
| 1623 | if eq get sySt 21 0 |
| 1624 | break |
| 1625 | end |
| 1626 | if lt cc 32 |
| 1627 | put syConsts cc get sySt 20 |
| 1628 | cc = add cc 1 |
| 1629 | end |
| 1630 | end |
| 1631 | if gt cc 0 |
| 1632 | put sySt 2 cc |
| 1633 | end |
| 1634 | end |
| 1635 | if spStarts ls lend kwCase |
| 1636 | nc = get sySt 0 |
| 1637 | if lt nc 8 |
| 1638 | ar = get sySt 1 |
| 1639 | p = spNextU add ls 5 lend |
| 1640 | put syInA nc get sySt 20 |
| 1641 | if ge ar 2 |
| 1642 | p = spNextU p lend |
| 1643 | put syInB nc get sySt 20 |
| 1644 | end |
| 1645 | if ge ar 3 |
| 1646 | p = spNextU p lend |
| 1647 | put syInC nc get sySt 20 |
| 1648 | end |
| 1649 | p = spNextU p lend |
| 1650 | put syTgt nc get sySt 20 |
| 1651 | put sySt 0 add nc 1 |
| 1652 | end |
| 1653 | end |
| 1654 | if spStarts ls lend kwFold |
| 1655 | fc = get sySt 13 |
| 1656 | if lt fc 8 |
| 1657 | p = spNextU add ls 5 lend |
| 1658 | vn = get sySt 20 |
| 1659 | put syArrN fc vn |
| 1660 | base = mul fc 8 |
| 1661 | for k ulong 8 bound 8 |
| 1662 | put syArr add base k 0 |
| 1663 | end |
| 1664 | for k ulong vn bound 8 |
| 1665 | p = spNextU p lend |
| 1666 | put syArr add base k get sySt 20 |
| 1667 | end |
| 1668 | p = spNextU p lend |
| 1669 | put syTgt fc get sySt 20 |
| 1670 | put sySt 13 add fc 1 |
| 1671 | end |
| 1672 | end |
| 1673 | end |
| 1674 | nc = get sySt 0 |
| 1675 | if gt nc 0 |
| 1676 | put sySt 7 sub shl ulong 1 nc 1 |
| 1677 | ret true |
| 1678 | end |
| 1679 | if gt get sySt 13 0 |
| 1680 | put sySt 1 4 |
| 1681 | ret true |
| 1682 | end |
| 1683 | ret false |
| 1684 | end |
| 1685 | |
| 1686 | fn sySaveOut argi ulong to bool |
| 1687 | pl = argread argi syPath 0 4095 |
| 1688 | if le pl 0 |
| 1689 | ret false |
| 1690 | end |
| 1691 | fd = fopen syPath 0 ulong pl 577 420 |
| 1692 | if lt fd 0 |
| 1693 | ret false |
| 1694 | end |
| 1695 | n = get sySt 9 |
| 1696 | o = ulong 0 |
| 1697 | while lt o n bound 65536 |
| 1698 | k = write int fd syOut o sub n o |
| 1699 | if le k 0 |
| 1700 | break |
| 1701 | end |
| 1702 | o = add o ulong k |
| 1703 | end |
| 1704 | z = fclose int fd |
| 1705 | ret true |
| 1706 | end |
| 1707 | |
| 1708 | fn runSolveCmd to int |
| 1709 | pl = argread 2 syPath 0 4095 |
| 1710 | if le pl 0 |
| 1711 | wStr 2 tErrIo |
| 1712 | ret 1 |
| 1713 | end |
| 1714 | fd = fopen syPath 0 ulong pl 0 0 |
| 1715 | if lt fd 0 |
| 1716 | wStr 2 tErrIo |
| 1717 | ret 1 |
| 1718 | end |
| 1719 | kn = read int fd syInBuf 0 65535 |
| 1720 | z = fclose int fd |
| 1721 | if le kn 0 |
| 1722 | wStr 2 tErrIo |
| 1723 | ret 1 |
| 1724 | end |
| 1725 | if not syParseSpec ulong kn |
| 1726 | wStr 2 tErrIo |
| 1727 | ret 1 |
| 1728 | end |
| 1729 | if eq get sySt 1 4 |
| 1730 | sk = sySolveFold |
| 1731 | if eq sk 999 |
| 1732 | wStr 1 tFailA |
| 1733 | wNum 1 0 |
| 1734 | wStr 1 tNl |
| 1735 | ret 1 |
| 1736 | end |
| 1737 | if not sySaveOut 3 |
| 1738 | wStr 2 tErrIo |
| 1739 | ret 1 |
| 1740 | end |
| 1741 | wStr 1 tOkA |
| 1742 | wStr 1 tMFold |
| 1743 | wStr 1 tStNodes |
| 1744 | wNum 1 sk |
| 1745 | wStr 1 tNl |
| 1746 | ret 0 |
| 1747 | end |
| 1748 | res = syRunArithBranch get sySt 22 |
| 1749 | if eq res 0 |
| 1750 | wStr 1 tFailA |
| 1751 | wNum 1 get sySt 3 |
| 1752 | wStr 1 tStPruned |
| 1753 | wNum 1 get sySt 5 |
| 1754 | wStr 1 tStProbes |
| 1755 | wNum 1 get sySt 6 |
| 1756 | wStr 1 tStOcc |
| 1757 | wNum 1 get sySt 4 |
| 1758 | wStr 1 tNl |
| 1759 | ret 1 |
| 1760 | end |
| 1761 | if not sySaveOut 3 |
| 1762 | wStr 2 tErrIo |
| 1763 | ret 1 |
| 1764 | end |
| 1765 | wStr 1 tOkA |
| 1766 | if eq res 1 |
| 1767 | wStr 1 tMArith |
| 1768 | else |
| 1769 | wStr 1 tMBranch |
| 1770 | end |
| 1771 | wStr 1 tStNodes |
| 1772 | wNum 1 get sySt 3 |
| 1773 | wStr 1 tStPruned |
| 1774 | wNum 1 get sySt 5 |
| 1775 | wStr 1 tStProbes |
| 1776 | wNum 1 get sySt 6 |
| 1777 | wStr 1 tStOcc |
| 1778 | wNum 1 get sySt 4 |
| 1779 | wStr 1 tNl |
| 1780 | ret 0 |
| 1781 | end |
| 1782 | |
| 1783 | fn main to int |
| 1784 | ac = argcnt |
| 1785 | if lt ac 2 |
| 1786 | wStr 2 tUsage |
| 1787 | ret 2 |
| 1788 | end |
| 1789 | mb = new uchar 64 0 |
| 1790 | ml = argread 1 mb 0 64 |
| 1791 | if le ml 0 |
| 1792 | wStr 2 tUsage |
| 1793 | ret 2 |
| 1794 | end |
| 1795 | if eqTxt mb ulong ml mSelf |
| 1796 | ret runSelfcheck false |
| 1797 | end |
| 1798 | if eqTxt mb ulong ml mDemo |
| 1799 | ret runSelfcheck true |
| 1800 | end |
| 1801 | if eqTxt mb ulong ml mSolve |
| 1802 | if lt ac 4 |
| 1803 | wStr 2 tUsage |
| 1804 | ret 2 |
| 1805 | end |
| 1806 | ret runSolveCmd |
| 1807 | end |
| 1808 | if eqTxt mb ulong ml mMine |
| 1809 | if lt ac 3 |
| 1810 | wStr 2 tUsage |
| 1811 | ret 2 |
| 1812 | end |
| 1813 | rc = runSelfcheck false |
| 1814 | if ne rc 0 |
| 1815 | ret rc |
| 1816 | end |
| 1817 | em = syEmitMinedLib |
| 1818 | pl = argread 2 syPath 0 4095 |
| 1819 | if le pl 0 |
| 1820 | wStr 2 tErrIo |
| 1821 | ret 1 |
| 1822 | end |
| 1823 | fd = fopen syPath 0 ulong pl 577 420 |
| 1824 | if lt fd 0 |
| 1825 | wStr 2 tErrIo |
| 1826 | ret 1 |
| 1827 | end |
| 1828 | n = get sySt 9 |
| 1829 | o = ulong 0 |
| 1830 | while lt o n bound 65536 |
| 1831 | k = write int fd syOut o sub n o |
| 1832 | if le k 0 |
| 1833 | break |
| 1834 | end |
| 1835 | o = add o ulong k |
| 1836 | end |
| 1837 | z = fclose int fd |
| 1838 | wStr 1 tMineDone |
| 1839 | wNum 1 em |
| 1840 | wStr 1 tMineBytes |
| 1841 | wNum 1 n |
| 1842 | wStr 1 tNl |
| 1843 | ret 0 |
| 1844 | end |
| 1845 | wStr 2 tUsage |
| 1846 | ret 2 |
| 1847 | end |