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 / om / encoder / bw_enc_sm121.om
| 1 | note bw_enc_sm121.om: the sm_121 instruction encoder of CUDApp (aien-dev/CUDApp#79, OM-GPU-RETIRE). |
| 2 | note It turns a solved BlackwellIR program into machine code: four 32-bit words per instruction, |
| 3 | note little-endian, padded with NOPs to a multiple of 8 and at least 32 instructions. |
| 4 | note It replaces encode_single_insn and omega_bw_encode_program of src/omega_blackwell_codegen.c, |
| 5 | note which stays compiled only behind CUDAPP_MIGRATION_PENDING_C_ENCODER as the differential oracle |
| 6 | note (and in the freestanding build, which has no native binding yet). |
| 7 | note |
| 8 | note Two copies stay two files for two reasons only. seed/ng/cudapp.lock hashes |
| 9 | note gpu/nvidia/om/encoder/bw_enc_sm121.om, and that file encodes ops 64..79, which this file refuses. |
| 10 | note This file is what om/units.sh and mk/om-encoder.mk link. Op 11 and op 21 were bugs here. |
| 11 | note Op 11 dropped imm, so nvdisasm read LDG.E R4, desc[UR4][R8.64]; the signed 24-bit offset is now in |
| 12 | note word1, and imm 64 reads LDG.E R4, desc[UR4][R8.64+0x40]. Op 21's word2 was 202250496 (0x0c0e1900), |
| 13 | note which nvdisasm reads as LDG.E.EF; it is now 203364608 (0x0c1f1900), LDG.E.MMIO.GPU. The C oracle's |
| 14 | note LDG_MMIO case moved with it. om/encoder/guard-gate.sh exits nonzero while any word on ops 0..63 differs. |
| 15 | note |
| 16 | note Input (bw_om_encode in src/omega_blackwell_codegen.c packs it; 8 ulong per instruction, at most 1024 instructions): |
| 17 | note 0 op (the BlackwellIROpcode number) 1 dst_vreg 2 src1_vreg 3 src2_vreg 4 src3_vreg |
| 18 | note 5 ureg (the five vreg fields are C int, passed as 64-bit two's complement: negative = none) |
| 19 | note 6 imm or control shl 32 |
| 20 | note 7 is_uniform or predicate_p0 shl 1 or predicate_not shl 2 or bar_reg shl 8 |
| 21 | note or dst_subreg shl 16 or src1_subreg shl 24 or src2_subreg shl 32 or src3_subreg shl 40 |
| 22 | note phys: vreg_to_phys 0..255 then uvreg_to_phys at 256..287 (C int, two's complement). |
| 23 | note pad 1: omega_bw_encode_program (pad to the multiple of 8, at least 32); pad 0: exactly n instructions. |
| 24 | note Result: the bytes written, or 0 when an instruction is refused (unknown op, an offset outside its |
| 25 | note field, a BSSY delta below 2, a barrier register above 15) or n is above 1024. |
| 26 | note Every constant is the decimal form of the C encoder's hex word (conversions by Wolfram, |
| 27 | note evidence/CUDAPP-OM-ENCODER/wolfram-constants.txt). |
| 28 | |
| 29 | const NEG ulong 9223372036854775808 |
| 30 | const NOPW ulong 31000 |
| 31 | const NOPC ulong 1032192 |
| 32 | |
| 33 | fn put4 w edit ulong 4 a ulong b ulong c ulong d ulong to void |
| 34 | put w 0 a |
| 35 | put w 1 b |
| 36 | put w 2 c |
| 37 | put w 3 d |
| 38 | end |
| 39 | |
| 40 | note the physical register of one operand field: phys + subreg, or dflt when the vreg is negative |
| 41 | fn preg phys view ulong 288 v ulong sb ulong dflt ulong to ulong |
| 42 | if ge v NEG |
| 43 | ret dflt |
| 44 | end |
| 45 | ret add get phys v sb |
| 46 | end |
| 47 | |
| 48 | note 1 when a vreg field is given (not negative), else 0 |
| 49 | fn pres v ulong to ulong |
| 50 | if ge v NEG |
| 51 | ret 0 |
| 52 | end |
| 53 | ret 1 |
| 54 | end |
| 55 | |
| 56 | fn opnds ins view ulong 8192 i ulong phys view ulong 288 o edit ulong 16 to void |
| 57 | b = mul i 8 |
| 58 | f = get ins add b 7 |
| 59 | put o 0 get ins b |
| 60 | put o 1 preg phys get ins add b 1 and shr f 16 255 0 |
| 61 | put o 2 preg phys get ins add b 2 and shr f 24 255 0 |
| 62 | put o 3 preg phys get ins add b 3 and shr f 32 255 0 |
| 63 | put o 4 preg phys get ins add b 4 and shr f 40 255 255 |
| 64 | u = get ins add b 5 |
| 65 | put o 5 0 |
| 66 | if lt u NEG |
| 67 | put o 5 get phys add u 256 |
| 68 | end |
| 69 | put o 14 pres u |
| 70 | x = get ins add b 6 |
| 71 | put o 6 and x 4294967295 |
| 72 | put o 7 shr x 32 |
| 73 | put o 8 and f 1 |
| 74 | put o 9 and shr f 1 1 |
| 75 | put o 10 and shr f 2 1 |
| 76 | put o 11 and shr f 8 255 |
| 77 | put o 12 pres get ins add b 2 |
| 78 | put o 13 pres get ins add b 3 |
| 79 | d = get ins add b 1 |
| 80 | put o 15 pres d |
| 81 | if and eq and f 1 1 lt d NEG |
| 82 | put o 1 get phys add d 256 |
| 83 | end |
| 84 | end |
| 85 | |
| 86 | note the control word: the instruction's own, else the op's default |
| 87 | fn ctl o view ulong 16 dflt ulong to ulong |
| 88 | c = get o 7 |
| 89 | if ne c 0 |
| 90 | ret c |
| 91 | end |
| 92 | ret dflt |
| 93 | end |
| 94 | |
| 95 | note low 8 bits of operand slot k |
| 96 | fn rb o view ulong 16 k ulong to ulong |
| 97 | ret and get o k 255 |
| 98 | end |
| 99 | |
| 100 | note slot k when its vreg (presence slot h) is given, else RZ |
| 101 | fn rz o view ulong 16 k ulong h ulong to ulong |
| 102 | if ne get o h 0 |
| 103 | ret rb o k |
| 104 | end |
| 105 | ret 255 |
| 106 | end |
| 107 | |
| 108 | fn wd o view ulong 16 base ulong to ulong |
| 109 | ret or base shl rb o 1 16 |
| 110 | end |
| 111 | |
| 112 | fn wa o view ulong 16 base ulong to ulong |
| 113 | ret or base shl rb o 2 24 |
| 114 | end |
| 115 | |
| 116 | fn wda o view ulong 16 base ulong to ulong |
| 117 | ret or wd o base shl rb o 2 24 |
| 118 | end |
| 119 | |
| 120 | note the 4-bit guard predicate field: 7 always, 0 @P0, 8 @!P0 |
| 121 | fn pred o view ulong 16 to ulong |
| 122 | if eq get o 9 0 |
| 123 | ret 7 |
| 124 | end |
| 125 | if eq get o 10 0 |
| 126 | ret 0 |
| 127 | end |
| 128 | ret 8 |
| 129 | end |
| 130 | |
| 131 | note a signed 24-bit byte offset (imm read as int32) fits |
| 132 | fn off24 imm ulong to bool |
| 133 | ret or lt imm 8388608 ge imm 4286578688 |
| 134 | end |
| 135 | |
| 136 | note ops 0..14: moves, constants, integer multiply-add, compares and global memory |
| 137 | fn enc_a o view ulong 16 w edit ulong 4 to ulong |
| 138 | op = get o 0 |
| 139 | imm = get o 6 |
| 140 | if eq op 0 |
| 141 | put4 w NOPW 0 0 ctl o NOPC |
| 142 | ret 0 |
| 143 | end |
| 144 | if eq op 1 |
| 145 | put4 w wd o 29186 255 3840 ctl o 1040896 |
| 146 | ret 0 |
| 147 | end |
| 148 | if eq op 2 |
| 149 | put4 w wd o 30722 imm 3840 ctl o 1040896 |
| 150 | ret 0 |
| 151 | end |
| 152 | if eq op 3 |
| 153 | put4 w wd o 31001 0 shl and imm 255 8 ctl o 926208 |
| 154 | ret 0 |
| 155 | end |
| 156 | if eq op 4 |
| 157 | put4 w wd o 4278221698 and shl imm 6 16776960 2048 ctl o 1040896 |
| 158 | ret 0 |
| 159 | end |
| 160 | if eq op 5 |
| 161 | put4 w wd o 4278221698 and shl imm 6 16776960 2560 ctl o 926208 |
| 162 | ret 0 |
| 163 | end |
| 164 | if eq op 6 |
| 165 | put4 w wd o 4278220716 and shl imm 5 16776960 134219776 ctl o 926208 |
| 166 | ret 0 |
| 167 | end |
| 168 | if eq op 7 |
| 169 | put4 w wd o 4278220716 and shl imm 5 16776960 134220288 ctl o 945664 |
| 170 | ret 0 |
| 171 | end |
| 172 | if eq op 8 |
| 173 | if ne get o 13 0 |
| 174 | put4 w wda o 29220 rb o 3 or 126747136 rb o 4 ctl o 2083328 |
| 175 | ret 0 |
| 176 | end |
| 177 | if and ne get o 8 0 ne get o 14 0 |
| 178 | put4 w wda o 31780 rb o 5 or 260964864 rb o 4 ctl o 2083328 |
| 179 | ret 0 |
| 180 | end |
| 181 | put4 w wda o 30756 imm or 126747136 rb o 4 ctl o 2083328 |
| 182 | ret 0 |
| 183 | end |
| 184 | if eq op 9 |
| 185 | put4 w wda o 30757 imm or 126746624 rb o 4 ctl o 2083840 |
| 186 | ret 0 |
| 187 | end |
| 188 | if eq op 10 |
| 189 | if and ne get o 8 0 ne get o 14 0 |
| 190 | put4 w wda o 31756 rb o 5 200302704 ctl o 3136000 |
| 191 | ret 0 |
| 192 | end |
| 193 | put4 w wda o 30732 imm 66085488 ctl o 2087424 |
| 194 | ret 0 |
| 195 | end |
| 196 | if eq op 11 |
| 197 | if not off24 imm |
| 198 | ret 1 |
| 199 | end |
| 200 | put4 w wda o 31105 or rb o 5 shl and imm 16777215 8 203299072 ctl o 991744 |
| 201 | ret 0 |
| 202 | end |
| 203 | if eq op 12 |
| 204 | if not off24 imm |
| 205 | ret 1 |
| 206 | end |
| 207 | put4 w wa o 31110 or rb o 3 shl and imm 16777215 8 or 202381568 rb o 5 ctl o 1040896 |
| 208 | ret 0 |
| 209 | end |
| 210 | if eq op 13 |
| 211 | put4 w wa o 31110 rb o 3 or 202447104 rb o 5 ctl o 1040896 |
| 212 | ret 0 |
| 213 | end |
| 214 | if eq op 14 |
| 215 | put4 w wda o 29200 rb o 3 134209791 ctl o 17811968 |
| 216 | ret 0 |
| 217 | end |
| 218 | ret 1 |
| 219 | end |
| 220 | |
| 221 | note ops 15..29: tensor core, shifts, wide and strong loads, stores, fences, atomics |
| 222 | fn enc_b o view ulong 16 w edit ulong 4 to ulong |
| 223 | op = get o 0 |
| 224 | imm = get o 6 |
| 225 | if or eq op 15 eq op 16 |
| 226 | p = ulong 0 |
| 227 | if eq op 16 |
| 228 | p = 262144 |
| 229 | end |
| 230 | put4 w wda o 29244 rb o 3 or or rb o 4 6144 p ctl o 1040896 |
| 231 | ret 0 |
| 232 | end |
| 233 | if eq op 17 |
| 234 | put4 w or wd o 30745 4278190080 imm or 71168 rb o 2 ctl o 2083328 |
| 235 | ret 0 |
| 236 | end |
| 237 | if eq op 18 |
| 238 | put4 w wda o 30738 imm 126796031 ctl o 2083328 |
| 239 | ret 0 |
| 240 | end |
| 241 | if eq op 19 |
| 242 | put4 w wda o 31105 rb o 5 203298048 ctl o 991744 |
| 243 | ret 0 |
| 244 | end |
| 245 | if eq op 20 |
| 246 | put4 w wda o 31105 rb o 5 203380992 ctl o 991744 |
| 247 | ret 0 |
| 248 | end |
| 249 | if eq op 21 |
| 250 | put4 w wda o 31105 rb o 5 203364608 ctl o 991744 |
| 251 | ret 0 |
| 252 | end |
| 253 | if eq op 22 |
| 254 | a = wa o 31110 |
| 255 | if ne get o 9 0 |
| 256 | a = or wa o 2438 shl pred o 12 |
| 257 | end |
| 258 | put4 w a rb o 3 or 202463488 rb o 5 ctl o 1040896 |
| 259 | ret 0 |
| 260 | end |
| 261 | if eq op 23 |
| 262 | put4 w 31122 0 45056 ctl o 1043456 |
| 263 | ret 0 |
| 264 | end |
| 265 | if eq op 24 |
| 266 | put4 w 31122 0 12288 ctl o 1043456 |
| 267 | ret 0 |
| 268 | end |
| 269 | if eq op 25 |
| 270 | put4 w 4278221199 0 33554432 ctl o 1042432 |
| 271 | ret 0 |
| 272 | end |
| 273 | if eq op 26 |
| 274 | put4 w wda o 31144 or rb o 3 2147483648 or 136270080 rb o 5 ctl o 3284480 |
| 275 | ret 0 |
| 276 | end |
| 277 | if eq op 27 |
| 278 | put4 w wda o 31144 or rb o 3 2147483648 or 203378944 rb o 5 ctl o 3284480 |
| 279 | ret 0 |
| 280 | end |
| 281 | if eq op 28 |
| 282 | put4 w wa o 29196 rb o 3 66084976 ctl o 2087424 |
| 283 | ret 0 |
| 284 | end |
| 285 | if eq op 29 |
| 286 | put4 w wda o 29202 rb o 3 126762239 ctl o 2083328 |
| 287 | ret 0 |
| 288 | end |
| 289 | ret 1 |
| 290 | end |
| 291 | |
| 292 | note ops 30..45: floating point, special functions, shuffles, shared memory, exit |
| 293 | fn enc_c o view ulong 16 w edit ulong 4 to ulong |
| 294 | op = get o 0 |
| 295 | imm = get o 6 |
| 296 | if eq op 30 |
| 297 | put4 w wda o 29217 rb o 3 0 ctl o 5227520 |
| 298 | ret 0 |
| 299 | end |
| 300 | if eq op 31 |
| 301 | put4 w wda o 29217 or rb o 3 2147483648 0 ctl o 5227520 |
| 302 | ret 0 |
| 303 | end |
| 304 | if eq op 32 |
| 305 | put4 w wda o 29216 rb o 3 4194304 ctl o 5227520 |
| 306 | ret 0 |
| 307 | end |
| 308 | if eq op 33 |
| 309 | put4 w wda o 29219 rb o 3 rb o 4 ctl o 5227520 |
| 310 | ret 0 |
| 311 | end |
| 312 | if eq op 34 |
| 313 | c = ulong 66084864 |
| 314 | if ne imm 0 |
| 315 | c = imm |
| 316 | end |
| 317 | a = or or 29195 shl and get o 1 7 16 shl rb o 2 24 |
| 318 | put4 w a rb o 3 c ctl o 5227520 |
| 319 | ret 0 |
| 320 | end |
| 321 | if eq op 35 |
| 322 | put4 w wda o 29192 rb o 3 and get o 4 7 ctl o 1034752 |
| 323 | ret 0 |
| 324 | end |
| 325 | if eq op 36 |
| 326 | put4 w wda o 29193 rb o 3 58720256 ctl o 5227520 |
| 327 | ret 0 |
| 328 | end |
| 329 | if eq op 37 |
| 330 | put4 w wda o 29193 rb o 3 125829120 ctl o 5227520 |
| 331 | ret 0 |
| 332 | end |
| 333 | if eq op 38 |
| 334 | put4 w wd o 29253 rb o 2 2102272 ctl o 5235200 |
| 335 | ret 0 |
| 336 | end |
| 337 | if eq op 39 |
| 338 | put4 w wd o 29445 rb o 2 2158848 ctl o 5120512 |
| 339 | ret 0 |
| 340 | end |
| 341 | if eq op 40 |
| 342 | put4 w wd o 29448 rb o 2 4096 ctl o 926720 |
| 343 | ret 0 |
| 344 | end |
| 345 | if eq op 41 |
| 346 | put4 w wd o 29448 rb o 2 5120 ctl o 926720 |
| 347 | ret 0 |
| 348 | end |
| 349 | if eq op 42 |
| 350 | put4 w wda o 32649 or 134225664 shl and imm 31 21 917504 ctl o 926720 |
| 351 | ret 0 |
| 352 | end |
| 353 | if eq op 43 |
| 354 | put4 w wda o 31108 0 and imm 65535 ctl o 1040896 |
| 355 | ret 0 |
| 356 | end |
| 357 | if eq op 44 |
| 358 | put4 w wa o 29576 rb o 3 and imm 65535 ctl o 1040896 |
| 359 | ret 0 |
| 360 | end |
| 361 | if eq op 45 |
| 362 | a = ulong 31053 |
| 363 | if ne get o 9 0 |
| 364 | a = 2381 |
| 365 | end |
| 366 | put4 w a 0 58720256 ctl o 1042944 |
| 367 | ret 0 |
| 368 | end |
| 369 | ret 1 |
| 370 | end |
| 371 | |
| 372 | note op 46: BRA. rel = imm - 1 as int32; low 6 bits at w0 18..23, rel arithmetic-shifted by 6 at w1 bit 2 |
| 373 | fn enc_bra o view ulong 16 w edit ulong 4 to ulong |
| 374 | imm = get o 6 |
| 375 | rel = and sub imm 1 4294967295 |
| 376 | s = shr rel 6 |
| 377 | c = ulong 58720256 |
| 378 | if ge rel 2147483648 |
| 379 | s = or s 4227858432 |
| 380 | c = 58982399 |
| 381 | end |
| 382 | d = get o 7 |
| 383 | if eq d 0 |
| 384 | d = 1042944 |
| 385 | if and eq imm 0 eq get o 9 0 |
| 386 | d = NOPC |
| 387 | end |
| 388 | end |
| 389 | a = or or 2375 shl pred o 12 shl and rel 63 18 |
| 390 | put4 w a and shl s 2 4294967295 c d |
| 391 | ret 0 |
| 392 | end |
| 393 | |
| 394 | note ops 46..59: branches, reconvergence, barriers, wide shared loads, three-source integer ops |
| 395 | fn enc_d o view ulong 16 w edit ulong 4 to ulong |
| 396 | op = get o 0 |
| 397 | imm = get o 6 |
| 398 | bar = get o 11 |
| 399 | if eq op 46 |
| 400 | ret enc_bra o w |
| 401 | end |
| 402 | if eq op 47 |
| 403 | put4 w wd o 29448 rb o 2 2048 ctl o 926720 |
| 404 | ret 0 |
| 405 | end |
| 406 | if eq op 48 |
| 407 | put4 w 31517 0 65536 ctl o 1043456 |
| 408 | ret 0 |
| 409 | end |
| 410 | if eq op 49 |
| 411 | put4 w wda o 31108 255 134219776 ctl o 927744 |
| 412 | ret 0 |
| 413 | end |
| 414 | if eq op 50 |
| 415 | put4 w wa o 31112 rb o 3 134220031 ctl o 1040896 |
| 416 | ret 0 |
| 417 | end |
| 418 | if eq op 51 |
| 419 | a = or or 29202 shl rb o 1 16 shl rz o 2 12 24 |
| 420 | put4 w a rz o 3 13 or or 126746624 shl and imm 255 8 rb o 4 ctl o 2083328 |
| 421 | ret 0 |
| 422 | end |
| 423 | if eq op 52 |
| 424 | a = or or 29209 shl rb o 1 16 shl rz o 2 12 24 |
| 425 | put4 w a rz o 3 13 or 1536 rb o 4 ctl o 2083328 |
| 426 | ret 0 |
| 427 | end |
| 428 | if eq op 53 |
| 429 | a = or or 29223 shl rb o 1 16 shl rz o 2 12 24 |
| 430 | put4 w a rz o 3 13 or 126746624 rb o 4 ctl o 2083328 |
| 431 | ret 0 |
| 432 | end |
| 433 | if eq op 54 |
| 434 | if or or lt imm 2 ge imm 2147483648 ge bar 16 |
| 435 | ret 1 |
| 436 | end |
| 437 | a = or or 2373 shl pred o 12 shl bar 16 |
| 438 | put4 w a and mul sub imm 1 16 4294967295 58720768 ctl o 1040896 |
| 439 | ret 0 |
| 440 | end |
| 441 | if eq op 55 |
| 442 | if ge bar 16 |
| 443 | ret 1 |
| 444 | end |
| 445 | a = or or 2369 shl pred o 12 shl bar 16 |
| 446 | put4 w a 0 58720768 ctl o 1042944 |
| 447 | ret 0 |
| 448 | end |
| 449 | if eq op 56 |
| 450 | if not off24 imm |
| 451 | ret 1 |
| 452 | end |
| 453 | put4 w wda o 31105 or rb o 5 shl and imm 16777215 8 203299584 ctl o 991744 |
| 454 | ret 0 |
| 455 | end |
| 456 | if eq op 57 |
| 457 | if not off24 imm |
| 458 | ret 1 |
| 459 | end |
| 460 | put4 w wda o 31105 or rb o 5 shl and imm 16777215 8 203300096 ctl o 991744 |
| 461 | ret 0 |
| 462 | end |
| 463 | if eq op 58 |
| 464 | if ge imm 8388608 |
| 465 | ret 1 |
| 466 | end |
| 467 | put4 w wda o 31108 shl and imm 16777215 8 3072 ctl o 1042432 |
| 468 | ret 0 |
| 469 | end |
| 470 | if eq op 59 |
| 471 | put4 w wd o 29448 rb o 2 3072 ctl o 926720 |
| 472 | ret 0 |
| 473 | end |
| 474 | ret 1 |
| 475 | end |
| 476 | |
| 477 | note ops 60..63 (Training R5): SHFL.BFLY (SHFL.DOWN's words with w1 bit 26), F2FP.BF16.F32.PACK_AB, |
| 478 | note ATOMG.E.ADD.F32.FTZ.RN.STRONG.SYS and .GPU (no dst vreg encodes RZ, presence slot 15). |
| 479 | note Constants by Wolfram: FromDigits of 0c001f00 7f89 000e0000 000e2400 723e 10ff 004fc400 79a3 80000000 |
| 480 | note 0c1f5300 0c1ef300 00321e00 base 16 = 201334528 32649 917504 926720 29246 4351 5227520 31139 2147483648 |
| 481 | note 203379456 203354880 3284480. |
| 482 | fn enc_e o view ulong 16 w edit ulong 4 to ulong |
| 483 | op = get o 0 |
| 484 | if eq op 60 |
| 485 | put4 w wda o 32649 or 201334528 shl and get o 6 31 21 917504 ctl o 926720 |
| 486 | ret 0 |
| 487 | end |
| 488 | if eq op 61 |
| 489 | put4 w wda o 29246 rb o 3 4351 ctl o 5227520 |
| 490 | ret 0 |
| 491 | end |
| 492 | if or eq op 62 eq op 63 |
| 493 | s = ulong 203379456 |
| 494 | if eq op 63 |
| 495 | s = 203354880 |
| 496 | end |
| 497 | a = or or 31139 shl rz o 1 15 16 shl rb o 2 24 |
| 498 | put4 w a or rb o 3 2147483648 or s rb o 5 ctl o 3284480 |
| 499 | ret 0 |
| 500 | end |
| 501 | ret 1 |
| 502 | end |
| 503 | |
| 504 | fn encraw o view ulong 16 w edit ulong 4 to ulong |
| 505 | op = get o 0 |
| 506 | if lt op 15 |
| 507 | ret enc_a o w |
| 508 | end |
| 509 | if lt op 30 |
| 510 | ret enc_b o w |
| 511 | end |
| 512 | if lt op 46 |
| 513 | ret enc_c o w |
| 514 | end |
| 515 | if lt op 60 |
| 516 | ret enc_d o w |
| 517 | end |
| 518 | ret enc_e o w |
| 519 | end |
| 520 | |
| 521 | note LDCU and LDCU.64: the guard bits name a uniform predicate, so a P0 guard is refused (DRA-599). |
| 522 | fn isuld op ulong to bool |
| 523 | ret or eq op 6 eq op 7 |
| 524 | end |
| 525 | |
| 526 | note After the op's own words, a predicated instruction gets pred o in w0 bits 12..15. |
| 527 | note Unpredicated words already carry 7 there, so they are left as the C oracle wrote them. |
| 528 | note 61440 is the guard mask 0xf000. |
| 529 | fn enc1 o view ulong 16 w edit ulong 4 to ulong |
| 530 | r = encraw o w |
| 531 | if or ne r 0 eq get o 9 0 |
| 532 | ret r |
| 533 | end |
| 534 | if isuld get o 0 |
| 535 | ret 1 |
| 536 | end |
| 537 | x = get w 0 |
| 538 | put w 0 or sub x and x 61440 shl pred o 12 |
| 539 | ret 0 |
| 540 | end |
| 541 | |
| 542 | note the 16 bytes of instruction i, each word little-endian |
| 543 | fn store code edit uchar 16384 i ulong w view ulong 4 to void |
| 544 | for k ulong 4 |
| 545 | x = get w k |
| 546 | q = add mul i 16 mul k 4 |
| 547 | for j ulong 4 |
| 548 | put code add q j uchar and shr x mul j 8 255 |
| 549 | end |
| 550 | end |
| 551 | end |
| 552 | |
| 553 | fn bw_enc_sm121 ins view ulong 8192 phys view ulong 288 n ulong pad ulong code edit uchar 16384 to ulong |
| 554 | o = new ulong 16 0 |
| 555 | w = new ulong 4 0 |
| 556 | if gt n 1024 |
| 557 | ret 0 |
| 558 | end |
| 559 | cnt = n |
| 560 | if ne pad 0 |
| 561 | cnt = mul div add n 7 8 8 |
| 562 | if lt cnt 32 |
| 563 | cnt = 32 |
| 564 | end |
| 565 | end |
| 566 | for i ulong cnt |
| 567 | if lt i n |
| 568 | opnds ins i phys edit o |
| 569 | if ne enc1 view o edit w 0 |
| 570 | ret 0 |
| 571 | end |
| 572 | else |
| 573 | put4 edit w NOPW 0 0 NOPC |
| 574 | end |
| 575 | store code i view w |
| 576 | end |
| 577 | ret mul cnt 16 |
| 578 | end |