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

448 lines · 8476 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 this encoder emits (DRA-599).
3note Concatenate after om/encoder/bw_enc_sm121.om; om/encoder/guard-gate.sh 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..63 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 133 instructions (2128 bytes) on stdout for the ORACLE: the @P0 and @!P0 forms of the 62
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 < 124, even / odd),
20note then @UP0 / @!UP0 (124..127), then no guard, @P0, @!P0, @!P0, @!P0 (128..132). 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: 61440 = 0xf000 (guard mask), 124 = 2 * 62, 128 = 124 + 4, 133 = 128 + 5, 2128 = 133 * 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 gprow "row guards:"
32text gps " "
33text gpnl "\n"
34global gpbuf uchar 65536
35const GPNONE ulong 18446744073709551615
36
37note uniform-datapath ops: the guard bits name a uniform predicate
38fn gp_uni op ulong to bool
39ret or eq op 6 eq op 7
40end
41
42note encode op with form f (0 none, 1 @P0, 2 @!P0) into w; enc1's result (0 accepted)
43fn gp_enc op ulong f ulong w edit ulong 4 to ulong
44o = new ulong 16 0
45put o 0 op
46put o 1 4
47put o 2 8
48put o 3 12
49put o 4 16
50put o 5 4
51if or eq op 46 eq op 54
52put o 6 2
53end
54put o 12 1
55put o 13 1
56put o 14 1
57put o 15 1
58if ne f 0
59put o 9 1
60end
61if eq f 2
62put o 10 1
63end
64ret enc1 view o w
65end
66
67fn gp_dec x ulong to void
68b = new uchar 20 0
69i = ulong 20
70v = x
71c = true
72while c bound 20
73i = sub i 1
74put b i uchar add 48 rem v 10
75v = div v 10
76if eq v 0
77c = false
78end
79end
80k = write 1 b i sub 20 i
81end
82
83fn gp_fail op ulong f ulong g ulong to void
84k = write 1 gpm1 0 len gpm1
85gp_dec op
86k = write 1 gpm2 0 len gpm2
87gp_dec f
88k = write 1 gpm3 0 len gpm3
89gp_dec g
90k = write 1 gpnl 0 1
91end
92
93note the guard field of w0
94fn gp_g w view ulong 4 to ulong
95ret and shr get w 0 12 15
96end
97
98note equal outside the guard field
99fn gp_same u view ulong 4 p view ulong 4 to bool
100if ne or get u 0 61440 or get p 0 61440
101ret false
102end
103for k ulong 3
104if ne get u add k 1 get p add k 1
105ret false
106end
107end
108ret true
109end
110
111note the failing forms of op (0..2)
112fn gp_row op ulong to ulong
113u = new ulong 4 0
114p = new ulong 4 0
115if ne gp_enc op 0 edit u 0
116gp_fail op 0 99
117ret 1
118end
119bad = ulong 0
120for f ulong 2
121fm = add f 1
122r = gp_enc op fm edit p
123if gp_uni op
124if eq r 0
125gp_fail op fm 98
126bad = add bad 1
127end
128else
129if ne r 0
130gp_fail op fm 99
131bad = add bad 1
132else
133g = gp_g view p
134if ne g mul f 8
135gp_fail op fm g
136bad = add bad 1
137else
138if not gp_same view u view p
139gp_fail op fm 97
140bad = add bad 1
141end
142end
143end
144end
145end
146ret bad
147end
148
149note program row r: op, dst, src1, src2, imm, word 7 (2 @P0, 6 @!P0), and the guard it must get
150fn gp_pop r ulong to ulong
151if eq r 2
152ret 12
153end
154ret 2
155end
156fn gp_pdst r ulong to ulong
157if eq r 2
158ret GPNONE
159end
160if eq r 3
161ret 5
162end
163ret 4
164end
165fn gp_pimm r ulong to ulong
166if or eq r 1 eq r 3
167ret 1
168end
169ret 0
170end
171fn gp_pfl r ulong to ulong
172if eq r 0
173ret 0
174end
175if eq r 1
176ret 2
177end
178ret 6
179end
180fn gp_pg r ulong to ulong
181if eq r 0
182ret 7
183end
184if eq r 1
185ret 0
186end
187ret 8
188end
189
190note the five #1044 rows through bw_enc_sm121 into code; the byte count (80 when accepted)
191fn gp_penc code edit uchar 16384 to ulong
192ins = new ulong 8192 0
193phys = new ulong 288 0
194for v ulong 256
195put phys v v
196end
197for u ulong 32
198put phys add 256 u u
199end
200for r ulong 5
201b = mul r 8
202put ins b gp_pop r
203put ins add b 1 gp_pdst r
204put ins add b 2 GPNONE
205put ins add b 3 GPNONE
206put ins add b 4 GPNONE
207put ins add b 5 GPNONE
208put ins add b 6 gp_pimm r
209put ins add b 7 gp_pfl r
210if eq r 2
211put ins add b 2 8
212put ins add b 3 12
213put ins add b 5 4
214end
215end
216ret bw_enc_sm121 view ins view phys 5 0 code
217end
218
219fn gp_prog to ulong
220code = new uchar 16384 0
221if ne gp_penc edit code 80
222gp_fail 100 0 99
223ret 1
224end
225k = write 1 gprow 0 len gprow
226for r ulong 5
227k = write 1 gps 0 1
228g = and shr get code add mul r 16 1 4 15
229gp_dec ulong g
230end
231k = write 1 gpnl 0 1
232bad = ulong 0
233for r ulong 5
234g = and shr get code add mul r 16 1 4 15
235if ne ulong g gp_pg r
236gp_fail add 100 r gp_pfl r ulong g
237bad = add bad 1
238end
239end
240ret bad
241end
242
243fn gp_rows to int
244bad = ulong 0
245for op ulong 64
246bad = add bad gp_row op
247end
248bad = add bad gp_prog
249k = write 1 gpm4 0 len gpm4
250gp_dec bad
251k = write 1 gpnl 0 1
252if ne bad 0
253ret 1
254end
255ret 0
256end
257
258fn gp_bin to int
259w = new ulong 4 0
260code = new uchar 16384 0
261pc = new uchar 16384 0
262i = ulong 0
263for op ulong 64
264if not gp_uni op
265for f ulong 2
266if ne gp_enc op add f 1 edit w 0
267ret int add 10 op
268end
269store edit code i view w
270i = add i 1
271end
272end
273end
274for op ulong 64
275if gp_uni op
276if ne gp_enc op 0 edit w 0
277ret int add 10 op
278end
279x = get w 0
280for f ulong 2
281put w 0 or sub x and x 61440 shl mul f 8 12
282store edit code i view w
283i = add i 1
284end
285end
286end
287if ne gp_penc edit pc 80
288ret 9
289end
290for q ulong 80
291put code add mul i 16 q get pc q
292end
293n = add mul i 16 80
294off = ulong 0
295while lt off n bound 4096
296k = write 1 code off sub n off
297if le k 0
298ret 3
299end
300off = add off ulong k
301end
302ret 0
303end
304
305fn gp_ts t ulong to ulong
306if eq t 0
307ret 0
308end
309if eq t 1
310ret 4
311end
312if eq t 2
313ret 9
314end
315ret 14
316end
317
318note does token t of gptok start at gpbuf[j]? Token 4 is no guard (the mnemonic is not an @ word).
319fn gp_tok j ulong n ulong t ulong to bool
320if eq t 4
321if ge j n
322ret false
323end
324ret ne get gpbuf j 64
325end
326s = gp_ts t
327e = gp_ts add t 1
328if eq t 3
329e = 20
330end
331if gt add j sub e s n
332ret false
333end
334for q ulong sub e s
335if ne get gpbuf add j q get gptok add s q
336ret false
337end
338end
339ret true
340end
341
342note an address marker "/*" then a hex digit at gpbuf[i]; the caller keeps i + 2 below n
343fn gp_mark i ulong to bool
344if ne get gpbuf i 47
345ret false
346end
347if ne get gpbuf add i 1 42
348ret false
349end
350c = get gpbuf add i 2
351if and ge c 48 le c 57
352ret true
353end
354ret and ge c 97 le c 102
355end
356
357note the index after the marker's "*/" and the blanks that follow
358fn gp_after i ulong n ulong to ulong
359j = add i 2
360while lt add j 1 n bound 65536
361if eq get gpbuf j 42
362if eq get gpbuf add j 1 47
363j = add j 2
364break
365end
366end
367j = add j 1
368end
369while lt j n bound 65536
370c = get gpbuf j
371if and ne c 32 ne c 9
372break
373end
374j = add j 1
375end
376ret j
377end
378
379note the token instruction k must carry
380fn gp_want k ulong to ulong
381if lt k 124
382ret rem k 2
383end
384if lt k 128
385ret add 2 rem k 2
386end
387if eq k 128
388ret 4
389end
390if eq k 129
391ret 0
392end
393ret 1
394end
395
396fn gp_check to int
397n = ulong 0
398while lt n 65536 bound 65536
399r = read 0 gpbuf n sub 65536 n
400if lt r 0
401ret 70
402end
403if eq r 0
404break
405end
406n = add n ulong r
407end
408if eq n 65536
409ret 71
410end
411k = ulong 0
412bad = ulong 0
413i = ulong 0
414while lt add i 2 n bound 65536
415if gp_mark i
416j = gp_after i n
417if not gp_tok j n gp_want k
418bad = add bad 1
419end
420k = add k 1
421i = j
422else
423i = add i 1
424end
425end
426w = write 1 gpm5 0 len gpm5
427gp_dec k
428w = write 1 gpm6 0 len gpm6
429gp_dec bad
430w = write 1 gpnl 0 1
431if or ne k 133 ne bad 0
432ret 4
433end
434ret 0
435end
436
437fn main to int
438if gt argcnt 3
439ret 64
440end
441if eq argcnt 3
442ret gp_check
443end
444if eq argcnt 2
445ret gp_bin
446end
447ret gp_rows
448end