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 / nvidia / om / cache / templates.om

537 lines · 10660 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Private retained-snapshot consistency checker, NOT artifact admission authority.
3note Existing successful admission supplies bytes/name/actualid; selected immutable bundle supplies launch/expectedid.
4note Concatenate digest.om and Composer realize.om dependencies before this unit.
5note Function image has no text globals; prefix words reuse cubin_elf.om Wolfram-filed constants.
6fn kt_range n ulong off ulong count ulong to bool
7if gt off n
8ret false
9end
10ret le count sub n off
11end
12fn kt_u b view uchar 32768 off ulong count ulong to ulong
13v = ulong 0
14for j ulong count
15v = or v shl ulong get b add off j mul j 8
16end
17ret v
18end
19fn kt_obs b view uchar 2048 off ulong count ulong to ulong
20v = ulong 0
21for j ulong count
22v = or v shl ulong get b add off j mul j 8
23end
24ret v
25end
26fn kt_plen kind ulong to ulong
27if eq kind 0
28ret 9
29end
30if eq kind 1
31ret 6
32end
33ret 14
34end
35fn kt_pbyte word ulong i ulong to uchar
36ret uchar and shr word mul i 8 255
37end
38fn kt_pref kind ulong i ulong to uchar
39if eq kind 0
40if lt i 8
41ret kt_pbyte 8027224783864622638 i
42end
43ret 46
44end
45if eq kind 1
46ret kt_pbyte 51077770998830 i
47end
48if lt i 8
49ret kt_pbyte 8317708033571843630 i
50end
51ret kt_pbyte 50785646698868 sub i 8
52end
53note ctx12: filelen shoff shcount stroff strlen infohdr infooff infolen symoff symlen symcount reserved.
54fn kt_named b view uchar 32768 ctx view ulong 12 off ulong obs view uchar 2048 count ulong kind ulong to bool
55pn = kt_plen kind
56if not kt_range get ctx 4 off add add pn count 1
57ret false
58end
59base = add get ctx 3 off
60for j ulong pn
61if ne get b add base j kt_pref kind j
62ret false
63end
64end
65base = add base pn
66for j ulong count
67if ne get b add base j get obs add 896 j
68ret false
69end
70end
71ret eq get b add base count 0
72end
73fn kt_elf b view uchar 32768 n ulong obs view uchar 2048 count ulong ctx edit ulong 12 to int
74if or lt n 64 gt n 32768
75ret -21
76end
77if ne get b 0 127
78ret -21
79end
80for j ulong 3
81if ne get b add j 1 kt_pbyte 4684026196722992511 add j 1
82ret -21
83end
84end
85if or ne get b 4 2 or ne get b 5 1 ne get b 6 1
86ret -21
87end
88if or ne kt_u b 16 2 2 ne kt_u b 18 2 190
89ret -21
90end
91if or ne kt_u b 20 4 1 or ne kt_u b 52 2 64 ne kt_u b 58 2 64
92ret -21
93end
94put ctx 0 n
95put ctx 1 kt_u b 40 8
96put ctx 2 kt_u b 60 2
97if or eq get ctx 2 0 gt get ctx 2 512
98ret -21
99end
100if not kt_range n get ctx 1 mul get ctx 2 64
101ret -21
102end
103si = kt_u b 62 2
104if or eq si 0 ge si get ctx 2
105ret -21
106end
107sh = add get ctx 1 mul si 64
108if ne kt_u b add sh 4 4 3
109ret -21
110end
111put ctx 3 kt_u b add sh 24 8
112put ctx 4 kt_u b add sh 32 8
113if not kt_range n get ctx 3 get ctx 4
114ret -21
115end
116for i ulong get ctx 2
117sh = add get ctx 1 mul i 64
118si = kt_u b sh 4
119if ge si get ctx 4
120ret -21
121end
122if kt_named b ctx si obs count 0
123if ne get ctx 5 0
124ret -22
125end
126put ctx 5 sh
127end
128end
129if eq get ctx 5 0
130ret -22
131end
132sh = get ctx 5
133if ne kt_u b add sh 4 4 shl ulong 7 28
134ret -22
135end
136put ctx 6 kt_u b add sh 24 8
137put ctx 7 kt_u b add sh 32 8
138if not kt_range n get ctx 6 get ctx 7
139ret -22
140end
141ret 0
142end
143fn kt_assoc b view uchar 32768 ctx edit ulong 12 obs view uchar 2048 count ulong to int
144sh = get ctx 5
145ti = kt_u b add sh 44 4
146si = kt_u b add sh 40 4
147if or eq ti 0 ge ti get ctx 2
148ret -22
149end
150if or eq si 0 ge si get ctx 2
151ret -22
152end
153sh = add get ctx 1 mul ti 64
154if ne kt_u b add sh 4 4 1
155ret -22
156end
157if not kt_named b ctx kt_u b sh 4 obs count 1
158ret -22
159end
160if not kt_range get ctx 0 kt_u b add sh 24 8 kt_u b add sh 32 8
161ret -22
162end
163sh = add get ctx 1 mul si 64
164if or ne kt_u b add sh 4 4 2 ne kt_u b add sh 56 8 24
165ret -22
166end
167put ctx 8 kt_u b add sh 24 8
168put ctx 9 kt_u b add sh 32 8
169if ne rem get ctx 9 24 0
170ret -22
171end
172if not kt_range get ctx 0 get ctx 8 get ctx 9
173ret -22
174end
175put ctx 10 div get ctx 9 24
176ret 0
177end
178fn kt_symbol b view uchar 32768 ctx view ulong 12 obs view uchar 2048 count ulong index ulong need ulong to bool
179if ge index get ctx 10
180ret false
181end
182p = add get ctx 8 mul index 24
183if ne and get b add p 4 15 3
184ret false
185end
186si = kt_u b add p 6 2
187if or eq si 0 ge si get ctx 2
188ret false
189end
190p = add get ctx 1 mul si 64
191if ne kt_u b add p 4 4 1
192ret false
193end
194if not kt_named b ctx kt_u b p 4 obs count 2
195ret false
196end
197if lt kt_u b add p 32 8 need
198ret false
199end
200ret kt_range get ctx 0 kt_u b add p 24 8 kt_u b add p 32 8
201end
202note ABI numeric encodings come unchanged from om/cubin/cubin_elf.om wpar/wtail.
203fn kt_prefix b view uchar 32768 ctx view ulong 12 launch view uchar 4096 span edit ulong 4 to int
204p = get ctx 6
205lim = add p get ctx 7
206if not kt_range lim p 8
207ret -23
208end
209if or ne kt_u b p 2 14084 ne kt_u b add p 2 2 4
210ret -23
211end
212if ne kt_u b add p 4 4 130
213ret -23
214end
215put span 0 p
216p = add p 8
217ord = ulong 0
218last = ulong 0
219while lt p lim bound 33
220if not kt_range lim p 4
221ret -23
222end
223if ne kt_u b p 2 5892
224break
225end
226if or ge ord 32 not kt_range lim p 16
227ret -23
228end
229if or ne kt_u b add p 2 2 12 ne kt_u b add p 4 4 0
230ret -23
231end
232v = kt_u b add p 8 4
233if ne and v 65535 ord
234ret -23
235end
236v = shr v 16
237if or lt v last ge v mul compose_word launch 12 4
238ret -23
239end
240last = add v 1
241v = kt_u b add p 12 4
242if not or eq v 1175552 eq v 2225408
243ret -23
244end
245if eq v 2225408
246if ne rem sub last 1 8 0
247ret -23
248end
249last = add last 7
250end
251ord = add ord 1
252p = add p 16
253end
254if not kt_range lim p 20
255ret -23
256end
257if or ne kt_u b p 2 6403 ne kt_u b add p 4 2 2564
258ret -23
259end
260if ne kt_u b add p 6 2 8
261ret -23
262end
263v = kt_u b add p 2 2
264if or gt v mul compose_word launch 12 4 lt v last
265ret -23
266end
267if ne kt_u b add p 12 4 or compose_word launch 11 shl v 16
268ret -23
269end
270put span 2 kt_u b add p 8 4
271put span 3 add compose_word launch 11 v
272p = add p 16
273put span 1 sub p get span 0
274if gt get span 1 4096
275ret -23
276end
277ret 0
278end
279fn kt_banklink b view uchar 32768 ctx view ulong 12 obs view uchar 2048 count ulong span view ulong 4 to int
280if not kt_symbol b ctx obs count get span 2 get span 3
281ret -23
282end
283ret 0
284end
285fn kt_abiid attr ulong to bool
286ret or eq attr 55 or eq attr 23 or eq attr 25 or eq attr 10 eq attr 80
287end
288fn kt_tail b view uchar 32768 ctx view ulong 12 launch view uchar 4096 span view ulong 4 to int
289p = add get span 0 get span 1
290lim = add get ctx 6 get ctx 7
291if or ne kt_u b p 2 20483 ne kt_u b add p 2 2 0
292ret -23
293end
294p = add p 4
295ord = ulong 0
296while lt p lim bound 8192
297if not kt_range lim p 4
298ret -23
299end
300v = kt_u b p 2
301if kt_abiid shr v 8
302ret -23
303end
304if eq v 6915
305if or ne ord 0 ne kt_u b add p 2 2 compose_word launch 8
306ret -23
307end
308ord = 1
309end
310v = and v 255
311if eq v 4
312v = add 4 kt_u b add p 2 2
313else
314if not or eq v 2 eq v 3
315ret -23
316end
317v = 4
318end
319if not kt_range lim p v
320ret -23
321end
322p = add p v
323end
324if ne ord 1
325ret -23
326end
327ret 0
328end
329fn kt_hex c uchar to int
330if and ge c 48 le c 57
331ret sub int c 48
332end
333if and ge c 97 le c 102
334ret add sub int c 97 10
335end
336ret -1
337end
338fn kt_shape launch view uchar 4096 obs view uchar 2048 sizes view ulong 8 to int
339if or eq get sizes 0 0 gt get sizes 0 32768
340ret -20
341end
342if or eq get sizes 1 0 gt get sizes 1 128
343ret -20
344end
345if or eq get sizes 2 0 gt get sizes 2 63
346ret -20
347end
348for i ulong 5
349if ne get sizes add i 3 0
350ret -20
351end
352end
353if ne get sizes 1 mul compose_word launch 12 4
354ret -20
355end
356if or ne compose_word launch 0 1 ne compose_word launch 11 896
357ret -20
358end
359if or ne compose_word launch 13 1 ne compose_word launch 14 1
360ret -20
361end
362for i ulong 3880
363note Canonical launch tail begins at27 words, including reserved words27..31.
364if ne get launch add 216 i 0
365ret -20
366end
367end
368for i ulong 128
369if and ge i get sizes 1 ne get obs add 768 i 0
370ret -20
371end
372end
373for i ulong 64
374if lt i get sizes 2
375if eq get obs add 896 i 0
376ret -20
377end
378else
379if ne get obs add 896 i 0
380ret -20
381end
382end
383end
384for i ulong 32
385if ne get obs add 992 i 0
386ret -20
387end
388hi = kt_hex get obs add 1024 mul i 2
389lo = kt_hex get obs add 1025 mul i 2
390if or lt hi 0 lt lo 0
391ret -24
392end
393if ne get obs add 960 i uchar or shl hi 4 lo
394ret -24
395end
396end
397for i ulong 960
398if ne get obs add 1088 i 0
399ret -20
400end
401end
402ret 0
403end
404fn kt_qcheck launch view uchar 4096 obs view uchar 2048 to int
405for i ulong 3
406if ne kt_obs obs add 384 mul add 39 i 4 4 compose_word launch add 1 i
407ret -25
408end
409end
410if or eq compose_word launch 1 0 or eq compose_word launch 2 0 ne compose_word launch 3 1
411ret -25
412end
413if or eq compose_word launch 4 0 or gt compose_word launch 4 65535 ne compose_word launch 5 1
414ret -25
415end
416if ne compose_word launch 6 1
417ret -25
418end
419v = compose_word launch 4
420v = or v shl compose_word launch 5 16
421if ne kt_obs obs add ulong 384 mul ulong 34 4 4 v
422ret -25
423end
424v = kt_obs obs add ulong 384 mul ulong 35 4 4
425if ne and v 255 compose_word launch 6
426ret -25
427end
428gpr = compose_word launch 8
429if lt gpr 16
430gpr = 16
431end
432if or gt gpr 511 ne and shr v 8 511 gpr
433ret -25
434end
435v = compose_word launch 7
436if gt v 4294967295
437ret -25
438end
439if eq v 0
440v = 8
441else
442v = div add v 127 128
443end
444if gt v 2047
445ret -25
446end
447if ne and kt_obs obs add ulong 384 mul ulong 36 4 4 2047 v
448ret -25
449end
450ret 0
451end
452fn kt_equal launch view uchar 4096 hash view uchar 32 slot ulong to bool
453for i ulong 32
454if ne get launch add mul slot 8 i get hash i
455ret false
456end
457end
458ret true
459end
460fn kt_hashinfo launch view uchar 4096 cubin view uchar 32768 span view ulong 4 to bool
461buf = new uchar 4096 0
462hash = new uchar 32 0
463for i ulong get span 1
464put buf i get cubin add get span 0 i
465end
466if ne kc_sha buf get span 1 hash 0
467ret false
468end
469ret kt_equal launch hash 15
470end
471fn kt_obshash launch view uchar 4096 obs view uchar 2048 off ulong count ulong slot ulong to bool
472buf = new uchar 4096 0
473hash = new uchar 32 0
474for i ulong count
475put buf i get obs add off i
476end
477if ne kc_sha buf count hash 0
478ret false
479end
480ret kt_equal launch hash slot
481end
482fn kt_hashes launch view uchar 4096 cubin view uchar 32768 obs view uchar 2048 sizes view ulong 8 span view ulong 4 to int
483if not kt_hashinfo launch cubin span
484ret -26
485end
486if not kt_obshash launch obs 768 get sizes 1 19
487ret -27
488end
489if not kt_obshash launch obs 0 768 23
490ret -28
491end
492ret 0
493end
494fn kt_tailzero cubin view uchar 32768 n ulong to bool
495for i ulong sub 32768 n
496if ne get cubin add n i 0
497ret false
498end
499end
500ret true
501end
502fn native_templates launch view uchar 4096 cubin view uchar 32768 observed view uchar 2048 sizes view ulong 8 to long
503ctx = new ulong 12 0
504span = new ulong 4 0
505rc = kt_shape launch observed sizes
506if ne rc 0
507ret long rc
508end
509if not kt_tailzero cubin get sizes 0
510ret -20
511end
512rc = kt_elf cubin get sizes 0 observed get sizes 2 ctx
513if ne rc 0
514ret long rc
515end
516rc = kt_assoc cubin ctx observed get sizes 2
517if ne rc 0
518ret long rc
519end
520rc = kt_prefix cubin ctx launch span
521if ne rc 0
522ret long rc
523end
524rc = kt_banklink cubin ctx observed get sizes 2 span
525if ne rc 0
526ret long rc
527end
528rc = kt_tail cubin ctx launch span
529if ne rc 0
530ret long rc
531end
532rc = kt_qcheck launch observed
533if ne rc 0
534ret long rc
535end
536ret long kt_hashes launch cubin observed sizes span
537end