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

203 lines · 4092 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/runtime/check/platpolicy-check.om: runs plat_policy of gpu/nvidia/om/platform-linux/plat_policy.om for every
3note message kind 0..15 on xorshift64 inputs with boundary values (for kind 7, every other case a short text of
4note digits, blanks and signs packed eight bytes to a word from m[2], its length in m[1]), and prints what the C
5note oracle printed for plat_c of CUDApp src/omega_gpu_platform_linux_cpolicy.h (gpu/runtime/README.md).
6note gpu/runtime/check/platpolicy.expect.txt is that oracle's output. Composed after plat_policy.om. OM-1, as
7note plat_policy.om is (it names a parameter out, a word OM-2 reserves), so the output goes through a fixed buffer
8note that is written out whenever it fills, and the fixed texts are ranges of pq_all.
9global pq_s ulong 1
10global pq_o uchar 4096
11global pq_n ulong 1
12global pq_b ulong 32
13text pq_tx " \t\n+-0123456789x"
14note kind 0 5, case 5 6, r= 11 3, q= 14 3, cases= 17 7, nonzero= 24 9, fnv= 33 5
15text pq_all "kind case r= q= cases= nonzero= fnv="
16fn pqflush to void
17n = get pq_n 0
18o = ulong 0
19while lt o n bound 9223372036854775807
20x = write 1 pq_o o sub n o
21if le x 0
22exit 3
23end
24o = add o ulong x
25end
26put pq_n 0 0
27end
28fn pqoc c ulong to void
29if ge get pq_n 0 len pq_o
30pqflush
31end
32n = get pq_n 0
33put pq_o n uchar c
34put pq_n 0 add n 1
35end
36fn pqt off ulong n ulong to void
37for i ulong n
38pqoc ulong get pq_all add off i
39end
40end
41fn pqnum v ulong to void
42if ge v 10
43pqnum div v 10
44end
45pqoc add 48 rem v 10
46end
47fn pqhex v ulong to void
48for i ulong 16
49c = and shr v mul 4 sub 15 i 15
50if lt c 10
51pqoc add 48 c
52else
53pqoc add 87 c
54end
55end
56end
57fn pqrnd to ulong
58s = get pq_s 0
59s = xor s shl s 13
60s = xor s shr s 7
61s = xor s shl s 17
62put pq_s 0 s
63ret s
64end
65fn pqval to ulong
66r = pqrnd
67sel = and r 7
68if lt sel 4
69ret get pq_b and shr r 3 31
70end
71if lt sel 6
72ret and shr r 3 127
73end
74ret pqrnd
75end
76fn pqfnv h ulong w ulong to ulong
77for b ulong 8
78h = mul xor h and shr w mul 8 b 255 1099511628211
79end
80ret h
81end
82note the text case of kind 7: n = 1 + rnd mod 34 bytes, each the text pq_tx at rnd and 15, from m[2] up
83fn pqtext m edit ulong 16 to void
84n = add 1 rem pqrnd 34
85for i ulong 5
86put m add i 2 0
87end
88for i ulong n
89if lt i 40
90w = add 2 div i 8
91c = ulong get pq_tx and pqrnd 15
92put m w or get m w shl c mul rem i 8 8
93end
94end
95put m 1 n
96end
97fn pqline kind ulong c ulong r ulong q view ulong 16 to void
98pqt 0 5
99pqnum kind
100pqt 5 6
101pqnum c
102pqt 11 3
103pqnum r
104pqt 14 3
105for i ulong 16
106pqnum get q i
107if lt i 15
108pqoc 44
109else
110pqoc 10
111end
112end
113end
114fn pqcase kind ulong c ulong m edit ulong 16 to void
115for i ulong 16
116put m i pqval
117end
118put m 0 kind
119if and eq kind 7 eq rem c 2 0
120pqtext m
121end
122note kind 12, every other case: a slot (c/2) mod 3 that matches m[2], m[3]
123if and eq kind 12 eq rem c 2 0
124s = mul rem div c 2 3 2
125put m 1 add 2 rem get m 1 4
126put m add 4 s get m 2
127put m add 5 s get m 3
128end
129end
130fn pqkind kind ulong to void
131nc = ulong 4096
132m = new ulong 16 0
133q = new ulong 16 0
134h = ulong 14695981039346656037
135nz = ulong 0
136for c ulong nc
137pqcase kind c m
138note q starts zero, as plat_decide of CUDApp src/omega_gpu_platform_linux.c sets it before each call
139for i ulong 16
140put q i 0
141end
142r = plat_policy m q
143if lt c 2
144pqline kind c r q
145end
146h = pqfnv h r
147for i ulong 16
148h = pqfnv h get q i
149end
150if ne r 0
151nz = add nz 1
152end
153end
154pqt 0 5
155pqnum kind
156pqt 17 7
157pqnum nc
158pqt 24 9
159pqnum nz
160pqt 33 5
161pqhex h
162pqoc 10
163pqflush
164end
165fn main to int
166put pq_s 0 88172645463325252
167put pq_b 0 0
168put pq_b 1 1
169put pq_b 2 2
170put pq_b 3 3
171put pq_b 4 4
172put pq_b 5 8
173put pq_b 6 9
174put pq_b 7 10
175put pq_b 8 12
176put pq_b 9 13
177put pq_b 10 15
178put pq_b 11 16
179put pq_b 12 32
180put pq_b 13 33
181put pq_b 14 47
182put pq_b 15 50
183put pq_b 16 51
184put pq_b 17 52
185put pq_b 18 121
186put pq_b 19 4095
187put pq_b 20 4096
188put pq_b 21 4097
189put pq_b 22 65536
190put pq_b 23 999999
191put pq_b 24 4294967295
192put pq_b 25 4294967296
193put pq_b 26 1099511627776
194put pq_b 27 1844674407370955161
195put pq_b 28 9223372036854775808
196put pq_b 29 18446744073709547520
197put pq_b 30 18446744073709551614
198put pq_b 31 18446744073709551615
199for kind ulong 16
200pqkind kind
201end
202ret 0
203end