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
omega-mv / gpu / runtime / check / apiplan-check.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/runtime/check/apiplan-check.om: runs ap_plan of gpu/runtime/apiplan.om for every family 0..5 and mode |
| 3 | note 0..last+1, and family 6, on xorshift64 inputs with boundary values, and prints what the C oracle printed for |
| 4 | note ap_c of CUDApp src/omega_api_plan.h (gpu/runtime/README.md). gpu/runtime/check/apiplan.expect.txt is that |
| 5 | note oracle's output. Composed after the six plan units and apiplan.om. |
| 6 | global ak_s ulong 1 |
| 7 | global ak_o uchar * |
| 8 | global ak_n ulong 1 |
| 9 | global ak_b ulong 32 |
| 10 | global ak_last ulong 7 |
| 11 | text ak_tf "family " |
| 12 | text ak_tm " mode " |
| 13 | text ak_tc " case " |
| 14 | text ak_tr " r=" |
| 15 | text ak_ta " a=" |
| 16 | text ak_tn " cases=" |
| 17 | text ak_tz " nonzero=" |
| 18 | text ak_th " fnv=" |
| 19 | text ak_mem "apiplan-check: the host refused memory\n" |
| 20 | fn akdie to void |
| 21 | w = write 2 ak_mem 0 len ak_mem |
| 22 | exit 4 |
| 23 | end |
| 24 | fn akoc c ulong to void |
| 25 | n = get ak_n 0 |
| 26 | if ge n len ak_o |
| 27 | r = enlarge ak_o add mul n 2 4096 |
| 28 | if ne r 0 |
| 29 | akdie |
| 30 | end |
| 31 | end |
| 32 | put ak_o n uchar c |
| 33 | put ak_n 0 add n 1 |
| 34 | end |
| 35 | fn akt t view uchar * to void |
| 36 | for i ulong len t |
| 37 | akoc ulong get t i |
| 38 | end |
| 39 | end |
| 40 | fn aknum v ulong to void |
| 41 | if ge v 10 |
| 42 | aknum div v 10 |
| 43 | end |
| 44 | akoc add 48 rem v 10 |
| 45 | end |
| 46 | fn akhex v ulong to void |
| 47 | for i ulong 16 |
| 48 | c = and shr v mul 4 sub 15 i 15 |
| 49 | if lt c 10 |
| 50 | akoc add 48 c |
| 51 | else |
| 52 | akoc add 87 c |
| 53 | end |
| 54 | end |
| 55 | end |
| 56 | fn akflush to void |
| 57 | n = get ak_n 0 |
| 58 | o = ulong 0 |
| 59 | while lt o n bound 9223372036854775807 |
| 60 | x = write 1 ak_o o sub n o |
| 61 | if le x 0 |
| 62 | exit 3 |
| 63 | end |
| 64 | o = add o ulong x |
| 65 | end |
| 66 | put ak_n 0 0 |
| 67 | end |
| 68 | fn akrnd to ulong |
| 69 | s = get ak_s 0 |
| 70 | s = xor s shl s 13 |
| 71 | s = xor s shr s 7 |
| 72 | s = xor s shl s 17 |
| 73 | put ak_s 0 s |
| 74 | ret s |
| 75 | end |
| 76 | fn akval to ulong |
| 77 | r = akrnd |
| 78 | sel = and r 7 |
| 79 | if lt sel 4 |
| 80 | ret get ak_b and shr r 3 31 |
| 81 | end |
| 82 | if lt sel 6 |
| 83 | ret and shr r 3 127 |
| 84 | end |
| 85 | ret akrnd |
| 86 | end |
| 87 | fn akfnv h ulong w ulong to ulong |
| 88 | for b ulong 8 |
| 89 | h = mul xor h and shr w mul 8 b 255 1099511628211 |
| 90 | end |
| 91 | ret h |
| 92 | end |
| 93 | fn aknz v ulong to ulong |
| 94 | if eq v 0 |
| 95 | ret 1 |
| 96 | end |
| 97 | ret v |
| 98 | end |
| 99 | note the oracle's dom(): keeps a case where the C is defined (no division by zero, no shift past 63, no loop of |
| 100 | note 2^64 passes); the same rewrites in the same order |
| 101 | fn akdom f ulong mode ulong a edit ulong 16 to void |
| 102 | if eq f 0 |
| 103 | if eq mode 1 |
| 104 | put a 0 add mul and get a 0 511 16 16 |
| 105 | put a 1 add mul and get a 1 32767 8 8 |
| 106 | end |
| 107 | if and eq mode 2 ne get a 3 0 |
| 108 | put a 0 add and get a 0 32767 1 |
| 109 | end |
| 110 | if eq mode 3 |
| 111 | if ne and get a 1 1 0 |
| 112 | put a 1 ulong 16 |
| 113 | else |
| 114 | put a 1 ulong 8 |
| 115 | end |
| 116 | end |
| 117 | if eq mode 7 |
| 118 | put a 2 aknz and get a 2 7 |
| 119 | end |
| 120 | end |
| 121 | if eq f 1 |
| 122 | if eq mode 1 |
| 123 | put a 0 and get a 0 8589934591 |
| 124 | end |
| 125 | if eq mode 2 |
| 126 | put a 1 aknz get a 1 |
| 127 | put a 2 aknz get a 2 |
| 128 | end |
| 129 | if eq mode 3 |
| 130 | put a 1 aknz and get a 1 4294967295 |
| 131 | end |
| 132 | if eq mode 4 |
| 133 | put a 0 rem get a 0 5 |
| 134 | put a 1 aknz and get a 1 1023 |
| 135 | end |
| 136 | if eq mode 5 |
| 137 | put a 4 and get a 4 8589934591 |
| 138 | put a 5 aknz get a 5 |
| 139 | end |
| 140 | if eq mode 7 |
| 141 | put a 3 and get a 3 4294967295 |
| 142 | end |
| 143 | if eq mode 15 |
| 144 | put a 2 aknz get a 2 |
| 145 | end |
| 146 | if eq mode 22 |
| 147 | put a 1 and get a 1 4294967295 |
| 148 | end |
| 149 | if and eq mode 17 ne get a 4 0 |
| 150 | put a 3 and get a 3 4294967295 |
| 151 | end |
| 152 | if eq mode 25 |
| 153 | put a 2 aknz and get a 2 1023 |
| 154 | put a 1 mul get a 2 aknz and get a 1 63 |
| 155 | end |
| 156 | end |
| 157 | if and eq f 3 eq mode 0 |
| 158 | put a 0 and get a 0 16777215 |
| 159 | end |
| 160 | if and eq f 3 eq mode 1 |
| 161 | put a 3 aknz get a 3 |
| 162 | end |
| 163 | end |
| 164 | fn akline f ulong mode ulong c ulong r ulong a view ulong 16 to void |
| 165 | akt ak_tf |
| 166 | aknum f |
| 167 | akt ak_tm |
| 168 | aknum mode |
| 169 | akt ak_tc |
| 170 | aknum c |
| 171 | akt ak_tr |
| 172 | aknum r |
| 173 | akt ak_ta |
| 174 | for i ulong 16 |
| 175 | aknum get a i |
| 176 | if lt i 15 |
| 177 | akoc 44 |
| 178 | end |
| 179 | end |
| 180 | akoc 10 |
| 181 | end |
| 182 | fn akmode f ulong mode ulong to void |
| 183 | nc = ulong 4096 |
| 184 | a = new ulong 16 0 |
| 185 | h = ulong 14695981039346656037 |
| 186 | nz = ulong 0 |
| 187 | for c ulong nc |
| 188 | for i ulong 8 |
| 189 | put a i akval |
| 190 | end |
| 191 | for i ulong 8 |
| 192 | put a add i 8 add 2654435769 add i 8 |
| 193 | end |
| 194 | akdom f mode a |
| 195 | s = ap_plan f mode a |
| 196 | r = ulong neg s |
| 197 | if lt c 2 |
| 198 | akline f mode c r a |
| 199 | end |
| 200 | h = akfnv h r |
| 201 | for i ulong 16 |
| 202 | h = akfnv h get a i |
| 203 | end |
| 204 | if ne r 0 |
| 205 | nz = add nz 1 |
| 206 | end |
| 207 | end |
| 208 | akt ak_tf |
| 209 | aknum f |
| 210 | akt ak_tm |
| 211 | aknum mode |
| 212 | akt ak_tn |
| 213 | aknum nc |
| 214 | akt ak_tz |
| 215 | aknum nz |
| 216 | akt ak_th |
| 217 | akhex h |
| 218 | akoc 10 |
| 219 | akflush |
| 220 | end |
| 221 | fn main to int |
| 222 | put ak_s 0 88172645463325252 |
| 223 | put ak_b 0 0 |
| 224 | put ak_b 1 1 |
| 225 | put ak_b 2 2 |
| 226 | put ak_b 3 3 |
| 227 | put ak_b 4 4 |
| 228 | put ak_b 5 8 |
| 229 | put ak_b 6 15 |
| 230 | put ak_b 7 16 |
| 231 | put ak_b 8 47 |
| 232 | put ak_b 9 64 |
| 233 | put ak_b 10 128 |
| 234 | put ak_b 11 256 |
| 235 | put ak_b 12 1000 |
| 236 | put ak_b 13 1024 |
| 237 | put ak_b 14 4095 |
| 238 | put ak_b 15 4096 |
| 239 | put ak_b 16 8192 |
| 240 | put ak_b 17 16384 |
| 241 | put ak_b 18 65535 |
| 242 | put ak_b 19 65536 |
| 243 | put ak_b 20 131072 |
| 244 | put ak_b 21 262144 |
| 245 | put ak_b 22 999999 |
| 246 | put ak_b 23 2147483647 |
| 247 | put ak_b 24 4294967295 |
| 248 | put ak_b 25 4294967296 |
| 249 | put ak_b 26 268435456 |
| 250 | put ak_b 27 1099511627776 |
| 251 | put ak_b 28 1065353216 |
| 252 | put ak_b 29 4607182418800017408 |
| 253 | put ak_b 30 9223372036854775808 |
| 254 | put ak_b 31 18446744073709551615 |
| 255 | put ak_last 0 8 |
| 256 | put ak_last 1 27 |
| 257 | put ak_last 2 6 |
| 258 | put ak_last 3 6 |
| 259 | put ak_last 4 4 |
| 260 | put ak_last 5 4 |
| 261 | put ak_last 6 0 |
| 262 | for f ulong 7 |
| 263 | for mode ulong add get ak_last f 2 |
| 264 | akmode f mode |
| 265 | end |
| 266 | end |
| 267 | ret 0 |
| 268 | end |