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 / encoder / guard_pred_test.om

439 lines · 8299 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note guard_pred_test.om: gate for the guard predicate of every sm_121 op in the seeded encoder (DRA-483, C1b).
3note Concatenate after bw_enc_sm121.om; mk/om-encoder.mk test-om-encoder-guard compiles it with the pinned omc.
4note Input word 7 bit 1 (predicate_p0) and bit 2 (predicate_not) ask for @P0 / @!P0; the guard is w0 bits 12..15:
5note 7 always (PT), 0 @P0, 8 @!P0. Every op 0..64 is encoded three times with R4 <- R8, R12, R16, UR4 (imm 2 for
6note BRA and BSSY, else 0): unpredicated, @P0 and @!P0. The @P0 / @!P0 words must carry guard 0 / 8 and equal the
7note unpredicated words in every other bit. LDCU and LDCU.64 (ops 6, 7) are uniform-datapath instructions: their
8note guard bits name UP0..UPT, so @P0 cannot be encoded there and both forms must be refused.
9note Program rows: the omega-mv #1044 seed/oscgpu bool and trap shapes (gpuir.om bw_bool, bw_trap; the C twin is
10note src/omega_osc_gpu.c Bool, Trap) go through the program entry bw_enc_sm121 with word 7 as the C packer writes
11note it: MOV R4, 0 / @P0 MOV R4, 1 / @!P0 STG.E desc[UR4][R8.64], R12 / @!P0 MOV R5, 1 / @!P0 MOV R4, 0. Their
12note guards must be 7, 0, 8, 8, 8.
13note No arguments: print one line per failing form (op, form 1 @P0 / 2 @!P0, guard read; 99 refused, 98 accepted
14note but must refuse, 97 another bit changed; program rows as op 100 + row), then the failure count; exit 0 when
15note none, else 1.
16note One argument: write 135 instructions (2160 bytes) on stdout for the ORACLE: the @P0 and @!P0 forms of the 63
17note P-guarded ops in op order, then the unpredicated LDCU and LDCU.64 words with their guard bits set to 0 and 8
18note (an oracle probe, not encoder output), then the five program rows.
19note Two arguments: read the ORACLE's text on stdin; instruction k must start with @P0 / @!P0 (k < 126, even / odd),
20note then @UP0 / @!UP0 (126..129), then no guard, @P0, @!P0, @!P0, @!P0 (130..134). Exit 0, 4 when a guard or the
21note instruction count is wrong, 70 read error, 71 text too long.
22note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex.
23note Constants (Wolfram): 61440 = 0xf000 (guard mask), 130 = 2 * 65, 135 = 130 + 5, 2160 = 135 * 16.
24text gptok "@P0 @!P0 @UP0 @!UP0 "
25text gpm1 "FAIL op "
26text gpm2 " form "
27text gpm3 " guard "
28text gpm4 "guard predicate failures: "
29text gpm5 "oracle instructions: "
30text gpm6 " guard mismatches: "
31text gpnl "\n"
32global gpbuf uchar 65536
33const GPNONE ulong 18446744073709551615
34
35note uniform-datapath ops: the guard bits name a uniform predicate
36fn gp_uni op ulong to bool
37ret or eq op 6 eq op 7
38end
39
40note encode op with form f (0 none, 1 @P0, 2 @!P0) into w; enc1's result (0 accepted)
41fn gp_enc op ulong f ulong w edit ulong 4 to ulong
42o = new ulong 16 0
43put o 0 op
44put o 1 4
45put o 2 8
46put o 3 12
47put o 4 16
48put o 5 4
49if or eq op 46 eq op 54
50put o 6 2
51end
52put o 12 1
53put o 13 1
54put o 14 1
55put o 15 1
56if ne f 0
57put o 9 1
58end
59if eq f 2
60put o 10 1
61end
62ret enc1 view o w
63end
64
65fn gp_dec x ulong to void
66b = new uchar 20 0
67i = ulong 20
68v = x
69c = true
70while c bound 20
71i = sub i 1
72put b i uchar add 48 rem v 10
73v = div v 10
74if eq v 0
75c = false
76end
77end
78k = write 1 b i sub 20 i
79end
80
81fn gp_fail op ulong f ulong g ulong to void
82k = write 1 gpm1 0 len gpm1
83gp_dec op
84k = write 1 gpm2 0 len gpm2
85gp_dec f
86k = write 1 gpm3 0 len gpm3
87gp_dec g
88k = write 1 gpnl 0 1
89end
90
91note the guard field of w0
92fn gp_g w view ulong 4 to ulong
93ret and shr get w 0 12 15
94end
95
96note equal outside the guard field
97fn gp_same u view ulong 4 p view ulong 4 to bool
98if ne or get u 0 61440 or get p 0 61440
99ret false
100end
101for k ulong 3
102if ne get u add k 1 get p add k 1
103ret false
104end
105end
106ret true
107end
108
109note the failing forms of op (0..2)
110fn gp_row op ulong to ulong
111u = new ulong 4 0
112p = new ulong 4 0
113if ne gp_enc op 0 edit u 0
114gp_fail op 0 99
115ret 1
116end
117bad = ulong 0
118for f ulong 2
119fm = add f 1
120r = gp_enc op fm edit p
121if gp_uni op
122if eq r 0
123gp_fail op fm 98
124bad = add bad 1
125end
126else
127if ne r 0
128gp_fail op fm 99
129bad = add bad 1
130else
131g = gp_g view p
132if ne g mul f 8
133gp_fail op fm g
134bad = add bad 1
135else
136if not gp_same view u view p
137gp_fail op fm 97
138bad = add bad 1
139end
140end
141end
142end
143end
144ret bad
145end
146
147note program row r: op, dst, src1, src2, imm, word 7 (2 @P0, 6 @!P0), and the guard it must get
148fn gp_pop r ulong to ulong
149if eq r 2
150ret 12
151end
152ret 2
153end
154fn gp_pdst r ulong to ulong
155if eq r 2
156ret GPNONE
157end
158if eq r 3
159ret 5
160end
161ret 4
162end
163fn gp_pimm r ulong to ulong
164if or eq r 1 eq r 3
165ret 1
166end
167ret 0
168end
169fn gp_pfl r ulong to ulong
170if eq r 0
171ret 0
172end
173if eq r 1
174ret 2
175end
176ret 6
177end
178fn gp_pg r ulong to ulong
179if eq r 0
180ret 7
181end
182if eq r 1
183ret 0
184end
185ret 8
186end
187
188note the five #1044 rows through bw_enc_sm121 into code; the byte count (80 when accepted)
189fn gp_penc code edit uchar 16384 to ulong
190ins = new ulong 8192 0
191phys = new ulong 288 0
192for v ulong 256
193put phys v v
194end
195for u ulong 32
196put phys add 256 u u
197end
198for r ulong 5
199b = mul r 8
200put ins b gp_pop r
201put ins add b 1 gp_pdst r
202put ins add b 2 GPNONE
203put ins add b 3 GPNONE
204put ins add b 4 GPNONE
205put ins add b 5 GPNONE
206put ins add b 6 gp_pimm r
207put ins add b 7 gp_pfl r
208if eq r 2
209put ins add b 2 8
210put ins add b 3 12
211put ins add b 5 4
212end
213end
214ret bw_enc_sm121 view ins view phys 5 0 code
215end
216
217fn gp_prog to ulong
218code = new uchar 16384 0
219if ne gp_penc edit code 80
220gp_fail 100 0 99
221ret 1
222end
223bad = ulong 0
224for r ulong 5
225g = and shr get code add mul r 16 1 4 15
226if ne ulong g gp_pg r
227gp_fail add 100 r gp_pfl r ulong g
228bad = add bad 1
229end
230end
231ret bad
232end
233
234fn gp_rows to int
235bad = ulong 0
236for op ulong 65
237bad = add bad gp_row op
238end
239bad = add bad gp_prog
240k = write 1 gpm4 0 len gpm4
241gp_dec bad
242k = write 1 gpnl 0 1
243if ne bad 0
244ret 1
245end
246ret 0
247end
248
249fn gp_bin to int
250w = new ulong 4 0
251code = new uchar 16384 0
252pc = new uchar 16384 0
253i = ulong 0
254for op ulong 65
255if not gp_uni op
256for f ulong 2
257if ne gp_enc op add f 1 edit w 0
258ret int add 10 op
259end
260store edit code i view w
261i = add i 1
262end
263end
264end
265for op ulong 65
266if gp_uni op
267if ne gp_enc op 0 edit w 0
268ret int add 10 op
269end
270x = get w 0
271for f ulong 2
272put w 0 or sub x and x 61440 shl mul f 8 12
273store edit code i view w
274i = add i 1
275end
276end
277end
278if ne gp_penc edit pc 80
279ret 9
280end
281for q ulong 80
282put code add mul i 16 q get pc q
283end
284n = add mul i 16 80
285off = ulong 0
286while lt off n bound 4096
287k = write 1 code off sub n off
288if le k 0
289ret 3
290end
291off = add off ulong k
292end
293ret 0
294end
295
296fn gp_ts t ulong to ulong
297if eq t 0
298ret 0
299end
300if eq t 1
301ret 4
302end
303if eq t 2
304ret 9
305end
306ret 14
307end
308
309note does token t of gptok start at gpbuf[j]? Token 4 is no guard (the mnemonic is not an @ word).
310fn gp_tok j ulong n ulong t ulong to bool
311if eq t 4
312if ge j n
313ret false
314end
315ret ne get gpbuf j 64
316end
317s = gp_ts t
318e = gp_ts add t 1
319if eq t 3
320e = 20
321end
322if gt add j sub e s n
323ret false
324end
325for q ulong sub e s
326if ne get gpbuf add j q get gptok add s q
327ret false
328end
329end
330ret true
331end
332
333note an address marker "/*" then a hex digit at gpbuf[i]; the caller keeps i + 2 below n
334fn gp_mark i ulong to bool
335if ne get gpbuf i 47
336ret false
337end
338if ne get gpbuf add i 1 42
339ret false
340end
341c = get gpbuf add i 2
342if and ge c 48 le c 57
343ret true
344end
345ret and ge c 97 le c 102
346end
347
348note the index after the marker's "*/" and the blanks that follow
349fn gp_after i ulong n ulong to ulong
350j = add i 2
351while lt add j 1 n bound 65536
352if eq get gpbuf j 42
353if eq get gpbuf add j 1 47
354j = add j 2
355break
356end
357end
358j = add j 1
359end
360while lt j n bound 65536
361c = get gpbuf j
362if and ne c 32 ne c 9
363break
364end
365j = add j 1
366end
367ret j
368end
369
370note the token instruction k must carry
371fn gp_want k ulong to ulong
372if lt k 126
373ret rem k 2
374end
375if lt k 130
376ret add 2 rem k 2
377end
378if eq k 130
379ret 4
380end
381if eq k 131
382ret 0
383end
384ret 1
385end
386
387fn gp_check to int
388n = ulong 0
389while lt n 65536 bound 65536
390r = read 0 gpbuf n sub 65536 n
391if lt r 0
392ret 70
393end
394if eq r 0
395break
396end
397n = add n ulong r
398end
399if eq n 65536
400ret 71
401end
402k = ulong 0
403bad = ulong 0
404i = ulong 0
405while lt add i 2 n bound 65536
406if gp_mark i
407j = gp_after i n
408if not gp_tok j n gp_want k
409bad = add bad 1
410end
411k = add k 1
412i = j
413else
414i = add i 1
415end
416end
417w = write 1 gpm5 0 len gpm5
418gp_dec k
419w = write 1 gpm6 0 len gpm6
420gp_dec bad
421w = write 1 gpnl 0 1
422if or ne k 135 ne bad 0
423ret 4
424end
425ret 0
426end
427
428fn main to int
429if gt argcnt 3
430ret 64
431end
432if eq argcnt 3
433ret gp_check
434end
435if eq argcnt 2
436ret gp_bin
437end
438ret gp_rows
439end