interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / amd / rest / gate.om

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