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 / runtime / check / scanref-check.om

284 lines · 4980 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/runtime/check/scanref-check.om: prints gpu/runtime/scanref.om on fixed xorshift64 vectors, one line
3note per case, in the form the C oracle printed for CUDApp src/omega_gpu_scan_ref.c (gpu/runtime/README.md);
4note gpu/runtime/check/scanref.expect.txt is that oracle's output. Composed after scan.om and scanref.om.
5global ck_s ulong 1
6global ck_o uchar *
7global ck_n ulong 1
8global ck_k2 uint *
9note The output words, one table (OM-1 has no unsized view to pass a text by): segment i ends at the i-th |.
10text ck_tx "n=| s=| red|=|refused|ok| pre=| last=| u32=| rk=| rv=| rko=|refuse red_op3=| red_n0=| pre_n0=| u32_n0=| radix_n0=|"
11const ck_ns ulong 0
12const ck_ss ulong 1
13const ck_red ulong 2
14const ck_eq ulong 3
15const ck_ref ulong 4
16const ck_ok ulong 5
17const ck_pre ulong 6
18const ck_last ulong 7
19const ck_u32 ulong 8
20const ck_rk ulong 9
21const ck_rv ulong 10
22const ck_rko ulong 11
23const ck_r1 ulong 12
24const ck_r2 ulong 13
25const ck_r3 ulong 14
26const ck_r4 ulong 15
27const ck_r5 ulong 16
28text ck_mem "scanref-check: the host refused memory\n"
29fn ckdie to void
30w = write 2 ck_mem 0 len ck_mem
31exit 4
32end
33fn ckoc c ulong to void
34n = get ck_n 0
35if ge n len ck_o
36r = enlarge ck_o add mul n 2 4096
37if ne r 0
38ckdie
39end
40end
41put ck_o n uchar c
42put ck_n 0 add n 1
43end
44fn ckot id ulong to void
45k = ulong 0
46for i ulong len ck_tx
47c = ulong get ck_tx i
48if eq c 124
49k = add k 1
50else
51if eq k id
52ckoc c
53end
54end
55end
56end
57fn cknum v ulong to void
58if ge v 10
59cknum div v 10
60end
61ckoc add 48 rem v 10
62end
63fn ckhex v ulong d ulong to void
64for i ulong d
65c = and shr v mul 4 sub sub d 1 i 15
66if lt c 10
67ckoc add 48 c
68else
69ckoc add 87 c
70end
71end
72end
73fn ckres r ulong to void
74if eq r 0
75ckot ck_ok
76else
77ckot ck_ref
78end
79end
80fn ckflush to void
81n = get ck_n 0
82o = ulong 0
83while lt o n bound 9223372036854775807
84x = write 1 ck_o o sub n o
85if le x 0
86exit 3
87end
88o = add o ulong x
89end
90put ck_n 0 0
91end
92fn ckrnd to ulong
93s = get ck_s 0
94s = xor s shl s 13
95s = xor s shr s 7
96s = xor s shl s 17
97put ck_s 0 s
98ret s
99end
100note The float bits of the oracle's fbits: with sp, one in sixteen each of +0, -0, quiet NaN, +inf, -inf.
101fn ckfb sp ulong to uint
102r = ckrnd
103c = and r 15
104if ne sp 0
105if eq c 0
106ret uint 0
107end
108if eq c 1
109ret uint 2147483648
110end
111if eq c 2
112ret uint 2143289344
113end
114if eq c 3
115ret uint 2139095040
116end
117if eq c 4
118ret uint 4286578688
119end
120end
121sg = shl and shr r 4 1 31
122ex = add 100 rem shr r 5 51
123mn = and shr r 32 8388607
124ret uint or or sg shl ex 23 mn
125end
126note FNV-1a 64 of one 32-bit value's little-endian bytes, folded into h.
127fn ckfnv h ulong w ulong to ulong
128for b ulong 4
129h = mul xor h and shr w mul 8 b 255 1099511628211
130end
131ret h
132end
133note FNV-1a 64 over the first n values of pool p: 0 sr_y (float bits), 1 sr_uy, 2 sr_k, 3 sr_v.
134fn ckhash p ulong n ulong to ulong
135h = ulong 14695981039346656037
136for i ulong n bound 9223372036854775807
137w = ulong 0
138if eq p 0
139w = ulong bitcast uint get sr_y i
140end
141if eq p 1
142w = ulong get sr_uy i
143end
144if eq p 2
145w = ulong get sr_k i
146end
147if eq p 3
148w = ulong get sr_v i
149end
150h = ckfnv h w
151end
152ret h
153end
154fn ckbits f f32 to void
155ckhex ulong bitcast uint f 8
156end
157fn ckgrow n ulong to void
158r = enlarge sr_x n
159if ne r 0
160ckdie
161end
162r = enlarge sr_u n
163if ne r 0
164ckdie
165end
166r = enlarge sr_k n
167if ne r 0
168ckdie
169end
170r = enlarge sr_v n
171if ne r 0
172ckdie
173end
174r = enlarge ck_k2 n
175if ne r 0
176ckdie
177end
178end
179note One case: n values, specials sp, key mask m; the draws in the oracle's order.
180fn ckcase n ulong sp ulong m ulong to void
181ckgrow n
182for i ulong n bound 9223372036854775807
183put sr_x i bitcast f32 ckfb sp
184end
185ckot ck_ns
186cknum n
187ckot ck_ss
188cknum sp
189for op ulong 3
190ckot ck_red
191cknum op
192ckot ck_eq
193if eq sr_reduce op n 0
194ckbits get sr_r 0
195else
196ckot ck_ref
197end
198end
199ckot ck_pre
200if eq sr_prefix n 0
201ckhex ckhash 0 n 16
202ckot ck_last
203ckbits get sr_y sub n 1
204else
205ckot ck_ref
206end
207for i ulong n bound 9223372036854775807
208put sr_u i uint and shr ckrnd 16 4294967295
209end
210ckot ck_u32
211if eq sr_pu32 n 0
212ckhex ckhash 1 n 16
213else
214ckot ck_ref
215end
216ckradix n m
217ckoc 10
218end
219fn ckradix n ulong m ulong to void
220for i ulong n bound 9223372036854775807
221w = uint and shr ckrnd 8 m
222put sr_k i w
223put sr_v i uint i
224put ck_k2 i w
225end
226ckot ck_rk
227if eq sr_radix n 1 0
228ckhex ckhash 2 n 16
229ckot ck_rv
230ckhex ckhash 3 n 16
231else
232ckot ck_ref
233end
234for i ulong n bound 9223372036854775807
235put sr_k i get ck_k2 i
236end
237ckot ck_rko
238if eq sr_radix n 0 0
239ckhex ckhash 2 n 16
240else
241ckot ck_ref
242end
243end
244fn ckrefuse to void
245ckot ck_r1
246ckres sr_reduce 3 4
247ckot ck_r2
248ckres sr_reduce 0 0
249ckot ck_r3
250ckres sr_prefix 0
251ckot ck_r4
252ckres sr_pu32 0
253ckot ck_r5
254ckres sr_radix 0 1
255ckoc 10
256end
257fn main to int
258put ck_s 0 88172645463325252
259ns = new ulong 12 0
260put ns 0 1
261put ns 1 2
262put ns 2 31
263put ns 3 32
264put ns 4 33
265put ns 5 100
266put ns 6 1023
267put ns 7 1024
268put ns 8 1025
269put ns 9 4097
270put ns 10 33000
271put ns 11 70001
272ms = new ulong 3 4294967295
273put ms 1 255
274put ms 2 252645135
275for sp ulong 2
276for c ulong 12
277ckcase get ns c sp get ms rem c 3
278ckflush
279end
280end
281ckrefuse
282ckflush
283ret 0
284end