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 / scanref-check.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/runtime/check/scanref-check.om: prints gpu/runtime/scanref.om on fixed xorshift64 vectors, one line |
| 3 | note per case, in the form the C oracle printed for CUDApp src/omega_gpu_scan_ref.c (gpu/runtime/README.md); |
| 4 | note gpu/runtime/check/scanref.expect.txt is that oracle's output. Composed after scan.om and scanref.om. |
| 5 | global ck_s ulong 1 |
| 6 | global ck_o uchar * |
| 7 | global ck_n ulong 1 |
| 8 | global ck_k2 uint * |
| 9 | note The output words, one table (OM-1 has no unsized view to pass a text by): segment i ends at the i-th |. |
| 10 | text ck_tx "n=| s=| red|=|refused|ok| pre=| last=| u32=| rk=| rv=| rko=|refuse red_op3=| red_n0=| pre_n0=| u32_n0=| radix_n0=|" |
| 11 | const ck_ns ulong 0 |
| 12 | const ck_ss ulong 1 |
| 13 | const ck_red ulong 2 |
| 14 | const ck_eq ulong 3 |
| 15 | const ck_ref ulong 4 |
| 16 | const ck_ok ulong 5 |
| 17 | const ck_pre ulong 6 |
| 18 | const ck_last ulong 7 |
| 19 | const ck_u32 ulong 8 |
| 20 | const ck_rk ulong 9 |
| 21 | const ck_rv ulong 10 |
| 22 | const ck_rko ulong 11 |
| 23 | const ck_r1 ulong 12 |
| 24 | const ck_r2 ulong 13 |
| 25 | const ck_r3 ulong 14 |
| 26 | const ck_r4 ulong 15 |
| 27 | const ck_r5 ulong 16 |
| 28 | text ck_mem "scanref-check: the host refused memory\n" |
| 29 | fn ckdie to void |
| 30 | w = write 2 ck_mem 0 len ck_mem |
| 31 | exit 4 |
| 32 | end |
| 33 | fn ckoc c ulong to void |
| 34 | n = get ck_n 0 |
| 35 | if ge n len ck_o |
| 36 | r = enlarge ck_o add mul n 2 4096 |
| 37 | if ne r 0 |
| 38 | ckdie |
| 39 | end |
| 40 | end |
| 41 | put ck_o n uchar c |
| 42 | put ck_n 0 add n 1 |
| 43 | end |
| 44 | fn ckot id ulong to void |
| 45 | k = ulong 0 |
| 46 | for i ulong len ck_tx |
| 47 | c = ulong get ck_tx i |
| 48 | if eq c 124 |
| 49 | k = add k 1 |
| 50 | else |
| 51 | if eq k id |
| 52 | ckoc c |
| 53 | end |
| 54 | end |
| 55 | end |
| 56 | end |
| 57 | fn cknum v ulong to void |
| 58 | if ge v 10 |
| 59 | cknum div v 10 |
| 60 | end |
| 61 | ckoc add 48 rem v 10 |
| 62 | end |
| 63 | fn ckhex v ulong d ulong to void |
| 64 | for i ulong d |
| 65 | c = and shr v mul 4 sub sub d 1 i 15 |
| 66 | if lt c 10 |
| 67 | ckoc add 48 c |
| 68 | else |
| 69 | ckoc add 87 c |
| 70 | end |
| 71 | end |
| 72 | end |
| 73 | fn ckres r ulong to void |
| 74 | if eq r 0 |
| 75 | ckot ck_ok |
| 76 | else |
| 77 | ckot ck_ref |
| 78 | end |
| 79 | end |
| 80 | fn ckflush to void |
| 81 | n = get ck_n 0 |
| 82 | o = ulong 0 |
| 83 | while lt o n bound 9223372036854775807 |
| 84 | x = write 1 ck_o o sub n o |
| 85 | if le x 0 |
| 86 | exit 3 |
| 87 | end |
| 88 | o = add o ulong x |
| 89 | end |
| 90 | put ck_n 0 0 |
| 91 | end |
| 92 | fn ckrnd to ulong |
| 93 | s = get ck_s 0 |
| 94 | s = xor s shl s 13 |
| 95 | s = xor s shr s 7 |
| 96 | s = xor s shl s 17 |
| 97 | put ck_s 0 s |
| 98 | ret s |
| 99 | end |
| 100 | note The float bits of the oracle's fbits: with sp, one in sixteen each of +0, -0, quiet NaN, +inf, -inf. |
| 101 | fn ckfb sp ulong to uint |
| 102 | r = ckrnd |
| 103 | c = and r 15 |
| 104 | if ne sp 0 |
| 105 | if eq c 0 |
| 106 | ret uint 0 |
| 107 | end |
| 108 | if eq c 1 |
| 109 | ret uint 2147483648 |
| 110 | end |
| 111 | if eq c 2 |
| 112 | ret uint 2143289344 |
| 113 | end |
| 114 | if eq c 3 |
| 115 | ret uint 2139095040 |
| 116 | end |
| 117 | if eq c 4 |
| 118 | ret uint 4286578688 |
| 119 | end |
| 120 | end |
| 121 | sg = shl and shr r 4 1 31 |
| 122 | ex = add 100 rem shr r 5 51 |
| 123 | mn = and shr r 32 8388607 |
| 124 | ret uint or or sg shl ex 23 mn |
| 125 | end |
| 126 | note FNV-1a 64 of one 32-bit value's little-endian bytes, folded into h. |
| 127 | fn ckfnv h ulong w ulong to ulong |
| 128 | for b ulong 4 |
| 129 | h = mul xor h and shr w mul 8 b 255 1099511628211 |
| 130 | end |
| 131 | ret h |
| 132 | end |
| 133 | note FNV-1a 64 over the first n values of pool p: 0 sr_y (float bits), 1 sr_uy, 2 sr_k, 3 sr_v. |
| 134 | fn ckhash p ulong n ulong to ulong |
| 135 | h = ulong 14695981039346656037 |
| 136 | for i ulong n bound 9223372036854775807 |
| 137 | w = ulong 0 |
| 138 | if eq p 0 |
| 139 | w = ulong bitcast uint get sr_y i |
| 140 | end |
| 141 | if eq p 1 |
| 142 | w = ulong get sr_uy i |
| 143 | end |
| 144 | if eq p 2 |
| 145 | w = ulong get sr_k i |
| 146 | end |
| 147 | if eq p 3 |
| 148 | w = ulong get sr_v i |
| 149 | end |
| 150 | h = ckfnv h w |
| 151 | end |
| 152 | ret h |
| 153 | end |
| 154 | fn ckbits f f32 to void |
| 155 | ckhex ulong bitcast uint f 8 |
| 156 | end |
| 157 | fn ckgrow n ulong to void |
| 158 | r = enlarge sr_x n |
| 159 | if ne r 0 |
| 160 | ckdie |
| 161 | end |
| 162 | r = enlarge sr_u n |
| 163 | if ne r 0 |
| 164 | ckdie |
| 165 | end |
| 166 | r = enlarge sr_k n |
| 167 | if ne r 0 |
| 168 | ckdie |
| 169 | end |
| 170 | r = enlarge sr_v n |
| 171 | if ne r 0 |
| 172 | ckdie |
| 173 | end |
| 174 | r = enlarge ck_k2 n |
| 175 | if ne r 0 |
| 176 | ckdie |
| 177 | end |
| 178 | end |
| 179 | note One case: n values, specials sp, key mask m; the draws in the oracle's order. |
| 180 | fn ckcase n ulong sp ulong m ulong to void |
| 181 | ckgrow n |
| 182 | for i ulong n bound 9223372036854775807 |
| 183 | put sr_x i bitcast f32 ckfb sp |
| 184 | end |
| 185 | ckot ck_ns |
| 186 | cknum n |
| 187 | ckot ck_ss |
| 188 | cknum sp |
| 189 | for op ulong 3 |
| 190 | ckot ck_red |
| 191 | cknum op |
| 192 | ckot ck_eq |
| 193 | if eq sr_reduce op n 0 |
| 194 | ckbits get sr_r 0 |
| 195 | else |
| 196 | ckot ck_ref |
| 197 | end |
| 198 | end |
| 199 | ckot ck_pre |
| 200 | if eq sr_prefix n 0 |
| 201 | ckhex ckhash 0 n 16 |
| 202 | ckot ck_last |
| 203 | ckbits get sr_y sub n 1 |
| 204 | else |
| 205 | ckot ck_ref |
| 206 | end |
| 207 | for i ulong n bound 9223372036854775807 |
| 208 | put sr_u i uint and shr ckrnd 16 4294967295 |
| 209 | end |
| 210 | ckot ck_u32 |
| 211 | if eq sr_pu32 n 0 |
| 212 | ckhex ckhash 1 n 16 |
| 213 | else |
| 214 | ckot ck_ref |
| 215 | end |
| 216 | ckradix n m |
| 217 | ckoc 10 |
| 218 | end |
| 219 | fn ckradix n ulong m ulong to void |
| 220 | for i ulong n bound 9223372036854775807 |
| 221 | w = uint and shr ckrnd 8 m |
| 222 | put sr_k i w |
| 223 | put sr_v i uint i |
| 224 | put ck_k2 i w |
| 225 | end |
| 226 | ckot ck_rk |
| 227 | if eq sr_radix n 1 0 |
| 228 | ckhex ckhash 2 n 16 |
| 229 | ckot ck_rv |
| 230 | ckhex ckhash 3 n 16 |
| 231 | else |
| 232 | ckot ck_ref |
| 233 | end |
| 234 | for i ulong n bound 9223372036854775807 |
| 235 | put sr_k i get ck_k2 i |
| 236 | end |
| 237 | ckot ck_rko |
| 238 | if eq sr_radix n 0 0 |
| 239 | ckhex ckhash 2 n 16 |
| 240 | else |
| 241 | ckot ck_ref |
| 242 | end |
| 243 | end |
| 244 | fn ckrefuse to void |
| 245 | ckot ck_r1 |
| 246 | ckres sr_reduce 3 4 |
| 247 | ckot ck_r2 |
| 248 | ckres sr_reduce 0 0 |
| 249 | ckot ck_r3 |
| 250 | ckres sr_prefix 0 |
| 251 | ckot ck_r4 |
| 252 | ckres sr_pu32 0 |
| 253 | ckot ck_r5 |
| 254 | ckres sr_radix 0 1 |
| 255 | ckoc 10 |
| 256 | end |
| 257 | fn main to int |
| 258 | put ck_s 0 88172645463325252 |
| 259 | ns = new ulong 12 0 |
| 260 | put ns 0 1 |
| 261 | put ns 1 2 |
| 262 | put ns 2 31 |
| 263 | put ns 3 32 |
| 264 | put ns 4 33 |
| 265 | put ns 5 100 |
| 266 | put ns 6 1023 |
| 267 | put ns 7 1024 |
| 268 | put ns 8 1025 |
| 269 | put ns 9 4097 |
| 270 | put ns 10 33000 |
| 271 | put ns 11 70001 |
| 272 | ms = new ulong 3 4294967295 |
| 273 | put ms 1 255 |
| 274 | put ms 2 252645135 |
| 275 | for sp ulong 2 |
| 276 | for c ulong 12 |
| 277 | ckcase get ns c sp get ms rem c 3 |
| 278 | ckflush |
| 279 | end |
| 280 | end |
| 281 | ckrefuse |
| 282 | ckflush |
| 283 | ret 0 |
| 284 | end |