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 / lib / xorwow_mix.om

229 lines · 4006 bytes Raw Blame History
1note SPDX-License-Identifier Apache-2.0 WITH LLVM-exception
2note L441 host check. XORWOW is Marsaglia, J. Stat. Soft. 8(14), 2003, page 5, from the published state
3note Metric: Berlekamp-Massey linear complexity over GF(2) of each output bit, first 1000 outputs
4note An ideal bit scores about 500. Raw XORWOW bit 0 scores 162 and bit 1 scores 323
5note The fold mix o xor (o shr 16) is a bijection on 32 bits and lifts every bit to about 500
6note Expected values are the Wolfram receipts in evidence/xorwow-mix-20261109/README.md
7note Prints one line of 32 scores for raw and one for fold. Exit 0 only if all checks hold
8note Not curand: the fold changes every output word. Not the GPU
9global xmst ulong 6
10global xmow ulong 1000
11global xmsq ulong 1000
12global xmcc ulong 1001
13global xmbb ulong 1001
14global xmtt ulong 1001
15global xmob uchar 24
16global xmlc ulong 64
17text xmlraw "raw "
18text xmlfold "fold"
19text xmlnl "\n"
20fn xmixmask x ulong to ulong
21ret and x 4294967295
22end
23fn xmixinit to void
24put xmst 0 ulong 123456789
25put xmst 1 ulong 362436069
26put xmst 2 ulong 521288629
27put xmst 3 ulong 88675123
28put xmst 4 ulong 5783321
29put xmst 5 ulong 6615241
30end
31fn xmixstep to ulong
32t = xmixmask xor get xmst 0 shr get xmst 0 2
33old4 = get xmst 4
34put xmst 0 get xmst 1
35put xmst 1 get xmst 2
36put xmst 2 get xmst 3
37put xmst 3 old4
38n4 = xmixmask xor xor old4 shl old4 4 xor t shl t 1
39put xmst 4 n4
40d = xmixmask add get xmst 5 362437
41put xmst 5 d
42ret xmixmask add n4 d
43end
44fn xmixfold o ulong to ulong
45ret xor o shr o 16
46end
47fn xmixbits k ulong fold ulong to void
48i = ulong 0
49while lt i 1000 bound 1000
50o = get xmow i
51if eq fold 1
52o = xmixfold o
53end
54put xmsq i and shr o k 1
55i = add i 1
56end
57end
58fn xmixdisc i ulong lc ulong to ulong
59d = get xmsq i
60j = ulong 1
61while le j lc bound 1001
62d = xor d and get xmcc j get xmsq sub i j
63j = add j 1
64end
65ret d
66end
67fn xmixsave to void
68j = ulong 0
69while le j 1000 bound 1001
70put xmtt j get xmcc j
71j = add j 1
72end
73end
74fn xmixrest to void
75j = ulong 0
76while le j 1000 bound 1001
77put xmbb j get xmtt j
78j = add j 1
79end
80end
81fn xmixfix sh ulong to void
82j = sh
83while le j 1000 bound 1001
84put xmcc j xor get xmcc j get xmbb sub j sh
85j = add j 1
86end
87end
88fn xmixbm to ulong
89j = ulong 0
90while le j 1000 bound 1001
91put xmcc j ulong 0
92put xmbb j ulong 0
93j = add j 1
94end
95put xmcc 0 ulong 1
96put xmbb 0 ulong 1
97lc = ulong 0
98mp = ulong 0
99i = ulong 0
100while lt i 1000 bound 1000
101d = xmixdisc i lc
102if eq d 1
103xmixsave
104xmixfix sub add i 1 mp
105if le mul 2 lc i
106lc = sub add i 1 lc
107mp = add i 1
108xmixrest
109end
110end
111i = add i 1
112end
113ret lc
114end
115fn xmixnum v ulong to int
116x = v
117p = ulong 23
118while lt p 24 bound 21
119put xmob p uchar add 48 rem x 10
120x = div x 10
121if eq x 0
122break
123end
124p = sub p 1
125end
126p = sub p 1
127put xmob p uchar 32
128n = sub 24 p
129k = write 1 xmob p n
130if ne k long n
131ret 1
132end
133ret 0
134end
135fn xmixline fold ulong to int
136if eq fold 1
137k = write 1 xmlfold 0 len xmlfold
138else
139k = write 1 xmlraw 0 len xmlraw
140end
141b = ulong 0
142while lt b 32 bound 32
143r = xmixnum get xmlc add mul fold 32 b
144if ne r 0
145ret 1
146end
147b = add b 1
148end
149k = write 1 xmlnl 0 len xmlnl
150ret 0
151end
152fn xmixfirst to int
153if ne get xmow 0 246875399
154ret 1
155end
156if ne get xmow 1 3690007200
157ret 1
158end
159if ne get xmow 2 1264581005
160ret 1
161end
162if ne get xmow 3 3906711041
163ret 1
164end
165if ne get xmow 4 1866187943
166ret 1
167end
168if ne get xmow 5 2481925219
169ret 1
170end
171if ne get xmow 6 2464530826
172ret 1
173end
174if ne get xmow 7 1604040631
175ret 1
176end
177ret 0
178end
179fn xmixlow fold ulong to ulong
180c = ulong 0
181b = ulong 0
182while lt b 32 bound 32
183if lt get xmlc add mul fold 32 b 480
184c = add c 1
185end
186b = add b 1
187end
188ret c
189end
190fn main to int
191xmixinit
192i = ulong 0
193while lt i 1000 bound 1000
194put xmow i xmixstep
195i = add i 1
196end
197f = ulong 0
198while lt f 2 bound 2
199b = ulong 0
200while lt b 32 bound 32
201xmixbits b f
202put xmlc add mul f 32 b xmixbm
203b = add b 1
204end
205f = add f 1
206end
207if ne xmixline 0 0
208ret 2
209end
210if ne xmixline 1 0
211ret 2
212end
213if ne xmixfirst 0
214ret 10
215end
216if ne get xmlc 0 162
217ret 20
218end
219if ne get xmlc 1 323
220ret 21
221end
222if ne xmixlow 0 2
223ret 22
224end
225if ne xmixlow 1 0
226ret 30
227end
228ret 0
229end