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

81 lines · 1215 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Stable total binary64 ordering. NaNs follow numbers; equal values use bits.
3fn cms_less a ulong b ulong to bool
4x = bitcast f64 a
5y = bitcast f64 b
6if ne x x
7if eq y y
8ret false
9end
10ret lt a b
11end
12if ne y y
13ret true
14end
15if lt x y
16ret true
17end
18if gt x y
19ret false
20end
21ret lt a b
22end
23fn cms_run a edit ulong 256 n ulong to void
24for i ulong n
25j = i
26while gt j 0
27if not cms_less get a j get a sub j 1
28break
29end
30x = get a j
31put a j get a sub j 1
32put a sub j 1 x
33j = sub j 1
34end
35end
36end
37note meta: valid left/right then consumed left/right; C advances only these counts.
38fn cm_sort a edit ulong 256 b view ulong 256 out edit ulong 256 meta edit ulong 4 to ulong
39na = get meta 0
40nb = get meta 1
41if or gt na 256 gt nb 256
42ret 0
43end
44if eq get meta 2 0
45cms_run a na
46ret na
47end
48ia = ulong 0
49ib = ulong 0
50n = ulong 0
51while lt n 256
52if and eq ia na eq ib nb
53break
54end
55left = eq ib nb
56if and lt ia na lt ib nb
57left = not cms_less get b ib get a ia
58end
59if left
60put out n get a ia
61ia = add ia 1
62else
63put out n get b ib
64ib = add ib 1
65end
66n = add n 1
67if gt na 0
68if eq ia na
69break
70end
71end
72if gt nb 0
73if eq ib nb
74break
75end
76end
77end
78put meta 2 ia
79put meta 3 ib
80ret n
81end