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 / disasm / opmove_test.om

238 lines · 5869 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note opmove_test.om: BlackwellIR ops 64..79 after the #280 numbering move (evidence/INTEG-280-20261110/numbering.txt),
3note through the seeded encoder and Omega's own sm_121 decoder (C6). Concatenate after om/encoder/bw_enc_sm121.om
4note and om/disasm/sm121_dis.om; mk/sm121dis.mk test-sm121dis-opmove compiles it with the pinned omc.
5note No arguments: encode one row of each op 64..79 with enc1 and decode its word with sm121_dis. Every word must
6note decode (no ??) and its mnemonic, the text before the first space, must equal the op's entry of omnem.
7note Exit 0; 10 + (op - 64) when the encoder refuses the row or the decoder does not know the word; 40 + (op - 64)
8note when the mnemonic differs.
9note Three arguments: the same check with the rows numbered as before the move (I2FP_U32 .. S32_F64 at 64..78, the
10note stale numbering, no ATOMG row). It must fail: the I2FP_U32 row then encodes op 64, ATOMG, so the exit is 41.
11note One argument: write the sixteen instructions (256 bytes) on stdout for the ORACLE.
12note Two arguments: read the ORACLE's text on stdin and require the decoder's text of each instruction, followed by
13note " ;", in order. Exit 0, 4 when a line is missing or out of order, 70 on a read error, 71 when the text is too long.
14note Four arguments: print the decoder's text of each instruction, one line each (a word it does not know prints ??).
15note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex, run on these
16note encoder bytes only. omnem holds the mnemonics it printed for them (evidence/INTEG-280-20261110/opmove-nvdisasm.txt).
17note Rows (op: dst, src1, src2, src3), all unguarded, default control:
18note 64 ATOMG_MIN_U64_STRONG_SYS R4, R2, R6, UR8 65 I2FP_U32 R4, R2 66 F2I_U32 R4, R2 67 F16_TO_F32 R4, R2
19note 68 F32_TO_F16 R4, R2 69 DADD R4, R2, R6 70 DMUL R4, R2, R6 71 DFMA R4, R2, R6, R8
20note 72 DSETP (no destination register) R2, R6 73 MUFU_RCP64H R4, R3 74 MUFU_RSQ64H R4, R3
21note 75 F64_F32 R4, R2 76 F32_F64 R4, R2 77 F64_S32 R4, R2 78 F64_U32 R4, R2 79 S32_F64 R4, R2
22text omnem "ATOMG.E.MIN.64.STRONG.SYS|I2FP.F32.U32|F2I.U32.TRUNC.NTZ|HADD2.F32|F2F.F16.F32|DADD|DMUL|DFMA|DSETP.GE.AND|MUFU.RCP64H|MUFU.RSQ64H|F2F.F64.F32|F2F.F32.F64|I2F.F64|I2F.F64.U32|F2I.F64.TRUNC|"
23
24note the record of row i (op 64 + i) in enc1's operand layout; the caller sets the op number
25fn om_row i ulong o edit ulong 16 to void
26for k ulong 16
27put o k 0
28end
29put o 1 4
30put o 2 2
31put o 3 6
32put o 4 255
33put o 15 1
34if eq i 0
35put o 5 8
36end
37if eq i 7
38put o 4 8
39end
40if eq i 8
41put o 15 0
42end
43if or eq i 9 eq i 10
44put o 2 3
45end
46end
47
48note the start of entry i of omnem
49fn om_tok i ulong to ulong
50s = ulong 0
51c = ulong 0
52while lt c i
53if eq get omnem s 124
54c = add c 1
55end
56s = add s 1
57end
58ret s
59end
60
61note is the text t[0..n) up to its first space entry i of omnem?
62fn om_mnem t view uchar 256 n ulong i ulong to bool
63s = om_tok i
64k = ulong 0
65while lt add s k len omnem
66c = get omnem add s k
67if eq c 124
68if eq k n
69ret true
70end
71ret eq get t k 32
72end
73if ge k n
74ret false
75end
76if ne get t k c
77ret false
78end
79k = add k 1
80end
81ret false
82end
83
84note decode the encoded words w of instruction i (byte address i * 16) into t; sm121_dis's result
85fn om_dis w view ulong 4 i ulong t edit uchar 256 to ulong
86lo = or get w 0 shl get w 1 32
87hi = or get w 2 shl get w 3 32
88ret sm121_dis lo hi mul i 16 t
89end
90
91note rows st..15; st 0 numbers row i as op 64 + i (the move), st 1 as op 63 + i (the stale numbering)
92fn om_self st ulong to int
93o = new ulong 16 0
94w = new ulong 4 0
95t = new uchar 256 0
96i = st
97while lt i 16
98om_row i edit o
99put o 0 sub add 64 i st
100if ne enc1 view o edit w 0
101ret int add 10 i
102end
103r = om_dis view w i edit t
104if ne and r 327680 0
105ret int add 10 i
106end
107if not om_mnem view t and r 65535 i
108ret int add 40 i
109end
110i = add i 1
111end
112ret 0
113end
114
115note the decoder's text of every row, one line each; 10 + (op - 64) when the encoder refuses a row
116fn om_list to int
117o = new ulong 16 0
118w = new ulong 4 0
119t = new uchar 256 0
120for i ulong 16
121om_row i edit o
122put o 0 add 64 i
123if ne enc1 view o edit w 0
124ret int add 10 i
125end
126r = om_dis view w i edit t
127n = and r 65535
128put t n 10
129if le write 1 t 0 add n 1 0
130ret 3
131end
132end
133ret 0
134end
135
136fn om_bin to int
137o = new ulong 16 0
138w = new ulong 4 0
139code = new uchar 16384 0
140for i ulong 16
141om_row i edit o
142put o 0 add 64 i
143if ne enc1 view o edit w 0
144ret int add 10 i
145end
146store edit code i view w
147end
148off = ulong 0
149while lt off 256
150n = write 1 code off sub 256 off
151if le n 0
152ret 3
153end
154off = add off ulong n
155end
156ret 0
157end
158
159note is buf[p..) the text t[0..n) followed by " ;"? The caller keeps p + n + 2 within buf's bytes.
160fn om_at buf view uchar 65536 p ulong t view uchar 256 n ulong to bool
161for j ulong n
162if ne get buf add p j get t j
163ret false
164end
165end
166if ne get buf add p n 32
167ret false
168end
169ret eq get buf add p add n 1 59
170end
171
172note the end of the first match of t[0..n) " ;" in buf[p..bn), or bn + 1 when absent
173fn om_find buf view uchar 65536 bn ulong p ulong t view uchar 256 n ulong to ulong
174while le add p add n 2 bn
175if om_at buf p t n
176ret add p add n 2
177end
178p = add p 1
179end
180ret add bn 1
181end
182
183fn om_check to int
184buf = new uchar 65536 0
185bn = ulong 0
186while lt bn 65536
187k = read 0 buf bn sub 65536 bn
188if lt k 0
189ret 70
190end
191if eq k 0
192break
193end
194bn = add bn ulong k
195end
196if eq bn 65536
197ret 71
198end
199o = new ulong 16 0
200w = new ulong 4 0
201t = new uchar 256 0
202pos = ulong 0
203for i ulong 16
204om_row i edit o
205put o 0 add 64 i
206if ne enc1 view o edit w 0
207ret int add 10 i
208end
209r = om_dis view w i edit t
210if ne and r 327680 0
211ret int add 10 i
212end
213pos = om_find view buf bn pos view t and r 65535
214if gt pos bn
215ret 4
216end
217end
218ret 0
219end
220
221fn main to int
222if gt argcnt 5
223ret 64
224end
225if eq argcnt 5
226ret om_list
227end
228if eq argcnt 4
229ret om_self 1
230end
231if eq argcnt 3
232ret om_check
233end
234if eq argcnt 2
235ret om_bin
236end
237ret om_self 0
238end