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