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/nvidia/driver/gate.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 / nvidia / driver / gate.om` 849 lines ยท 18158 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note gpu/nvidia/driver/gate.om: the gpu-driver gate. It reads the cases the C oracle printed 3 note (gpu/nvidia/driver/oracle-cases.tsv: CUDApp `84b524ca` nvrm/ and m16/ C, run outside this tree) and 4 note recomputes each one with card.om, diag.om, m16.om, nvrm.om and eng.om fcls. For the first case of each 5 note kind it also runs a control: the same case with its expected answer changed, which must be caught. 6 note Exit 0 is PASS. 7 note Line kinds, tab separated, numbers decimal, bytes lowercase hex, "-" absent, "e" empty bytes: 8 note card HAS BDF CARDS INDEX+1 / cls SM VENDOR DEVICE CLASSES M10 M11 / amem PREV SIZE MEMINFO MESSAGE / 9 note chan PREV ATTEMPTS DELAY MEMINFO BUDDYINFO MESSAGE / maps MAPS HIT / name KIND CODE TEXT / 10 note wge NOW TIMEOUT T MARKER TARGET RC+1 CLOCK_READS / ret RETIRED PUT UPTO NEWRETIRED / 11 note enq PBSIZE COUNT RC+1 NWORDS (0: not enqueued) / slot HANDLES ARC+1 RC+1 SLOT (the slot count: none) / 12 note cput NEXTRA PUT0 PUT1 PUT2 PUT3 CH RESULT / cret NEXTRA CH RETIRED1 PUT1 RETIRED2 PUT2 RETIRED3 PUT3 UPTO 13 note NEWRETIRED1 NEWRETIRED2 NEWRETIRED3 / copy DIR NOBUF FAULTED OFF BYTES HANDLE VA SIZE CPU ROWS RC+1 MSG / 14 note alloc VRAM DISCRETE SM FAULTED LIVECOUNT CAP SIZE RC+1 CODE VASIZE / vinfo DISCRETE IORC STATUS TOTAL FREE 15 note RC+1 CODE OUTFREE OUTTOTAL / fcls RESULT KIND LAST EXPECTED MARKER2 MARKER2WANT PROGRESS CLASS. 16 note A card record is 9 bytes: index, valid, domain u32 LE, bus, slot, function. CLASSES and HANDLES are u32 17 note LE words. ROWS are live rows of 7 u64 LE: handle, va, size, cpu, cpu_live, rm_live, quarantined (cpu as an 18 note offset from one buffer, as is CPU). alloc CODE: 0 none, 1 SM86, 2 size, 3 table full, 4 VA exhausted (the 19 note oracle's va_take answers 0, so a case that passes every check ends there with VASIZE the size it asked 20 note for). vinfo CODE: 0 none, 1 errno or status, 2 invalid heap information. fcls CLASS: 0 wrong_marker, 21 note 1 late_progress, 2 no_progress. In wge the clock reads NOW, then T, then 2^64 - 1. 22 note Lines starting with # are notes. One line is read into a 65536-byte array (an Omega array's size is fixed 23 note when it is compiled), so a longer line is refused by name, never cut. Arrays are passed as arguments, so 24 note they are main's locals: l line, d decoded fields, 25 note c card table, u class words, o recomputed message. 26 27 text gt_k "card|cls|amem|chan|maps|name|wge|ret|enq|slot|cput|cret|copy|alloc|vinfo|fcls|" 28 text gt_mf "MemFree" 29 text gt_ma "MemAvailable" 30 text gt_use "usage: gate ORACLE-CASES.tsv\n" 31 text gt_open "gate: cannot open, size or map the cases file\n" 32 text gt_long "gate: a line of the cases file is longer than 65536 bytes; refused\n" 33 text gt_fl1 "FAIL line " 34 text gt_bad "FAIL malformed line " 35 text gt_none "FAIL no cases of kind " 36 text gt_ctl "FAIL control not caught, kind " 37 text gt_sum "OMEGA-GPU-DRIVER " 38 text gt_pass "PASS" 39 text gt_fail "FAIL" 40 text gt_cs " cases=" 41 text gt_co " controls=" 42 text gt_ca " caught=" 43 text gt_hw " hardware=NOT_RUN\n" 44 text gt_nl "\n" 45 global g_p uchar 4096 46 global g_st uchar 256 47 global g_nb uchar 24 48 global g_fs ulong 16 49 global g_fe ulong 16 50 global g_ds ulong 8 51 global g_dl ulong 8 52 global g_kc ulong 16 53 note g_n: 0 decode top, 1 control on, 2 fields, 3 line number, 4 cases, 5 fails, 6 controls, 7 caught, 54 note 8 malformed lines, 9 clock reads, 10 clock NOW, 11 clock T 55 global g_n ulong 16 56 57 fn gnum v ulong to void 58 k = ulong 0 59 x = v 60 while true bound 20 61 put g_nb k uchar add 48 rem x 10 62 k = add k 1 63 x = div x 10 64 if eq x 0 65 break 66 end 67 end 68 for j ulong div k 2 bound 10 69 a = get g_nb j 70 put g_nb j get g_nb sub sub k j 1 71 put g_nb sub sub k j 1 a 72 end 73 r = write 1 g_nb 0 k 74 end 75 76 fn gbad to void 77 put g_n 8 add get g_n 8 1 78 end 79 80 note decimal field i: 1 to 20 digits below 2^64; anything else marks the line malformed 81 fn fdec i ulong l view uchar 65536 to ulong 82 v = ulong 0 83 s = get g_fs i 84 n = sub get g_fe i s 85 if or eq n 0 gt n 20 86 gbad 87 ret 0 88 end 89 for j ulong n bound 20 90 c = ulong get l add s j 91 if or lt c 48 gt c 57 92 gbad 93 ret 0 94 end 95 if gt v div sub ulong `18446744073709551615` sub c 48 10 96 gbad 97 ret 0 98 end 99 v = add mul v 10 sub c 48 100 end 101 ret v 102 end 103 104 note the byte whose two hex digits start at l[q], or 256 when they are not lowercase hex 105 fn ghex2 q ulong l view uchar 65536 to ulong 106 h = drv_hexd ulong get l q 107 x = drv_hexd ulong get l add q 1 108 if or gt h 15 gt x 15 109 ret 256 110 end 111 ret or shl h 4 x 112 end 113 114 note hex field i decoded into d as segment slot; false when the field is "-" (absent) 115 fn fhex i ulong slot ulong l view uchar 65536 d edit uchar 65536 to bool 116 s = get g_fs i 117 n = sub get g_fe i s 118 p = get g_n 0 119 put g_ds slot p 120 put g_dl slot 0 121 if eq n 1 122 if eq get l s 45 123 ret false 124 end 125 if eq get l s 101 126 ret true 127 end 128 end 129 if ne rem n 2 0 130 gbad 131 ret false 132 end 133 n = div n 2 134 if gt add p n 65536 135 gbad 136 ret false 137 end 138 for j ulong n bound 65536 139 x = ghex2 add s mul j 2 l 140 if gt x 255 141 gbad 142 ret false 143 end 144 put d add p j uchar x 145 end 146 put g_n 0 add p n 147 put g_dl slot n 148 ret true 149 end 150 151 note o[0, n) equals segment slot of d; with the control on, the first expected byte is changed 152 fn gcmp n ulong slot ulong d view uchar 65536 o view uchar 65536 to bool 153 if ne n get g_dl slot 154 ret false 155 end 156 b = get g_ds slot 157 for i ulong n bound 65536 158 x = ulong get d add b i 159 if and eq i 0 eq get g_n 1 1 160 x = xor x 1 161 end 162 if ne ulong get o i x 163 ret false 164 end 165 end 166 ret true 167 end 168 169 note place the 9-byte card record at d[q] into the 64 x 72-byte table c; false when its index is past 63 170 fn gcrec q ulong d view uchar 65536 c edit uchar 4608 to bool 171 p = mul ulong get d q 72 172 if ge p 4608 173 gbad 174 ret false 175 end 176 put c p get d add q 1 177 for j ulong 4 178 put c add add p 4 j get d add add q 2 j 179 end 180 put c add p 8 get d add q 6 181 put c add p 9 get d add q 7 182 put c add p 10 get d add q 8 183 ret true 184 end 185 186 fn hcard l view uchar 65536 d edit uchar 65536 c edit uchar 4608 to bool 187 pb = fhex 2 0 l d 188 pc = fhex 3 1 l d 189 for z ulong 4608 190 put c z 0 191 end 192 for r ulong div get g_dl 1 9 bound 65536 193 if not gcrec add get g_ds 1 mul r 9 d c 194 ret false 195 end 196 end 197 got = drv_card c ne fdec 1 l 0 part d get g_ds 0 get g_dl 0 198 ret eq got add fdec 4 l get g_n 1 199 end 200 201 note the little-endian u32 at d[q] 202 fn gu32 q ulong d view uchar 65536 to ulong 203 x = or ulong get d q shl ulong get d add q 1 8 204 ret or x or shl ulong get d add q 2 16 shl ulong get d add q 3 24 205 end 206 207 fn hcls l view uchar 65536 d edit uchar 65536 u edit uint 16384 to bool 208 pc = fhex 4 0 l d 209 n = div get g_dl 0 4 210 for i ulong n bound 16384 211 put u i uint gu32 add get g_ds 0 mul i 4 d 212 end 213 m = new ulong 16 0 214 drv_marshal fdec 1 l fdec 2 l fdec 3 l part u 0 n m 215 if ne get m 10 add fdec 5 l get g_n 1 216 ret false 217 end 218 ret eq get m 11 fdec 6 l 219 end 220 221 note MemFree (w 0) or MemAvailable (w 1) of segment slot of d into r[0] 222 fn gmem slot ulong w ulong d view uchar 65536 r edit ulong 1 to bool 223 if eq w 0 224 ret drv_meminfo part d get g_ds slot get g_dl slot part gt_mf 0 len gt_mf r 225 end 226 ret drv_meminfo part d get g_ds slot get g_dl slot part gt_ma 0 len gt_ma r 227 end 228 229 fn hamem l view uchar 65536 d edit uchar 65536 o edit uchar 65536 to bool 230 pp = fhex 1 0 l d 231 pm = fhex 3 1 l d 232 px = fhex 4 2 l d 233 v = new ulong 3 0 234 r = new ulong 1 0 235 put v 0 fdec 2 l 236 if pm 237 if not gmem 1 0 d r 238 ret false 239 end 240 put v 1 get r 0 241 if not gmem 1 1 d r 242 ret false 243 end 244 put v 2 get r 0 245 end 246 n = drv_amsg part d get g_ds 0 get g_dl 0 v o 247 ret gcmp n 2 d o 248 end 249 250 fn hchan l view uchar 65536 d edit uchar 65536 o edit uchar 65536 to bool 251 pp = fhex 1 0 l d 252 pm = fhex 4 1 l d 253 pb = fhex 5 2 l d 254 px = fhex 6 3 l d 255 v = new ulong 4 0 256 r = new ulong 1 0 257 put v 0 fdec 2 l 258 put v 1 fdec 3 l 259 if pm 260 if not gmem 1 0 d r 261 ret false 262 end 263 put v 2 get r 0 264 end 265 put v 3 `18446744073709551615` 266 if pb 267 if not drv_buddy part d get g_ds 2 get g_dl 2 9 r 268 ret false 269 end 270 put v 3 get r 0 271 end 272 n = drv_cmsg part d get g_ds 0 get g_dl 0 v o 273 ret gcmp n 3 d o 274 end 275 276 fn hmaps l view uchar 65536 d edit uchar 65536 to bool 277 if not fhex 1 0 l d 278 ret false 279 end 280 got = drv_maps part d get g_ds 0 get g_dl 0 281 ret eq got add fdec 2 l get g_n 1 282 end 283 284 fn hname l view uchar 65536 d edit uchar 65536 o edit uchar 65536 to bool 285 p = fhex 3 0 l d 286 code = fdec 2 l 287 r = long code 288 if ge code `2147483648` 289 r = neg long sub `4294967296` code 290 end 291 w = new ulong 2 0 292 if eq fdec 1 l 0 293 drv_wres r w 294 else 295 drv_wkind r w 296 end 297 for i ulong get w 1 bound 64 298 put o i get drv_m16t add get w 0 i 299 end 300 ret gcmp get w 1 0 d o 301 end 302 303 note the scripted clock of a wge case: NOW, then T, then 2^64 - 1 304 fn gclk to ulong 305 c = get g_n 9 306 put g_n 9 add c 1 307 if eq c 0 308 ret get g_n 10 309 end 310 if eq c 1 311 ret get g_n 11 312 end 313 ret `18446744073709551615` 314 end 315 316 note m16_native_wait_marker_ge on the scripted clock: the loop of drv_wait_ge with gclk in place of monons 317 note and the case's marker in place of mapget; each look is drv_wstep, the function drv_wait_ge calls 318 fn hwge l view uchar 65536 to bool 319 put g_n 10 fdec 1 l 320 put g_n 11 fdec 3 l 321 put g_n 9 0 322 mk = fdec 4 l 323 tg = fdec 5 l 324 dur = drv_wdur fdec 2 l 325 endt = ulong `18446744073709551615` 326 if ne dur `18446744073709551615` 327 endt = drv_wend gclk dur 328 end 329 st = ulong 1 330 while eq st 1 bound 8 331 st = drv_wstep lt gclk endt mk tg 332 end 333 rc = ulong 0 334 if eq st 0 335 rc = ulong 1 336 end 337 if ne rc add fdec 6 l get g_n 1 338 ret false 339 end 340 ret eq get g_n 9 fdec 7 l 341 end 342 343 note nvrm_retire: the retired count after a completion report 344 fn hret l view uchar 65536 to bool 345 got = drv_retire fdec 1 l fdec 2 l fdec 3 l 346 ret eq got add fdec 4 l get g_n 1 347 end 348 349 note m16_native_enqueue_methods with nvrm_enqueue answering 0: RC+1 1 and NWORDS = COUNT when drv_enqok 350 fn henq l view uchar 65536 to bool 351 cnt = fdec 2 l 352 rc = ulong 0 353 nw = ulong 0 354 if drv_enqok cnt fdec 1 l 355 rc = ulong 1 356 nw = cnt 357 end 358 if ne rc add fdec 3 l get g_n 1 359 ret false 360 end 361 ret eq nw fdec 4 l 362 end 363 364 note m16_native_alloc_memory: drv_slot over the handles, then nvrm_alloc's answer ARC decides RC 365 fn hslot l view uchar 65536 d edit uchar 65536 u edit uint 16384 to bool 366 if not fhex 1 0 l d 367 ret false 368 end 369 n = div get g_dl 0 4 370 for i ulong n bound 16384 371 put u i uint gu32 add get g_ds 0 mul i 4 d 372 end 373 s = drv_slot part u 0 n 374 if ne s add fdec 4 l get g_n 1 375 ret false 376 end 377 rc = ulong 0 378 if and lt s n eq fdec 2 l 1 379 rc = ulong 1 380 end 381 ret eq rc fdec 3 l 382 end 383 384 note nvrm_chan_put: PUT0 for the main channel, PUT(ch) for an extra one, 0 for no channel. A line carries 385 note three extra puts, so NEXTRA above 3 is malformed. 386 fn hcput l view uchar 65536 to bool 387 nx = fdec 1 l 388 if gt nx 3 389 gbad 390 ret false 391 end 392 ch = fdec 6 l 393 s = drv_chan ch nx 394 got = ulong 0 395 if eq s 0 396 got = fdec 2 l 397 end 398 if eq s 1 399 got = fdec add 2 ch l 400 end 401 ret eq got add fdec 7 l get g_n 1 402 end 403 404 note nvrm_chan_retire: only the entry ch names moves, by drv_retire; the others keep their retired count 405 fn hcret l view uchar 65536 to bool 406 nx = fdec 1 l 407 if gt nx 3 408 gbad 409 ret false 410 end 411 ch = fdec 2 l 412 s = drv_chan ch nx 413 up = fdec 9 l 414 for i ulong 3 415 want = fdec add 3 mul i 2 l 416 if and eq s 1 eq add i 1 ch 417 want = drv_retire want fdec add 4 mul i 2 l up 418 end 419 if eq i 0 420 want = add want get g_n 1 421 end 422 if ne want fdec add 10 i l 423 ret false 424 end 425 end 426 ret true 427 end 428 429 note the little-endian u64 at d[q] 430 fn gu64 q ulong d view uchar 65536 to ulong 431 ret or gu32 q d shl gu32 add q 4 d 32 432 end 433 434 note true when one of the live rows decoded into d is the allocation m (drv_lrow) 435 fn glive d view uchar 65536 m view ulong 4 to bool 436 a = new ulong 7 0 437 for r ulong div get g_dl 0 56 bound 65536 438 q = add get g_ds 0 mul r 56 439 for j ulong 7 440 put a j gu64 add q mul j 8 d 441 end 442 if drv_lrow a m 443 ret true 444 end 445 end 446 ret false 447 end 448 449 note nvrm_copy_to and nvrm_copy_from up to the byte copy: glive, then drv_copy; 450 note 0 is RC+1 1 with no message, 1 RC+1 0 with no message, 2 RC+1 0 with the message 451 fn hcopy l view uchar 65536 d edit uchar 65536 to bool 452 m = new ulong 4 0 453 for j ulong 4 454 put m j fdec add 6 j l 455 end 456 if not fhex 10 0 l d 457 ret false 458 end 459 live = glive d m 460 st = drv_copy eq fdec 2 l 0 ne fdec 3 l 0 fdec 4 l fdec 5 l get m 2 live 461 rc = ulong 0 462 if eq st 0 463 rc = ulong 1 464 end 465 if ne rc add fdec 11 l get g_n 1 466 ret false 467 end 468 ret eq bv eq st 2 fdec 12 l 469 end 470 471 note nvrm_alloc_vram (VRAM 1) and alloc_with_cacheability up to va_take: the first check that refuses gives 472 note CODE; a case that passes every check asks va_take for drv_asize's size (CODE 4, the oracle's va_take 473 note answers 0). RC+1 is 0 on every line. 474 fn halloc l view uchar 65536 to bool 475 code = ulong 0 476 vs = ulong 0 477 if and eq fdec 1 l 1 not drv_vramok ne fdec 2 l 0 fdec 3 l 478 code = ulong 1 479 end 480 if eq code 0 481 vs = drv_asize ne fdec 4 l 0 fdec 7 l 482 if eq vs 0 483 code = ulong 2 484 end 485 end 486 if eq code 0 487 if drv_livefull fdec 5 l fdec 6 l 488 code = ulong 3 489 vs = ulong 0 490 end 491 end 492 if eq code 0 493 code = ulong 4 494 end 495 if ne code add fdec 9 l get g_n 1 496 ret false 497 end 498 if ne fdec 8 l 0 499 ret false 500 end 501 ret eq vs fdec 10 l 502 end 503 504 note nvrm_vram_info: drv_vinfo; on 0 the call returns the heap's free and total bytes, otherwise it leaves 505 note the caller's two numbers (7 in the oracle) alone 506 fn hvinfo l view uchar 65536 to bool 507 t = fdec 4 l 508 f = fdec 5 l 509 st = drv_vinfo ne fdec 1 l 0 fdec 2 l fdec 3 l t f 510 rc = ulong 0 511 code = ulong 0 512 of = ulong 7 513 ot = ulong 7 514 if eq st 0 515 rc = ulong 1 516 of = f 517 ot = t 518 end 519 if or eq st 1 eq st 2 520 code = st 521 end 522 if ne rc add fdec 6 l get g_n 1 523 ret false 524 end 525 if ne code fdec 7 l 526 ret false 527 end 528 ret and eq of fdec 8 l eq ot fdec 9 l 529 end 530 531 note m16_gpu_wait_failure_class, C branch: eng.om fcls with the report in m[1] to m[7] 532 fn hfcls l view uchar 65536 to bool 533 m = new ulong 24 0 534 for j ulong 7 535 put m add j 1 fdec add 1 j l 536 end 537 w = new ulong 16 0 538 fcls m w 539 ret eq get w 0 add fdec 8 l get g_n 1 540 end 541 542 note fields a line of kind k has 543 fn gnf k ulong to ulong 544 if or eq k 0 eq k 2 545 ret 5 546 end 547 if or eq k 1 eq k 3 548 ret 7 549 end 550 if eq k 4 551 ret 3 552 end 553 if eq k 5 554 ret 4 555 end 556 if or eq k 7 or eq k 8 eq k 9 557 ret 5 558 end 559 if or eq k 6 eq k 10 560 ret 8 561 end 562 if or eq k 11 eq k 12 563 ret 13 564 end 565 if eq k 13 566 ret 11 567 end 568 if eq k 14 569 ret 10 570 end 571 ret 9 572 end 573 574 note kind of field 0 (index of its piece in gt_k), or 16 when it names none 575 fn gkind l view uchar 65536 to ulong 576 s = get g_fs 0 577 n = sub get g_fe 0 s 578 i = ulong 0 579 for k ulong 16 580 st = i 581 while ne get gt_k i 124 bound 16 582 i = add i 1 583 end 584 if eq sub i st n 585 same = true 586 for j ulong n bound 16 587 if ne get l add s j get gt_k add st j 588 same = false 589 end 590 end 591 if same 592 ret k 593 end 594 end 595 i = add i 1 596 end 597 ret 16 598 end 599 600 fn hrun k ulong l view uchar 65536 d edit uchar 65536 c edit uchar 4608 u edit uint 16384 o edit uchar 65536 to bool 601 put g_n 0 0 602 if eq k 0 603 ret hcard l d c 604 end 605 if eq k 1 606 ret hcls l d u 607 end 608 if eq k 2 609 ret hamem l d o 610 end 611 if eq k 3 612 ret hchan l d o 613 end 614 if eq k 4 615 ret hmaps l d 616 end 617 if eq k 5 618 ret hname l d o 619 end 620 if eq k 6 621 ret hwge l 622 end 623 if eq k 7 624 ret hret l 625 end 626 if eq k 8 627 ret henq l 628 end 629 if eq k 9 630 ret hslot l d u 631 end 632 if eq k 10 633 ret hcput l 634 end 635 if eq k 11 636 ret hcret l 637 end 638 if eq k 12 639 ret hcopy l d 640 end 641 if eq k 13 642 ret halloc l 643 end 644 if eq k 14 645 ret hvinfo l 646 end 647 ret hfcls l 648 end 649 650 note split l[0, n) into fields at tabs; false when it has more than 16 651 fn gsplit n ulong l view uchar 65536 to bool 652 f = ulong 0 653 put g_fs 0 0 654 for i ulong n bound 65536 655 if eq get l i 9 656 if ge add f 1 16 657 ret false 658 end 659 put g_fe f i 660 f = add f 1 661 put g_fs f add i 1 662 end 663 end 664 put g_fe f n 665 put g_n 2 add f 1 666 ret true 667 end 668 669 note report a case result: a failing case prints its line number 670 fn gcase ok bool to void 671 put g_n 4 add get g_n 4 1 672 if not ok 673 put g_n 5 add get g_n 5 1 674 r = write 1 gt_fl1 0 len gt_fl1 675 gnum get g_n 3 676 r = write 1 gt_nl 0 len gt_nl 677 end 678 end 679 680 note report a control result: a control that is not caught prints its kind 681 fn gctl caught bool k ulong to void 682 put g_n 6 add get g_n 6 1 683 if caught 684 put g_n 7 add get g_n 7 1 685 else 686 r = write 1 gt_ctl 0 len gt_ctl 687 gnum k 688 r = write 1 gt_nl 0 len gt_nl 689 end 690 end 691 692 note one line l[0, n): split, check, run, and the control for a kind's first case 693 fn gline n ulong l view uchar 65536 d edit uchar 65536 c edit uchar 4608 u edit uint 16384 o edit uchar 65536 to void 694 put g_n 3 add get g_n 3 1 695 if eq n 0 696 ret 697 end 698 if eq get l 0 35 699 ret 700 end 701 bad = get g_n 8 702 if not gsplit n l 703 gbad 704 end 705 k = ulong 16 706 if eq get g_n 8 bad 707 k = gkind l 708 if or eq k 16 ne get g_n 2 gnf k 709 gbad 710 end 711 end 712 if eq get g_n 8 bad 713 put g_n 1 0 714 ok = hrun k l d c u o 715 if eq get g_n 8 bad 716 gcase ok 717 if eq get g_kc k 0 718 put g_n 1 1 719 cc = hrun k l d c u o 720 put g_n 1 0 721 gctl not cc k 722 end 723 put g_kc k add get g_kc k 1 724 end 725 end 726 if ne get g_n 8 bad 727 r = write 1 gt_bad 0 len gt_bad 728 gnum get g_n 3 729 r = write 1 gt_nl 0 len gt_nl 730 end 731 end 732 733 note the size of the open file fd from fstat (st_size, byte 48 of the AArch64 struct stat), 0 on failure 734 fn gsize fd int to ulong 735 if ne fstat fd g_st 0 128 0 736 ret 0 737 end 738 size = ulong 0 739 for j ulong 8 740 size = or size shl ulong get g_st add 48 j mul j 8 741 end 742 ret size 743 end 744 745 fn gsummary to int 746 fl = add get g_n 5 get g_n 8 747 for k ulong 16 748 if eq get g_kc k 0 749 fl = add fl 1 750 r = write 1 gt_none 0 len gt_none 751 gnum k 752 r = write 1 gt_nl 0 len gt_nl 753 end 754 end 755 if ne get g_n 6 get g_n 7 756 fl = add fl 1 757 end 758 r = write 1 gt_sum 0 len gt_sum 759 if eq fl 0 760 r = write 1 gt_pass 0 len gt_pass 761 else 762 r = write 1 gt_fail 0 len gt_fail 763 end 764 r = write 1 gt_cs 0 len gt_cs 765 gnum get g_n 4 766 r = write 1 gt_co 0 len gt_co 767 gnum get g_n 6 768 r = write 1 gt_ca 0 len gt_ca 769 gnum get g_n 7 770 r = write 1 gt_hw 0 len gt_hw 771 if ne fl 0 772 ret 1 773 end 774 ret 0 775 end 776 777 note open argv[1] and map it whole; g_n 12 gets the descriptor and g_n 13 the size. 0 when it cannot. 778 fn gopen to long 779 if ne argcnt 2 780 r = write 2 gt_use 0 len gt_use 781 ret 0 782 end 783 pl = argread 1 g_p 0 4095 784 if lt pl 1 785 r = write 2 gt_use 0 len gt_use 786 ret 0 787 end 788 fd = int fopen g_p 0 ulong pl 524288 0 789 if lt fd 0 790 r = write 2 gt_open 0 len gt_open 791 ret 0 792 end 793 size = gsize fd 794 put g_n 12 ulong fd 795 put g_n 13 size 796 h = long 0 797 if gt size 0 798 h = mapnew fd 0 size 1 2 799 end 800 if le h 0 801 r = write 2 gt_open 0 len gt_open 802 ret 0 803 end 804 ret h 805 end 806 807 note the offset of the first newline in l[0, k), or k when there is none 808 fn geol k ulong l view uchar 65536 to ulong 809 for i ulong k bound 65536 810 if eq get l i 10 811 ret i 812 end 813 end 814 ret k 815 end 816 817 fn main to int 818 l = new uchar 65536 0 819 d = new uchar 65536 0 820 c = new uchar 4608 0 821 u = new uint 16384 0 822 o = new uchar 65536 0 823 h = gopen 824 if le h 0 825 ret 2 826 end 827 size = get g_n 13 828 pos = ulong 0 829 while lt pos size bound `9223372036854775807` 830 k = sub size pos 831 if gt k 65536 832 k = ulong 65536 833 end 834 if ne mapread h pos l 0 k long k 835 r = write 2 gt_open 0 len gt_open 836 ret 2 837 end 838 e = geol k l 839 if and eq e k eq k 65536 840 r = write 2 gt_long 0 len gt_long 841 ret 2 842 end 843 gline e l d c u o 844 pos = add pos add e 1 845 end 846 r = mapdrop h 847 q = fclose int get g_n 12 848 ret gsummary 849 end