Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/amd/gfx942/exec/main.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / amd / gfx942 / exec / main.om` 950 lines ยท 16238 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Usage: exec RAW_TEXT MEMORY GRID_X GRID_Y. MEMORY is a seekable flat byte file, modified in place. 3 note Kernarg is byte zero. Decimal grid extents are work-items; local size is (64,1,1). 4 note Dispatch ceil(GRID_X/64) by GRID_Y wave64 groups; s[0:1]=0, s2=group x, s3=group y, v0=lane. 5 note Source: LLVM llvmorg-18.1.3 llvm/lib/Target/AMDGPU/{SM,SOP,VOP1,VOP2,VOP3,VOPC,FLAT}Instructions.td, 6 note the format and opcode definitions cited in PROVENANCE.md section 8; no NVIDIA facts. 7 note Raw .text is decoded, not vadd.isa or an assembly listing. The gate extracts it using ELF headers. 8 note Subset only: SDWA only CVT_F32_FP8 BYTE0; VOP3 only unsigned MUL_LO/HI with VGPR src0. 9 note Inline integer sources 0..64 and -1..-16, SGPR, VCC/EXEC halves, VGPR, and literal supported. 10 note Waits complete immediately: loads/stores are synchronous, not a latency or race model. 11 note Fixed target profile: mi300x-vf-rocm722-d16-zero, not a universal gfx942 memory-mode claim. 12 note Raw card evidence: AMD-MI300X-CODEX-20261113T0315Z/amdserve-d16probe.txt 13 note SHA256 `af7365ee4f2f0da6db6e995cda83c4ac4a6ee6da3df3446936621ca96c4ac0c7`. 14 note Refusals: 64 usage/path; 65 malformed code/branch/truncated word; 66 unsupported encoding; 15 note 67 memory range; 74 I/O. Compiler loop fuel trap 104 is a defined sandbox refusal. 16 note No code/memory buffer cap: both are seekable files. Register sizes are ISA boundaries. 17 note Path scratch is Linux PATH_MAX. Loops use the assigned compiler's maximum bound 999999. 18 note The wave step, code-scan and grid dispatch loops (Y, then workgroups) run an inner loop that leaves cleanly after 999998 passes inside an outer loop bound 999999 (about 10^12 steps), so a kernel's run length is not capped by the compiler bound. 19 note st: code fd/bytes, memory fd/bytes, PC/next, word/extension/literal, class/op/src0/src1/dst, EXEC/VCC/SCC, incoming VCC. 20 global st ulong 18 21 global sr ulong 102 22 global vr ulong 16384 23 global io uchar 4 24 global perm ulong 64 25 fn fail c int to void 26 exit c 27 end 28 fn fld w ulong s ulong n ulong to ulong 29 ret and shr w s sub shl ulong 1 n 1 30 end 31 fn rdword fd int p ulong lim ulong to ulong 32 if lt lim 4 33 fail 65 34 end 35 if gt p sub lim 4 36 fail 65 37 end 38 r = fseek fd long p 0 39 if ne r long p 40 fail 74 41 end 42 i = ulong 0 43 while lt i 4 bound 999999 44 r = read fd io i sub 4 i 45 if le r 0 46 fail 74 47 end 48 i = add i ulong r 49 end 50 v = ulong 0 51 for j ulong 4 52 v = or v shl ulong get io j mul j 8 53 end 54 ret v 55 end 56 fn memaddr p ulong to void 57 if lt get st 3 4 58 fail 67 59 end 60 if gt p sub get st 3 4 61 fail 67 62 end 63 end 64 fn mread p ulong to ulong 65 memaddr p 66 ret rdword int get st 2 p get st 3 67 end 68 fn mbyte p ulong to ulong 69 if ge p get st 3 70 fail 67 71 end 72 r = pread int get st 2 io 0 1 long p 73 if ne r 1 74 fail 74 75 end 76 ret ulong get io 0 77 end 78 fn mhalf p ulong to ulong 79 if lt get st 3 2 80 fail 67 81 end 82 if gt p sub get st 3 2 83 fail 67 84 end 85 r = pread int get st 2 io 0 2 long p 86 if ne r 2 87 fail 74 88 end 89 ret or ulong get io 0 shl ulong get io 1 8 90 end 91 fn mwrite p ulong v ulong to void 92 memaddr p 93 for j ulong 4 94 put io j uchar and shr v mul j 8 255 95 end 96 r = fseek int get st 2 long p 0 97 if ne r long p 98 fail 74 99 end 100 i = ulong 0 101 while lt i 4 bound 999999 102 r = write int get st 2 io i sub 4 i 103 if le r 0 104 fail 74 105 end 106 i = add i ulong r 107 end 108 end 109 fn fetch to ulong 110 v = rdword int get st 0 get st 5 get st 1 111 put st 5 add get st 5 4 112 ret v 113 end 114 fn srcok s ulong vector bool to void 115 if le s 101 116 ret 117 end 118 if or or eq s 106 eq s 107 or eq s 126 eq s 127 119 ret 120 end 121 if and ge s 128 le s 208 122 ret 123 end 124 if and ge s 240 le s 248 125 ret 126 end 127 if eq s 255 128 ret 129 end 130 if and vector and ge s 256 le s 511 131 ret 132 end 133 fail 66 134 end 135 fn scalar s ulong to ulong 136 if le s 101 137 ret get sr s 138 end 139 if eq s 106 140 ret and get st 15 0xffffffff 141 end 142 if eq s 107 143 ret shr get st 15 32 144 end 145 if eq s 126 146 ret and get st 14 0xffffffff 147 end 148 if eq s 127 149 ret shr get st 14 32 150 end 151 if and ge s 128 le s 192 152 ret sub s 128 153 end 154 if and ge s 193 le s 208 155 ret sub 0x100000000 sub s 192 156 end 157 if eq s 248 158 ret 0x3e22f983 159 end 160 if and ge s 240 le s 247 161 ret or shl add 126 div sub s 240 2 23 shl and s 1 31 162 end 163 if eq s 255 164 ret get st 8 165 end 166 fail 66 167 ret 0 168 end 169 fn vg r ulong lane ulong to ulong 170 ret get vr add mul r 64 lane 171 end 172 fn vs r ulong lane ulong v ulong to void 173 put vr add mul r 64 lane and v 0xffffffff 174 end 175 fn source s ulong lane ulong to ulong 176 if eq s 106 177 ret and get st 17 0xffffffff 178 end 179 if eq s 107 180 ret shr get st 17 32 181 end 182 if ge s 256 183 ret vg sub s 256 lane 184 end 185 ret scalar s 186 end 187 fn lit to void 188 if eq get st 11 255 189 put st 8 fetch 190 end 191 end 192 fn decsm w ulong to void 193 if ne fld w 13 5 16 194 fail 66 195 end 196 op = fld w 18 8 197 if gt op 2 198 fail 66 199 end 200 sd = fld w 6 7 201 sb = mul fld w 0 6 2 202 if or gt add sd shl ulong 1 op 102 gt sb 100 203 fail 66 204 end 205 if ne and sd sub shl ulong 1 op 1 0 206 fail 66 207 end 208 x = fetch 209 note The manual disagrees on the IMM=1 offset: PDF p67 calls it a 21-bit unsigned byte offset, the S_LOAD notes on p146 a 21-bit signed one, and p68 leaves a negative offset undefined. With bit 20 set the address depends on which reading the chip follows, so it is refused (66) rather than guessed; the kernels use offsets below 64. 210 if ne shr x 20 0 211 fail 66 212 end 213 put st 9 1 214 put st 10 op 215 put st 11 sb 216 put st 12 and x 0xfffffffc 217 put st 13 sd 218 end 219 fn decsop w ulong to void 220 if eq shr w 23 0x17f 221 op = fld w 16 7 222 im = and w 65535 223 if or eq op 0 eq op 1 224 if and eq op 1 ne im 0 225 fail 66 226 end 227 else 228 if and ne op 8 and ne op 4 ne op 5 229 if ne op 12 230 fail 66 231 end 232 if and ne im 0xc07f ne im 0x0f70 233 fail 66 234 end 235 end 236 end 237 put st 9 4 238 put st 10 op 239 put st 11 im 240 ret 241 end 242 if eq shr w 23 0x17d 243 op = fld w 8 8 244 if and ne op 1 and ne op 32 ne op 0 245 fail 66 246 end 247 ss = and w 255 248 sd = fld w 16 7 249 if and eq op 1 or ne sd 126 or gt ss 100 ne and ss 1 0 250 fail 66 251 end 252 if and ne op 1 or gt sd 101 and eq op 32 or gt sd 100 ne and sd 1 0 253 fail 66 254 end 255 if eq op 32 256 if ne ss 106 257 if or gt ss 100 ne and ss 1 0 258 fail 66 259 end 260 end 261 else 262 if ne op 1 263 srcok ss false 264 if eq ss 255 265 put st 8 fetch 266 end 267 end 268 end 269 put st 9 3 270 put st 10 op 271 put st 11 ss 272 put st 13 sd 273 ret 274 end 275 if eq shr w 30 2 276 op = fld w 23 7 277 ok = or or eq op 28 eq op 29 or eq op 0 eq op 1 278 ok = or ok or or eq op 4 eq op 36 eq op 44 279 ok = or ok eq op 30 280 if not ok 281 fail 66 282 end 283 sd = fld w 16 7 284 if gt sd 101 285 fail 66 286 end 287 s0 = and w 255 288 s1 = fld w 8 8 289 srcok s0 false 290 srcok s1 false 291 if eq op 29 292 if or gt sd 100 ne and sd 1 0 293 fail 66 294 end 295 if or gt s0 100 ne and s0 1 0 296 fail 66 297 end 298 end 299 put st 9 2 300 put st 10 op 301 put st 11 s0 302 put st 12 s1 303 put st 13 sd 304 if or eq s0 255 eq s1 255 305 put st 8 fetch 306 end 307 ret 308 end 309 fail 66 310 end 311 fn decglob w ulong to void 312 if ne fld w 13 5 4 313 fail 66 314 end 315 if ne fld w 25 1 0 316 fail 66 317 end 318 op = fld w 18 7 319 if and ne op 21 and ne op 23 and ne op 37 and ne op 16 and ne op 20 ne op 28 320 fail 66 321 end 322 x = fetch 323 if ne fld x 16 8 127 324 fail 66 325 end 326 va = and x 255 327 if or ge va 255 ne and va 1 0 328 fail 66 329 end 330 if ne op 28 331 if ne fld x 8 8 0 332 fail 66 333 end 334 else 335 if ne shr x 24 0 336 fail 66 337 end 338 end 339 if or and eq op 21 gt shr x 24 254 and eq op 23 gt shr x 24 252 340 fail 66 341 end 342 put st 9 7 343 put st 10 op 344 put st 11 va 345 put st 12 fld x 8 8 346 put st 13 shr x 24 347 put st 7 and w 8191 348 end 349 fn decv3 w ulong to void 350 op = fld w 16 10 351 if and ne op 645 ne op 646 352 fail 66 353 end 354 if ne and w 0xff00 0 355 fail 66 356 end 357 x = fetch 358 a = and x 511 359 b = fld x 9 9 360 if or lt a 256 ne shr x 18 0 361 fail 66 362 end 363 if and gt b 101 lt b 256 364 fail 66 365 end 366 put st 9 10 367 put st 10 op 368 put st 11 a 369 put st 12 b 370 put st 13 and w 255 371 end 372 fn decfp8 w ulong to void 373 if ne and w 511 249 374 fail 66 375 end 376 x = fetch 377 note Accept exactly LLVM18's BYTE0 SDWA word: DST_SEL=DWORD, other modifiers zero. 378 if ne and x 0xffffff00 0x600 379 fail 66 380 end 381 put st 9 9 382 put st 11 add 256 and x 255 383 put st 13 fld w 17 8 384 end 385 fn decvec w ulong to void 386 if and eq shr w 25 63 eq fld w 9 8 84 387 decfp8 w 388 ret 389 end 390 ss = and w 511 391 srcok ss true 392 put st 11 ss 393 put st 12 fld w 9 8 394 put st 13 fld w 17 8 395 if eq shr w 25 63 396 op = fld w 9 8 397 if eq op 2 398 note V_READFIRSTLANE_B32: VGPR source, ordinary SGPR destination only. 399 if or lt ss 256 gt get st 13 101 400 fail 66 401 end 402 put st 9 12 403 ret 404 end 405 if and ne op 1 and ne op 32 and ne op 33 and ne op 34 ne op 36 406 fail 66 407 end 408 put st 9 8 409 put st 10 op 410 else 411 if eq shr w 25 62 412 if ne fld w 17 8 204 413 fail 66 414 end 415 put st 9 6 416 else 417 op = shr w 25 418 ok = or or eq op 1 eq op 16 or eq op 18 eq op 19 419 ok = or ok or or eq op 25 eq op 28 eq op 52 420 ok = or ok or eq op 5 eq op 59 421 ok = or ok eq op 21 422 ok = or ok or eq op 2 eq op 11 423 note ADDC consumes VCC on the constant bus; another SGPR or literal is outside the valid subset. 424 if and eq op 28 or lt ss 128 eq ss 255 425 fail 66 426 end 427 if not ok 428 fail 66 429 end 430 put st 9 5 431 put st 10 op 432 end 433 end 434 lit 435 end 436 fn decperm w ulong to void 437 note DS_BPERMUTE_B32 only, VGPR not accumulator, GDS=0, unused DATA1=0. 438 if ne shr w 16 0xd87e 439 fail 66 440 end 441 x = fetch 442 if ne fld x 16 8 0 443 fail 66 444 end 445 put st 9 11 446 put st 7 and w 65535 447 put st 11 and x 255 448 put st 12 fld x 8 8 449 put st 13 shr x 24 450 end 451 fn decode pc ulong to void 452 put st 4 pc 453 put st 5 pc 454 put st 8 0 455 w = fetch 456 put st 6 w 457 if eq shr w 26 54 458 decperm w 459 ret 460 end 461 if eq shr w 26 48 462 decsm w 463 ret 464 end 465 if eq shr w 26 55 466 decglob w 467 ret 468 end 469 if eq shr w 26 52 470 decv3 w 471 ret 472 end 473 if eq shr w 31 0 474 decvec w 475 ret 476 end 477 decsop w 478 end 479 fn branch to ulong 480 im = get st 11 481 pc = get st 5 482 if ge im 32768 483 back = mul sub 65536 im 4 484 if gt back pc 485 fail 65 486 end 487 pc = sub pc back 488 else 489 pc = add pc mul im 4 490 end 491 if ge pc get st 1 492 fail 65 493 end 494 ret pc 495 end 496 fn boundary targetpc ulong to void 497 pc = ulong 0 498 while lt pc targetpc bound 999999 499 c = ulong 0 500 while and lt pc targetpc lt c 999998 bound 999999 501 decode pc 502 pc = get st 5 503 c = add c 1 504 end 505 end 506 if ne pc targetpc 507 fail 65 508 end 509 end 510 fn validate to void 511 pc = ulong 0 512 while lt pc get st 1 bound 999999 513 c = ulong 0 514 while and lt pc get st 1 lt c 999998 bound 999999 515 decode pc 516 nx = get st 5 517 op = get st 10 518 if and eq get st 9 4 or eq op 8 or eq op 4 eq op 5 519 t = branch 520 boundary t 521 end 522 pc = nx 523 c = add c 1 524 end 525 end 526 if ne pc get st 1 527 fail 65 528 end 529 end 530 fn smexec to void 531 sb = get st 11 532 p = or and get sr sb 0xfffffffc shl get sr add sb 1 32 533 if gt p sub ulong `18446744073709551615` get st 12 534 fail 67 535 end 536 p = add p get st 12 537 sd = get st 13 538 n = shl ulong 1 get st 10 539 for i ulong n 540 put sr add sd i mread add p mul i 4 541 end 542 end 543 fn sop2run to void 544 a = scalar get st 11 545 b = scalar get st 12 546 d = get st 13 547 op = get st 10 548 r = ulong 0 549 if eq op 29 550 a = or a shl get sr add get st 11 1 32 551 r = shl a and b 63 552 put sr add d 1 shr r 32 553 put st 16 fmbool ne r 0 554 end 555 if eq op 28 556 r = and shl a and b 31 0xffffffff 557 put st 16 fmbool ne r 0 558 end 559 if eq op 30 560 r = shr a and b 31 561 put st 16 fmbool ne r 0 562 end 563 if or eq op 0 eq op 4 564 r = add a b 565 if eq op 4 566 r = add r get st 16 567 end 568 put st 16 fmbool gt r 0xffffffff 569 end 570 if eq op 1 571 r = sub a b 572 put st 16 fmbool lt a b 573 end 574 if eq op 36 575 r = mul a b 576 end 577 if eq op 44 578 r = shr mul a b 32 579 end 580 put sr d and r 0xffffffff 581 end 582 fn sexec to void 583 cl = get st 9 584 if eq cl 1 585 smexec 586 ret 587 end 588 if eq cl 2 589 sop2run 590 ret 591 end 592 if eq cl 3 593 if eq get st 10 1 594 ss = get st 11 595 put st 14 or get sr ss shl get sr add ss 1 32 596 ret 597 end 598 if eq get st 10 0 599 put sr get st 13 scalar get st 11 600 ret 601 end 602 ss = get st 11 603 v = get st 15 604 if ne ss 106 605 v = or get sr ss shl get sr add ss 1 32 606 end 607 ex = get st 14 608 put sr get st 13 and ex 0xffffffff 609 put sr add get st 13 1 shr ex 32 610 put st 14 and ex v 611 put st 16 fmbool ne get st 14 0 612 ret 613 end 614 if eq cl 4 615 op = get st 10 616 cc = get st 16 617 if eq op 8 618 if eq get st 14 0 619 put st 5 branch 620 end 621 end 622 if or and eq op 4 eq cc 0 and eq op 5 ne cc 0 623 put st 5 branch 624 end 625 ret 626 end 627 fail 66 628 end 629 fn carry lane ulong yes bool to void 630 mask = shl ulong 1 lane 631 v = and get st 15 xor mask ulong `18446744073709551615` 632 if yes 633 v = or v mask 634 end 635 put st 15 v 636 end 637 fn fp8bits a ulong to ulong 638 v = and a 255 639 if eq v 128 640 ret 0x7fc00000 641 end 642 m = and v 127 643 if eq m 0 644 ret 0 645 end 646 e = shr m 3 647 f = and m 7 648 if eq e 0 649 e = 120 650 while lt f 8 bound 3 651 f = shl f 1 652 e = sub e 1 653 end 654 else 655 e = add e 119 656 end 657 ret or shl and v 128 24 or shl e 23 shl and f 7 20 658 end 659 fn vecalu lane ulong to void 660 a = source get st 11 lane 661 b = vg get st 12 lane 662 op = get st 10 663 r = ulong 0 664 if eq op 1 665 r = fpadd a b 666 end 667 if eq op 2 668 r = fpadd a xor b 0x80000000 669 end 670 if eq op 11 671 r = fpmax a b 672 end 673 if eq op 59 674 r = fpfma a b vg get st 13 lane 675 end 676 if eq op 5 677 r = fpfma a b and xor a b 0x80000000 678 end 679 if eq op 16 680 r = shr b and a 31 681 end 682 if eq op 18 683 r = shl b and a 31 684 end 685 if eq op 19 686 r = and a b 687 end 688 if eq op 21 689 r = xor a b 690 end 691 if or or eq op 25 eq op 28 eq op 52 692 r = add a b 693 if eq op 28 694 r = add r and shr get st 17 lane 1 695 end 696 if ne op 52 697 carry lane gt r 0xffffffff 698 end 699 end 700 vs get st 13 lane r 701 end 702 fn wide p ulong lane ulong to void 703 n = sub get st 10 19 704 if lt get st 3 mul n 4 705 fail 67 706 end 707 if gt p sub get st 3 mul n 4 708 fail 67 709 end 710 for i ulong n 711 vs add get st 13 i lane mread add p mul i 4 712 end 713 end 714 fn globalop lane ulong to void 715 va = get st 11 716 p = or vg va lane shl vg add va 1 lane 32 717 im = get st 7 718 if ge im 4096 719 im = sub 8192 im 720 if lt p im 721 fail 67 722 end 723 p = sub p im 724 else 725 if gt p sub ulong `18446744073709551615` im 726 fail 67 727 end 728 p = add p im 729 end 730 if or eq get st 10 21 eq get st 10 23 731 wide p lane 732 ret 733 end 734 if eq get st 10 16 735 vs get st 13 lane mbyte p 736 ret 737 end 738 if eq get st 10 37 739 note Target profile zeroes the unused low16; active lanes only, no old destination dependency. 740 h = mhalf p 741 vs get st 13 lane shl h 16 742 ret 743 end 744 if eq get st 10 20 745 vs get st 13 lane mread p 746 else 747 mwrite p vg get st 12 lane 748 end 749 end 750 fn permute to void 751 note PDF p437: all source reads precede every destination write, including aliases. 752 for lane ulong 64 753 src = and shr add vg get st 11 lane get st 7 2 63 754 value = ulong 0 755 if ne and shr get st 14 src 1 0 756 value = vg get st 12 src 757 end 758 put perm lane value 759 end 760 for lane ulong 64 761 if ne and shr get st 14 lane 1 0 762 vs get st 13 lane get perm lane 763 end 764 end 765 end 766 fn vexec to void 767 cl = get st 9 768 if eq cl 12 769 note CDNA3 p187: lowest active lane; EXEC=0 still reads lane zero. Flags unchanged. 770 first = ulong 0 771 if ne get st 14 0 772 while eq and shr get st 14 first 1 0 bound 64 773 first = add first 1 774 end 775 end 776 put sr get st 13 vg sub get st 11 256 first 777 ret 778 end 779 if eq cl 11 780 permute 781 ret 782 end 783 note All VCC writers replace the whole mask; every source sees the incoming mask (PDF p22). 784 put st 17 get st 15 785 if or eq cl 6 and eq cl 5 or eq get st 10 25 eq get st 10 28 786 put st 15 0 787 end 788 for lane ulong 64 789 if ne and shr get st 14 lane 1 0 790 if eq cl 5 791 vecalu lane 792 end 793 if eq cl 6 794 carry lane gt source get st 11 lane vg get st 12 lane 795 end 796 if eq cl 7 797 globalop lane 798 end 799 if eq cl 8 800 r = source get st 11 lane 801 if eq get st 10 32 802 r = fpexp r 803 end 804 if eq get st 10 33 805 r = fplog r 806 end 807 if eq get st 10 34 808 r = fprcp r 809 end 810 if eq get st 10 36 811 r = fprsq r 812 end 813 vs get st 13 lane r 814 end 815 if eq cl 9 816 vs get st 13 lane fp8bits source get st 11 lane 817 end 818 if eq cl 10 819 r = mul source get st 11 lane source get st 12 lane 820 if eq get st 10 646 821 r = shr r 32 822 end 823 vs get st 13 lane r 824 end 825 end 826 end 827 end 828 fn step pc ulong to bool 829 decode pc 830 if and eq get st 9 4 eq get st 10 1 831 ret false 832 end 833 if le get st 9 4 834 sexec 835 else 836 vexec 837 end 838 ret true 839 end 840 fn wave group ulong row ulong to void 841 for i ulong 102 842 put sr i 0 843 end 844 for i ulong 16384 845 put vr i 0 846 end 847 put sr 2 group 848 put sr 3 row 849 for i ulong 64 850 vs 0 i i 851 end 852 put st 14 `18446744073709551615` 853 put st 15 0 854 put st 16 0 855 pc = ulong 0 856 while true bound 999999 857 c = ulong 0 858 while lt c 999998 bound 999999 859 if not step pc 860 ret 861 end 862 pc = get st 5 863 c = add c 1 864 end 865 end 866 end 867 fn openarg idx ulong flags int to ulong 868 path = new uchar 4096 0 869 n = argread idx path 0 len path 870 if le n 0 871 fail 64 872 end 873 fd = fopen path 0 ulong n flags 0 874 if lt fd 0 875 fail 74 876 end 877 ret ulong fd 878 end 879 fn filesize fd ulong to ulong 880 n = fseek int fd 0 2 881 if lt n 0 882 fail 74 883 end 884 ret ulong n 885 end 886 fn gridarg idx ulong to ulong 887 p = new uchar 4096 0 888 n = argread idx p 0 len p 889 if le n 0 890 fail 64 891 end 892 v = ulong 0 893 for i ulong ulong n 894 c = ulong get p i 895 if or lt c 48 gt c 57 896 fail 64 897 end 898 c = sub c 48 899 if gt v div sub ulong `18446744073709551615` c 10 900 fail 64 901 end 902 v = add mul v 10 c 903 end 904 if gt v 0xffffffff 905 fail 64 906 end 907 ret v 908 end 909 fn main to int 910 if ne argcnt 5 911 ret 64 912 end 913 put st 0 openarg 1 0 914 put st 1 filesize get st 0 915 if or eq get st 1 0 ne and get st 1 3 0 916 ret 65 917 end 918 validate 919 put st 2 openarg 2 2 920 put st 3 filesize get st 2 921 nx = gridarg 3 922 ny = gridarg 4 923 groups = div add nx 63 64 924 y = ulong 0 925 while lt y ny bound 999999 926 c = ulong 0 927 while and lt y ny lt c 999998 bound 999999 928 g = ulong 0 929 while lt g groups bound 999999 930 d = ulong 0 931 while and lt g groups lt d 999998 bound 999999 932 wave g y 933 g = add g 1 934 d = add d 1 935 end 936 end 937 y = add y 1 938 c = add c 1 939 end 940 end 941 r = fclose int get st 2 942 if ne r 0 943 ret 74 944 end 945 r = fclose int get st 0 946 if ne r 0 947 ret 74 948 end 949 ret 0 950 end