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 / hw / cpu.om

201 lines · 3611 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note cpu.om: hwman unit 2, the NATIVE_ISA CPU runner (runner hwman-cpu). The operations execute as
3note AArch64 instructions emitted by omc in this process; identity comes from the kernel's view of the
4note core this process is pinned to:
5note /proc/self/status Cpus_allowed_list must name exactly one CPU (taskset -c N), else refused
6note /proc/self/stat field 39 (processor, proc(5)) must equal that CPU
7note NODE/cpuN/regs/identification/midr_el1 (Linux Documentation/arch/arm64/cpu-feature-registers.rst)
8note Operations (fixed definitions; their oracle is computed independently, never by this program):
9note sumsq64 N sum of i*i for 0 <= i < N, modulo 2^64
10note fnv1a64 N FNV-1a 64-bit over the N bytes b_i = i mod 251 (offset basis 0xcbf29ce484222325,
11note prime 0x100000001b3)
12note N must be 1..16777216 (2^24); loops run in blocks of 4096 (a for count above 1000000 traps 4).
13
14text CPUSTS "/proc/self/status"
15text CPUSTAT "/proc/self/stat"
16text CPUALLOW "Cpus_allowed_list:"
17text CPUDIR "/cpu"
18text CPUMIDR "/regs/identification/midr_el1"
19text CPUSUMSQ "sumsq64"
20text CPUFNV "fnv1a64"
21const CPUMAXN ulong 16777216
22
23note the single CPU in Cpus_allowed_list, or -1 when not pinned to exactly one CPU, or -errno
24fn cpupin to long
25pclear
26pt CPUSTS
27r = readpath
28if lt r 0
29ret r
30end
31n = get gst 7
32k = len CPUALLOW
33i = ulong 0
34while true bound 65536
35if gt add i k n
36ret -1
37end
38hit = true
39for j ulong k
40if ne get gfile add i j get CPUALLOW j
41hit = false
42end
43end
44if hit
45break
46end
47i = add i 1
48end
49i = add i k
50while true bound 64
51if ge i n
52ret -1
53end
54c = get gfile i
55if or eq c 9 eq c 32
56i = add i 1
57else
58break
59end
60end
61v = ulong 0
62d = ulong 0
63while true bound 16
64if ge i n
65ret -1
66end
67c = get gfile i
68if or lt c 48 gt c 57
69break
70end
71v = add mul v 10 ulong sub c 48
72d = add d 1
73i = add i 1
74end
75if or eq d 0 ge i n
76ret -1
77end
78if ne get gfile i 10
79ret -1
80end
81ret long v
82end
83
84note field 39 (processor) of /proc/self/stat: the CPU this process last ran on, or a negative value
85fn cpucur to long
86pclear
87pt CPUSTAT
88r = readpath
89if lt r 0
90ret r
91end
92n = get gst 7
93e = ulong 0
94found = false
95for i ulong n
96if eq get gfile i 41
97e = i
98found = true
99end
100end
101if not found
102ret -1
103end
104note after ") " the next token is field 3; field 39 is token 36 counted from 0
105i = add e 2
106tok = ulong 0
107while true bound 4096
108if ge i n
109ret -1
110end
111if eq tok 36
112break
113end
114if eq get gfile i 32
115tok = add tok 1
116end
117i = add i 1
118end
119v = ulong 0
120d = ulong 0
121while true bound 16
122if ge i n
123break
124end
125c = get gfile i
126if or lt c 48 gt c 57
127break
128end
129v = add mul v 10 ulong sub c 48
130d = add d 1
131i = add i 1
132end
133if eq d 0
134ret -1
135end
136ret long v
137end
138
139note MIDR_EL1 of CPU cpu read below the node directory of the current row; -errno or -1 on a bad file
140fn cpumidr cpu ulong to long
141pclear
142pfield CNODE
143pt CPUDIR
144pdec cpu
145pt CPUMIDR
146r = readpath
147if lt r 0
148ret r
149end
150ret hexat 0 get gst 7
151end
152
153note sum of i*i for 0 <= i < n, modulo 2^64
154fn cpusumsq n ulong to ulong
155acc = ulong 0
156i = ulong 0
157for b ulong 4097
158if ge i n
159break
160end
161for j ulong 4096
162if ge i n
163break
164end
165acc = add acc mul i i
166i = add i 1
167end
168end
169ret acc
170end
171
172fn cpufnv n ulong to ulong
173h = ulong 0xcbf29ce484222325
174i = ulong 0
175for b ulong 4097
176if ge i n
177break
178end
179for j ulong 4096
180if ge i n
181break
182end
183h = mul xor h rem i 251 0x100000001b3
184i = add i 1
185end
186end
187ret h
188end
189
190note run operation argument a on n; sets gst 9 to 1 when the operation is unknown to this runner
191fn cpuop a ulong n ulong to ulong
192put gst 9 0
193if argeq a CPUSUMSQ
194ret cpusumsq n
195end
196if argeq a CPUFNV
197ret cpufnv n
198end
199put gst 9 1
200ret 0
201end