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 / targets.om

1128 lines · 19535 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note targets.om: the portable backend's target table and code-object loader checks (seeded Omega,
3note AArch64 host). docs/ARCHITECTURE.md "Portable backend" defines the formats; this file is the
4note first IMPLEMENTED piece of that split. It opens no device: it reads one file and prints.
5note
6note targets doctor print every target row with its honest status
7note targets load FORMAT FILE [ARG] validate FILE as FORMAT; print LOAD ACCEPT or LOAD REFUSE
8note
9note Formats (ob_code_load tags): SM121_RAW, SPIRV_CL, SPIRV_VK, AMDGPU_HSACO accepted after checks;
10note MSL_SOURCE and AARCH64 (cpu-ref) have no backend yet (PLANNED, refused); CUBIN is reserved (#864 HOLD, refused).
11note ARG: for SPIRV_CL/SPIRV_VK an entry point name that must exist; for AMDGPU_HSACO the gfx target
12note (required), checked against e_flags and the NT_AMDGPU_METADATA note.
13note Checks:
14note SPIR-V magic 0x07230203, version 1.0..1.6, bound 1..4194303, schema 0, every instruction inside
15note the file; SPIRV_VK: Shader, no Kernel, Logical GLSL450, a GLCompute entry;
16note SPIRV_CL: Kernel and Addresses, no Shader, Physical64 OpenCL, a Kernel entry.
17note Authority: registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html sections 2.3, 3.
18note HSACO ELF64 little-endian version 1, OSABI 64 (HSA), ABI version 2 (code object v4) or 3 (v5),
19note ET_DYN, e_machine 224 (EM_AMDGPU), e_flags & 0xff == the target's mach, a PT_NOTE
20note holding owner "AMDGPU" type 32 (NT_AMDGPU_METADATA) whose msgpack map has
21note amdhsa.version [1, x], a non-empty amdhsa.kernels and amdhsa.target equal to
22note "amdgcn-amd-amdhsa--" + ARG (no feature suffix). Authority for the numbers:
23note llvm/BinaryFormat/ELF.h at LLVM 18.1.3 (EM_AMDGPU, ELFOSABI_AMDGPU_HSA,
24note ELFABIVERSION_AMDGPU_HSA_V4/V5, EF_AMDGPU_MACH_AMDGCN_*, NT_AMDGPU_METADATA) and
25note llvm.org/docs/AMDGPUUsage.html "Code Object Metadata"; msgpack.org spec for the walk.
26note SM121_RAW non-empty, a whole number of 16-byte instructions, not ELF and not SPIR-V.
27note Validation is offline: an AMD or SPIR-V ACCEPT here says the bytes are well formed for that
28note target, never that a GPU ran them (hardware NOT_RUN on every non-GB10 row).
29note Exit: 0 accept or doctor; 2 usage; 3 I/O or file over 1 MiB; 10 unknown format; 11 format has
30note no backend (PLANNED); 12 format reserved; 20 SPIR-V header; 21 SPIR-V instruction stream;
31note 22 SPIR-V capability or memory model wrong for the format; 23 entry point missing;
32note 30 ELF header; 31 OSABI or ABI version; 32 ELF type or machine; 33 e_flags mach is not the target;
33note 34 AMDGPU metadata note missing or malformed; 35 msgpack malformed; 36 metadata target, version
34note or kernels wrong; 37 unknown gfx target; 40 SM121_RAW shape. Traps exit 100 + code.
35om2
36
37text tuse "usage: targets doctor | targets load FORMAT FILE [ENTRY|GFX]\n"
38text tio "targets: cannot read FILE, or FILE is empty or over 1 MiB\n"
39text tdoc "doctor"
40text tload "load"
41text fsm "SM121_RAW"
42text fcl "SPIRV_CL"
43text fvk "SPIRV_VK"
44text fhs "AMDGPU_HSACO"
45text fms "MSL_SOURCE"
46text fa64 "AARCH64"
47text fcu "CUBIN"
48text tacc "LOAD ACCEPT "
49text tref "LOAD REFUSE "
50text tcode " code="
51text trsn " reason="
52text tnl "\n"
53text tsp " "
54text tdot "."
55text tver " version="
56text tbnd " bound="
57text twds " words="
58text tent " entry="
59text tmach " mach=0x"
60text tabi " abi="
61text tkern " kernels="
62text ttgt " target="
63text tnote " note=AMDGPU/NT_AMDGPU_METADATA"
64text tsz " bytes="
65text tinsn " insns="
66text tpfx "amdgcn-amd-amdhsa--"
67text kver "amdhsa.version"
68text kkern "amdhsa.kernels"
69text ktgt "amdhsa.target"
70text rnofmt "unknown format tag"
71text rplan "format has no backend yet (PLANNED)"
72text rresv "format reserved (CUBIN, #864 HOLD)"
73text rmagic "not a SPIR-V module (magic, version, bound or schema)"
74text rstrm "SPIR-V instruction runs past the end, has word count 0, or the module does not end with OpFunctionEnd"
75text rcapv "not Vulkan compute SPIR-V (needs Shader, no Kernel, Logical GLSL450)"
76text rcapc "not OpenCL kernel SPIR-V (needs Kernel+Addresses, no Shader, Physical64 OpenCL)"
77text rentry "no entry point of the right model (or with that name)"
78text relf "not an ELF64 little-endian version-1 file"
79text rabi "OSABI is not HSA (64) or ABI version is not code object v4/v5"
80text rmach "not an AMDGPU shared object (e_type 3, e_machine 224)"
81text rflag "e_flags mach does not match the requested gfx target"
82text rnote "no well-formed AMDGPU NT_AMDGPU_METADATA note in a PT_NOTE segment"
83text rmsg "metadata msgpack malformed"
84text rtgt "metadata amdhsa.target, amdhsa.version or amdhsa.kernels does not match"
85text rgfx "unknown gfx target (known: gfx900 gfx90a gfx942 gfx1030 gfx1100 gfx1151 gfx1200 gfx1201)"
86text rraw "SM121_RAW must be non-empty 16-byte instructions and not ELF or SPIR-V"
87text rarg "AMDGPU_HSACO needs the gfx target argument"
88text g900 "gfx900"
89text g90a "gfx90a"
90text g942 "gfx942"
91text g1030 "gfx1030"
92text g1100 "gfx1100"
93text g1151 "gfx1151"
94text g1200 "gfx1200"
95text g1201 "gfx1201"
96text hdr "TARGET id vendor arch format status hardware loader\n"
97text tt "TARGET "
98text sSUP "SUPPORTED"
99text sPLN "PLANNED"
100text sHOST "HOST-ONLY(not-a-GPU)"
101text hGB "chip-receipts(README)"
102text hNR "NOT_RUN"
103text hCPU "EXERCISED(host-CPU)"
104text lRAW "SM121_RAW"
105text lNONE "none"
106text lSPV "spirv-validate"
107text lHSA "hsaco-validate"
108text vNV "nvidia"
109text vAMD "amd"
110text vINT "intel"
111text vAPL "apple"
112text vQC "qualcomm"
113text vARM "arm"
114text vIMG "imagination"
115text vBCM "broadcom"
116text vVTX "vortex"
117text vCPU "cpu"
118text fSASS "SASS(encoder-per-arch)"
119text fMSL "MSL_SOURCE"
120text fSPCL "SPIRV_CL|SPIRV_VK"
121
122const MAXF ulong 1048576
123
124global gbuf uchar 1048576
125global garg uchar 64
126global gfmt uchar 32
127global gtgt uchar 96
128global gob uchar 512
129note gst: 0 file size, 1 output fill, 2 msgpack cursor, 3 msgpack end, 4 format length,
130note 5 kernels, 6 target ok, 7 version ok, 8 expected target length, 9 entry name length
131global gst ulong 12
132
133fn oflush to void
134n = write 1 gob 0 get gst 1
135put gst 1 0
136end
137
138fn oc b uchar to void
139if ge get gst 1 len gob
140oflush
141end
142f = get gst 1
143put gob f b
144put gst 1 add f 1
145end
146
147fn ot t view uchar * to void
148for i ulong len t
149oc get t i
150end
151end
152
153fn odec v ulong to void
154d = new uchar 20 0
155k = ulong 0
156x = v
157while true bound 21
158put d k uchar add rem x 10 48
159k = add k 1
160x = div x 10
161if eq x 0
162break
163end
164end
165for i ulong k
166oc get d sub sub k i 1
167end
168end
169
170fn ohx v ulong to void
171for i ulong 2
172s = sub 4 mul i 4
173d = and shr v s 15
174if lt d 10
175oc uchar add d 48
176else
177oc uchar add d 87
178end
179end
180end
181
182fn ofmt to void
183for i ulong get gst 4
184oc get gfmt i
185end
186end
187
188fn refuse code int msg view uchar * to void
189ot tref
190ofmt
191ot tcode
192odec ulong code
193ot trsn
194ot msg
195ot tnl
196oflush
197exit code
198end
199
200fn fail code int msg view uchar * to void
201oflush
202n = write 2 msg 0 len msg
203exit code
204end
205
206fn fmtis t view uchar * to bool
207if ne get gst 4 len t
208ret false
209end
210for k ulong len t
211if ne get gfmt k get t k
212ret false
213end
214end
215ret true
216end
217
218fn argis t view uchar * to bool
219if ne get gst 9 len t
220ret false
221end
222for k ulong len t
223if ne get garg k get t k
224ret false
225end
226end
227ret true
228end
229
230fn row id view uchar * vn view uchar * ar view uchar * to void
231note starts a row: id, vendor, arch (a view parameter takes two of the 6 parameter slots)
232ot tt
233ot id
234ot tsp
235ot vn
236ot tsp
237ot ar
238end
239
240fn rf fm view uchar * st view uchar * hw view uchar * to void
241note the middle of a row: format, status, hardware
242ot tsp
243ot fm
244ot tsp
245ot st
246ot tsp
247ot hw
248end
249
250fn rl ld view uchar * to void
251note ends a row: the loader column (a function has at most 6 parameters)
252ot tsp
253ot ld
254ot tnl
255end
256
257text i121 "nvidia-sm_121"
258text a121 "sm_121(GB10)"
259text i80 "nvidia-sm_80"
260text a80 "sm_80(A100)"
261text i86 "nvidia-sm_86"
262text a86 "sm_86(RTX30)"
263text i89 "nvidia-sm_89"
264text a89 "sm_89(RTX40/L40)"
265text i90 "nvidia-sm_90"
266text a90 "sm_90(H100/H200)"
267text i100 "nvidia-sm_100"
268text a100 "sm_100(B200)"
269text i120 "nvidia-sm_120"
270text a120 "sm_120(RTX50)"
271text ig9 "amd-gfx9"
272text ag9 "gfx900/gfx90a/gfx942(MI300)"
273text ig10 "amd-gfx10"
274text ag10 "gfx1030(RDNA2)"
275text ig11 "amd-gfx11"
276text ag11 "gfx1100(RDNA3)/gfx1151(Strix-Halo)"
277text ig12 "amd-gfx12"
278text ag12 "gfx1200/gfx1201(RDNA4)"
279text ixlp "intel-xe-lp"
280text axlp "Xe-LP(Gen12-iGPU)"
281text ixhp "intel-xe-hpg"
282text axhp "Xe-HPG(Arc-Alchemist)"
283text ixe2 "intel-xe2"
284text axe2 "Xe2(Lunar-Lake/Battlemage)"
285text iapl "apple-m"
286text aapl "Apple-GPU(M-series)"
287text iqc "qualcomm-adreno"
288text aqc "Adreno"
289text iarm "arm-mali"
290text aarm "Mali/Immortalis"
291text iimg "imagination-powervr"
292text aimg "PowerVR"
293text ibcm "broadcom-v3d"
294text abcm "V3D(Raspberry-Pi)"
295text ivtx "vortex"
296text avtx "Vortex(RISC-V-GPGPU)"
297text ipcl "cpu-pocl"
298text apcl "PoCL-7.2-CPU"
299text ilvp "cpu-lavapipe"
300text alvp "Mesa-lavapipe-CPU"
301text ssc "SPIRV_CL"
302text svk "SPIRV_VK"
303
304fn doctor to int
305ot hdr
306row i121 vNV a121
307rf lRAW sSUP hGB
308rl lRAW
309row i80 vNV a80
310rf fSASS sPLN hNR
311rl lNONE
312row i86 vNV a86
313rf fSASS sPLN hNR
314rl lNONE
315row i89 vNV a89
316rf fSASS sPLN hNR
317rl lNONE
318row i90 vNV a90
319rf fSASS sPLN hNR
320rl lNONE
321row i100 vNV a100
322rf fSASS sPLN hNR
323rl lNONE
324row i120 vNV a120
325rf fSASS sPLN hNR
326rl lNONE
327row ig9 vAMD ag9
328rf fhs sPLN hNR
329rl lHSA
330row ig10 vAMD ag10
331rf fhs sPLN hNR
332rl lHSA
333row ig11 vAMD ag11
334rf fhs sPLN hNR
335rl lHSA
336row ig12 vAMD ag12
337rf fhs sPLN hNR
338rl lHSA
339row ixlp vINT axlp
340rf fSPCL sPLN hNR
341rl lSPV
342row ixhp vINT axhp
343rf fSPCL sPLN hNR
344rl lSPV
345row ixe2 vINT axe2
346rf fSPCL sPLN hNR
347rl lSPV
348row iapl vAPL aapl
349rf fMSL sPLN hNR
350rl lNONE
351row iqc vQC aqc
352rf svk sPLN hNR
353rl lSPV
354row iarm vARM aarm
355rf svk sPLN hNR
356rl lSPV
357row iimg vIMG aimg
358rf svk sPLN hNR
359rl lSPV
360row ibcm vBCM abcm
361rf svk sPLN hNR
362rl lSPV
363row ivtx vVTX avtx
364rf ssc sPLN hNR
365rl lSPV
366row ipcl vCPU apcl
367rf ssc sHOST hCPU
368rl lSPV
369row ilvp vCPU alvp
370rf svk sHOST hCPU
371rl lSPV
372oflush
373ret 0
374end
375
376fn b8 o ulong to ulong
377ret ulong get gbuf o
378end
379
380fn le16 o ulong to ulong
381ret or b8 o shl b8 add o 1 8
382end
383
384fn le32 o ulong to ulong
385ret or le16 o shl le16 add o 2 16
386end
387
388fn le64 o ulong to ulong
389ret or le32 o shl le32 add o 4 32
390end
391
392fn be16 o ulong to ulong
393ret or shl b8 o 8 b8 add o 1
394end
395
396fn be32 o ulong to ulong
397ret or shl be16 o 16 be16 add o 2
398end
399
400fn rdfile ai ulong to void
401p = new uchar 4096 0
402n = argread ai p 0 4095
403if le n 0
404fail 2 tuse
405end
406fd = fopen p 0 ulong n 0 0
407if lt fd 0
408fail 3 tio
409end
410sz = fseek int fd 0 2
411if le sz 0
412fail 3 tio
413end
414if gt ulong sz MAXF
415fail 3 tio
416end
417r = pread int fd gbuf 0 ulong sz 0
418if ne r sz
419fail 3 tio
420end
421c = fclose int fd
422put gst 0 ulong sz
423end
424
425fn spvword i ulong to ulong
426ret le32 mul i 4
427end
428
429fn namehit w ulong nw ulong to bool
430note entry name of an OpEntryPoint starting at word w (nw words); compares with garg
431o = mul add w 3 4
432e = mul add w nw 4
433k = ulong 0
434while true bound 4096
435if ge add o k e
436ret false
437end
438c = get gbuf add o k
439if eq c 0
440ret eq k get gst 9
441end
442if ge k get gst 9
443ret false
444end
445if ne c get garg k
446ret false
447end
448k = add k 1
449end
450ret false
451end
452
453fn spvhdr to void
454sz = get gst 0
455if lt sz 20
456refuse 20 rmagic
457end
458if ne rem sz 4 0
459refuse 20 rmagic
460end
461if ne spvword 0 0x07230203
462refuse 20 rmagic
463end
464v = spvword 1
465if ne and v 0xff0000ff 0
466refuse 20 rmagic
467end
468if ne and shr v 16 255 1
469refuse 20 rmagic
470end
471if gt and shr v 8 255 6
472refuse 20 rmagic
473end
474bd = spvword 3
475if eq bd 0
476refuse 20 rmagic
477end
478if ge bd 4194304
479refuse 20 rmagic
480end
481if ne spvword 4 0
482refuse 20 rmagic
483end
484end
485
486fn spvop w ulong wc ulong seen ulong to ulong
487note one instruction at word w; returns seen with the bits it proves:
488note 1 Shader, 2 Kernel, 4 Addresses, 8 Logical GLSL450, 16 Physical64 OpenCL,
489note 32 GLCompute entry (named, if a name was given), 64 Kernel entry (named, if given)
490op = and spvword w 0xffff
491s = seen
492if eq op 17
493if lt wc 2
494refuse 21 rstrm
495end
496cp = spvword add w 1
497if eq cp 1
498s = or s 1
499end
500if eq cp 6
501s = or s 2
502end
503if eq cp 4
504s = or s 4
505end
506end
507if eq op 14
508if lt wc 3
509refuse 21 rstrm
510end
511am = spvword add w 1
512mm = spvword add w 2
513if eq am 0
514if eq mm 1
515s = or s 8
516end
517end
518if eq am 2
519if eq mm 2
520s = or s 16
521end
522end
523end
524if eq op 15
525if lt wc 4
526refuse 21 rstrm
527end
528em = spvword add w 1
529ok = true
530if gt get gst 9 0
531ok = namehit w wc
532end
533if ok
534if eq em 5
535s = or s 32
536end
537if eq em 6
538s = or s 64
539end
540end
541end
542ret s
543end
544
545fn spvwalk to ulong
546note walks every instruction; returns the seen bits, leaves the instruction count in gst 11
547nw = div get gst 0 4
548w = ulong 5
549ni = ulong 0
550seen = ulong 0
551lw = ulong 5
552while lt w nw bound 999999
553wc = shr spvword w 16
554if eq wc 0
555refuse 21 rstrm
556end
557if gt add w wc nw
558refuse 21 rstrm
559end
560seen = spvop w wc seen
561lw = w
562w = add w wc
563ni = add ni 1
564end
565if lt w nw
566refuse 21 rstrm
567end
568if ne and spvword lw 65535 56
569refuse 21 rstrm
570end
571put gst 11 ni
572ret seen
573end
574
575fn spirv vk bool to int
576spvhdr
577seen = spvwalk
578if vk
579if ne and seen 11 9
580refuse 22 rcapv
581end
582if eq and seen 32 0
583refuse 23 rentry
584end
585else
586if ne and seen 23 22
587refuse 22 rcapc
588end
589if eq and seen 64 0
590refuse 23 rentry
591end
592end
593v = spvword 1
594ot tacc
595ofmt
596ot tver
597odec and shr v 16 255
598ot tdot
599odec and shr v 8 255
600ot tbnd
601odec spvword 3
602ot twds
603odec div get gst 0 4
604ot tinsn
605odec get gst 11
606if gt get gst 9 0
607ot tent
608for i ulong get gst 9
609oc get garg i
610end
611end
612ot tnl
613oflush
614ret 0
615end
616
617fn gfxmach to ulong
618note EF_AMDGPU_MACH_AMDGCN_* from llvm/BinaryFormat/ELF.h, LLVM 18.1.3
619if argis g900
620ret 0x2c
621end
622if argis g90a
623ret 0x3f
624end
625if argis g942
626ret 0x4c
627end
628if argis g1030
629ret 0x36
630end
631if argis g1100
632ret 0x41
633end
634if argis g1151
635ret 0x4a
636end
637if argis g1200
638ret 0x48
639end
640if argis g1201
641ret 0x4e
642end
643ret 0
644end
645
646fn mpneed n ulong to void
647if gt add get gst 2 n get gst 3
648refuse 35 rmsg
649end
650end
651
652fn mpbyte to ulong
653mpneed 1
654p = get gst 2
655put gst 2 add p 1
656ret b8 p
657end
658
659fn mplen n ulong to ulong
660note read an n-byte big-endian length or value at the cursor (n = 1, 2 or 4)
661mpneed n
662p = get gst 2
663put gst 2 add p n
664if eq n 1
665ret b8 p
666end
667if eq n 2
668ret be16 p
669end
670ret be32 p
671end
672
673fn mpstr to ulong
674note string header at the cursor: returns the length; the cursor moves to the first byte
675b = mpbyte
676if eq and b 0xe0 0xa0
677ret and b 31
678end
679if eq b 0xd9
680ret mplen 1
681end
682if eq b 0xda
683ret mplen 2
684end
685if eq b 0xdb
686ret mplen 4
687end
688refuse 35 rmsg
689ret 0
690end
691
692fn mpskip to void
693note skip one complete value; pending counts values still to skip (bounded, no recursion)
694pend = ulong 1
695while gt pend 0 bound 999999
696pend = sub pend 1
697b = mpbyte
698sk = ulong 0
699if le b 0x7f
700sk = 0
701else
702if ge b 0xe0
703sk = 0
704else
705if eq and b 0xf0 0x80
706pend = add pend mul and b 15 2
707else
708if eq and b 0xf0 0x90
709pend = add pend and b 15
710else
711if eq and b 0xe0 0xa0
712sk = and b 31
713else
714sk = mpskipx b
715pend = add pend get gst 10
716end
717end
718end
719end
720end
721mpneed sk
722put gst 2 add get gst 2 sk
723if gt pend 1000000
724refuse 35 rmsg
725end
726end
727end
728
729fn mpskipx b ulong to ulong
730note non-fix forms: returns bytes to skip; sets gst 10 to extra pending values
731put gst 10 0
732if eq b 0xc0
733ret 0
734end
735if eq b 0xc2
736ret 0
737end
738if eq b 0xc3
739ret 0
740end
741if eq b 0xcc
742ret 1
743end
744if eq b 0xd0
745ret 1
746end
747if eq b 0xcd
748ret 2
749end
750if eq b 0xd1
751ret 2
752end
753if eq b 0xca
754ret 4
755end
756if eq b 0xce
757ret 4
758end
759if eq b 0xd2
760ret 4
761end
762if eq b 0xcb
763ret 8
764end
765if eq b 0xcf
766ret 8
767end
768if eq b 0xd3
769ret 8
770end
771if eq b 0xc4
772ret mplen 1
773end
774if eq b 0xd9
775ret mplen 1
776end
777if eq b 0xc5
778ret mplen 2
779end
780if eq b 0xda
781ret mplen 2
782end
783if eq b 0xc6
784ret mplen 4
785end
786if eq b 0xdb
787ret mplen 4
788end
789if eq b 0xdc
790put gst 10 mplen 2
791ret 0
792end
793if eq b 0xdd
794put gst 10 mplen 4
795ret 0
796end
797if eq b 0xde
798put gst 10 mul mplen 2 2
799ret 0
800end
801if eq b 0xdf
802put gst 10 mul mplen 4 2
803ret 0
804end
805refuse 35 rmsg
806ret 0
807end
808
809fn mpkey t view uchar * n ulong to bool
810note the string of length n at the cursor equals t (cursor not moved)
811if ne n len t
812ret false
813end
814p = get gst 2
815for k ulong n
816if ne get gbuf add p k get t k
817ret false
818end
819end
820ret true
821end
822
823fn mparr to ulong
824note array header at the cursor: returns the count
825b = mpbyte
826if eq and b 0xf0 0x90
827ret and b 15
828end
829if eq b 0xdc
830ret mplen 2
831end
832if eq b 0xdd
833ret mplen 4
834end
835refuse 36 rtgt
836ret 0
837end
838
839fn mpval kk ulong to void
840note value of the key kk (1 version, 2 kernels, 3 target) at the cursor
841st = get gst 2
842if eq kk 1
843c = mparr
844if ge c 1
845if eq mpbyte 1
846put gst 7 1
847end
848end
849end
850if eq kk 2
851put gst 5 mparr
852end
853if eq kk 3
854n = mpstr
855mpneed n
856if eq n get gst 8
857p = get gst 2
858ok = true
859for k ulong n
860if ne get gbuf add p k get gtgt k
861ok = false
862end
863end
864if ok
865put gst 6 1
866end
867end
868end
869put gst 2 st
870mpskip
871end
872
873fn metadata o ulong n ulong to void
874put gst 2 o
875put gst 3 add o n
876b = mpbyte
877c = ulong 0
878if eq and b 0xf0 0x80
879c = and b 15
880else
881if eq b 0xde
882c = mplen 2
883else
884refuse 35 rmsg
885end
886end
887for i ulong c
888kn = mpstr
889mpneed kn
890kk = ulong 0
891if mpkey kver kn
892kk = 1
893end
894if mpkey kkern kn
895kk = 2
896end
897if mpkey ktgt kn
898kk = 3
899end
900put gst 2 add get gst 2 kn
901mpval kk
902end
903end
904
905fn notes o ulong n ulong to bool
906note walk the notes of one PT_NOTE segment; true once the AMDGPU metadata note was parsed
907e = add o n
908p = o
909while lt p e bound 4096
910if gt add p 12 e
911refuse 34 rnote
912end
913nz = le32 p
914dz = le32 add p 4
915ty = le32 add p 8
916nm = add p 12
917ds = add nm and add nz 3 0xfffffffc
918nx = add ds and add dz 3 0xfffffffc
919if gt nx e
920refuse 34 rnote
921end
922if eq nz 7
923if eq ty 32
924if eq le32 nm 0x47444d41
925if eq le16 add nm 4 0x5550
926if eq b8 add nm 6 0
927metadata ds dz
928ret true
929end
930end
931end
932end
933end
934p = nx
935end
936ret false
937end
938
939fn hsaco to int
940sz = get gst 0
941if eq get gst 9 0
942fail 2 rarg
943end
944mach = gfxmach
945if eq mach 0
946refuse 37 rgfx
947end
948if lt sz 64
949refuse 30 relf
950end
951if ne le32 0 0x464c457f
952refuse 30 relf
953end
954if ne b8 4 2
955refuse 30 relf
956end
957if ne b8 5 1
958refuse 30 relf
959end
960if ne b8 6 1
961refuse 30 relf
962end
963if ne b8 7 64
964refuse 31 rabi
965end
966abi = b8 8
967if lt abi 2
968refuse 31 rabi
969end
970if gt abi 3
971refuse 31 rabi
972end
973if ne le16 16 3
974refuse 32 rmach
975end
976if ne le16 18 224
977refuse 32 rmach
978end
979fl = le32 48
980if ne and fl 0xff mach
981refuse 33 rflag
982end
983po = le64 32
984pe = le16 54
985pn = le16 56
986if ne pe 56
987refuse 30 relf
988end
989if gt add po mul pn 56 sz
990refuse 30 relf
991end
992done = false
993for i ulong pn
994h = add po mul i 56
995if eq le32 h 4
996off = le64 add h 8
997fs = le64 add h 32
998if gt add off fs sz
999refuse 34 rnote
1000end
1001if not done
1002done = notes off fs
1003end
1004end
1005end
1006if not done
1007refuse 34 rnote
1008end
1009if eq get gst 7 0
1010refuse 36 rtgt
1011end
1012if eq get gst 5 0
1013refuse 36 rtgt
1014end
1015if eq get gst 6 0
1016refuse 36 rtgt
1017end
1018ot tacc
1019ofmt
1020ot ttgt
1021ot tpfx
1022for i ulong get gst 9
1023oc get garg i
1024end
1025ot tmach
1026ohx and fl 0xff
1027ot tabi
1028odec abi
1029ot tkern
1030odec get gst 5
1031ot tnote
1032ot tsz
1033odec sz
1034ot tnl
1035oflush
1036ret 0
1037end
1038
1039fn rawsm to int
1040sz = get gst 0
1041if ne rem sz 16 0
1042refuse 40 rraw
1043end
1044if eq le32 0 0x464c457f
1045refuse 40 rraw
1046end
1047if eq le32 0 0x07230203
1048refuse 40 rraw
1049end
1050ot tacc
1051ofmt
1052ot tsz
1053odec sz
1054ot tnl
1055oflush
1056ret 0
1057end
1058
1059fn main to int
1060ac = argcnt
1061if lt ac 2
1062fail 2 tuse
1063end
1064n = argread 1 gfmt 0 len gfmt
1065put gst 4 ulong n
1066if fmtis tdoc
1067if ne ac 2
1068fail 2 tuse
1069end
1070ret doctor
1071end
1072if not fmtis tload
1073fail 2 tuse
1074end
1075if lt ac 4
1076fail 2 tuse
1077end
1078if gt ac 5
1079fail 2 tuse
1080end
1081n = argread 2 gfmt 0 len gfmt
1082if le n 0
1083fail 2 tuse
1084end
1085put gst 4 ulong n
1086put gst 9 0
1087if eq ac 5
1088m = argread 4 garg 0 len garg
1089if le m 0
1090fail 2 tuse
1091end
1092put gst 9 ulong m
1093end
1094for i ulong len tpfx
1095put gtgt i get tpfx i
1096end
1097for i ulong get gst 9
1098put gtgt add len tpfx i get garg i
1099end
1100put gst 8 add len tpfx get gst 9
1101if fmtis fms
1102refuse 11 rplan
1103end
1104if fmtis fa64
1105refuse 11 rplan
1106end
1107if fmtis fcu
1108refuse 12 rresv
1109end
1110if fmtis fsm
1111rdfile 3
1112ret rawsm
1113end
1114if fmtis fcl
1115rdfile 3
1116ret spirv false
1117end
1118if fmtis fvk
1119rdfile 3
1120ret spirv true
1121end
1122if fmtis fhs
1123rdfile 3
1124ret hsaco
1125end
1126refuse 10 rnofmt
1127ret 10
1128end