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

313 lines · 4676 bytes Raw Blame History
1note bw_spec_cmp.om: comparison of spec-driven encoder/decoder vs reference encoder
2
3fn read_exact fd int buf edit uchar 128 n ulong to long
4got = ulong 0
5while lt got n bound 128
6r = read fd buf got sub n got
7if lt r 0
8ret -1
9end
10if eq r 0
11if ne got 0
12ret -1
13end
14ret 0
15end
16got = add got ulong r
17end
18ret long got
19end
20
21fn unpack_u64 buf view uchar 128 off ulong to ulong
22v = ulong 0
23for b ulong 8
24sh = mul b 8
25byte_v = ulong get buf add off b
26v = or v shl byte_v sh
27end
28ret v
29end
30
31fn unpack_case buf view uchar 128 o edit ulong 16 to void
32for i ulong 16
33off = mul i 8
34put o i unpack_u64 buf off
35end
36end
37
38note Compare active semantic roles, not inactive packing slots. Zero control
39note and FSET default are documented canonicalizations, absent RA/RB means RZ.
40note Keep field-local values out of the seeded comparator's register live range.
41fn same_fld sp_tbl view ulong 3001 fb ulong o view ulong 16 dec view ulong 16 to bool
42role = get sp_tbl fb
43word = get sp_tbl add fb 1
44a = sp_val role word o
45b = sp_val role word dec
46if and eq role R_FSET eq a 0
47a = 66084864
48end
49if ne a b
50ret false
51end
52ret true
53end
54
55fn same_sem sp_tbl view ulong 3001 o view ulong 16 dec view ulong 16 to bool
56idx = sp_find sp_tbl o
57if eq idx 63
58ret false
59end
60if ne sp_find sp_tbl dec idx
61ret false
62end
63if ne get o 0 get dec 0
64ret false
65end
66base = mul idx 45
67control = get o 7
68if eq control 0
69control = get sp_tbl add base 8
70if eq get o 0 46
71if and eq get o 6 0 eq get o 9 0
72control = 1032192
73else
74control = 1042944
75end
76end
77end
78if ne control get dec 7
79ret false
80end
81nf = get sp_tbl add base 9
82for f ulong nf
83fb = add add base 10 mul f 7
84if not same_fld sp_tbl fb o dec
85ret false
86end
87end
88ret true
89end
90
91fn run_check_loop sp_tbl edit ulong 3001 corrupt bool to int
92buf = new uchar 128 0
93o = new ulong 16 0
94w_ref = new ulong 4 0
95w_spec = new ulong 4 0
96o_dec = new ulong 16 0
97count = ulong 0
98
99while lt count 500 bound 500
100r = read_exact int 0 buf 128
101if lt r 0
102ret 2
103end
104if eq r 0
105break
106end
107unpack_case buf o
108if ne enc1 o w_ref 0
109ret 1
110end
111if ne sp_enc sp_tbl o w_spec 0
112ret 1
113end
114if and corrupt eq count 0
115put w_ref 0 xor get w_ref 0 1
116end
117for k ulong 4
118if ne get w_ref k get w_spec k
119ret 1
120end
121end
122if ne sp_dec sp_tbl w_spec o_dec 0
123ret 1
124end
125if not same_sem sp_tbl o o_dec
126ret 1
127end
128count = add count 1
129end
130
131if ne count 461
132ret 1
133end
134ret 0
135end
136
137fn emit_sample sp_tbl edit ulong 3001 s_idx ulong to int
138o = new ulong 16 0
139w = new ulong 4 0
140buf = new uchar 16 0
141
142if eq s_idx 0
143note NOP
144put o 0 0
145end
146if eq s_idx 1
147note IMAD R0, R1, R2, R3
148put o 0 8
149put o 1 0
150put o 2 1
151put o 3 2
152put o 4 3
153put o 12 1
154put o 13 1
155end
156if eq s_idx 2
157note FADD R4, R5, R6
158put o 0 30
159put o 1 4
160put o 2 5
161put o 3 6
162put o 12 1
163put o 13 1
164end
165if eq s_idx 3
166note LDG.E R10, desc[UR5][R12.64]
167put o 0 11
168put o 1 10
169put o 2 12
170put o 5 5
171put o 12 1
172put o 14 1
173end
174if eq s_idx 4
175note BRA 0x100
176put o 0 46
177put o 6 16
178end
179
180st = sp_enc sp_tbl o w
181if ne st 0
182ret 1
183end
184
185for i ulong 4
186v = get w i
187off = mul i 4
188for b ulong 4
189sh = mul b 8
190put buf add off b uchar and shr v sh 255
191end
192end
193
194sent = ulong 0
195while lt sent 16 bound 16
196k = write int 1 buf sent sub 16 sent
197if le k 0
198ret 1
199end
200sent = add sent ulong k
201end
202ret 0
203end
204
205fn run_neg_mutant sp_tbl edit ulong 3001 to int
206o = new ulong 16 0
207w_mut = new ulong 4 0
208w_ref = new ulong 4 0
209decoded = new ulong 16 0
210put o 0 1
211put o 1 5
212r_ref = enc1 o w_ref
213if ne r_ref 0
214ret 1
215end
216
217note Shift field on form 1 (MOV_RZ): fbase = 55, shift is at 57
218orig_sh = get sp_tbl 57
219put sp_tbl 57 add orig_sh 1
220r_mut = sp_enc sp_tbl o w_mut
221put sp_tbl 57 orig_sh
222
223if ne r_mut 0
224ret 1
225end
226
227same = true
228for i ulong 4
229if ne get w_mut i get w_ref i
230same = false
231end
232end
233
234if same
235ret 1
236end
237if ne sp_dec sp_tbl w_mut decoded E_OK
238ret 1
239end
240if same_sem sp_tbl o decoded
241ret 1
242end
243ret 0
244end
245
246fn run_neg_range sp_tbl edit ulong 3001 to int
247o = new ulong 16 0
248w = new ulong 4 0
249put o 0 1
250put o 1 256
251st = sp_enc sp_tbl o w
252if ne st E_RANGE
253ret 1
254end
255ret 0
256end
257
258fn run_neg_nomat sp_tbl edit ulong 3001 to int
259w = new ulong 4 4294967295
260dec = new ulong 16 0
261dst = sp_dec sp_tbl w dec
262if ne dst E_NOMAT
263ret 1
264end
265ret 0
266end
267
268fn main to int
269sp_tbl = new ulong 3001 0
270sp_init sp_tbl
271mode = new uchar 16 0
272k = ulong 0
273if ge argcnt 2
274read_k = argread 1 mode 0 16
275if gt read_k 0
276k = ulong read_k
277end
278end
279
280if eq k 0
281ret run_check_loop sp_tbl false
282end
283
284c0 = get mode 0
285
286if eq c0 99
287note 'c' -> corrupt
288ret run_check_loop sp_tbl true
289end
290
291if eq c0 115
292note 's' -> sample
293s_idx = sub ulong get mode 6 48
294ret emit_sample sp_tbl s_idx
295end
296
297if eq c0 109
298note 'm' -> mutant
299ret run_neg_mutant sp_tbl
300end
301
302if eq c0 114
303note 'r' -> range
304ret run_neg_range sp_tbl
305end
306
307if eq c0 110
308note 'n' -> nomat
309ret run_neg_nomat sp_tbl
310end
311
312ret 1
313end