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 / nvidia / om / encoder / guard_pred_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note guard_pred_test.om: gate for the guard predicate of every sm_121 op in the seeded encoder (DRA-483, C1b). |
| 3 | note Concatenate after bw_enc_sm121.om; mk/om-encoder.mk test-om-encoder-guard compiles it with the pinned omc. |
| 4 | note Input word 7 bit 1 (predicate_p0) and bit 2 (predicate_not) ask for @P0 / @!P0; the guard is w0 bits 12..15: |
| 5 | note 7 always (PT), 0 @P0, 8 @!P0. Every op 0..64 is encoded three times with R4 <- R8, R12, R16, UR4 (imm 2 for |
| 6 | note BRA and BSSY, else 0): unpredicated, @P0 and @!P0. The @P0 / @!P0 words must carry guard 0 / 8 and equal the |
| 7 | note unpredicated words in every other bit. LDCU and LDCU.64 (ops 6, 7) are uniform-datapath instructions: their |
| 8 | note guard bits name UP0..UPT, so @P0 cannot be encoded there and both forms must be refused. |
| 9 | note Program rows: the omega-mv #1044 seed/oscgpu bool and trap shapes (gpuir.om bw_bool, bw_trap; the C twin is |
| 10 | note src/omega_osc_gpu.c Bool, Trap) go through the program entry bw_enc_sm121 with word 7 as the C packer writes |
| 11 | note it: MOV R4, 0 / @P0 MOV R4, 1 / @!P0 STG.E desc[UR4][R8.64], R12 / @!P0 MOV R5, 1 / @!P0 MOV R4, 0. Their |
| 12 | note guards must be 7, 0, 8, 8, 8. |
| 13 | note No arguments: print one line per failing form (op, form 1 @P0 / 2 @!P0, guard read; 99 refused, 98 accepted |
| 14 | note but must refuse, 97 another bit changed; program rows as op 100 + row), then the failure count; exit 0 when |
| 15 | note none, else 1. |
| 16 | note One argument: write 135 instructions (2160 bytes) on stdout for the ORACLE: the @P0 and @!P0 forms of the 63 |
| 17 | note P-guarded ops in op order, then the unpredicated LDCU and LDCU.64 words with their guard bits set to 0 and 8 |
| 18 | note (an oracle probe, not encoder output), then the five program rows. |
| 19 | note Two arguments: read the ORACLE's text on stdin; instruction k must start with @P0 / @!P0 (k < 126, even / odd), |
| 20 | note then @UP0 / @!UP0 (126..129), then no guard, @P0, @!P0, @!P0, @!P0 (130..134). Exit 0, 4 when a guard or the |
| 21 | note instruction count is wrong, 70 read error, 71 text too long. |
| 22 | note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex. |
| 23 | note Constants (Wolfram): 61440 = 0xf000 (guard mask), 130 = 2 * 65, 135 = 130 + 5, 2160 = 135 * 16. |
| 24 | text gptok "@P0 @!P0 @UP0 @!UP0 " |
| 25 | text gpm1 "FAIL op " |
| 26 | text gpm2 " form " |
| 27 | text gpm3 " guard " |
| 28 | text gpm4 "guard predicate failures: " |
| 29 | text gpm5 "oracle instructions: " |
| 30 | text gpm6 " guard mismatches: " |
| 31 | text gpnl "\n" |
| 32 | global gpbuf uchar 65536 |
| 33 | const GPNONE ulong 18446744073709551615 |
| 34 | |
| 35 | note uniform-datapath ops: the guard bits name a uniform predicate |
| 36 | fn gp_uni op ulong to bool |
| 37 | ret or eq op 6 eq op 7 |
| 38 | end |
| 39 | |
| 40 | note encode op with form f (0 none, 1 @P0, 2 @!P0) into w; enc1's result (0 accepted) |
| 41 | fn gp_enc op ulong f ulong w edit ulong 4 to ulong |
| 42 | o = new ulong 16 0 |
| 43 | put o 0 op |
| 44 | put o 1 4 |
| 45 | put o 2 8 |
| 46 | put o 3 12 |
| 47 | put o 4 16 |
| 48 | put o 5 4 |
| 49 | if or eq op 46 eq op 54 |
| 50 | put o 6 2 |
| 51 | end |
| 52 | put o 12 1 |
| 53 | put o 13 1 |
| 54 | put o 14 1 |
| 55 | put o 15 1 |
| 56 | if ne f 0 |
| 57 | put o 9 1 |
| 58 | end |
| 59 | if eq f 2 |
| 60 | put o 10 1 |
| 61 | end |
| 62 | ret enc1 view o w |
| 63 | end |
| 64 | |
| 65 | fn gp_dec x ulong to void |
| 66 | b = new uchar 20 0 |
| 67 | i = ulong 20 |
| 68 | v = x |
| 69 | c = true |
| 70 | while c bound 20 |
| 71 | i = sub i 1 |
| 72 | put b i uchar add 48 rem v 10 |
| 73 | v = div v 10 |
| 74 | if eq v 0 |
| 75 | c = false |
| 76 | end |
| 77 | end |
| 78 | k = write 1 b i sub 20 i |
| 79 | end |
| 80 | |
| 81 | fn gp_fail op ulong f ulong g ulong to void |
| 82 | k = write 1 gpm1 0 len gpm1 |
| 83 | gp_dec op |
| 84 | k = write 1 gpm2 0 len gpm2 |
| 85 | gp_dec f |
| 86 | k = write 1 gpm3 0 len gpm3 |
| 87 | gp_dec g |
| 88 | k = write 1 gpnl 0 1 |
| 89 | end |
| 90 | |
| 91 | note the guard field of w0 |
| 92 | fn gp_g w view ulong 4 to ulong |
| 93 | ret and shr get w 0 12 15 |
| 94 | end |
| 95 | |
| 96 | note equal outside the guard field |
| 97 | fn gp_same u view ulong 4 p view ulong 4 to bool |
| 98 | if ne or get u 0 61440 or get p 0 61440 |
| 99 | ret false |
| 100 | end |
| 101 | for k ulong 3 |
| 102 | if ne get u add k 1 get p add k 1 |
| 103 | ret false |
| 104 | end |
| 105 | end |
| 106 | ret true |
| 107 | end |
| 108 | |
| 109 | note the failing forms of op (0..2) |
| 110 | fn gp_row op ulong to ulong |
| 111 | u = new ulong 4 0 |
| 112 | p = new ulong 4 0 |
| 113 | if ne gp_enc op 0 edit u 0 |
| 114 | gp_fail op 0 99 |
| 115 | ret 1 |
| 116 | end |
| 117 | bad = ulong 0 |
| 118 | for f ulong 2 |
| 119 | fm = add f 1 |
| 120 | r = gp_enc op fm edit p |
| 121 | if gp_uni op |
| 122 | if eq r 0 |
| 123 | gp_fail op fm 98 |
| 124 | bad = add bad 1 |
| 125 | end |
| 126 | else |
| 127 | if ne r 0 |
| 128 | gp_fail op fm 99 |
| 129 | bad = add bad 1 |
| 130 | else |
| 131 | g = gp_g view p |
| 132 | if ne g mul f 8 |
| 133 | gp_fail op fm g |
| 134 | bad = add bad 1 |
| 135 | else |
| 136 | if not gp_same view u view p |
| 137 | gp_fail op fm 97 |
| 138 | bad = add bad 1 |
| 139 | end |
| 140 | end |
| 141 | end |
| 142 | end |
| 143 | end |
| 144 | ret bad |
| 145 | end |
| 146 | |
| 147 | note program row r: op, dst, src1, src2, imm, word 7 (2 @P0, 6 @!P0), and the guard it must get |
| 148 | fn gp_pop r ulong to ulong |
| 149 | if eq r 2 |
| 150 | ret 12 |
| 151 | end |
| 152 | ret 2 |
| 153 | end |
| 154 | fn gp_pdst r ulong to ulong |
| 155 | if eq r 2 |
| 156 | ret GPNONE |
| 157 | end |
| 158 | if eq r 3 |
| 159 | ret 5 |
| 160 | end |
| 161 | ret 4 |
| 162 | end |
| 163 | fn gp_pimm r ulong to ulong |
| 164 | if or eq r 1 eq r 3 |
| 165 | ret 1 |
| 166 | end |
| 167 | ret 0 |
| 168 | end |
| 169 | fn gp_pfl r ulong to ulong |
| 170 | if eq r 0 |
| 171 | ret 0 |
| 172 | end |
| 173 | if eq r 1 |
| 174 | ret 2 |
| 175 | end |
| 176 | ret 6 |
| 177 | end |
| 178 | fn gp_pg r ulong to ulong |
| 179 | if eq r 0 |
| 180 | ret 7 |
| 181 | end |
| 182 | if eq r 1 |
| 183 | ret 0 |
| 184 | end |
| 185 | ret 8 |
| 186 | end |
| 187 | |
| 188 | note the five #1044 rows through bw_enc_sm121 into code; the byte count (80 when accepted) |
| 189 | fn gp_penc code edit uchar 16384 to ulong |
| 190 | ins = new ulong 8192 0 |
| 191 | phys = new ulong 288 0 |
| 192 | for v ulong 256 |
| 193 | put phys v v |
| 194 | end |
| 195 | for u ulong 32 |
| 196 | put phys add 256 u u |
| 197 | end |
| 198 | for r ulong 5 |
| 199 | b = mul r 8 |
| 200 | put ins b gp_pop r |
| 201 | put ins add b 1 gp_pdst r |
| 202 | put ins add b 2 GPNONE |
| 203 | put ins add b 3 GPNONE |
| 204 | put ins add b 4 GPNONE |
| 205 | put ins add b 5 GPNONE |
| 206 | put ins add b 6 gp_pimm r |
| 207 | put ins add b 7 gp_pfl r |
| 208 | if eq r 2 |
| 209 | put ins add b 2 8 |
| 210 | put ins add b 3 12 |
| 211 | put ins add b 5 4 |
| 212 | end |
| 213 | end |
| 214 | ret bw_enc_sm121 view ins view phys 5 0 code |
| 215 | end |
| 216 | |
| 217 | fn gp_prog to ulong |
| 218 | code = new uchar 16384 0 |
| 219 | if ne gp_penc edit code 80 |
| 220 | gp_fail 100 0 99 |
| 221 | ret 1 |
| 222 | end |
| 223 | bad = ulong 0 |
| 224 | for r ulong 5 |
| 225 | g = and shr get code add mul r 16 1 4 15 |
| 226 | if ne ulong g gp_pg r |
| 227 | gp_fail add 100 r gp_pfl r ulong g |
| 228 | bad = add bad 1 |
| 229 | end |
| 230 | end |
| 231 | ret bad |
| 232 | end |
| 233 | |
| 234 | fn gp_rows to int |
| 235 | bad = ulong 0 |
| 236 | for op ulong 65 |
| 237 | bad = add bad gp_row op |
| 238 | end |
| 239 | bad = add bad gp_prog |
| 240 | k = write 1 gpm4 0 len gpm4 |
| 241 | gp_dec bad |
| 242 | k = write 1 gpnl 0 1 |
| 243 | if ne bad 0 |
| 244 | ret 1 |
| 245 | end |
| 246 | ret 0 |
| 247 | end |
| 248 | |
| 249 | fn gp_bin to int |
| 250 | w = new ulong 4 0 |
| 251 | code = new uchar 16384 0 |
| 252 | pc = new uchar 16384 0 |
| 253 | i = ulong 0 |
| 254 | for op ulong 65 |
| 255 | if not gp_uni op |
| 256 | for f ulong 2 |
| 257 | if ne gp_enc op add f 1 edit w 0 |
| 258 | ret int add 10 op |
| 259 | end |
| 260 | store edit code i view w |
| 261 | i = add i 1 |
| 262 | end |
| 263 | end |
| 264 | end |
| 265 | for op ulong 65 |
| 266 | if gp_uni op |
| 267 | if ne gp_enc op 0 edit w 0 |
| 268 | ret int add 10 op |
| 269 | end |
| 270 | x = get w 0 |
| 271 | for f ulong 2 |
| 272 | put w 0 or sub x and x 61440 shl mul f 8 12 |
| 273 | store edit code i view w |
| 274 | i = add i 1 |
| 275 | end |
| 276 | end |
| 277 | end |
| 278 | if ne gp_penc edit pc 80 |
| 279 | ret 9 |
| 280 | end |
| 281 | for q ulong 80 |
| 282 | put code add mul i 16 q get pc q |
| 283 | end |
| 284 | n = add mul i 16 80 |
| 285 | off = ulong 0 |
| 286 | while lt off n bound 4096 |
| 287 | k = write 1 code off sub n off |
| 288 | if le k 0 |
| 289 | ret 3 |
| 290 | end |
| 291 | off = add off ulong k |
| 292 | end |
| 293 | ret 0 |
| 294 | end |
| 295 | |
| 296 | fn gp_ts t ulong to ulong |
| 297 | if eq t 0 |
| 298 | ret 0 |
| 299 | end |
| 300 | if eq t 1 |
| 301 | ret 4 |
| 302 | end |
| 303 | if eq t 2 |
| 304 | ret 9 |
| 305 | end |
| 306 | ret 14 |
| 307 | end |
| 308 | |
| 309 | note does token t of gptok start at gpbuf[j]? Token 4 is no guard (the mnemonic is not an @ word). |
| 310 | fn gp_tok j ulong n ulong t ulong to bool |
| 311 | if eq t 4 |
| 312 | if ge j n |
| 313 | ret false |
| 314 | end |
| 315 | ret ne get gpbuf j 64 |
| 316 | end |
| 317 | s = gp_ts t |
| 318 | e = gp_ts add t 1 |
| 319 | if eq t 3 |
| 320 | e = 20 |
| 321 | end |
| 322 | if gt add j sub e s n |
| 323 | ret false |
| 324 | end |
| 325 | for q ulong sub e s |
| 326 | if ne get gpbuf add j q get gptok add s q |
| 327 | ret false |
| 328 | end |
| 329 | end |
| 330 | ret true |
| 331 | end |
| 332 | |
| 333 | note an address marker "/*" then a hex digit at gpbuf[i]; the caller keeps i + 2 below n |
| 334 | fn gp_mark i ulong to bool |
| 335 | if ne get gpbuf i 47 |
| 336 | ret false |
| 337 | end |
| 338 | if ne get gpbuf add i 1 42 |
| 339 | ret false |
| 340 | end |
| 341 | c = get gpbuf add i 2 |
| 342 | if and ge c 48 le c 57 |
| 343 | ret true |
| 344 | end |
| 345 | ret and ge c 97 le c 102 |
| 346 | end |
| 347 | |
| 348 | note the index after the marker's "*/" and the blanks that follow |
| 349 | fn gp_after i ulong n ulong to ulong |
| 350 | j = add i 2 |
| 351 | while lt add j 1 n bound 65536 |
| 352 | if eq get gpbuf j 42 |
| 353 | if eq get gpbuf add j 1 47 |
| 354 | j = add j 2 |
| 355 | break |
| 356 | end |
| 357 | end |
| 358 | j = add j 1 |
| 359 | end |
| 360 | while lt j n bound 65536 |
| 361 | c = get gpbuf j |
| 362 | if and ne c 32 ne c 9 |
| 363 | break |
| 364 | end |
| 365 | j = add j 1 |
| 366 | end |
| 367 | ret j |
| 368 | end |
| 369 | |
| 370 | note the token instruction k must carry |
| 371 | fn gp_want k ulong to ulong |
| 372 | if lt k 126 |
| 373 | ret rem k 2 |
| 374 | end |
| 375 | if lt k 130 |
| 376 | ret add 2 rem k 2 |
| 377 | end |
| 378 | if eq k 130 |
| 379 | ret 4 |
| 380 | end |
| 381 | if eq k 131 |
| 382 | ret 0 |
| 383 | end |
| 384 | ret 1 |
| 385 | end |
| 386 | |
| 387 | fn gp_check to int |
| 388 | n = ulong 0 |
| 389 | while lt n 65536 bound 65536 |
| 390 | r = read 0 gpbuf n sub 65536 n |
| 391 | if lt r 0 |
| 392 | ret 70 |
| 393 | end |
| 394 | if eq r 0 |
| 395 | break |
| 396 | end |
| 397 | n = add n ulong r |
| 398 | end |
| 399 | if eq n 65536 |
| 400 | ret 71 |
| 401 | end |
| 402 | k = ulong 0 |
| 403 | bad = ulong 0 |
| 404 | i = ulong 0 |
| 405 | while lt add i 2 n bound 65536 |
| 406 | if gp_mark i |
| 407 | j = gp_after i n |
| 408 | if not gp_tok j n gp_want k |
| 409 | bad = add bad 1 |
| 410 | end |
| 411 | k = add k 1 |
| 412 | i = j |
| 413 | else |
| 414 | i = add i 1 |
| 415 | end |
| 416 | end |
| 417 | w = write 1 gpm5 0 len gpm5 |
| 418 | gp_dec k |
| 419 | w = write 1 gpm6 0 len gpm6 |
| 420 | gp_dec bad |
| 421 | w = write 1 gpnl 0 1 |
| 422 | if or ne k 135 ne bad 0 |
| 423 | ret 4 |
| 424 | end |
| 425 | ret 0 |
| 426 | end |
| 427 | |
| 428 | fn main to int |
| 429 | if gt argcnt 3 |
| 430 | ret 64 |
| 431 | end |
| 432 | if eq argcnt 3 |
| 433 | ret gp_check |
| 434 | end |
| 435 | if eq argcnt 2 |
| 436 | ret gp_bin |
| 437 | end |
| 438 | ret gp_rows |
| 439 | end |