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/rest/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 / amd / rest / gate.om` 2871 lines ยท 50197 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/amd/rest/gate.om: OMEGA-GPU-AMD-REST, one slice of the AMD gfx942 back end's leftovers: the checks CUDApp 3 note ran in C, shell and Python, written in seeded Omega (Linux AArch64). The old instruments stay in CUDApp as 4 note oracles; their recorded verdicts are the *-verdicts.tsv and *-sections.tsv tables beside this file (generated, 5 note see README.md). A case not replayed is a notrun row with its reason, printed NOT_RUN. 6 note Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies sh_dat, sh_all, sh_dig): 7 note { printf 'om2\n'; cat seed/ng/sha256.om gpu/amd/rest/gate.om; } | seed/out/omc > gate 8 note Run from the repository root: gate OMC SCRATCH 9 note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing runs 10 note (exit 69, nothing written) 11 note SCRATCH a new directory (created 0700), at most 1024 bytes of path; an existing one is refused (exit 2) 12 note 1. llvm-mc parity (was tests/amd/run.sh with llvm-objcopy, dd, awk). For each row of llvm18-sections.tsv the 13 note writer builds gpu/amd/gfx942/K.isa; .text and .note bytes, rodata[0,16) and rodata[24,end) hash as 14 note llvm-mc-18 made them from K-gfx942.s; rodata[16,24) equals sym(K) - sym(K.kd); e_flags is 0x54C. 15 note 2. Launcher verdicts (was tests/amd-kfd-launch/check.py, CPU part). launch-verdicts.tsv: every object hashes 16 note as check.py built it; each mutated object and input file is rebuilt here and hashes as check.py's input did; 17 note each plan unit is composed here and hashes as check.py's unit did; each run row gives check.py's exit, 18 note stdout and stderr. x86 rows run under /usr/bin/qemu-x86_64. Rows whose verb is vadd or run would open 19 note /dev/kfd; the absent-device verdict is the one recorded. Without qemu-x86_64, or with /dev/kfd present, 20 note the gate runs nothing and prints OMEGA-GPU-AMD-REST NOT_RUN reason=... (exit 3). 21 note 3. Writer verdicts (was tests/amd/{branches,formats,boundaries}.py and the MessagePack part of run.sh). 22 note writer-verdicts.tsv: each SOPP and format table is generated here and hashes as the oracle's did; the 23 note writer's exit and bytes match; the MessagePack probe main is generated here and hashes as boundaries.py's; 24 note the spec bytes computed here hash as boundaries.py's; hsaco.om's encoder emits exactly them. 25 note 4. Controls, each must be caught: a compiler one byte longer; vadd.isa with "I 5 260 8 4 0x01 " changed to 261; 26 note a llvm table digest changed; an object with no llvm row; a launcher verdict with its expected bytes changed; 27 note two MessagePack encoder mutants (they compile and run, the bytes differ); the loader refusing a wrong 28 note machine (exit 33) and a truncated object (exit 34); the wrong-request table must differ from the header 29 note oracle; records.om without its 2^64-1 index guard must exit 0 there (the table says 3); a kfd verdict with 30 note its expected stderr changed. 31 note 5. KFD host verdicts (was tests/amd-kfd/{run.sh,oracle.py}, CPU part). kfd-verdicts.tsv: requests.tsv has 32 note the numbers the C sizeof/offsetof oracle printed, line for line; aql, kernarg, records and ring (unit + 33 note cli.om) build twice to the oracle's bytes; the three mutated tables and the over-fuel table are written 34 note here and hash as oracle.py's; each devctl allowlist program is refused by omc as recorded (exit 9); each 35 note run row gives oracle.py's exit, stdout and stderr. 36 note 6. Plan verdicts (was tests/amd-kfd-launch/plan-check.py, CPU part). plan-verdicts.tsv: each input and 37 note patched plan file is written here and hashes as plan-check.py's did; each run row gives its exit, stdout 38 note and stderr. 39 note Output: one line per check, then OMEGA-GPU-AMD-REST PASS|FAIL sections=S objects=O verdicts=V not_run=N 40 note writer=W kfd=F plan=P controls=C caught=K hardware=NOT_RUN. Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 41 note 3 host NOT_RUN, 69 refused. 42 note Buffers: inputs are read into fixed buffers (g_b and the verdict-table buffer, sizes at their declarations); 43 note a larger input fails its check by name, never truncates silently. 44 text t_pin "seed/out/omc.sha256" 45 text t_isa "gpu/amd/gfx942/" 46 text t_isx ".isa" 47 text t_om ".om" 48 text t_bin ".bin" 49 text t_err ".err" 50 text t_hs ".hsaco" 51 text t_hse ".hsaco.err" 52 text t_ok_ ".llvm-ok" 53 text t_e "" 54 text t_e2 "" 55 text t_kd ".kd" 56 text t_null "/dev/null" 57 text t_kfd "/dev/kfd" 58 text t_qemu "/usr/bin/qemu-x86_64" 59 text t_hsaco "hsaco" 60 text t_hsom "gpu/amd/gfx942/hsaco.om" 61 text t_tgom "gpu/targets.om" 62 text t_tgts "targets" 63 text t_load "load" 64 text t_fmt "AMDGPU_HSACO" 65 text t_gfx "gfx942" 66 text t_om2 "om2\n" 67 text t_x86 "target x86linux\n" 68 text t_main "fn main to int" 69 text t_lc "gpu/amd/kfd/launch/common.om" 70 text t_le "gpu/amd/kfd/launch/elf.om" 71 text t_ldv "gpu/amd/kfd/launch/device.om" 72 text t_ldi "gpu/amd/kfd/launch/dispatch.om" 73 text t_lpl "gpu/amd/kfd/launch/plan.om" 74 text t_lmn "gpu/amd/kfd/launch/main.om" 75 text t_cli "gpu/amd/kfd/cli.om" 76 text t_la "launch-a64" 77 text t_lx "launch-x86" 78 text t_tsec "gpu/amd/rest/llvm18-sections.tsv" 79 text t_tlv "gpu/amd/rest/launch-verdicts.tsv" 80 text t_twv "gpu/amd/rest/writer-verdicts.tsv" 81 text t_text ".text" 82 text t_note ".note" 83 text t_rod ".rodata" 84 text t_symtab ".symtab" 85 text t_strtab ".strtab" 86 text t_vadd "vadd" 87 text t_sgemm "sgemm" 88 text t_fp8 "fp8gemv" 89 text t_f260 "I 5 260 8 4 0x01 " 90 text t_k261 "vadd-text261" 91 text t_kobj "obj" 92 text t_kmut "mut" 93 text t_kfile "file" 94 text t_kunit "unit" 95 text t_krun "run" 96 text t_kisa "isa" 97 text t_ksopp "sopp" 98 text t_kfmt "format" 99 text t_kmp "msgpack" 100 text t_a64 "a64" 101 text t_vx86 "x86" 102 text t_vvadd "vadd" 103 text t_vrun "run" 104 text t_keep "keep" 105 text t_set16 "set16" 106 text t_set32 "set32" 107 text t_set64 "set64" 108 text t_or16 "or16" 109 text t_or32 "or32" 110 text t_bf "f" 111 text t_bk "k" 112 text t_fmax "forward-max" 113 text t_bmin "backward-min" 114 text t_fovf "forward-overflow" 115 text t_bovf "backward-overflow" 116 text t_undl "undefined-label" 117 text t_dupl "duplicate-label" 118 text t_sparse "sparse-format-ids" 119 text t_grow "growing-format-count" 120 text t_undf "undefined-format" 121 text t_br "I 4 @99 0x05\n" 122 text t_t99 "T 99\n" 123 text t_t99b "T 99\n" 124 text t_wait "I 4 0xc07f 0x0c\n" 125 text t_end "I 4 0 0x01\n" 126 text t_fi "F " 127 text t_fi2 " 1\nB " 128 text t_fi3 " 0 0 32 0\n" 129 text t_i1m "I `1000002`\n" 130 text t_fmn "fn main to int\n" 131 text t_mpu "mpuint " 132 text t_mps "s" 133 text t_mpn " = new uchar " 134 text t_mpstr "mpstr s" 135 text t_mpend "flush\nret 0\nend\n" 136 text t_mpm "mpmain" 137 text t_mpo "msgpack" 138 text t_mpe "msgpack.expected" 139 text t_mpl1 "if le v 127" 140 text t_mpr1 "if le v `18446744073709551615`" 141 text t_mpl2 "if le n 65535" 142 text t_mpr2 "if le n 65534" 143 text t_mpk1 "mp-mutant" 144 text t_mpk2 "mp-mutant2" 145 text t_out ".out" 146 text t_plus "omc-plus-one" 147 text t_flip "llvm-digest-changed" 148 text t_nrow "object-without-llvm-row" 149 text t_vflip "verdict-expected-changed" 150 text t_wmach "wrong-mach" 151 text t_trunc "truncated" 152 text t_usage "usage: gate OMC SCRATCH (run from the omega-mv repository root)\n" 153 text t_refd "OMEGA-GPU-AMD-REST REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n" 154 text t_nopin "OMEGA-GPU-AMD-REST INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n" 155 text t_noscr "OMEGA-GPU-AMD-REST INVALID: SCRATCH exists or cannot be made\n" 156 text t_hnoq "OMEGA-GPU-AMD-REST NOT_RUN reason=/usr/bin/qemu-x86_64 missing (the x86 launcher rows run under it) (exit 3)\n" 157 text t_hkfd "OMEGA-GPU-AMD-REST NOT_RUN reason=/dev/kfd present (the launcher and plan rows would open the device) (exit 3)\n" 158 text t_long "OMEGA-GPU-AMD-REST INVALID: SCRATCH path longer than 1024 bytes\n" 159 text t_ok "ok " 160 text t_fail "FAIL " 161 text t_nr "NOT_RUN " 162 text t_unit "unit " 163 text t_sec "llvm-mc " 164 text t_ver "verdict " 165 text t_wri "writer " 166 text t_tbl "table " 167 text t_ctl "control " 168 text t_bytes " bytes=" 169 text t_sha " sha256=" 170 text t_exit " exit=" 171 text t_textn " text=" 172 text t_noten " note=" 173 text t_src "source unreadable or over 16 MiB" 174 text t_unread "unreadable, over 1 MiB, or malformed" 175 text t_cmp "compile failed or stderr not empty" 176 text t_write "cannot write" 177 text t_wexit "writer exit differs" 178 text t_mism "bytes differ from the recorded oracle" 179 text t_inmis "input differs from the oracle's input" 180 text t_noobj "object unreadable" 181 text t_rowbad "malformed row" 182 text t_nmlong "name over 255 bytes" 183 text t_unk "unknown label" 184 text t_dev " reason=/dev/kfd present (row would open the device)" 185 text t_noq " reason=no /usr/bin/qemu-x86_64" 186 text t_caught " caught" 187 text t_esc " ESCAPED" 188 text t_noapp " not applied" 189 text t_sum "OMEGA-GPU-AMD-REST " 190 text t_pass "PASS" 191 text t_fl "FAIL" 192 text t_ss " sections=" 193 text t_so " objects=" 194 text t_sv " verdicts=" 195 text t_snr " not_run=" 196 text t_sw " writer=" 197 text t_sc " controls=" 198 text t_sk " caught=" 199 text t_hw " hardware=NOT_RUN\n" 200 text t_skfd " kfd=" 201 text t_kdir "gpu/amd/kfd/" 202 text t_kreq "gpu/amd/kfd/requests.tsv" 203 text t_tkfd "gpu/amd/rest/kfd-verdicts.tsv" 204 text t_khdr "hdr" 205 text t_kbin "bin" 206 text t_ktf "tfile" 207 text t_kfuel "fuel" 208 text t_kref "refuse" 209 text t_kgd "guard" 210 text t_kkr "krun" 211 text t_rep ".repeat" 212 text t_kfd_ "kfd " 213 text t_hdrn "requests.tsv-header" 214 text t_kwr "wrong-request.tsv" 215 text t_cwr "wrong-request-header" 216 text t_kgdn "records-guard" 217 text t_kflip "kfd-verdict-changed" 218 text t_kgl "global b uchar " 219 text t_kfn "\nfn main to int\nr = devctl neg int 1 uint " 220 text t_kb0 " b 0 " 221 text t_kend "\nret 0\nend\n" 222 text t_f04 "0 4 " 223 text t_f041 "0 4 1\n" 224 text t_hdrbad "differs from the live header oracle" 225 text t_nodet "the two builds differ or differ from the oracle's" 226 text t_tpv "gpu/amd/rest/plan-verdicts.tsv" 227 text t_kpat "patch" 228 text t_knr "notrun" 229 text t_vplan "plan" 230 text t_rsn " reason=" 231 text t_vpl "valid.plan" 232 text t_bmp "bad-magic.plan" 233 text t_cbm "a64 refuses bad-magic" 234 text t_cvalid "plan-refusal-given-valid-input" 235 text t_cshift "plan-patch-shifted" 236 text t_spl " plan=" 237 global g_pa uchar 4096 238 global g_scr uchar 4096 239 global g_omc uchar 4096 240 global g_nm uchar 256 241 global g_av uchar 8192 242 global g_b uchar `16777216` 243 global g_c uchar `1048576` 244 global g_t uchar `1048576` 245 global g_o uchar 8192 246 global g_hx uchar 64 247 global g_pin uchar 64 248 global g_d1 uchar 32 249 global g_stb uchar 4 250 global g_st uchar 128 251 global g_n ulong 32 252 global g_m ulong 32 253 global g_fs ulong 16 254 global g_fe ulong 16 255 note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length, 256 note 6 g_b length, 11 failures, 12 controls, 13 caught, 14 name length 257 note g_m: 0 table length, 1 field count, 2 bad read, 3 section size, 4 section address, 5 qemu present, 6 kfd absent, 258 note 7 not run, 8 llvm rows, 9 verdict rows, 10 object rows, 11 writer rows, 12 g_c length, 14 flip once, 259 note 19 plan verdict rows, 24 plan patch shift (control) 260 note g_fs/g_fe: start and end of each field of the current table row 261 note ---- output 262 fn oc c ulong to void 263 n = get g_n 5 264 if ge n len g_o 265 oflush 266 n = ulong 0 267 end 268 put g_o n uchar c 269 put g_n 5 add n 1 270 end 271 fn ot t view uchar * to void 272 for i ulong len t bound 4096 273 oc ulong get t i 274 end 275 end 276 fn onm to void 277 for i ulong get g_n 14 bound 256 278 oc ulong get g_nm i 279 end 280 end 281 fn onum v ulong to void 282 if ge v 10 283 onum div v 10 284 end 285 oc add 48 rem v 10 286 end 287 fn ohex to void 288 for j ulong 32 289 b = get sh_dig j 290 oc ulong sh_hexd uint shr b 4 291 oc ulong sh_hexd uint and b 15 292 end 293 end 294 fn oflush to void 295 r = write 1 g_o 0 get g_n 5 296 put g_n 5 0 297 end 298 fn onl to void 299 oc 10 300 oflush 301 end 302 note a failed check: FAIL KIND NAME then the reason; counts a failure 303 fn ofail kind view uchar * why view uchar * to void 304 ot t_fail 305 ot kind 306 onm 307 oc 32 308 ot why 309 onl 310 put g_n 11 add get g_n 11 1 311 end 312 fn ookn kind view uchar * to void 313 ot t_ok 314 ot kind 315 onm 316 end 317 note ---- paths: g_pa[0, g_n 0) 318 fn pclr to void 319 put g_n 0 0 320 end 321 fn pc c ulong to void 322 n = get g_n 0 323 if lt n len g_pa 324 put g_pa n uchar c 325 end 326 put g_n 0 add n 1 327 end 328 fn pt t view uchar * to void 329 for i ulong len t bound 4096 330 pc ulong get t i 331 end 332 end 333 fn pscr to void 334 for j ulong get g_n 2 bound 4096 335 pc ulong get g_scr j 336 end 337 end 338 fn pnm to void 339 for j ulong get g_n 14 bound 256 340 pc ulong get g_nm j 341 end 342 end 343 fn psn suf view uchar * to void 344 pclr 345 pscr 346 pnm 347 pt suf 348 end 349 fn nmset t view uchar * to void 350 for i ulong len t bound 256 351 put g_nm i get t i 352 end 353 put g_n 14 len t 354 end 355 note the path is usable (shorter than its buffer) 356 fn pok to bool 357 ret lt get g_n 0 len g_pa 358 end 359 note ---- files 360 fn fopn fl ulong mode ulong to int 361 if not pok 362 ret -1 363 end 364 r = fopen g_pa 0 get g_n 0 int fl int mode 365 if lt r 0 366 ret -1 367 end 368 ret int r 369 end 370 fn frd to int 371 ret fopn 524288 0 372 end 373 fn fwr to int 374 ret fopn 524865 420 375 end 376 fn fexe to int 377 if pok 378 r = unlink g_pa 0 get g_n 0 379 end 380 ret fopn 524865 448 381 end 382 fn fclo fd int to void 383 if ge fd 0 384 r = fclose fd 385 end 386 end 387 note append the file at g_pa to g_b; false when unreadable or past the buffer 388 fn bload to bool 389 fd = frd 390 if lt fd 0 391 ret false 392 end 393 n = get g_n 6 394 ok = true 395 while true bound `16777218` 396 x = read fd g_b n sub len g_b n 397 if lt x 0 398 ok = false 399 break 400 end 401 if eq x 0 402 break 403 end 404 n = add n ulong x 405 if ge n len g_b 406 ok = false 407 break 408 end 409 end 410 fclo fd 411 put g_n 6 n 412 ret ok 413 end 414 note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe) 415 fn bsave exe bool to bool 416 fd = int -1 417 if exe 418 fd = fexe 419 else 420 fd = fwr 421 end 422 if lt fd 0 423 ret false 424 end 425 n = get g_n 6 426 o = ulong 0 427 ok = true 428 while lt o n bound `16777217` 429 x = write fd g_b o sub n o 430 if le x 0 431 ok = false 432 break 433 end 434 o = add o ulong x 435 end 436 fclo fd 437 ret ok 438 end 439 note sha256 of the file at g_pa into sh_dig; false when unreadable or past 16 MiB 440 fn fhash to bool 441 fd = frd 442 if lt fd 0 443 ret false 444 end 445 n = ulong 0 446 ok = true 447 while true bound `16777218` 448 x = read fd sh_dat n sub len sh_dat n 449 if lt x 0 450 ok = false 451 break 452 end 453 if eq x 0 454 break 455 end 456 n = add n ulong x 457 if ge n len sh_dat 458 ok = false 459 break 460 end 461 end 462 fclo fd 463 if not ok 464 ret false 465 end 466 sh_all n 467 ret true 468 end 469 note the size of the file at g_pa, or 2^63 when unreadable 470 fn fsize to ulong 471 put g_n 6 0 472 if not bload 473 ret shl ulong 1 63 474 end 475 ret get g_n 6 476 end 477 note sh_dig equals the hex in g_hx 478 fn digeq to bool 479 for j ulong 32 480 b = get sh_dig j 481 if ne get g_hx mul j 2 sh_hexd uint shr b 4 482 ret false 483 end 484 if ne get g_hx add mul j 2 1 sh_hexd uint and b 15 485 ret false 486 end 487 end 488 ret true 489 end 490 note the path g_pa names an existing file (stat, never opened) 491 fn pexists to bool 492 if not pok 493 ret false 494 end 495 ret eq stat g_pa 0 get g_n 0 g_st 0 len g_st 0 496 end 497 note ---- processes 498 fn aclr to void 499 put g_n 3 2 500 put g_n 4 0 501 put g_av 0 0 502 put g_av 1 0 503 end 504 note append g_pa as one argument; false past the argument buffer 505 fn apa to bool 506 p = get g_n 3 507 n = get g_n 0 508 if or not pok gt add add p 2 n len g_av 509 ret false 510 end 511 for j ulong n bound 4096 512 put g_av add add p 2 j get g_pa j 513 end 514 put g_av p uchar and n 255 515 put g_av add p 1 uchar shr n 8 516 put g_n 3 add p add n 2 517 c = add get g_n 4 1 518 put g_n 4 c 519 put g_av 0 uchar and c 255 520 put g_av 1 uchar shr c 8 521 ret true 522 end 523 fn atx t view uchar * to void 524 pclr 525 pt t 526 z = apa 527 end 528 fn redir s int d int to void 529 if ne dupfd s d 0 long d 530 exit 127 531 end 532 end 533 note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512 534 note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed) 535 fn spawn fi int fo int fe int to ulong 536 if or lt fi 0 or lt fo 0 lt fe 0 537 fclo fi 538 fclo fo 539 fclo fe 540 ret 512 541 end 542 pid = fork 543 if lt pid 0 544 exit 2 545 end 546 if eq pid 0 547 redir fi 0 548 redir fo 1 549 redir fe 2 550 r = execprog g_av 0 get g_n 3 551 exit 127 552 end 553 fclo fi 554 fclo fo 555 fclo fe 556 t0 = monons 557 while true bound `1000000000` 558 r = waitpid int pid g_stb 0 len g_stb 1 559 if eq r pid 560 x = ulong get g_stb 0 561 if ne x 0 562 ret add 256 x 563 end 564 ret ulong get g_stb 1 565 end 566 if lt r 0 567 exit 2 568 end 569 if gt sub monons t0 `600000000000` 570 r = killpid int pid 9 571 r = waitpid int pid g_stb 0 len g_stb 0 572 ret 1000 573 end 574 q = sleepns 200000 575 end 576 exit 2 577 end 578 note run the argument list with stdin /dev/null, stdout SCRATCH/NAME.SUF, stderr SCRATCH/NAME.ERR 579 fn spawnf suf view uchar * err view uchar * to ulong 580 pclr 581 pt t_null 582 fi = frd 583 psn suf 584 fo = fwr 585 psn err 586 fe = fwr 587 ret spawn fi fo fe 588 end 589 note OMC < SCRATCH/NAME.om > SCRATCH/NAME.bin 2> SCRATCH/NAME.err; the spawn result 590 fn omcr to ulong 591 psn t_om 592 fi = frd 593 aclr 594 pclr 595 for j ulong get g_n 1 bound 4096 596 pc ulong get g_omc j 597 end 598 z = apa 599 psn t_bin 600 fo = fexe 601 psn t_err 602 fe = fwr 603 r = spawn fi fo fe 604 ret r 605 end 606 fn omc to bool 607 if ne omcr 0 608 ret false 609 end 610 psn t_err 611 ret eq fsize 0 612 end 613 note save g_b as SCRATCH/NAME.om and compile it; reported 614 fn build to bool 615 psn t_om 616 if not bsave false 617 ofail t_unit t_write 618 ret false 619 end 620 if not omc 621 ofail t_unit t_cmp 622 ret false 623 end 624 psn t_bin 625 z = fhash 626 ookn t_unit 627 ot t_sha 628 ohex 629 onl 630 ret true 631 end 632 note ---- the compiler digest 633 fn pinread to bool 634 pclr 635 pt t_pin 636 put g_n 6 0 637 if not bload 638 ret false 639 end 640 if lt get g_n 6 64 641 ret false 642 end 643 for j ulong 64 644 c = get g_b j 645 ok = or and ge c 48 le c 57 and ge c 97 le c 102 646 if not ok 647 ret false 648 end 649 put g_pin j c 650 end 651 ret true 652 end 653 fn pinok to bool 654 if not fhash 655 ret false 656 end 657 for j ulong 64 658 put g_hx j get g_pin j 659 end 660 ret digeq 661 end 662 note ---- composing sources into g_b 663 fn lit t view uchar * to void 664 n = get g_n 6 665 if gt add n len t len g_b 666 put g_m 2 1 667 ret 668 end 669 for q ulong len t bound 4096 670 put g_b add n q get t q 671 end 672 put g_n 6 add n len t 673 end 674 note append decimal v to g_b 675 fn bnum v ulong to void 676 if ge v 10 677 bnum div v 10 678 end 679 n = get g_n 6 680 if ge n len g_b 681 put g_m 2 1 682 ret 683 end 684 put g_b n uchar add 48 rem v 10 685 put g_n 6 add n 1 686 end 687 fn bch c ulong to void 688 n = get g_n 6 689 if ge n len g_b 690 put g_m 2 1 691 ret 692 end 693 put g_b n uchar c 694 put g_n 6 add n 1 695 end 696 note append the file named by text t to g_b; reported when unreadable 697 fn capp t view uchar * to bool 698 pclr 699 pt t 700 if bload 701 ret true 702 end 703 nmset t 704 ofail t_unit t_src 705 ret false 706 end 707 note cut g_b at the first line, at or after st, that starts with "fn main to int" 708 fn mcut st ulong to void 709 n = get g_n 6 710 p = st 711 while lt p n bound `16777216` 712 if mline p n 713 put g_n 6 p 714 ret 715 end 716 while and lt p n ne get g_b p 10 bound `16777216` 717 p = add p 1 718 end 719 p = add p 1 720 end 721 end 722 fn mline p ulong n ulong to bool 723 if gt add p len t_main n 724 ret false 725 end 726 for q ulong len t_main 727 if ne get g_b add p q get t_main q 728 ret false 729 end 730 end 731 ret true 732 end 733 note copy g_b to g_c (false past g_c) 734 fn tocopy to bool 735 n = get g_n 6 736 if gt n len g_c 737 ret false 738 end 739 for j ulong n bound `1048576` 740 put g_c j get g_b j 741 end 742 put g_m 12 n 743 ret true 744 end 745 note ---- tables: g_t[0, g_m 0), fields of the current row in g_fs/g_fe 746 fn tload t view uchar * to bool 747 pclr 748 pt t 749 fd = frd 750 if lt fd 0 751 ret false 752 end 753 n = ulong 0 754 ok = true 755 while true bound `1048578` 756 x = read fd g_t n sub len g_t n 757 if lt x 0 758 ok = false 759 break 760 end 761 if eq x 0 762 break 763 end 764 n = add n ulong x 765 if ge n len g_t 766 ok = false 767 break 768 end 769 end 770 fclo fd 771 put g_m 0 n 772 ret ok 773 end 774 note split the row starting at s into fields; the index of its end (a newline or the table end) 775 fn trow s ulong to ulong 776 n = get g_m 0 777 k = ulong 0 778 put g_fs 0 s 779 p = s 780 while and lt p n ne get g_t p 10 bound `1048577` 781 if and eq get g_t p 9 lt k 15 782 put g_fe k p 783 k = add k 1 784 put g_fs k add p 1 785 end 786 p = add p 1 787 end 788 put g_fe k p 789 put g_m 1 add k 1 790 ret p 791 end 792 fn tcom s ulong e ulong to bool 793 if ge s e 794 ret true 795 end 796 ret eq get g_t s 35 797 end 798 fn flen i ulong to ulong 799 ret sub get g_fe i get g_fs i 800 end 801 fn fch i ulong j ulong to ulong 802 ret ulong get g_t add get g_fs i j 803 end 804 fn fis i ulong t view uchar * to bool 805 if ne flen i len t 806 ret false 807 end 808 for j ulong len t bound 4096 809 if ne fch i j ulong get t j 810 ret false 811 end 812 end 813 ret true 814 end 815 note the name := field i; false when longer than the name buffer 816 fn fnm i ulong to bool 817 n = flen i 818 if ge n len g_nm 819 nmset t_nmlong 820 ret false 821 end 822 for j ulong n bound 256 823 put g_nm j uchar fch i j 824 end 825 put g_n 14 n 826 ret true 827 end 828 note field i as a decimal number; sets g_m 2 when it is not one 829 fn fnum i ulong to ulong 830 n = flen i 831 if or eq n 0 gt n 20 832 put g_m 2 1 833 ret 0 834 end 835 v = ulong 0 836 for j ulong n bound 20 837 c = fch i j 838 if or lt c 48 gt c 57 839 put g_m 2 1 840 ret 0 841 end 842 v = add mul v 10 sub c 48 843 end 844 ret v 845 end 846 fn hexv c ulong to ulong 847 if and ge c 48 le c 57 848 ret sub c 48 849 end 850 if and ge c 97 le c 102 851 ret sub c 87 852 end 853 put g_m 2 1 854 ret 0 855 end 856 note field i as hex (at most 16 digits) 857 fn fhexn i ulong to ulong 858 n = flen i 859 if or eq n 0 gt n 16 860 put g_m 2 1 861 ret 0 862 end 863 v = ulong 0 864 for j ulong n bound 16 865 v = or shl v 4 hexv fch i j 866 end 867 ret v 868 end 869 note field i, 64 hex digits, into g_hx; flipped once when g_m 14 is set (a control) 870 fn fhx i ulong to bool 871 if ne flen i 64 872 ret false 873 end 874 for j ulong 64 875 put g_hx j uchar fch i j 876 end 877 if eq get g_m 14 1 878 put g_m 14 0 879 if eq get g_hx 0 48 880 put g_hx 0 49 881 else 882 put g_hx 0 48 883 end 884 end 885 ret true 886 end 887 fn hfld i ulong to bool 888 if not fhx i 889 ret false 890 end 891 ret digeq 892 end 893 note the file at g_pa hashes to field i 894 fn fhfld i ulong to bool 895 if not fhash 896 ret false 897 end 898 ret hfld i 899 end 900 note find the first row whose field 0 is a and (when b is not empty) field 1 is b; fields left set 901 fn tfind a view uchar * b view uchar * to bool 902 s = ulong 0 903 n = get g_m 0 904 while lt s n bound `1048577` 905 e = trow s 906 if and fis 0 a or eq len b 0 fis 1 b 907 ret true 908 end 909 s = add e 1 910 end 911 ret false 912 end 913 note append field i to g_b with backslash escapes undone 914 fn funesc i ulong to void 915 p = get g_fs i 916 e = get g_fe i 917 while lt p e bound `1048577` 918 c = fch i sub p get g_fs i 919 if and eq c 92 lt add p 1 e 920 p = add p 1 921 c = fch i sub p get g_fs i 922 if eq c 110 923 c = 10 924 end 925 if eq c 116 926 c = 9 927 end 928 end 929 bch c 930 p = add p 1 931 end 932 end 933 note append field i to the path 934 fn fpa i ulong to void 935 for j ulong flen i bound `1048576` 936 pc fch i j 937 end 938 end 939 note ---- ELF reading over g_b[0, g_n 6) 940 fn rdle o ulong w ulong to ulong 941 if or lt add o w o gt add o w get g_n 6 942 put g_m 2 1 943 ret 0 944 end 945 v = ulong 0 946 for j ulong w bound 8 947 v = or v shl ulong get g_b add o j mul j 8 948 end 949 ret v 950 end 951 fn bat p ulong c ulong to bool 952 if ge p get g_n 6 953 ret false 954 end 955 ret eq ulong get g_b p c 956 end 957 fn strat p ulong t view uchar * to bool 958 for j ulong len t bound 64 959 if not bat add p j ulong get t j 960 ret false 961 end 962 end 963 ret bat add p len t 0 964 end 965 note the bytes at p are the name, then suf, then NUL 966 fn stnm p ulong suf view uchar * to bool 967 k = get g_n 14 968 for j ulong k bound 256 969 if not bat add p j ulong get g_nm j 970 ret false 971 end 972 end 973 for j ulong len suf bound 64 974 if not bat add add p k j ulong get suf j 975 ret false 976 end 977 end 978 ret bat add add p k len suf 0 979 end 980 note file offset of the section named t; g_m 3 its size, g_m 4 its address; g_m 2 set when absent or past the file 981 fn secf t view uchar * to ulong 982 so = rdle 40 8 983 sn = rdle 60 2 984 stro = rdle add add so mul rdle 62 2 64 24 8 985 for i ulong sn bound 65536 986 h = add so mul i 64 987 if strat add stro rdle h 4 t 988 ret sech h 989 end 990 end 991 put g_m 3 0 992 put g_m 2 1 993 ret 0 994 end 995 fn sech h ulong to ulong 996 put g_m 3 rdle add h 32 8 997 put g_m 4 rdle add h 16 8 998 o = rdle add h 24 8 999 e = add o get g_m 3 1000 if or lt e o gt e get g_n 6 1001 put g_m 2 1 1002 end 1003 ret o 1004 end 1005 note the value of the symbol named NAME then suf; g_m 2 set when absent 1006 fn symv suf view uchar * to ulong 1007 so = secf t_strtab 1008 sy = secf t_symtab 1009 n = div get g_m 3 24 1010 for i ulong n bound `1048576` 1011 e = add sy mul i 24 1012 if stnm add so rdle e 4 suf 1013 ret rdle add e 8 8 1014 end 1015 end 1016 put g_m 2 1 1017 ret 0 1018 end 1019 note sha256 of g_b[o, o+n) into sh_dig 1020 fn bhash o ulong n ulong to void 1021 if or lt add o n o gt add o n get g_n 6 1022 put g_m 2 1 1023 n = 0 1024 end 1025 for j ulong n bound `16777216` 1026 put sh_dat j get g_b add o j 1027 end 1028 sh_all n 1029 end 1030 note ---- 1. llvm-mc parity 1031 note the writer: SCRATCH/hsaco.bin TABLE > SCRATCH/NAME.hsaco; TABLE is gpu/amd/gfx942/NAME.isa (tbl 0) or SCRATCH/NAME.isa 1032 fn wrun tbl ulong to ulong 1033 aclr 1034 nm0 = get g_n 14 1035 pclr 1036 pscr 1037 pt t_hsaco 1038 pt t_bin 1039 z = apa 1040 pclr 1041 if eq tbl 0 1042 pt t_isa 1043 pnm 1044 pt t_isx 1045 else 1046 pscr 1047 pnm 1048 pt t_isx 1049 end 1050 z = apa 1051 ret spawnf t_hs t_hse 1052 end 1053 note load SCRATCH/NAME.hsaco into g_b 1054 fn objload to bool 1055 put g_n 6 0 1056 psn t_hs 1057 ret bload 1058 end 1059 note the object in g_b against the current sections row (NAME is the kernel) 1060 fn secchk to bool 1061 put g_m 2 0 1062 xo = secf t_text 1063 tn = get g_m 3 1064 bhash xo tn 1065 ok = and eq tn fnum 1 hfld 2 1066 no = secf t_note 1067 nn = get g_m 3 1068 bhash no nn 1069 ok = and ok and eq nn fnum 3 hfld 4 1070 ro = secf t_rod 1071 rn = get g_m 3 1072 if lt rn 24 1073 ret false 1074 end 1075 bhash ro 16 1076 ok = and ok hfld 5 1077 bhash add ro 24 sub rn 24 1078 ok = and ok hfld 6 1079 disp = rdle add ro 16 8 1080 kv = symv t_e 1081 dv = symv t_kd 1082 ok = and ok eq disp sub kv dv 1083 ok = and ok eq rdle 48 4 1356 1084 ret and ok eq get g_m 2 0 1085 end 1086 fn slsec to void 1087 if not tload t_tsec 1088 nmset t_tsec 1089 ofail t_tbl t_unread 1090 ret 1091 end 1092 s = ulong 0 1093 n = get g_m 0 1094 while lt s n bound `1048577` 1095 e = trow s 1096 if not tcom s e 1097 if or ne get g_m 1 7 not fnm 0 1098 ofail t_sec t_rowbad 1099 else 1100 r = wrun 0 1101 if ne r 0 1102 ofail t_sec t_wexit 1103 else 1104 if not objload 1105 ofail t_sec t_noobj 1106 else 1107 if secchk 1108 ookn t_sec 1109 ot t_textn 1110 onum fnum 1 1111 ot t_noten 1112 onum fnum 3 1113 onl 1114 put g_m 8 add get g_m 8 1 1115 psn t_ok_ 1116 put g_n 6 0 1117 z = bsave false 1118 else 1119 ofail t_sec t_mism 1120 end 1121 end 1122 end 1123 end 1124 end 1125 s = add e 1 1126 end 1127 end 1128 note ---- controls 1129 fn caught c bool what view uchar * to void 1130 put g_n 12 add get g_n 12 1 1131 nmset what 1132 if c 1133 ot t_ok 1134 ot t_ctl 1135 onm 1136 ot t_caught 1137 onl 1138 put g_n 13 add get g_n 13 1 1139 else 1140 ofail t_ctl t_esc 1141 end 1142 end 1143 note a compiler one byte longer must fail the digest check 1144 fn cwrong to void 1145 pclr 1146 for j ulong get g_n 1 bound 4096 1147 pc ulong get g_omc j 1148 end 1149 put g_n 6 0 1150 ok = bload 1151 n = get g_n 6 1152 put g_b n 0 1153 put g_n 6 add n 1 1154 nmset t_plus 1155 psn t_e 1156 ok = and ok bsave true 1157 psn t_e 1158 c = and ok not pinok 1159 caught c t_plus 1160 end 1161 note the vadd llvm row with one digest character changed must not match the vadd object 1162 fn cflip to void 1163 nmset t_vadd 1164 ok = and objload tfind t_vadd t_e 1165 put g_m 14 1 1166 c = and ok not secchk 1167 put g_m 14 0 1168 caught c t_flip 1169 end 1170 note vadd.isa with the operand 260 changed to 261 must not match the vadd llvm row 1171 fn c261 to void 1172 put g_n 6 0 1173 pclr 1174 pt t_isa 1175 pt t_vadd 1176 pt t_isx 1177 ok = bload 1178 n = get g_n 6 1179 hit = n 1180 for p ulong n bound `16777216` 1181 if and eq hit n bmatch p t_f260 1182 hit = p 1183 end 1184 end 1185 nmset t_k261 1186 if or not ok eq hit n 1187 ofail t_ctl t_noapp 1188 ret 1189 end 1190 put g_b add hit 6 49 1191 psn t_isx 1192 ok = bsave false 1193 r = wrun 1 1194 c = ne r 0 1195 if not c 1196 z = objload 1197 nmset t_vadd 1198 c = not and tfind t_vadd t_e secchk 1199 end 1200 caught and ok c t_k261 1201 end 1202 fn bmatch p ulong t view uchar * to bool 1203 if gt add p len t get g_n 6 1204 ret false 1205 end 1206 for q ulong len t bound 64 1207 if ne get g_b add p q get t q 1208 ret false 1209 end 1210 end 1211 ret true 1212 end 1213 note ---- 2. launcher verdicts 1214 note compose the launcher sources (main.om too when withmain) after om2 (and the x86 target line) 1215 fn lsrc x86 bool withmain bool to bool 1216 put g_n 6 0 1217 if x86 1218 lit t_x86 1219 end 1220 lit t_om2 1221 ok = capp t_lc 1222 ok = and ok capp t_le 1223 ok = and ok capp t_ldv 1224 ok = and ok capp t_ldi 1225 ok = and ok capp t_lpl 1226 if withmain 1227 ok = and ok capp t_lmn 1228 end 1229 ret and ok capp t_cli 1230 end 1231 fn blaunch x86 bool to void 1232 if not lsrc x86 true 1233 ret 1234 end 1235 if x86 1236 nmset t_lx 1237 else 1238 nmset t_la 1239 end 1240 z = build 1241 end 1242 note an object built in slice 1 that passed its llvm row and hashes to field 2 1243 fn objchk to bool 1244 psn t_ok_ 1245 if not pexists 1246 ret false 1247 end 1248 psn t_hs 1249 ret fhfld 2 1250 end 1251 fn vobj to void 1252 if or ne get g_m 1 3 not fnm 1 1253 ofail t_ver t_rowbad 1254 ret 1255 end 1256 if objchk 1257 ookn t_ver 1258 ot t_sha 1259 ohex 1260 onl 1261 put g_m 10 add get g_m 10 1 1262 put g_m 9 add get g_m 9 1 1263 else 1264 ofail t_ver t_mism 1265 end 1266 end 1267 note store the w low bytes of v at o in g_b, or them in when isor 1268 fn stle o ulong w ulong v ulong isor bool to void 1269 x = v 1270 if isor 1271 x = or x rdle o w 1272 end 1273 if gt add o w get g_n 6 1274 put g_m 2 1 1275 ret 1276 end 1277 for j ulong w bound 8 1278 put g_b add o j uchar and shr x mul j 8 255 1279 end 1280 end 1281 fn vmut to void 1282 if or ne get g_m 1 7 not fnm 1 1283 ofail t_ver t_rowbad 1284 ret 1285 end 1286 put g_m 2 0 1287 nmset t_vadd 1288 z = objload 1289 kd = ulong 0 1290 if fis 3 t_bk 1291 kv = symv t_kd 1292 ro = secf t_rod 1293 kd = sub add ro kv get g_m 4 1294 end 1295 o = add kd fnum 4 1296 v = fnum 5 1297 if fis 2 t_keep 1298 if gt o get g_n 6 1299 put g_m 2 1 1300 end 1301 put g_n 6 o 1302 end 1303 if fis 2 t_set16 1304 stle o 2 v false 1305 end 1306 if fis 2 t_set32 1307 stle o 4 v false 1308 end 1309 if fis 2 t_set64 1310 stle o 8 v false 1311 end 1312 if fis 2 t_or16 1313 stle o 2 v true 1314 end 1315 if fis 2 t_or32 1316 stle o 4 v true 1317 end 1318 z = fnm 1 1319 psn t_hs 1320 ok = and eq get g_m 2 0 bsave false 1321 if and ok fhfld 6 1322 ookn t_ver 1323 ot t_sha 1324 ohex 1325 onl 1326 put g_m 9 add get g_m 9 1 1327 else 1328 ofail t_ver t_inmis 1329 end 1330 end 1331 fn vfile to void 1332 if or ne get g_m 1 4 not fnm 1 1333 ofail t_ver t_rowbad 1334 ret 1335 end 1336 put g_m 2 0 1337 put g_n 6 0 1338 n = flen 3 1339 for j ulong div n 2 bound `1048576` 1340 bch or shl hexv fch 3 mul j 2 4 hexv fch 3 add mul j 2 1 1341 end 1342 psn t_e 1343 ok = and eq get g_m 2 0 bsave false 1344 if and ok fhfld 2 1345 ookn t_ver 1346 ot t_sha 1347 ohex 1348 onl 1349 put g_m 9 add get g_m 9 1 1350 else 1351 ofail t_ver t_inmis 1352 end 1353 end 1354 fn vunit to void 1355 if or ne get g_m 1 4 not fnm 1 1356 ofail t_ver t_rowbad 1357 ret 1358 end 1359 put g_m 2 0 1360 if not lsrc false false 1361 ret 1362 end 1363 funesc 3 1364 z = fnm 1 1365 psn t_om 1366 ok = and eq get g_m 2 0 bsave false 1367 if not and ok fhfld 2 1368 ofail t_ver t_inmis 1369 ret 1370 end 1371 z = build 1372 end 1373 note the argv of field 3: ^X is SCRATCH/X.bin, @X is SCRATCH/X, others literal; x86 runs under qemu 1374 fn rargv x86 bool to bool 1375 aclr 1376 ok = true 1377 if x86 1378 pclr 1379 pt t_qemu 1380 ok = apa 1381 end 1382 p = get g_fs 3 1383 e = get g_fe 3 1384 b = get g_fs 3 1385 while lt p e bound `1048577` 1386 q = p 1387 while and lt q e ne get g_t q 32 bound `1048577` 1388 q = add q 1 1389 end 1390 pclr 1391 c = get g_t p 1392 st = p 1393 if or eq c 94 eq c 64 1394 pscr 1395 st = add p 1 1396 end 1397 if isemp p q 1398 st = q 1399 end 1400 for j ulong sub q st bound `1048576` 1401 pc ulong get g_t add st j 1402 end 1403 if eq c 94 1404 pt t_bin 1405 end 1406 ok = and ok apa 1407 p = add q 1 1408 end 1409 ret ok 1410 end 1411 note the second word of field 3 is t 1412 fn fverb t view uchar * to bool 1413 p = get g_fs 3 1414 e = get g_fe 3 1415 while and lt p e ne get g_t p 32 bound `1048577` 1416 p = add p 1 1417 end 1418 p = add p 1 1419 if gt add p len t e 1420 ret false 1421 end 1422 for j ulong len t bound 64 1423 if ne get g_t add p j get t j 1424 ret false 1425 end 1426 end 1427 q = add p len t 1428 ret or eq q e eq get g_t q 32 1429 end 1430 note the file at g_pa holds the unescaped field i (flipped once when g_m 14 is set) 1431 fn fcmp i ulong to bool 1432 put g_n 6 0 1433 if not bload 1434 ret false 1435 end 1436 n1 = get g_n 6 1437 funesc i 1438 n2 = get g_n 6 1439 if eq get g_m 14 1 1440 put g_m 14 0 1441 if gt n2 n1 1442 put g_b n1 uchar xor ulong get g_b n1 1 1443 else 1444 bch 88 1445 n2 = get g_n 6 1446 end 1447 end 1448 if ne sub n2 n1 n1 1449 ret false 1450 end 1451 for j ulong n1 bound `16777216` 1452 if ne get g_b j get g_b add n1 j 1453 ret false 1454 end 1455 end 1456 ret true 1457 end 1458 note run the current run row; 0 ok, 1 mismatch, 2 not run 1459 fn vrun1 to ulong 1460 x86 = fis 1 t_vx86 1461 if and x86 eq get g_m 5 0 1462 ret 2 1463 end 1464 dev = or or fverb t_vvadd fverb t_vrun fverb t_vplan 1465 if and dev eq get g_m 6 0 1466 ret 3 1467 end 1468 if not rargv x86 1469 ret 1 1470 end 1471 nmset t_krun 1472 r = spawnf t_out t_err 1473 put g_m 2 0 1474 ok = eq r fnum 4 1475 psn t_out 1476 ok = and ok fcmp 5 1477 psn t_err 1478 ok = and ok fcmp 6 1479 if and ok eq get g_m 2 0 1480 ret 0 1481 end 1482 ret 1 1483 end 1484 fn vrun to void 1485 if ne get g_m 1 7 1486 nmset t_krun 1487 ofail t_ver t_rowbad 1488 ret 1489 end 1490 r = vrun1 1491 put g_n 14 0 1492 for j ulong flen 2 bound 256 1493 put g_nm j uchar fch 2 j 1494 put g_n 14 add j 1 1495 end 1496 if eq r 0 1497 ookn t_ver 1498 ot t_exit 1499 onum fnum 4 1500 onl 1501 put g_m 9 add get g_m 9 1 1502 ret 1503 end 1504 if ge r 2 1505 ot t_nr 1506 ot t_ver 1507 onm 1508 if eq r 2 1509 ot t_noq 1510 else 1511 ot t_dev 1512 end 1513 onl 1514 put g_m 7 add get g_m 7 1 1515 ret 1516 end 1517 ofail t_ver t_mism 1518 end 1519 fn sllaunch to void 1520 pclr 1521 pt t_qemu 1522 if pexists 1523 put g_m 5 1 1524 end 1525 pclr 1526 pt t_kfd 1527 if not pexists 1528 put g_m 6 1 1529 end 1530 blaunch false 1531 blaunch true 1532 if not tload t_tlv 1533 nmset t_tlv 1534 ofail t_tbl t_unread 1535 ret 1536 end 1537 s = ulong 0 1538 n = get g_m 0 1539 while lt s n bound `1048577` 1540 e = trow s 1541 if not tcom s e 1542 if fis 0 t_kobj 1543 vobj 1544 else 1545 if fis 0 t_kmut 1546 vmut 1547 else 1548 if fis 0 t_kfile 1549 vfile 1550 else 1551 if fis 0 t_kunit 1552 vunit 1553 else 1554 if fis 0 t_krun 1555 vrun 1556 else 1557 if fis 0 t_knr 1558 vnotrun 1559 else 1560 nmset t_tlv 1561 ofail t_ver t_rowbad 1562 end 1563 end 1564 end 1565 end 1566 end 1567 end 1568 end 1569 s = add e 1 1570 end 1571 end 1572 note an object with no llvm row (the 261 control's) must not pass the object check 1573 fn cnorow to void 1574 nmset t_k261 1575 put g_m 1 3 1576 c = not objchk 1577 caught c t_nrow 1578 end 1579 note the first launcher verdict row with its expected bytes changed must not match 1580 fn cvflip to void 1581 ok = tfind t_krun t_a64 1582 if ok 1583 put g_m 14 1 1584 r = vrun1 1585 put g_m 14 0 1586 ok = eq r 1 1587 end 1588 caught ok t_vflip 1589 end 1590 note ---- 6. plan verdicts (was tests/amd-kfd-launch/plan-check.py, CPU part) 1591 note SCRATCH/BASE with the bytes of field 4 written at field 3 (one later when g_m 24 is set), saved as SCRATCH/NAME; 1592 note true when it hashes to field 5 1593 fn vpatch1 to bool 1594 put g_m 2 0 1595 put g_n 6 0 1596 if not fnm 2 1597 ret false 1598 end 1599 psn t_e 1600 ok = bload 1601 o = add fnum 3 get g_m 24 1602 n = flen 4 1603 if or ne rem n 2 0 gt add o div n 2 get g_n 6 1604 put g_m 2 1 1605 end 1606 if eq get g_m 2 0 1607 for j ulong div n 2 bound `1048576` 1608 put g_b add o j uchar or shl hexv fch 4 mul j 2 4 hexv fch 4 add mul j 2 1 1609 end 1610 end 1611 if not fnm 1 1612 ret false 1613 end 1614 psn t_e 1615 ok = and ok and eq get g_m 2 0 bsave false 1616 ret and ok fhfld 5 1617 end 1618 fn vpatch to void 1619 if ne get g_m 1 6 1620 nmset t_kpat 1621 ofail t_ver t_rowbad 1622 ret 1623 end 1624 if vpatch1 1625 ookn t_ver 1626 ot t_sha 1627 ohex 1628 onl 1629 put g_m 9 add get g_m 9 1 1630 else 1631 ofail t_ver t_inmis 1632 end 1633 end 1634 fn vnotrun to void 1635 if or ne get g_m 1 3 not fnm 1 1636 nmset t_knr 1637 ofail t_ver t_rowbad 1638 ret 1639 end 1640 ot t_nr 1641 ot t_ver 1642 onm 1643 ot t_rsn 1644 for j ulong flen 2 bound `1048576` 1645 oc fch 2 j 1646 end 1647 onl 1648 put g_m 7 add get g_m 7 1 1649 end 1650 note true when the token g_t[p, q) is '' (an empty argument) 1651 fn isemp p ulong q ulong to bool 1652 if ne sub q p 2 1653 ret false 1654 end 1655 ret and eq get g_t p 39 eq get g_t add p 1 39 1656 end 1657 fn planrow to void 1658 if fis 0 t_kfile 1659 vfile 1660 ret 1661 end 1662 if fis 0 t_kpat 1663 vpatch 1664 ret 1665 end 1666 if fis 0 t_krun 1667 vrun 1668 ret 1669 end 1670 if fis 0 t_knr 1671 vnotrun 1672 ret 1673 end 1674 nmset t_tpv 1675 ofail t_ver t_rowbad 1676 end 1677 note the start of the first row whose field 0 is a and field i is b; the table length when none 1678 fn tfrow a view uchar * i ulong b view uchar * to ulong 1679 s = ulong 0 1680 n = get g_m 0 1681 while lt s n bound `1048577` 1682 e = trow s 1683 if and fis 0 a fis i b 1684 ret s 1685 end 1686 s = add e 1 1687 end 1688 ret n 1689 end 1690 note controls: the bad-magic patch written one byte later must not hash as recorded; the a64 bad-magic refusal 1691 note row run on valid.plan's bytes must not give its recorded verdict (runs only when /dev/kfd is absent) 1692 fn cplan to void 1693 s = tfrow t_kpat 1 t_bmp 1694 ok = lt s get g_m 0 1695 if ok 1696 e = trow s 1697 put g_m 24 1 1698 ok = not vpatch1 1699 put g_m 24 0 1700 end 1701 caught ok t_cshift 1702 if eq get g_m 6 0 1703 nmset t_cvalid 1704 ot t_nr 1705 ot t_ctl 1706 onm 1707 ot t_dev 1708 onl 1709 put g_m 7 add get g_m 7 1 1710 ret 1711 end 1712 put g_n 6 0 1713 pclr 1714 pscr 1715 pt t_vpl 1716 ok = bload 1717 pclr 1718 pscr 1719 pt t_bmp 1720 ok = and ok bsave false 1721 s = tfrow t_krun 2 t_cbm 1722 ok = and ok lt s get g_m 0 1723 if ok 1724 e = trow s 1725 ok = eq vrun1 1 1726 end 1727 caught ok t_cvalid 1728 end 1729 fn slplan to void 1730 if not tload t_tpv 1731 nmset t_tpv 1732 ofail t_tbl t_unread 1733 ret 1734 end 1735 v0 = get g_m 9 1736 s = ulong 0 1737 n = get g_m 0 1738 while lt s n bound `1048577` 1739 e = trow s 1740 if not tcom s e 1741 planrow 1742 end 1743 s = add e 1 1744 end 1745 put g_m 19 sub get g_m 9 v0 1746 cplan 1747 end 1748 note ---- 3. writer verdicts 1749 note g_b := sgemm.isa up to its first line starting "I " 1750 fn sopphdr to bool 1751 put g_n 6 0 1752 pclr 1753 pt t_isa 1754 pt t_sgemm 1755 pt t_isx 1756 if not bload 1757 ret false 1758 end 1759 n = get g_n 6 1760 p = ulong 0 1761 while lt p n bound `16777216` 1762 if and bat p 73 bat add p 1 32 1763 put g_n 6 p 1764 ret true 1765 end 1766 while and lt p n ne get g_b p 10 bound `16777216` 1767 p = add p 1 1768 end 1769 p = add p 1 1770 end 1771 ret true 1772 end 1773 fn waits k ulong to void 1774 for j ulong k bound `1000000` 1775 lit t_wait 1776 end 1777 end 1778 fn sopp a view uchar * k ulong b view uchar * to bool 1779 if not sopphdr 1780 ret false 1781 end 1782 lit a 1783 waits k 1784 lit b 1785 lit t_end 1786 ret true 1787 end 1788 note g_b := fp8gemv.isa (and a copy in g_c) 1789 fn fp8load to bool 1790 put g_n 6 0 1791 pclr 1792 pt t_isa 1793 pt t_fp8 1794 pt t_isx 1795 if not bload 1796 ret false 1797 end 1798 ret tocopy 1799 end 1800 fn isws c ulong to bool 1801 ret or eq c 32 and ge c 9 le c 13 1802 end 1803 note the F/B/D/I lines whose second word is not 4 get `1000000` added to it, words joined by one space 1804 fn sparse to bool 1805 if not fp8load 1806 ret false 1807 end 1808 put g_n 6 0 1809 n = get g_m 12 1810 p = ulong 0 1811 while lt p n bound `1048577` 1812 q = p 1813 while and lt q n ne get g_c q 10 bound `1048577` 1814 q = add q 1 1815 end 1816 sline p q 1817 bch 10 1818 p = add q 1 1819 end 1820 ret true 1821 end 1822 fn gcw p ulong q ulong to ulong 1823 while and lt p q isws ulong get g_c p bound `1048577` 1824 p = add p 1 1825 end 1826 ret p 1827 end 1828 fn gce p ulong q ulong to ulong 1829 while and lt p q not isws ulong get g_c p bound `1048577` 1830 p = add p 1 1831 end 1832 ret p 1833 end 1834 fn sline p ulong q ulong to void 1835 a = gcw p q 1836 ae = gce a q 1837 b = gcw ae q 1838 be = gce b q 1839 four = or eq b be and eq sub be b 1 eq get g_c b 52 1840 if and not four stag a ae 1841 bch ulong get g_c a 1842 bch 32 1843 semit b be q 1844 ret 1845 end 1846 for j ulong sub q p bound `1048576` 1847 bch ulong get g_c add p j 1848 end 1849 end 1850 note the first word is one of F B D I 1851 fn stag a ulong ae ulong to bool 1852 c = ulong get g_c a 1853 ret and eq sub ae a 1 or or eq c 70 eq c 66 or eq c 68 eq c 73 1854 end 1855 note the second word plus `1000000`, then the remaining words, each after one space 1856 fn semit b ulong be ulong q ulong to void 1857 v = ulong 0 1858 for j ulong sub be b bound 20 1859 v = add mul v 10 sub ulong get g_c add b j 48 1860 end 1861 bnum add v `1000000` 1862 w = gcw be q 1863 while lt w q bound `1048577` 1864 we = gce w q 1865 bch 32 1866 for j ulong sub we w bound `1048576` 1867 bch ulong get g_c add w j 1868 end 1869 w = gcw we q 1870 end 1871 end 1872 fn grow to bool 1873 if not fp8load 1874 ret false 1875 end 1876 for i ulong 24 1877 lit t_fi 1878 bnum add i 11 1879 lit t_fi2 1880 bnum add i 11 1881 lit t_fi3 1882 end 1883 ret true 1884 end 1885 note generate SCRATCH/LABEL.isa for the current isa row 1886 fn wisa to void 1887 if or ne get g_m 1 3 not fnm 1 1888 ofail t_wri t_rowbad 1889 ret 1890 end 1891 put g_m 2 0 1892 ok = false 1893 if fis 1 t_fmax 1894 ok = sopp t_br 32767 t_t99 1895 end 1896 if fis 1 t_bmin 1897 ok = sopp t_t99 32767 t_br 1898 end 1899 if fis 1 t_fovf 1900 ok = sopp t_br 32768 t_t99 1901 end 1902 if fis 1 t_bovf 1903 ok = sopp t_t99 32768 t_br 1904 end 1905 if fis 1 t_undl 1906 ok = sopp t_br 0 t_e 1907 end 1908 if fis 1 t_dupl 1909 ok = sopp t_t99 0 t_t99b 1910 end 1911 if fis 1 t_sparse 1912 ok = sparse 1913 end 1914 if fis 1 t_grow 1915 ok = grow 1916 end 1917 if fis 1 t_undf 1918 ok = fp8load 1919 lit t_i1m 1920 end 1921 if not ok 1922 ofail t_wri t_unk 1923 ret 1924 end 1925 psn t_isx 1926 ok = and eq get g_m 2 0 bsave false 1927 if and ok fhfld 2 1928 ookn t_wri 1929 ot t_isx 1930 ot t_sha 1931 ohex 1932 onl 1933 put g_m 11 add get g_m 11 1 1934 else 1935 ofail t_wri t_inmis 1936 end 1937 end 1938 note sopp LABEL EXIT INDEX WORD and format LABEL EXIT SHA 1939 fn wver issopp bool to void 1940 if or ne get g_m 1 5 not fnm 1 1941 if or issopp ne get g_m 1 4 1942 ofail t_wri t_rowbad 1943 ret 1944 end 1945 end 1946 z = fnm 1 1947 put g_m 2 0 1948 want = fnum 2 1949 r = wrun 1 1950 ok = eq r want 1951 if and ok eq want 0 1952 if issopp 1953 z = objload 1954 xo = secf t_text 1955 ok = eq rdle add xo mul fnum 3 4 4 fhexn 4 1956 else 1957 psn t_hs 1958 ok = fhfld 3 1959 end 1960 end 1961 if and ok ne want 0 1962 psn t_hs 1963 ok = eq fsize 0 1964 end 1965 if and ok eq get g_m 2 0 1966 ookn t_wri 1967 ot t_exit 1968 onum r 1969 onl 1970 put g_m 11 add get g_m 11 1 1971 else 1972 ofail t_wri t_wexit 1973 end 1974 end 1975 note the MessagePack probe main of boundaries.py, appended to g_b 1976 fn mpmain to void 1977 lit t_fmn 1978 mpu 0 1979 for k ulong 5 1980 w = mpw k 1981 mpu pw1 w 1982 if lt w 64 1983 mpu shl ulong 1 w 1984 end 1985 end 1986 for i ulong 6 1987 lit t_mps 1988 bnum i 1989 lit t_mpn 1990 bnum mps i 1991 bch 32 1992 bnum add 65 i 1993 bch 10 1994 lit t_mpstr 1995 bnum i 1996 bch 10 1997 end 1998 lit t_mpend 1999 end 2000 fn mpw k ulong to ulong 2001 if eq k 0 2002 ret 7 2003 end 2004 if eq k 1 2005 ret 8 2006 end 2007 if eq k 2 2008 ret 16 2009 end 2010 if eq k 3 2011 ret 32 2012 end 2013 ret 64 2014 end 2015 note the string sizes: 2^w - 1 and 2^w for w in 5, 8, 16 2016 fn mps i ulong to ulong 2017 w = ulong 16 2018 if lt i 2 2019 w = 5 2020 else 2021 if lt i 4 2022 w = 8 2023 end 2024 end 2025 if eq rem i 2 0 2026 ret pw1 w 2027 end 2028 ret shl ulong 1 w 2029 end 2030 note 2^w - 1 for w in 1..64 2031 fn pw1 w ulong to ulong 2032 ret shr ulong `18446744073709551615` sub 64 w 2033 end 2034 fn mpu v ulong to void 2035 lit t_mpu 2036 bnum v 2037 bch 10 2038 end 2039 note big-endian n bytes of v 2040 fn bbe v ulong n ulong to void 2041 for j ulong n bound 8 2042 bch and shr v mul sub sub n 1 j 8 255 2043 end 2044 end 2045 note the MessagePack spec bytes for one uint 2046 fn xuint v ulong to void 2047 if lt v 128 2048 bch v 2049 ret 2050 end 2051 if lt v 256 2052 bch 204 2053 bbe v 1 2054 ret 2055 end 2056 if lt v 65536 2057 bch 205 2058 bbe v 2 2059 ret 2060 end 2061 if lt v `4294967296` 2062 bch 206 2063 bbe v 4 2064 ret 2065 end 2066 bch 207 2067 bbe v 8 2068 end 2069 fn xstr n ulong f ulong to void 2070 if lt n 32 2071 bch or 160 n 2072 else 2073 if lt n 256 2074 bch 217 2075 bbe n 1 2076 else 2077 if lt n 65536 2078 bch 218 2079 bbe n 2 2080 else 2081 bch 219 2082 bbe n 4 2083 end 2084 end 2085 end 2086 for j ulong n bound `4294967296` 2087 bch f 2088 end 2089 end 2090 fn mpexp to void 2091 xuint 0 2092 for k ulong 5 2093 w = mpw k 2094 xuint pw1 w 2095 if lt w 64 2096 xuint shl ulong 1 w 2097 end 2098 end 2099 for i ulong 6 2100 xstr mps i add 65 i 2101 end 2102 end 2103 note g_b := hsaco.om up to "fn main to int", with every line equal to a replaced by b (none when a is empty) 2104 fn mpsrc a view uchar * b view uchar * to bool 2105 put g_n 6 0 2106 if not capp t_hsom 2107 ret false 2108 end 2109 mcut 0 2110 if eq len a 0 2111 mpmain 2112 ret true 2113 end 2114 if not tocopy 2115 ret false 2116 end 2117 put g_n 6 0 2118 n = get g_m 12 2119 p = ulong 0 2120 hit = false 2121 while lt p n bound `1048577` 2122 q = ceol p 2123 if cline p q a 2124 lit b 2125 hit = true 2126 else 2127 ccopy p q 2128 end 2129 if lt q n 2130 bch 10 2131 end 2132 p = add q 1 2133 end 2134 mpmain 2135 ret hit 2136 end 2137 note the end of the g_c line starting at p 2138 fn ceol p ulong to ulong 2139 n = get g_m 12 2140 q = p 2141 while and lt q n ne get g_c q 10 bound `1048577` 2142 q = add q 1 2143 end 2144 ret q 2145 end 2146 fn ccopy p ulong q ulong to void 2147 for j ulong sub q p bound `1048576` 2148 bch ulong get g_c add p j 2149 end 2150 end 2151 fn cline p ulong q ulong t view uchar * to bool 2152 if ne sub q p len t 2153 ret false 2154 end 2155 for j ulong len t bound 64 2156 if ne get g_c add p j get t j 2157 ret false 2158 end 2159 end 2160 ret true 2161 end 2162 note compile SCRATCH/NAME.om from g_b and run it; stdout in SCRATCH/NAME.out; true when both exit 0 2163 fn mprun to bool 2164 psn t_om 2165 if not bsave false 2166 ret false 2167 end 2168 if not omc 2169 ret false 2170 end 2171 aclr 2172 psn t_bin 2173 z = apa 2174 ret eq spawnf t_out t_err 0 2175 end 2176 fn wmp to void 2177 if ne get g_m 1 4 2178 nmset t_kmp 2179 ofail t_wri t_rowbad 2180 ret 2181 end 2182 put g_m 2 0 2183 nmset t_mpm 2184 put g_n 6 0 2185 mpmain 2186 psn t_om 2187 ok = and eq get g_m 2 0 bsave false 2188 if not and ok fhfld 3 2189 ofail t_wri t_inmis 2190 ret 2191 end 2192 nmset t_mpe 2193 put g_n 6 0 2194 mpexp 2195 psn t_e 2196 ok = and eq get g_m 2 0 bsave false 2197 ok = and ok eq get g_n 6 fnum 2 2198 if not and ok fhfld 1 2199 ofail t_wri t_mism 2200 ret 2201 end 2202 ookn t_wri 2203 ot t_bytes 2204 onum fnum 2 2205 onl 2206 nmset t_mpo 2207 ok = and mpsrc t_e t_e2 mprun 2208 psn t_out 2209 if and ok fhfld 1 2210 ookn t_wri 2211 ot t_sha 2212 ohex 2213 onl 2214 put g_m 11 add get g_m 11 1 2215 else 2216 ofail t_wri t_mism 2217 end 2218 end 2219 note a MessagePack mutant must apply, compile and run, and give other bytes 2220 fn cmp1 k view uchar * a view uchar * b view uchar * to void 2221 nmset k 2222 if not mpsrc a b 2223 ofail t_ctl t_noapp 2224 ret 2225 end 2226 ok = mprun 2227 c = false 2228 if ok 2229 psn t_out 2230 c = not fhfld 1 2231 end 2232 caught and ok c k 2233 end 2234 fn slwriter to void 2235 if not tload t_twv 2236 nmset t_twv 2237 ofail t_tbl t_unread 2238 ret 2239 end 2240 s = ulong 0 2241 n = get g_m 0 2242 while lt s n bound `1048577` 2243 e = trow s 2244 if not tcom s e 2245 if fis 0 t_kisa 2246 wisa 2247 else 2248 if fis 0 t_ksopp 2249 wver true 2250 else 2251 if fis 0 t_kfmt 2252 wver false 2253 else 2254 if fis 0 t_kmp 2255 wmp 2256 cmp1 t_mpk1 t_mpl1 t_mpr1 2257 cmp1 t_mpk2 t_mpl2 t_mpr2 2258 else 2259 nmset t_twv 2260 ofail t_wri t_rowbad 2261 end 2262 end 2263 end 2264 end 2265 end 2266 s = add e 1 2267 end 2268 end 2269 note ---- loader controls: targets refuses a wrong machine (33) and a truncated object (34) 2270 fn tgrun to ulong 2271 aclr 2272 nm = get g_n 14 2273 pclr 2274 pscr 2275 pt t_tgts 2276 pt t_bin 2277 z = apa 2278 atx t_load 2279 atx t_fmt 2280 psn t_hs 2281 z = apa 2282 atx t_gfx 2283 ret spawnf t_out t_err 2284 end 2285 fn cloader to void 2286 put g_n 6 0 2287 if not capp t_tgom 2288 ret 2289 end 2290 nmset t_tgts 2291 if not build 2292 ret 2293 end 2294 nmset t_vadd 2295 z = objload 2296 put g_b 48 65 2297 nmset t_wmach 2298 psn t_hs 2299 ok = bsave false 2300 r = tgrun 2301 caught and ok eq r 33 t_wmach 2302 nmset t_vadd 2303 z = objload 2304 if gt get g_n 6 600 2305 put g_n 6 600 2306 end 2307 nmset t_trunc 2308 psn t_hs 2309 ok = bsave false 2310 r = tgrun 2311 caught and ok eq r 34 t_trunc 2312 end 2313 note ---- 5. KFD host verdicts; g_m 16 cursor, 17 match position, 18 kfd checks, 20..22 numbers 2314 fn isdig c ulong to bool 2315 ret and ge c 48 le c 57 2316 end 2317 fn isst c ulong to bool 2318 ret or eq c 32 eq c 9 2319 end 2320 note the index of the first byte at or after p in g_b[0, g_n 6) that is not a space or tab 2321 fn kskip p ulong to ulong 2322 n = get g_n 6 2323 q = p 2324 while and lt q n isst ulong get g_b q bound `16777217` 2325 q = add q 1 2326 end 2327 ret q 2328 end 2329 note the decimal at p in g_b into g_m (20 + slot); its end, or 2^63 when it is not one 2330 fn kdec p ulong slot ulong to ulong 2331 n = get g_n 6 2332 q = p 2333 v = ulong 0 2334 while and lt q n isdig ulong get g_b q bound `16777217` 2335 if ge sub q p 20 2336 ret shl ulong 1 63 2337 end 2338 v = add mul v 10 sub ulong get g_b q 48 2339 q = add q 1 2340 end 2341 if eq q p 2342 ret shl ulong 1 63 2343 end 2344 if lt q n 2345 c = ulong get g_b q 2346 if not or or eq c 32 eq c 9 or eq c 10 eq c 35 2347 ret shl ulong 1 63 2348 end 2349 end 2350 put g_m add 20 slot v 2351 ret q 2352 end 2353 note the numbers before "#" of the g_b line at g_m 16 into g_m 20..22; the cursor moves past the line 2354 fn klnum to bool 2355 n = get g_n 6 2356 p = get g_m 16 2357 k = ulong 0 2358 ok = true 2359 while true bound `1048576` 2360 p = kskip p 2361 if or ge p n or eq get g_b p 10 eq get g_b p 35 2362 break 2363 end 2364 if ge k 3 2365 ok = false 2366 break 2367 end 2368 p = kdec p k 2369 if eq p shl ulong 1 63 2370 ok = false 2371 break 2372 end 2373 k = add k 1 2374 end 2375 while and lt p n ne get g_b p 10 bound `16777217` 2376 p = add p 1 2377 end 2378 put g_m 16 add p 1 2379 ret and ok eq k 3 2380 end 2381 fn kh3 to bool 2382 put g_m 2 0 2383 a = and eq fnum 1 get g_m 20 eq fnum 2 get g_m 21 2384 ret and and a eq fnum 3 get g_m 22 eq get g_m 2 0 2385 end 2386 note the table at g_pa has, line for line, the numbers of the hdr rows 2387 fn khdr to bool 2388 put g_n 6 0 2389 if not bload 2390 ret false 2391 end 2392 put g_m 16 0 2393 s = ulong 0 2394 n = get g_m 0 2395 while lt s n bound `1048577` 2396 e = trow s 2397 if fis 0 t_khdr 2398 if ge get g_m 16 get g_n 6 2399 ret false 2400 end 2401 if not klnum 2402 ret false 2403 end 2404 if not kh3 2405 ret false 2406 end 2407 end 2408 s = add e 1 2409 end 2410 ret ge get g_m 16 get g_n 6 2411 end 2412 fn kreport ok bool why view uchar * to void 2413 if ok 2414 ookn t_kfd_ 2415 onl 2416 put g_m 18 add get g_m 18 1 2417 else 2418 ofail t_kfd_ why 2419 end 2420 end 2421 note g_b := gpu/amd/kfd/NAME.om (field 1) then cli.om 2422 fn kunit to bool 2423 put g_n 6 0 2424 pclr 2425 pt t_kdir 2426 fpa 1 2427 pt t_om 2428 if not bload 2429 ret false 2430 end 2431 ret capp t_cli 2432 end 2433 fn nmadd t view uchar * to void 2434 n = get g_n 14 2435 for j ulong len t bound 256 2436 if lt add n j len g_nm 2437 put g_nm add n j get t j 2438 end 2439 end 2440 put g_n 14 add n len t 2441 end 2442 note bin NAME SHA: built twice, both to SHA 2443 fn kbin to void 2444 if or ne get g_m 1 3 not fnm 1 2445 ofail t_kfd_ t_rowbad 2446 ret 2447 end 2448 ok = and kunit build 2449 z = fnm 1 2450 nmadd t_rep 2451 ok = and ok and kunit build 2452 z = fnm 1 2453 psn t_bin 2454 ok = and ok fhfld 2 2455 z = fnm 1 2456 nmadd t_rep 2457 psn t_bin 2458 ok = and ok fhfld 2 2459 z = fnm 1 2460 kreport ok t_nodet 2461 end 2462 note the decimal at p in g_c; its end in g_m 16 2463 fn cdec p ulong to ulong 2464 n = get g_m 12 2465 q = p 2466 v = ulong 0 2467 while and lt q n isdig ulong get g_c q bound `1048577` 2468 v = add mul v 10 sub ulong get g_c q 48 2469 q = add q 1 2470 end 2471 put g_m 16 q 2472 ret v 2473 end 2474 note g_b := g_c with number f of line l plus d 2475 fn kedit l ulong f ulong d ulong to void 2476 put g_n 6 0 2477 n = get g_m 12 2478 p = ulong 0 2479 ln = ulong 0 2480 fl = ulong 0 2481 while lt p n bound `1048577` 2482 c = ulong get g_c p 2483 if and and eq ln l eq fl f and ge c 48 le c 57 2484 v = cdec p 2485 bnum add v d 2486 p = get g_m 16 2487 fl = add fl 1000 2488 else 2489 bch c 2490 p = add p 1 2491 if eq c 10 2492 ln = add ln 1 2493 fl = 0 2494 end 2495 if eq c 9 2496 fl = add fl 1 2497 end 2498 end 2499 end 2500 end 2501 note write g_b to SCRATCH/NAME (field 1) and check it hashes to field i 2502 fn ksave i ulong to bool 2503 if not fnm 1 2504 ret false 2505 end 2506 psn t_e 2507 if not bsave false 2508 ret false 2509 end 2510 psn t_e 2511 ret fhfld i 2512 end 2513 note tfile NAME LINE FIELD DELTA SHA 2514 fn ktfile to void 2515 if ne get g_m 1 6 2516 ofail t_kfd_ t_rowbad 2517 ret 2518 end 2519 put g_n 6 0 2520 put g_m 2 0 2521 ok = capp t_kreq 2522 ok = and ok tocopy 2523 kedit fnum 2 fnum 3 fnum 4 2524 ok = and ok eq get g_m 2 0 2525 ok = and ok ksave 5 2526 kreport ok t_mism 2527 end 2528 note fuel NAME COUNT SHA 2529 fn kfuel to void 2530 if ne get g_m 1 4 2531 ofail t_kfd_ t_rowbad 2532 ret 2533 end 2534 put g_m 2 0 2535 c = fnum 2 2536 put g_n 6 0 2537 lit t_f04 2538 bnum c 2539 bch 10 2540 for j ulong c bound `16777216` 2541 lit t_f041 2542 end 2543 ok = eq get g_m 2 0 2544 ok = and ok ksave 3 2545 kreport ok t_mism 2546 end 2547 note refuse NAME REQUEST SIZE EXIT STDERR 2548 fn kref to void 2549 if or ne get g_m 1 6 not fnm 1 2550 ofail t_kfd_ t_rowbad 2551 ret 2552 end 2553 put g_m 2 0 2554 put g_n 6 0 2555 lit t_kgl 2556 bnum fnum 3 2557 lit t_kfn 2558 bnum fnum 2 2559 lit t_kb0 2560 bnum fnum 3 2561 lit t_kend 2562 psn t_om 2563 ok = bsave false 2564 r = omcr 2565 ok = and ok eq r fnum 4 2566 psn t_err 2567 ok = and ok fcmp 5 2568 ok = and ok eq get g_m 2 0 2569 kreport ok t_mism 2570 end 2571 note field 3 as arguments after SCRATCH/EXE.bin: % is gpu/amd/kfd/requests.tsv, @X is SCRATCH/X 2572 fn kargv to bool 2573 aclr 2574 pclr 2575 pscr 2576 fpa 2 2577 pt t_bin 2578 ok = apa 2579 p = get g_fs 3 2580 e = get g_fe 3 2581 while lt p e bound `1048577` 2582 q = p 2583 while and lt q e ne get g_t q 32 bound `1048577` 2584 q = add q 1 2585 end 2586 pclr 2587 c = get g_t p 2588 st = p 2589 if eq c 64 2590 pscr 2591 st = add p 1 2592 end 2593 if and eq c 37 eq sub q p 1 2594 pt t_kreq 2595 st = q 2596 end 2597 for j ulong sub q st bound `1048576` 2598 pc ulong get g_t add st j 2599 end 2600 ok = and ok apa 2601 p = add q 1 2602 end 2603 ret ok 2604 end 2605 note the file at g_pa holds the bytes of hex field i 2606 fn khex i ulong to bool 2607 put g_n 6 0 2608 if not bload 2609 ret false 2610 end 2611 n = get g_n 6 2612 if ne mul n 2 flen i 2613 ret false 2614 end 2615 for j ulong n bound `16777216` 2616 v = or shl hexv fch i mul j 2 4 hexv fch i add mul j 2 1 2617 if ne v ulong get g_b j 2618 ret false 2619 end 2620 end 2621 ret true 2622 end 2623 note run the current krun row; true when exit, stdout and stderr match 2624 fn krun1 to bool 2625 if not kargv 2626 ret false 2627 end 2628 nmset t_kkr 2629 r = spawnf t_out t_err 2630 put g_m 2 0 2631 ok = eq r fnum 4 2632 psn t_out 2633 ok = and ok khex 5 2634 psn t_err 2635 ok = and ok fcmp 6 2636 ret and ok eq get g_m 2 0 2637 end 2638 fn kkrun to void 2639 if or ne get g_m 1 7 not fnm 1 2640 ofail t_kfd_ t_rowbad 2641 ret 2642 end 2643 ok = krun1 2644 z = fnm 1 2645 kreport ok t_mism 2646 end 2647 note the number of places g_b[0, k) occurs in g_b[k, g_n 6); the first in g_m 17 2648 fn kcount k ulong to ulong 2649 n = get g_n 6 2650 c = ulong 0 2651 p = k 2652 while le add p k n bound `16777217` 2653 m = true 2654 for j ulong k bound `16777216` 2655 if ne get g_b add p j get g_b j 2656 m = false 2657 break 2658 end 2659 end 2660 if m 2661 if eq c 0 2662 put g_m 17 p 2663 end 2664 c = add c 1 2665 end 2666 p = add p 1 2667 end 2668 ret c 2669 end 2670 note guard UNIT TEXT INDEX EXIT: the unit without TEXT (found exactly once), run on requests.tsv INDEX, exits 2671 note EXIT with empty output 2672 fn kguard to void 2673 put g_n 6 0 2674 funesc 2 2675 k = get g_n 6 2676 pclr 2677 pt t_kdir 2678 fpa 1 2679 pt t_om 2680 ok = and gt k 0 bload 2681 if or not ok ne kcount k 1 2682 caught false t_kgdn 2683 ret 2684 end 2685 ok = tocopy 2686 p = get g_m 17 2687 n = get g_m 12 2688 put g_n 6 0 2689 ccopy k p 2690 ccopy add p k n 2691 ok = and ok capp t_cli 2692 nmset t_kgdn 2693 ok = and ok build 2694 aclr 2695 psn t_bin 2696 ok = and ok apa 2697 pclr 2698 pt t_kreq 2699 ok = and ok apa 2700 pclr 2701 fpa 3 2702 ok = and ok apa 2703 r = spawnf t_out t_err 2704 put g_m 2 0 2705 ok = and ok eq r fnum 4 2706 psn t_out 2707 ok = and ok eq fsize 0 2708 psn t_err 2709 ok = and ok eq fsize 0 2710 caught and ok eq get g_m 2 0 t_kgdn 2711 end 2712 fn kfdrow to void 2713 if fis 0 t_kbin 2714 kbin 2715 end 2716 if fis 0 t_ktf 2717 ktfile 2718 end 2719 if fis 0 t_kfuel 2720 kfuel 2721 end 2722 if fis 0 t_kref 2723 kref 2724 end 2725 if fis 0 t_kkr 2726 kkrun 2727 end 2728 if fis 0 t_kgd 2729 kguard 2730 end 2731 end 2732 note the first krun row with its expected stderr changed must not match 2733 fn ckflip to void 2734 ok = tfind t_kkr t_e 2735 if ok 2736 put g_m 14 1 2737 ok = not krun1 2738 put g_m 14 0 2739 end 2740 caught ok t_kflip 2741 end 2742 fn slkfd to void 2743 if not tload t_tkfd 2744 nmset t_tkfd 2745 ofail t_tbl t_unread 2746 ret 2747 end 2748 pclr 2749 pt t_kreq 2750 nmset t_hdrn 2751 kreport khdr t_hdrbad 2752 s = ulong 0 2753 n = get g_m 0 2754 while lt s n bound `1048577` 2755 e = trow s 2756 if not tcom s e 2757 kfdrow 2758 end 2759 s = add e 1 2760 end 2761 pclr 2762 pscr 2763 pt t_kwr 2764 caught not khdr t_cwr 2765 ckflip 2766 end 2767 note ---- main 2768 fn ausage to int 2769 r = write 2 t_usage 0 len t_usage 2770 ret 2 2771 end 2772 fn main to int 2773 if ne argcnt 3 2774 ret ausage 2775 end 2776 r = argread 1 g_omc 0 4095 2777 if lt r 1 2778 ret ausage 2779 end 2780 put g_n 1 ulong r 2781 if not pinread 2782 r = write 2 t_nopin 0 len t_nopin 2783 ret 2 2784 end 2785 pclr 2786 for j ulong get g_n 1 bound 4096 2787 pc ulong get g_omc j 2788 end 2789 if not pinok 2790 r = write 2 t_refd 0 len t_refd 2791 ret 69 2792 end 2793 pclr 2794 pt t_qemu 2795 if not pexists 2796 r = write 1 t_hnoq 0 len t_hnoq 2797 ret 3 2798 end 2799 pclr 2800 pt t_kfd 2801 if pexists 2802 r = write 1 t_hkfd 0 len t_hkfd 2803 ret 3 2804 end 2805 r = argread 2 g_scr 0 4094 2806 if lt r 1 2807 ret ausage 2808 end 2809 if gt r 1024 2810 r = write 2 t_long 0 len t_long 2811 ret 2 2812 end 2813 n = ulong r 2814 x = makedir g_scr 0 n 448 2815 if ne x 0 2816 r = write 2 t_noscr 0 len t_noscr 2817 ret 2 2818 end 2819 put g_scr n 47 2820 put g_n 2 add n 1 2821 put g_n 6 0 2822 if capp t_hsom 2823 nmset t_hsaco 2824 z = build 2825 end 2826 slsec 2827 cwrong 2828 cflip 2829 c261 2830 sllaunch 2831 cnorow 2832 cvflip 2833 slwriter 2834 cloader 2835 slkfd 2836 slplan 2837 f = get g_n 11 2838 ot t_sum 2839 if eq f 0 2840 ot t_pass 2841 else 2842 ot t_fl 2843 end 2844 ot t_ss 2845 onum get g_m 8 2846 ot t_so 2847 onum get g_m 10 2848 ot t_sv 2849 onum get g_m 9 2850 ot t_snr 2851 onum get g_m 7 2852 ot t_sw 2853 onum get g_m 11 2854 ot t_skfd 2855 onum get g_m 18 2856 ot t_spl 2857 onum get g_m 19 2858 ot t_sc 2859 onum get g_n 12 2860 ot t_sk 2861 onum get g_n 13 2862 ot t_hw 2863 oflush 2864 if ne f 0 2865 ret 1 2866 end 2867 if ne get g_n 12 get g_n 13 2868 ret 1 2869 end 2870 ret 0 2871 end