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 / checks / fmt.om

130 lines · 3118 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/nvidia/checks/fmt.om: the Omega port of CUDApp tests/tools-om/fmt_diff.c (run by tests/tools-om/fmt.sh).
3note Composed after gpu/nvidia/om/tools/fmt.om and gpu/nvidia/checks/lib.om; run with gpu/nvidia/checks/fmt.tsv,
4note which glibc snprintf("%.*f" / "%.*g") wrote through the old differential's own C mode: its special values and
5note its splitmix64 doubles in five families, nine conversions each ("%.Pf" for P 0 1 2 6 17, "%.Pg" for P 0 1 6 17).
6note Cases:
7note s BITS P G TEXT the f64 with bits BITS printed with precision P (G 0 "%.Pf", 1 "%.Pg") is TEXT
8note r FIRST COUNT DIGEST the random values FIRST..FIRST+COUNT-1 of the old test, regenerated here from its
9note splitmix64 stream (rows in order from 0), printed nine ways each: FNV-1a-64 over every
10note printed byte, a 0 byte after each conversion, is DIGEST
11note COUNT is at most 2^20 (the loop bound); a larger COUNT is an unreadable row.
12text t_name "FMT"
13global fx_s ulong 2
14note fx_s: 0 the splitmix64 state less its starting value 0x9e3779b97f4a7c15, 1 the next random index
15fn cname to void
16for i ulong len t_name bound 64
17ckoc ulong get t_name i
18end
19end
20fn fx_nx to ulong
21s = add get fx_s 0 11400714819323198485
22put fx_s 0 s
23z = add s 11400714819323198485
24z = mul xor z shr z 30 13787848793156543929
25z = mul xor z shr z 27 10723151780598845931
26ret xor z shr z 31
27end
28note random value i of the old test (i % 5 picks the family; the fifth also draws its exponent)
29fn fx_x i ulong to f64
30r = fx_nx
31k = rem i 5
32if eq k 0
33ret bitcast f64 r
34end
35if eq k 1
36ret div f64 shr r 20 f64 1024
37end
38if eq k 2
39ret sub div f64 rem r 2000001 f64 1000 f64 1000
40end
41if eq k 3
42ret div f64 shr r 11 f64 1048576
43end
44e = add rem fx_nx 200 873
45ret mul f64 shr r 12 bitcast f64 shl e 52
46end
47note precision k of conversion g: "%.Pf" takes 0 1 2 6 17, "%.Pg" takes 0 1 6 17 (the f list without its 2)
48fn fx_p g ulong k ulong to ulong
49if le k 1
50ret k
51end
52j = add k g
53if eq j 2
54ret 2
55end
56if eq j 3
57ret 6
58end
59ret 17
60end
61note print x into o; its length
62fn fx_cv x f64 p ulong g ulong o edit uchar 1600 to ulong
63if ne g 0
64ret fm_g x p o
65end
66ret fm_f x p o
67end
68note fold the nine conversions of x into the digest h
69fn fx_one x f64 h ulong to ulong
70o = new uchar 1600 0
71for g ulong 2
72nk = sub ulong 5 g
73for k ulong nk bound 5
74n = fx_cv x fx_p g k g o
75for j ulong n bound 1600
76h = mul xor h ulong get o j 1099511628211
77end
78h = mul h 1099511628211
79end
80end
81ret h
82end
83fn fx_spec to bool
84if ne ckcnt 5
85ckbad
86end
87o = new uchar 1600 0
88n = fx_cv bitcast f64 cknum 1 cknum 2 cknum 3 o
89if ne n cklen 4
90ret false
91end
92for j ulong n bound 1600
93if ne ulong get o j ckch 4 j
94ret false
95end
96end
97ret true
98end
99fn fx_rand to bool
100if ne ckcnt 4
101ckbad
102end
103f = cknum 1
104c = cknum 2
105if gt c 1048576
106ckbad
107end
108if ne f get fx_s 1
109ret false
110end
111h = ulong 14695981039346656037
112for i ulong c bound 1048576
113h = fx_one fx_x add f i h
114end
115put fx_s 1 add f c
116ret eq h cknum 3
117end
118fn crow to bool
119if ne cklen 0 1
120ckbad
121end
122k = ckch 0 0
123if eq k 115
124ret fx_spec
125end
126if ne k 114
127ckbad
128end
129ret fx_rand
130end