interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / core / eval.om

103 lines · 1348 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Copyright 2026 Drake Stapleton
3note WolframLanguageEvaluator: FullSimplify[a 2^i == Mod[a 2^i,2^64]+2^64 Quotient[a 2^i,2^64], integer bounds] -> True.
4fn emulhi a ulong b ulong to ulong
5lo = ulong 0
6hi = ulong 0
7for i ulong 64
8if ne and shr b i 1 0
9x = shl a i
10y = ulong 0
11if ne i 0
12y = shr a sub 64 i
13end
14t = add lo x
15hi = add hi y
16if lt t lo
17hi = add hi 1
18end
19lo = t
20end
21end
22ret hi
23end
24fn omeval v view ulong 6 o edit ulong 1 to long
25op = get v 0
26ov = get v 1
27width = get v 2
28mask = ulong 18446744073709551615
29if lt width 64
30mask = sub shl ulong 1 width 1
31end
32a = and get v 3 mask
33b = and get v 4 mask
34res = ulong 0
35over = false
36if eq op 3
37res = add a b
38over = or lt res a ne and res xor mask 18446744073709551615 0
39else
40if eq op 4
41res = sub a b
42over = lt a b
43else
44if eq op 5
45res = mul a b
46if lt width 64
47if ne a 0
48over = gt b div mask a
49end
50else
51if lt width 128
52over = ne shr emulhi a b sub width 64 0
53end
54end
55else
56if eq op 6
57if eq b 0
58ret -1
59end
60res = div a b
61else
62if eq op 7
63if eq a b
64put o 0 1
65else
66put o 0 0
67end
68ret 0
69else
70if eq op 8
71if lt a b
72put o 0 1
73else
74put o 0 0
75end
76ret 0
77else
78if eq op 9
79res = and a b
80else
81if eq op 10
82res = or a b
83else
84ret -1
85end
86end
87end
88end
89end
90end
91end
92end
93if over
94if eq ov 3
95ret -2
96end
97if eq ov 2
98res = mask
99end
100end
101put o 0 and res mask
102ret 0
103end