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

385 lines · 7805 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Compose after bw_enc_sm121.om. Host only. No device and no new instruction forms.
3note t emits 128-byte records for the existing C test adapter, c checks its 24-byte responses.
4note Each opcode 0..79 (#280 numbering: main op 64 ATOMG MIN, integ ops moved to 65..79) has eight operand forms, each with 1024 register/control/predicate samples.
5note Form bits: uniform-source selector, absent src2, absent src3. Samples also vary absent dst, src1 and ureg.
6note Then opcodes 0..81 (the two past the last op are unknown) each get PP_EDGES refusal-edge samples (pp_edge), printed as "edge op=" rows.
7note The oracle adapter only marshals fields and calls the independent C encoder.
8text pp_ok " parity samples="
9text pp_yes " accepted="
10text pp_no " refused="
11text pp_op "op="
12text pp_edg "edge "
13text pp_form " form="
14text pp_nl "\n"
15text pp_bad "ENCODER PARITY FAIL\n"
16fn pp_num n ulong to void
17b = new uchar 32 0
18v = n
19pos = ulong 32
20while true bound 32
21pos = sub pos 1
22put b pos uchar add rem v 10 48
23v = div v 10
24if eq v 0
25break
26end
27end
28r = write 2 b pos sub 32 pos
29if ne r long sub 32 pos
30exit 2
31end
32end
33fn pp_text b view uchar * to void
34r = write 2 b 0 len b
35if ne r long len b
36exit 2
37end
38end
39fn pp_case a edit ulong 16 op ulong j ulong to void
40for k ulong 16
41put a k 0
42end
43note Registers 0..251: 37 is prime to 252, so 252 consecutive indices give every residue, odd and high-bit included;
44note src3 = reg + 4 stays at or below 255. WolframLanguageEvaluator: Length[Union[Mod[37 Range[0,1023],252]]] -> 252.
45reg = rem mul shr j 3 37 252
46put a 0 op
47put a 1 reg
48if isuld op
49put a 1 rem reg 32
50end
51put a 2 reg
52put a 3 add reg 2
53put a 4 add reg 4
54put a 5 rem j 32
55put a 6 and j 31
56if eq op 54
57put a 6 add and j 31 2
58end
59if or eq op 18 eq op 29
60put a 6 and j 255
61end
62if eq op 51
63put a 6 and j 255
64end
65if ne and j 8 0
66note Control (passed through by both encoders) varies all 32 bits and is never 0: 2654435761 is odd, so j+1 below 2^32
67note never maps to 0. WolframLanguageEvaluator over the 4096 samples with j bit 3 set: 32 of 32 bits take both values.
68put a 7 rem mul add j 1 2654435761 4294967296
69end
70form = shr j 10
71put a 8 and form 1
72if ne rem j 3 0
73put a 9 1
74end
75if eq rem j 3 2
76put a 10 1
77end
78put a 11 and shr j 6 15
79note Subregs 0/1 on dst, src1, src2 and src3: both encoders use phys + subreg. On uniform loads both encoders ignore
80note dst_subreg; sampling it there keeps that rule under parity too.
81note src3 = reg + 4 + subreg stays at or below 255 because its subreg is set only while reg is below 251.
82put a 12 and shr j 4 1
83put a 13 and shr j 5 1
84put a 14 and shr j 9 1
85if lt reg 251
86put a 15 and shr j 2 1
87end
88note Absent operands exercise RZ/default routing independently of the physical register samples.
89if ne and form 2 0
90put a 3 18446744073709551615
91end
92if ne and form 4 0
93put a 4 18446744073709551615
94end
95if ne and j 64 0
96put a 2 18446744073709551615
97end
98if ne and j 128 0
99put a 1 18446744073709551615
100end
101if ne and j 256 0
102put a 5 18446744073709551615
103end
104end
105note Refusal edges. pp_case keeps imm below 288, barrier registers below 16, dst and src1 at or below 252 and the
106note opcode at or below 78, so it never reaches these refusal bounds of the two encoders: the signed 24-bit offsets
107note (LDG, STG, fragment loads: -2^23 accepted, -2^23-1 refused, 2^23-1 accepted, 2^23 refused), the LDS offset
108note (2^23 refused), the BSSY delta (0 and 1 refused, 2 accepted), the BSSY/BSYNC barrier limit (15 accepted, 16 and
109note 255 refused), the f64 pair bound (252 accepted, 254 refused, on dst, src1, src2 and src3, and 253 through a
110note subreg), the top uniform register 31, and unknown opcodes 79 and 80. Each case sets one field to one edge on
111note a fixed even-register base (dst 10, src1 12, src2 14, src3 16, ureg 4, imm 64, control 2654435761); cases
112note 22..43 repeat 0..21 with src2 and src3 absent, so ops that refuse a present src2 or src3 still reach the edge.
113note A C oracle (or encoder) that moves any of these bounds by one changes an accept or a refusal and fails parity.
114const PP_EDGES ulong 44
115fn pp_edge a edit ulong 16 op ulong b ulong to void
116for k ulong 16
117put a k 0
118end
119e = rem b 22
120put a 0 op
121put a 1 10
122put a 2 12
123put a 3 14
124put a 4 16
125put a 5 4
126put a 6 64
127put a 7 2654435761
128if ge b 22
129put a 3 18446744073709551615
130put a 4 18446744073709551615
131end
132if eq e 1
133put a 6 8388607
134end
135if eq e 2
136put a 6 8388608
137end
138if eq e 3
139put a 6 4286578688
140end
141if eq e 4
142put a 6 4286578687
143end
144if eq e 5
145put a 6 4294967295
146end
147if eq e 6
148put a 6 0
149end
150if eq e 7
151put a 6 1
152end
153if eq e 8
154put a 6 2
155end
156if eq e 9
157put a 11 15
158end
159if eq e 10
160put a 11 16
161end
162if eq e 11
163put a 11 255
164end
165if eq e 12
166put a 1 252
167end
168if eq e 13
169put a 1 254
170end
171if eq e 14
172put a 2 252
173end
174if eq e 15
175put a 2 254
176end
177if eq e 16
178put a 3 254
179end
180if eq e 17
181put a 4 254
182end
183if eq e 18
184put a 4 255
185end
186if eq e 19
187put a 1 252
188put a 12 1
189end
190if eq e 20
191put a 2 252
192put a 13 1
193end
194if eq e 21
195put a 5 31
196end
197note Uniform destinations index uvreg_to_phys (32 entries), as in pp_case.
198if isuld op
199put a 1 rem get a 1 32
200end
201end
202fn pp_pack a view ulong 16 ins edit ulong 8192 to void
203for k ulong 6
204put ins k get a k
205end
206put ins 6 or get a 6 shl get a 7 32
207f = or get a 8 shl get a 9 1
208f = or f shl get a 10 2
209f = or f shl get a 11 8
210for k ulong 4
211f = or f shl get a add k 12 add 16 mul k 8
212end
213put ins 7 f
214end
215fn pp_tape a view ulong 16 to void
216b = new uchar 128 0
217for k ulong 16
218for h ulong 8
219put b add mul k 8 h uchar and shr get a k mul h 8 255
220end
221end
222n = write 1 b 0 128
223if ne n 128
224exit 2
225end
226end
227fn pp_read b edit uchar 24 to void
228n = ulong 0
229while lt n 24 bound 24
230r = read 0 b n sub 24 n
231if le r 0
232exit 2
233end
234n = add n ulong r
235end
236end
237fn pp_check b view uchar 24 got ulong code view uchar 16384 to bool
238if eq got 16
239for k ulong 8
240if ne get b k 0
241ret false
242end
243end
244for k ulong 16
245if ne get b add k 8 get code k
246ret false
247end
248end
249else
250for k ulong 8
251if ne get b k 255
252ret false
253end
254end
255end
256ret true
257end
258note The refusal-edge pass: tape mode (m 116) writes the records, any other mode checks the replies in the same order.
259fn pp_edges m ulong to int
260a = new ulong 16 0
261ins = new ulong 8192 0
262phys = new ulong 288 0
263code = new uchar 16384 0
264reply = new uchar 24 0
265for k ulong 256
266put phys k k
267end
268for k ulong 32
269put phys add k 256 k
270end
271for op ulong 82
272yes = ulong 0
273for b ulong PP_EDGES
274pp_edge a op b
275if eq m 116
276pp_tape a
277else
278pp_pack a ins
279got = bw_enc_sm121 ins phys 1 0 code
280if eq got 16
281yes = add yes 1
282end
283pp_read reply
284if not pp_check reply got code
285pp_text pp_bad
286pp_num op
287pp_text pp_nl
288pp_num add 8192 b
289pp_text pp_nl
290ret 1
291end
292end
293end
294if ne m 116
295pp_text pp_edg
296pp_text pp_op
297pp_num op
298pp_text pp_ok
299pp_num PP_EDGES
300pp_text pp_yes
301pp_num yes
302pp_text pp_no
303pp_num sub PP_EDGES yes
304pp_text pp_nl
305end
306end
307ret 0
308end
309fn main to int
310mode = new uchar 8 0
311a = new ulong 16 0
312ins = new ulong 8192 0
313phys = new ulong 288 0
314code = new uchar 16384 0
315reply = new uchar 24 0
316r = argread 1 mode 0 8
317if lt r 1
318ret 2
319end
320for k ulong 256
321put phys k k
322end
323for k ulong 32
324put phys add k 256 k
325end
326for op ulong 80
327for form ulong 8
328yes = ulong 0
329for j ulong 1024
330pp_case a op add mul form 1024 j
331if eq get mode 0 116
332pp_tape a
333else
334pp_pack a ins
335got = bw_enc_sm121 ins phys 1 0 code
336if eq got 16
337yes = add yes 1
338end
339pp_read reply
340if eq get mode 0 114
341if eq op 0
342if eq form 0
343if eq j 0
344put reply 8 xor get reply 8 1
345end
346end
347end
348end
349if not pp_check reply got code
350pp_text pp_bad
351pp_num op
352pp_text pp_nl
353pp_num j
354pp_text pp_nl
355ret 1
356end
357end
358end
359if ne get mode 0 116
360pp_text pp_op
361pp_num op
362pp_text pp_form
363pp_num form
364pp_text pp_ok
365pp_num 1024
366pp_text pp_yes
367pp_num yes
368pp_text pp_no
369pp_num sub 1024 yes
370pp_text pp_nl
371end
372end
373end
374er = pp_edges ulong get mode 0
375if ne er 0
376ret 1
377end
378if ne get mode 0 116
379r = read 0 reply 0 1
380if ne r 0
381ret 2
382end
383end
384ret 0
385end