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 / components / cm_math.om

133 lines · 3498 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note First-party binary64 helpers; bits transport avoids public float ABI.
3note Constants from Wolfram binary-exact split evaluation, documented in HOST_POLICY.md.
4fn cm_norm h f64 l f64 o edit ulong 2 to void
5s = add h l
6put o 0 bitcast ulong s
7put o 1 bitcast ulong sub l sub s h
8end
9fn cm_add ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void
10s = add ah bh
11v = sub s ah
12e = add sub ah sub s v sub bh v
13e = add e add al bl
14cm_norm s e o
15end
16fn cm_prodlo a f64 b f64 p f64 to f64
17split = bitcast f64 ulong 4728779608772575232
18ca = mul split a
19cb = mul split b
20ah = sub ca sub ca a
21bh = sub cb sub cb b
22al = sub a ah
23bl = sub b bh
24e = sub mul ah bh p
25e = add e mul ah bl
26e = add e mul al bh
27ret add e mul al bl
28end
29fn cm_mul ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void
30p = mul ah bh
31e = cm_prodlo ah bh p
32e = add e add mul ah bl mul al bh
33e = add e mul al bl
34cm_norm p e o
35end
36fn cm_div ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void
37q = div ah bh
38cm_mul q f64 0.0 bh bl o
39cm_add ah al neg bitcast f64 get o 0 neg bitcast f64 get o 1 o
40r = div add bitcast f64 get o 0 bitcast f64 get o 1 bh
41cm_norm q r o
42end
43fn cm_dd_add a edit ulong 2 b view ulong 2 to void
44cm_add bitcast f64 get a 0 bitcast f64 get a 1 bitcast f64 get b 0 bitcast f64 get b 1 a
45end
46fn cm_dd_mul a edit ulong 2 b view ulong 2 to void
47cm_mul bitcast f64 get a 0 bitcast f64 get a 1 bitcast f64 get b 0 bitcast f64 get b 1 a
48end
49fn cm_dd_scale a edit ulong 2 b f64 to void
50cm_mul bitcast f64 get a 0 bitcast f64 get a 1 b f64 0.0 a
51end
52fn cm_logcore m f64 s edit ulong 2 to void
53t = new ulong 2 0
54p = new ulong 2 0
55u = new ulong 2 0
56cm_add m f64 0.0 f64 1.0 f64 0.0 u
57cm_div sub m f64 1.0 f64 0.0 bitcast f64 get u 0 bitcast f64 get u 1 t
58put p 0 get t 0
59put p 1 get t 1
60put s 0 get t 0
61put s 1 get t 1
62cm_mul bitcast f64 get t 0 bitcast f64 get t 1 bitcast f64 get t 0 bitcast f64 get t 1 t
63for i ulong 32
64cm_dd_mul p t
65den = f64 add mul i 2 3
66cm_div bitcast f64 get p 0 bitcast f64 get p 1 den f64 0.0 u
67cm_dd_add s u
68end
69end
70fn cm_log x f64 base2 bool to f64
71bits = bitcast ulong x
72if eq and bits 9223372036854775807 0
73ret bitcast f64 ulong 18442240474082181120
74end
75if ne x x
76ret add x x
77end
78if lt x f64 0.0
79ret bitcast f64 ulong 9221120237041090560
80end
81if eq bits 9218868437227405312
82ret x
83end
84adj = long 0
85if eq and shr bits 52 2047 0
86x = mul x bitcast f64 ulong 4850376798678024192
87bits = bitcast ulong x
88adj = -54
89end
90e = add sub long and shr bits 52 2047 1023 adj
91m = bitcast f64 or and bits 4503599627370495 4607182418800017408
92if gt m bitcast f64 ulong 4609047870845172685
93m = mul m f64 0.5
94e = add e 1
95end
96s = new ulong 2 0
97u = new ulong 2 0
98cm_logcore m s
99cm_mul f64 e f64 0.0 bitcast f64 ulong 4604418534313441775 bitcast f64 ulong 4358002977218854975 u
100cm_dd_scale s f64 2.0
101cm_dd_add s u
102if base2
103cm_mul bitcast f64 get s 0 bitcast f64 get s 1 bitcast f64 ulong 4609176140021203710 bitcast f64 ulong 4357082904033627428 s
104end
105ret add bitcast f64 get s 0 bitcast f64 get s 1
106end
107fn cm_ceil bits ulong to ulong
108x = bitcast f64 bits
109if ne x x
110ret bitcast ulong add x x
111end
112e = and shr bits 52 2047
113if ge e 1075
114ret bits
115end
116if lt e 1023
117if eq and bits 9223372036854775807 0
118ret bits
119end
120if ne and bits 9223372036854775808 0
121ret 9223372036854775808
122end
123ret 4607182418800017408
124end
125mask = sub shl ulong 1 sub 1075 e 1
126if eq and bits mask 0
127ret bits
128end
129if eq and bits 9223372036854775808 0
130bits = add bits add mask 1
131end
132ret and bits not mask
133end