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

164 lines · 4070 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note ldg_offset_test.om: gate for the signed 24-bit byte offset of LDG.E (op 11) in the seeded encoder (#373).
3note Concatenate after bw_enc_sm121.om; mk/om-encoder.mk test-om-encoder-ldg compiles it with the pinned omc.
4note No arguments: every row through enc1. Accepted offsets 0, +0x40, -0x100000, +0x7fffff, -0x800000 must give
5note exactly the words below; +0x800000, -0x800001, 0x7fffffff and 0x80000000 must be refused.
6note Exit 0, else 10+r for accepted row r, 20+r for refused row r.
7note One argument: write the five accepted instructions (80 bytes) on stdout for the ORACLE.
8note Two arguments: read the ORACLE's text on stdin and require the five LDG.E lines of ldgnd in order.
9note Exit 0, 4 when a line is missing or out of order, 70 on a read error, 71 when the text is too long.
10note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex. The packing is the
11note C encoder's (src/omega_blackwell_codegen.c bw_c_encode_insn: w1 = ureg or (imm and 0xffffff) shl 8); the
12note first four w1 values are the words that encoder produced in #373's freestanding run.
13note Operands: R2 <- desc[UR8][R30.64+imm]. Decimal constants by Wolfram: w0 503478657 = 0x1e027981,
14note w2 203299072 = 0x0c1e1900, w3 991744 = 0x000f2200; w1: 8, 16392 = 0x4008, 4026531848 = 0xf0000008,
15note 2147483400 = 0x7fffff08, 2147483656 = 0x80000008. Offsets as uint32: 64, 4293918720 = -0x100000,
16note 8388607, 4286578688 = -0x800000; refused 8388608 = 0x800000, 4286578687 = -0x800001, 2147483647, 2147483648.
17text ldgnd "LDG.E R2, desc[UR8][R30.64] ;|LDG.E R2, desc[UR8][R30.64+0x40] ;|LDG.E R2, desc[UR8][R30.64+-0x100000] ;|LDG.E R2, desc[UR8][R30.64+0x7fffff] ;|LDG.E R2, desc[UR8][R30.64+-0x800000] ;|"
18global lt_imm ulong 5
19global lt_w1 ulong 5
20global lt_bad ulong 4
21
22fn lt_init to void
23put lt_imm 0 0
24put lt_imm 1 64
25put lt_imm 2 4293918720
26put lt_imm 3 8388607
27put lt_imm 4 4286578688
28put lt_w1 0 8
29put lt_w1 1 16392
30put lt_w1 2 4026531848
31put lt_w1 3 2147483400
32put lt_w1 4 2147483656
33put lt_bad 0 8388608
34put lt_bad 1 4286578687
35put lt_bad 2 2147483647
36put lt_bad 3 2147483648
37end
38
39note encode LDG.E R2, desc[UR8][R30.64+imm] into w; enc1's result (0 accepted)
40fn lt_enc imm ulong w edit ulong 4 to ulong
41o = new ulong 16 0
42put o 0 11
43put o 1 2
44put o 2 30
45put o 5 8
46put o 6 imm
47ret enc1 view o w
48end
49
50fn lt_words w view ulong 4 r ulong to bool
51if ne get w 0 503478657
52ret false
53end
54if ne get w 1 get lt_w1 r
55ret false
56end
57if ne get w 2 203299072
58ret false
59end
60ret eq get w 3 991744
61end
62
63fn lt_rows to int
64w = new ulong 4 0
65for r ulong 5
66if ne lt_enc get lt_imm r edit w 0
67ret int add 10 r
68end
69if not lt_words view w r
70ret int add 10 r
71end
72end
73for r ulong 4
74if eq lt_enc get lt_bad r edit w 0
75ret int add 20 r
76end
77end
78ret 0
79end
80
81fn lt_bin to int
82w = new ulong 4 0
83code = new uchar 16384 0
84for r ulong 5
85if ne lt_enc get lt_imm r edit w 0
86ret int add 10 r
87end
88store edit code r view w
89end
90off = ulong 0
91while lt off 80
92n = write 1 code off sub 80 off
93if le n 0
94ret 3
95end
96off = add off ulong n
97end
98ret 0
99end
100
101note does needle ldgnd[s..e) start at buf[i]? The caller keeps i + e - s within the text.
102fn lt_at buf view uchar 65536 i ulong s ulong e ulong to bool
103for j ulong sub e s
104if ne get buf add i j get ldgnd add s j
105ret false
106end
107end
108ret true
109end
110
111note the end of the first match of ldgnd[s..e) in buf[i..n), or n+1 when absent
112fn lt_find buf view uchar 65536 n ulong i ulong s ulong e ulong to ulong
113while le add i sub e s n
114if lt_at buf i s e
115ret add i sub e s
116end
117i = add i 1
118end
119ret add n 1
120end
121
122fn lt_check to int
123buf = new uchar 65536 0
124n = ulong 0
125while lt n 65536
126k = read 0 buf n sub 65536 n
127if lt k 0
128ret 70
129end
130if eq k 0
131break
132end
133n = add n ulong k
134end
135if eq n 65536
136ret 71
137end
138pos = ulong 0
139s = ulong 0
140for e ulong len ldgnd
141if eq get ldgnd e 124
142pos = lt_find view buf n pos s e
143if gt pos n
144ret 4
145end
146s = add e 1
147end
148end
149ret 0
150end
151
152fn main to int
153lt_init
154if gt argcnt 3
155ret 64
156end
157if eq argcnt 3
158ret lt_check
159end
160if eq argcnt 2
161ret lt_bin
162end
163ret lt_rows
164end