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 / core / hostmath.om

165 lines · 3320 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Copyright 2026 Drake Stapleton
3note Source constants rounded to binary64 with Wolfram N[decimal80,MachinePrecision]; receipt records the exact query.
4fn LNHI to f64
5ret bitcast f64 ulong 4604418534311723008
6end
7fn LNLO to f64
8ret bitcast f64 ulong 4461442080421002358
9end
10fn ILN2 to f64
11ret bitcast f64 ulong 4609176140021203710
12end
13fn SQRT2 to f64
14ret bitcast f64 ulong 4609047870845172685
15end
16fn hpow2 k long to f64
17if gt k 1023
18ret bitcast f64 shl ulong 2047 52
19end
20if lt k -1074
21ret 0.0f64
22end
23if ge k -1022
24ret bitcast f64 shl ulong add k 1023 52
25end
26ret mul bitcast f64 shl ulong 1 52 bitcast f64 shl ulong add k 2045 52
27end
28fn hlogsum e long t f64 s f64 to f64
29ret add mul f64 e LNHI add mul mul 2.0f64 t s mul f64 e LNLO
30end
31fn hlog x f64 to f64
32if or not gt x 0.0f64 gt x bitcast f64 sub shl ulong 2047 52 1
33ret bitcast f64 or shl ulong 2047 52 shl ulong 1 51
34end
35e = long 0
36if lt x bitcast f64 shl ulong 1 52
37x = mul x 18014398509481984.0f64
38e = -54
39end
40u = bitcast ulong x
41e = sub add e long and shr u 52 2047 1023
42m = bitcast f64 or and u sub shl ulong 1 52 1 shl ulong 1023 52
43if gt m SQRT2
44m = mul m 0.5f64
45e = add e 1
46end
47t = div sub m 1.0f64 add m 1.0f64
48t2 = mul t t
49s = f64 0.0
50k = long 25
51while ge k 1 bound 13
52s = add mul s t2 div 1.0f64 f64 k
53k = sub k 2
54end
55ret hlogsum e t s
56end
57fn hexp y f64 to f64
58if ne y y
59ret y
60end
61if gt y bitcast f64 ulong 4649454506724284170
62ret bitcast f64 shl ulong 2047 52
63end
64if lt y bitcast f64 ulong 13873138101193906586
65ret 0.0f64
66end
67fk = mul y ILN2
68adj = f64 0.5
69if lt fk 0.0f64
70adj = -0.5f64
71end
72k = long add fk adj
73kd = f64 k
74r = sub sub y mul kd LNHI mul kd LNLO
75p = f64 1.0
76n = long 17
77while ge n 1 bound 17
78p = add 1.0f64 div mul r p f64 n
79n = sub n 1
80end
81if lt k -1020
82ret mul mul p hpow2 -1020 hpow2 add k 1020
83end
84ret mul p hpow2 k
85end
86fn hround x f64 to long
87if lt x 0.0f64
88ret long sub x 0.5f64
89end
90ret long add x 0.5f64
91end
92fn hpoly w f64 k long to f64
93p = f64 1.0
94while ge k 2 bound 8
95p = sub 1.0f64 div mul w p f64 mul k sub k 1
96k = sub k 2
97end
98ret p
99end
100fn hsin a f64 o edit ulong 2 to void
101n = hround mul a bitcast f64 ulong 4603909380684499075
102nd = f64 n
103r = sub a mul nd bitcast f64 ulong 4609753056924401664
104r = sub r mul nd bitcast f64 ulong 4454258360616747008
105r = sub r mul nd bitcast f64 ulong 4297306550709518336
106r = sub r mul nd bitcast f64 ulong 4142048980368378305
107w = mul r r
108sr = mul r hpoly w 15
109cr = hpoly w 16
110quad = ulong and n 3
111if eq quad 0
112put o 0 bitcast ulong sr
113put o 1 bitcast ulong cr
114end
115if eq quad 1
116put o 0 bitcast ulong cr
117put o 1 bitcast ulong neg sr
118end
119if eq quad 2
120put o 0 bitcast ulong neg sr
121put o 1 bitcast ulong neg cr
122end
123if eq quad 3
124put o 0 bitcast ulong neg cr
125put o 1 bitcast ulong sr
126end
127end
128fn omhost mode ulong abits ulong bbits ulong o edit ulong 2 to void
129a = bitcast f64 abits
130b = bitcast f64 bbits
131if eq mode 0
132put o 0 bitcast ulong hlog a
133ret
134end
135if eq mode 1
136put o 0 bitcast ulong hexp a
137ret
138end
139if eq mode 2
140if or eq a 1.0f64 eq b 0.0f64
141put o 0 bitcast ulong 1.0f64
142else
143put o 0 bitcast ulong hexp mul b hlog a
144end
145ret
146end
147if eq mode 3
148hsin a o
149ret
150end
151e = long a
152x = ulong 0
153if gt e 127
154x = shl ulong 255 23
155else
156if ge e -126
157x = shl ulong add e 127 23
158else
159if ge e -149
160x = shl ulong 1 ulong add e 149
161end
162end
163end
164put o 0 x
165end