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 / native / nvrm / counts.om

134 lines · 2095 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note sscanf decimal unsigned contract: optional sign, saturating overflow, prefix digits.
4fn nc_space c uchar to bool
5ret or eq c 32 and ge c 9 le c 13
6end
7fn nc_number b view uchar * pos ulong dst edit ulong 2 to bool
8i = pos
9while lt i len b bound 512
10if not nc_space get b i
11break
12end
13i = add i 1
14end
15minus = false
16if lt i len b
17if or eq get b i 43 eq get b i 45
18minus = eq get b i 45
19i = add i 1
20end
21end
22start = i
23v = ulong 0
24ov = false
25while lt i len b bound 512
26c = get b i
27if or lt c 48 gt c 57
28break
29end
30d = ulong sub c 48
31if gt v div sub ulong 18446744073709551615 d 10
32ov = true
33end
34if not ov
35v = add mul v 10 d
36end
37i = add i 1
38end
39if eq i start
40ret false
41end
42if ov
43v = ulong 18446744073709551615
44else
45if minus
46v = sub ulong 0 v
47end
48end
49put dst 0 v
50put dst 1 i
51ret true
52end
53fn nc_mem b view uchar * key view uchar * state edit ulong 2 to ulong
54dst = new ulong 2 0
55if le len b len key
56ret 0
57end
58for i ulong len key
59if ne get b i get key i
60ret 0
61end
62end
63if ne get b len key 58
64ret 0
65end
66put state 1 0
67ok = nc_number b add len key 1 dst
68if ok
69put state 1 get dst 0
70end
71ret 1
72end
73fn nc_buddy b view uchar * state edit ulong 2 to ulong
74dst = new ulong 2 0
75p = ulong 0
76found = false
77while le add p 4 len b bound 512
78if eq get b p 122
79if and eq get b add p 1 111 eq get b add p 2 110
80if eq get b add p 3 101
81found = true
82break
83end
84end
85end
86p = add p 1
87end
88if not found
89ret 0
90end
91p = add p 4
92while lt p len b bound 512
93if ne get b p 32
94break
95end
96p = add p 1
97end
98while lt p len b bound 512
99if or eq get b p 0 eq get b p 32
100break
101end
102p = add p 1
103end
104total = ulong 0
105for o ulong 32
106ok = nc_number b p dst
107if not ok
108break
109end
110if ge o get state 0
111total = add total get dst 0
112end
113while lt p len b bound 512
114if ne get b p 32
115break
116end
117p = add p 1
118end
119while lt p len b bound 512
120if or eq get b p 0 eq get b p 32
121break
122end
123p = add p 1
124end
125end
126put state 1 add get state 1 total
127ret 0
128end
129fn nvrm_counts mode ulong b view uchar * key view uchar * state edit ulong 2 to ulong
130if eq mode 0
131ret nc_mem b key state
132end
133ret nc_buddy b state
134end