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 / codegen / bw_hazard.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Static scoreboard hazard checker over encoded sm_121 bytes; successor of omega_bw_hazard.c at omega-mv 60b5d81e, |
| 3 | note except ATOMG with size field 2 or 3, whose Rd and Rb are two registers here (hz_atn) and one in that C |
| 4 | note (gpu/nvidia/checks/README.md, bwhz). |
| 5 | note hz_chk checks c[0..lc) (lc a nonzero multiple of 16, at most 32768: 2048 instructions) into the wire m. |
| 6 | note Decode record, 24 ulong: 0 op, 1 guard, 2 stall, 3 yield, 4 wbar, 5 rbar, 6 wait, 7 var, 8 late, |
| 7 | note 9 nr, 10 nw, 11..15 reads, 16 write, 17 flow (0 next, 1 exit, 2 bra), 18 target (long bits), 19 name id. |
| 8 | note Operand: reg | n << 8 | uniform << 16. Name id 0 is no name; 1..37 number the opcode name strings the C decode sets. |
| 9 | note Check wire m, ulong: 0 insns, 1 reachable, 2 count, 3 bad_pc (long bits); finding i < 256 at 8 + 3i: |
| 10 | note pc, src_pc, kind | reg << 8 | uniform << 16 | release << 24. State at 1024: w 512, r 512, |
| 11 | note hints 512 (wpc | rpc << 32): 1 + the smallest pc of a producer (wpc) or queued late reader (rpc) merged into |
| 12 | note the entry since it was last empty, 0 when it is empty; the join keeps the smaller, so src_pc does not depend |
| 13 | note on the order the walk visits successors. Records at 2560, then seen n, queued n, work n, IN states n x 1536. |
| 14 | note m is ulong 3203584 = 2560 + 1563 * 2048; the unit zeroes the used part. A walk longer than 999999 pops traps 4. |
| 15 | note Barrier 6 does not exist on sm_121 (0..5, 7 = none): hz_dec1 refuses it in either field, as the C does, so |
| 16 | note every shift amount below is at most 63. |
| 17 | note Portable two's-complement reinterpretation; the bridge lowers no integer-to-integer bitcast. |
| 18 | fn hz_u2l x ulong to long |
| 19 | if lt x ulong 9223372036854775808 |
| 20 | ret long x |
| 21 | end |
| 22 | ret sub long -1 long xor x ulong 18446744073709551615 |
| 23 | end |
| 24 | fn hz_l2u v long to ulong |
| 25 | if ge v long 0 |
| 26 | ret ulong v |
| 27 | end |
| 28 | ret xor ulong sub long -1 v ulong 18446744073709551615 |
| 29 | end |
| 30 | fn hz_u2i x ulong to long |
| 31 | if lt x ulong 2147483648 |
| 32 | ret long x |
| 33 | end |
| 34 | ret sub long x 4294967296 |
| 35 | end |
| 36 | fn hz_rd32 c view uchar 16 o ulong to ulong |
| 37 | a = ulong get c o |
| 38 | a = or a shl ulong get c add o 1 8 |
| 39 | a = or a shl ulong get c add o 2 16 |
| 40 | ret or a shl ulong get c add o 3 24 |
| 41 | end |
| 42 | fn hz_size w2 ulong to long |
| 43 | s = and shr w2 9 7 |
| 44 | if le s 4 |
| 45 | ret long 1 |
| 46 | end |
| 47 | if eq s 5 |
| 48 | ret long 2 |
| 49 | end |
| 50 | if eq s 6 |
| 51 | ret long 4 |
| 52 | end |
| 53 | ret long -1 |
| 54 | end |
| 55 | fn hz_r d edit ulong 24 o ulong reg ulong n long u ulong to void |
| 56 | if eq reg 255 |
| 57 | ret |
| 58 | end |
| 59 | if le n 0 |
| 60 | ret |
| 61 | end |
| 62 | k = get d add o 9 |
| 63 | if ge k 5 |
| 64 | ret |
| 65 | end |
| 66 | put d add add o 11 k or or reg shl ulong n 8 shl u 16 |
| 67 | put d add o 9 add k 1 |
| 68 | end |
| 69 | fn hz_w d edit ulong 24 o ulong reg ulong n long u ulong to void |
| 70 | if eq reg 255 |
| 71 | ret |
| 72 | end |
| 73 | if le n 0 |
| 74 | ret |
| 75 | end |
| 76 | if ge get d add o 10 1 |
| 77 | ret |
| 78 | end |
| 79 | put d add o 16 or or reg shl ulong n 8 shl u 16 |
| 80 | put d add o 10 1 |
| 81 | end |
| 82 | fn hz_nm d edit ulong 24 o ulong id ulong var ulong late ulong to void |
| 83 | put d add o 19 id |
| 84 | put d add o 7 var |
| 85 | put d add o 8 late |
| 86 | end |
| 87 | fn hz_atn w2 ulong to long |
| 88 | if or eq and shr w2 9 7 2 eq and shr w2 9 7 3 |
| 89 | ret 2 |
| 90 | end |
| 91 | ret 1 |
| 92 | end |
| 93 | fn hz_mem c view uchar 16 d edit ulong 24 o ulong op ulong to bool |
| 94 | w0 = hz_rd32 c 0 |
| 95 | w2 = hz_rd32 c 8 |
| 96 | rd = and shr w0 16 255 |
| 97 | ra = shr w0 24 |
| 98 | rb = and hz_rd32 c 4 255 |
| 99 | rc = and w2 255 |
| 100 | an = long 1 |
| 101 | if ne and w2 256 0 |
| 102 | an = long 2 |
| 103 | end |
| 104 | de = ne and w2 134217728 0 |
| 105 | if eq op 2433 |
| 106 | hz_nm d o 33 0 0 |
| 107 | n = hz_size w2 |
| 108 | if lt n 0 |
| 109 | ret false |
| 110 | end |
| 111 | hz_w d o rd n 0 |
| 112 | hz_r d o ra an 0 |
| 113 | if de |
| 114 | hz_r d o rb 1 1 |
| 115 | end |
| 116 | hz_nm d o 33 1 1 |
| 117 | ret true |
| 118 | end |
| 119 | if eq op 2438 |
| 120 | hz_nm d o 34 0 0 |
| 121 | n = hz_size w2 |
| 122 | if lt n 0 |
| 123 | ret false |
| 124 | end |
| 125 | hz_r d o ra an 0 |
| 126 | hz_r d o rb n 0 |
| 127 | if de |
| 128 | hz_r d o rc 1 1 |
| 129 | end |
| 130 | hz_nm d o 34 0 1 |
| 131 | ret true |
| 132 | end |
| 133 | if eq op 2472 |
| 134 | hz_w d o rd hz_atn w2 0 |
| 135 | hz_r d o ra an 0 |
| 136 | hz_r d o rb hz_atn w2 0 |
| 137 | if de |
| 138 | hz_r d o rc 1 1 |
| 139 | end |
| 140 | hz_nm d o 35 1 1 |
| 141 | ret true |
| 142 | end |
| 143 | ret hz_mem2 c d o op |
| 144 | end |
| 145 | fn hz_mem2 c view uchar 16 d edit ulong 24 o ulong op ulong to bool |
| 146 | w0 = hz_rd32 c 0 |
| 147 | w2 = hz_rd32 c 8 |
| 148 | rd = and shr w0 16 255 |
| 149 | ra = shr w0 24 |
| 150 | rb = and hz_rd32 c 4 255 |
| 151 | rc = and w2 255 |
| 152 | de = ne and w2 134217728 0 |
| 153 | if eq op 2436 |
| 154 | hz_nm d o 36 0 0 |
| 155 | n = hz_size w2 |
| 156 | if lt n 0 |
| 157 | ret false |
| 158 | end |
| 159 | hz_w d o rd n 0 |
| 160 | hz_r d o ra 1 0 |
| 161 | if de |
| 162 | hz_r d o rb 1 1 |
| 163 | end |
| 164 | hz_nm d o 36 1 1 |
| 165 | ret true |
| 166 | end |
| 167 | if or eq op 904 eq op 2440 |
| 168 | hz_nm d o 37 0 0 |
| 169 | n = hz_size w2 |
| 170 | if lt n 0 |
| 171 | ret false |
| 172 | end |
| 173 | hz_r d o ra 1 0 |
| 174 | hz_r d o rb n 0 |
| 175 | if de |
| 176 | hz_r d o rc 1 1 |
| 177 | end |
| 178 | hz_nm d o 37 0 1 |
| 179 | ret true |
| 180 | end |
| 181 | if eq op 2946 |
| 182 | hz_nm d o 11 0 0 |
| 183 | n = hz_size w2 |
| 184 | if lt n 0 |
| 185 | ret false |
| 186 | end |
| 187 | hz_w d o rd n 0 |
| 188 | hz_r d o ra 1 0 |
| 189 | hz_nm d o 11 1 1 |
| 190 | ret true |
| 191 | end |
| 192 | if eq op 1964 |
| 193 | hz_nm d o 12 0 0 |
| 194 | n = hz_size w2 |
| 195 | if lt n 0 |
| 196 | ret false |
| 197 | end |
| 198 | hz_w d o rd n 1 |
| 199 | hz_r d o ra 1 1 |
| 200 | hz_nm d o 12 1 1 |
| 201 | ret true |
| 202 | end |
| 203 | ret false |
| 204 | end |
| 205 | fn hz_wab c view uchar 16 d edit ulong 24 o ulong id ulong to void |
| 206 | w0 = hz_rd32 c 0 |
| 207 | hz_w d o and shr w0 16 255 1 0 |
| 208 | hz_r d o shr w0 24 1 0 |
| 209 | hz_r d o and hz_rd32 c 4 255 1 0 |
| 210 | hz_r d o and hz_rd32 c 8 255 1 0 |
| 211 | hz_nm d o id 0 0 |
| 212 | end |
| 213 | fn hz_ab c view uchar 16 d edit ulong 24 o ulong id ulong to void |
| 214 | w0 = hz_rd32 c 0 |
| 215 | hz_w d o and shr w0 16 255 1 0 |
| 216 | hz_r d o shr w0 24 1 0 |
| 217 | hz_r d o and hz_rd32 c 4 255 1 0 |
| 218 | hz_nm d o id 0 0 |
| 219 | end |
| 220 | fn hz_ac c view uchar 16 d edit ulong 24 o ulong id ulong to void |
| 221 | w0 = hz_rd32 c 0 |
| 222 | hz_w d o and shr w0 16 255 1 0 |
| 223 | hz_r d o shr w0 24 1 0 |
| 224 | hz_r d o and hz_rd32 c 8 255 1 0 |
| 225 | hz_nm d o id 0 0 |
| 226 | end |
| 227 | fn hz_mma c view uchar 16 d edit ulong 24 o ulong id ulong to void |
| 228 | w0 = hz_rd32 c 0 |
| 229 | hz_w d o and shr w0 16 255 4 0 |
| 230 | hz_r d o shr w0 24 4 0 |
| 231 | hz_r d o and hz_rd32 c 4 255 2 0 |
| 232 | hz_r d o and hz_rd32 c 8 255 4 0 |
| 233 | hz_nm d o id 0 0 |
| 234 | end |
| 235 | fn hz_bra d edit ulong 24 o ulong w0 ulong w1 ulong to void |
| 236 | s = shr w1 2 |
| 237 | if ne and w1 2147483648 0 |
| 238 | s = or s 3221225472 |
| 239 | end |
| 240 | u = and shl s 6 4294967295 |
| 241 | u = or u and shr w0 18 63 |
| 242 | t = add hz_u2i u 1 |
| 243 | if gt t 2147483647 |
| 244 | t = sub t 4294967296 |
| 245 | end |
| 246 | put d add o 17 2 |
| 247 | put d add o 18 hz_l2u t |
| 248 | hz_nm d o 6 0 0 |
| 249 | end |
| 250 | fn hz_alu c view uchar 16 d edit ulong 24 o ulong op ulong to bool |
| 251 | w0 = hz_rd32 c 0 |
| 252 | w1 = hz_rd32 c 4 |
| 253 | w2 = hz_rd32 c 8 |
| 254 | rd = and shr w0 16 255 |
| 255 | ra = shr w0 24 |
| 256 | rb = and w1 255 |
| 257 | if eq op 2328 |
| 258 | hz_nm d o 1 0 0 |
| 259 | ret true |
| 260 | end |
| 261 | if eq op 2845 |
| 262 | hz_nm d o 2 0 0 |
| 263 | ret true |
| 264 | end |
| 265 | if eq op 2450 |
| 266 | hz_nm d o 3 0 0 |
| 267 | ret true |
| 268 | end |
| 269 | if eq op 2447 |
| 270 | hz_r d o ra 1 0 |
| 271 | hz_nm d o 4 0 1 |
| 272 | ret true |
| 273 | end |
| 274 | if eq op 2381 |
| 275 | put d add o 17 1 |
| 276 | hz_nm d o 5 0 0 |
| 277 | ret true |
| 278 | end |
| 279 | if eq op 2375 |
| 280 | hz_bra d o w0 w1 |
| 281 | ret true |
| 282 | end |
| 283 | if eq op 2373 |
| 284 | hz_nm d o 7 0 0 |
| 285 | ret true |
| 286 | end |
| 287 | if eq op 2369 |
| 288 | hz_nm d o 8 0 0 |
| 289 | ret true |
| 290 | end |
| 291 | if eq op 514 |
| 292 | hz_w d o rd 1 0 |
| 293 | hz_r d o rb 1 0 |
| 294 | hz_nm d o 9 0 0 |
| 295 | ret true |
| 296 | end |
| 297 | if eq op 2050 |
| 298 | hz_w d o rd 1 0 |
| 299 | hz_nm d o 9 0 0 |
| 300 | ret true |
| 301 | end |
| 302 | if eq op 2329 |
| 303 | hz_w d o rd 1 0 |
| 304 | hz_nm d o 10 1 0 |
| 305 | ret true |
| 306 | end |
| 307 | if or eq op 548 eq op 528 |
| 308 | if eq op 548 |
| 309 | hz_wab c d o 13 |
| 310 | else |
| 311 | hz_wab c d o 17 |
| 312 | end |
| 313 | ret true |
| 314 | end |
| 315 | if eq op 2084 |
| 316 | hz_ac c d o 13 |
| 317 | ret true |
| 318 | end |
| 319 | if eq op 3108 |
| 320 | hz_w d o rd 1 0 |
| 321 | hz_r d o ra 1 0 |
| 322 | hz_r d o rb 1 1 |
| 323 | hz_r d o and w2 255 1 0 |
| 324 | hz_nm d o 13 0 0 |
| 325 | ret true |
| 326 | end |
| 327 | if eq op 2085 |
| 328 | hz_w d o rd 2 0 |
| 329 | hz_r d o ra 1 0 |
| 330 | hz_r d o and w2 255 2 0 |
| 331 | hz_nm d o 14 0 0 |
| 332 | ret true |
| 333 | end |
| 334 | if eq op 551 |
| 335 | hz_wab c d o 15 |
| 336 | ret true |
| 337 | end |
| 338 | if eq op 524 |
| 339 | hz_r d o ra 1 0 |
| 340 | hz_r d o rb 1 0 |
| 341 | hz_nm d o 16 0 0 |
| 342 | ret true |
| 343 | end |
| 344 | if eq op 2060 |
| 345 | hz_r d o ra 1 0 |
| 346 | hz_nm d o 16 0 0 |
| 347 | ret true |
| 348 | end |
| 349 | if eq op 3084 |
| 350 | hz_r d o ra 1 0 |
| 351 | hz_r d o rb 1 1 |
| 352 | hz_nm d o 16 0 0 |
| 353 | ret true |
| 354 | end |
| 355 | if eq op 572 |
| 356 | hz_mma c d o 18 |
| 357 | ret true |
| 358 | end |
| 359 | if eq op 634 |
| 360 | hz_mma c d o 19 |
| 361 | ret true |
| 362 | end |
| 363 | if eq op 2073 |
| 364 | hz_ac c d o 20 |
| 365 | ret true |
| 366 | end |
| 367 | if eq op 537 |
| 368 | hz_wab c d o 20 |
| 369 | ret true |
| 370 | end |
| 371 | if eq op 2066 |
| 372 | hz_ac c d o 21 |
| 373 | ret true |
| 374 | end |
| 375 | if eq op 530 |
| 376 | hz_wab c d o 21 |
| 377 | ret true |
| 378 | end |
| 379 | ret hz_flt c d o op |
| 380 | end |
| 381 | fn hz_flt c view uchar 16 d edit ulong 24 o ulong op ulong to bool |
| 382 | w0 = hz_rd32 c 0 |
| 383 | w1 = hz_rd32 c 4 |
| 384 | w2 = hz_rd32 c 8 |
| 385 | rd = and shr w0 16 255 |
| 386 | ra = shr w0 24 |
| 387 | rb = and w1 255 |
| 388 | if eq op 545 |
| 389 | hz_ab c d o 22 |
| 390 | ret true |
| 391 | end |
| 392 | if eq op 544 |
| 393 | hz_ab c d o 23 |
| 394 | ret true |
| 395 | end |
| 396 | if eq op 547 |
| 397 | hz_wab c d o 24 |
| 398 | ret true |
| 399 | end |
| 400 | if eq op 523 |
| 401 | hz_r d o ra 1 0 |
| 402 | hz_r d o rb 1 0 |
| 403 | hz_nm d o 25 0 0 |
| 404 | ret true |
| 405 | end |
| 406 | if eq op 520 |
| 407 | hz_ab c d o 26 |
| 408 | ret true |
| 409 | end |
| 410 | if eq op 521 |
| 411 | hz_ab c d o 27 |
| 412 | ret true |
| 413 | end |
| 414 | if eq op 574 |
| 415 | hz_ab c d o 28 |
| 416 | ret true |
| 417 | end |
| 418 | if eq op 581 |
| 419 | hz_w d o rd 1 0 |
| 420 | hz_r d o rb 1 0 |
| 421 | hz_nm d o 29 0 0 |
| 422 | ret true |
| 423 | end |
| 424 | if or eq op 773 eq op 776 |
| 425 | hz_w d o rd 1 0 |
| 426 | hz_r d o rb 1 0 |
| 427 | if eq op 773 |
| 428 | hz_nm d o 30 1 0 |
| 429 | else |
| 430 | hz_nm d o 31 1 0 |
| 431 | end |
| 432 | ret true |
| 433 | end |
| 434 | if eq op 3977 |
| 435 | hz_w d o rd 1 0 |
| 436 | hz_r d o ra 1 0 |
| 437 | hz_nm d o 32 1 0 |
| 438 | ret true |
| 439 | end |
| 440 | ret false |
| 441 | end |
| 442 | fn hz_dec1 c view uchar 16 d edit ulong 24 to long |
| 443 | o = ulong 0 |
| 444 | for i ulong 24 |
| 445 | put d add o i 0 |
| 446 | end |
| 447 | w0 = hz_rd32 c 0 |
| 448 | w3 = hz_rd32 c 12 |
| 449 | op = and w0 4095 |
| 450 | put d o op |
| 451 | put d add o 1 and shr w0 12 15 |
| 452 | put d add o 2 and shr w3 9 15 |
| 453 | put d add o 3 and shr w3 13 1 |
| 454 | put d add o 4 and shr w3 14 7 |
| 455 | put d add o 5 and shr w3 17 7 |
| 456 | if or eq get d add o 4 6 eq get d add o 5 6 |
| 457 | ret long -1 |
| 458 | end |
| 459 | put d add o 6 and shr w3 20 63 |
| 460 | if hz_alu c d o op |
| 461 | ret long 0 |
| 462 | end |
| 463 | if hz_mem c d o op |
| 464 | ret long 0 |
| 465 | end |
| 466 | ret long -1 |
| 467 | end |
| 468 | fn hz_kill wt ulong to ulong |
| 469 | k = ulong 0 |
| 470 | for m ulong 64 |
| 471 | if and gt m 0 ne and m wt 0 |
| 472 | k = or k shl ulong 1 m |
| 473 | end |
| 474 | end |
| 475 | ret k |
| 476 | end |
| 477 | fn hz_note m edit ulong 3203584 pc ulong p ulong kix ulong pend ulong to void |
| 478 | src = sub and get m p 4294967295 1 |
| 479 | if eq and kix 255 2 |
| 480 | src = sub shr get m p 32 1 |
| 481 | end |
| 482 | key = hz_key kix |
| 483 | if hz_dup m pc key |
| 484 | ret |
| 485 | end |
| 486 | cnt = get m 2 |
| 487 | if lt cnt 256 |
| 488 | f = add 8 mul cnt 3 |
| 489 | put m f pc |
| 490 | put m add f 1 src |
| 491 | put m add f 2 or key shl hz_low pend 24 |
| 492 | end |
| 493 | put m 2 add cnt 1 |
| 494 | end |
| 495 | fn hz_dup m edit ulong 3203584 pc ulong key ulong to bool |
| 496 | lim = get m 2 |
| 497 | if gt lim 256 |
| 498 | lim = 256 |
| 499 | end |
| 500 | for i ulong lim |
| 501 | f = add 8 mul i 3 |
| 502 | if eq get m f pc |
| 503 | if eq and get m add f 2 16777215 key |
| 504 | ret true |
| 505 | end |
| 506 | end |
| 507 | end |
| 508 | ret false |
| 509 | end |
| 510 | fn hz_low p ulong to ulong |
| 511 | for b ulong 64 |
| 512 | if ne and shr p b 1 0 |
| 513 | ret b |
| 514 | end |
| 515 | end |
| 516 | ret 0 |
| 517 | end |
| 518 | fn hz_key kix ulong to ulong |
| 519 | ix = shr kix 8 |
| 520 | uni = ulong 0 |
| 521 | if ge ix 256 |
| 522 | uni = 1 |
| 523 | end |
| 524 | ret or or and kix 255 shl and ix 255 8 shl uni 16 |
| 525 | end |
| 526 | fn hz_ix op ulong q ulong to ulong |
| 527 | reg = and op 255 |
| 528 | u = and shr op 16 1 |
| 529 | ret add mul u 256 and add reg q 255 |
| 530 | end |
| 531 | fn hz_raw m edit ulong 3203584 op ulong sb ulong pc ulong rep bool to void |
| 532 | for q ulong and shr op 8 255 |
| 533 | i = hz_ix op q |
| 534 | if ne and i 255 255 |
| 535 | hz_raw1 m add sb i i pc rep |
| 536 | end |
| 537 | end |
| 538 | end |
| 539 | fn hz_raw1 m edit ulong 3203584 x ulong i ulong pc ulong rep bool to void |
| 540 | w = get m x |
| 541 | if ne w 0 |
| 542 | if rep |
| 543 | hz_note m pc add x 1024 or 1 shl i 8 w |
| 544 | end |
| 545 | put m x 0 |
| 546 | put m add x 1024 and get m add x 1024 18446744069414584320 |
| 547 | end |
| 548 | end |
| 549 | fn hz_wfl m edit ulong 3203584 dr ulong rep bool to ulong |
| 550 | wb = get m add dr 4 |
| 551 | fl = ulong 0 |
| 552 | if rep |
| 553 | fl = 1 |
| 554 | end |
| 555 | if or ne wb 7 ne get m add dr 7 0 |
| 556 | fl = or fl 2 |
| 557 | end |
| 558 | if ne wb 7 |
| 559 | fl = or fl shl shl ulong 1 wb 8 |
| 560 | end |
| 561 | ret fl |
| 562 | end |
| 563 | fn hz_wop m edit ulong 3203584 dr ulong sb ulong pc ulong rep bool to void |
| 564 | fl = hz_wfl m dr rep |
| 565 | op = get m add dr 16 |
| 566 | for q ulong and shr op 8 255 |
| 567 | i = hz_ix op q |
| 568 | if ne and i 255 255 |
| 569 | hz_wop1 m add sb i i pc fl |
| 570 | end |
| 571 | end |
| 572 | end |
| 573 | fn hz_wop1 m edit ulong 3203584 x ulong i ulong pc ulong fl ulong to void |
| 574 | p = add x 1024 |
| 575 | r = get m add x 512 |
| 576 | if ne r 0 |
| 577 | if ne and fl 1 0 |
| 578 | hz_note m pc p or 2 shl i 8 r |
| 579 | end |
| 580 | put m add x 512 0 |
| 581 | put m p and get m p 4294967295 |
| 582 | end |
| 583 | w = get m x |
| 584 | if ne w 0 |
| 585 | if ne and fl 1 0 |
| 586 | hz_note m pc p or 3 shl i 8 w |
| 587 | end |
| 588 | put m x 0 |
| 589 | put m p and get m p 18446744069414584320 |
| 590 | end |
| 591 | if ne and fl 2 0 |
| 592 | put m x or get m x shl ulong 1 shr fl 8 |
| 593 | put m p or and get m p 18446744069414584320 add pc 1 |
| 594 | end |
| 595 | end |
| 596 | fn hz_late m edit ulong 3203584 op ulong sb ulong pc ulong bit ulong to void |
| 597 | for q ulong and shr op 8 255 |
| 598 | i = hz_ix op q |
| 599 | if ne and i 255 255 |
| 600 | hz_late1 m add sb i pc bit |
| 601 | end |
| 602 | end |
| 603 | end |
| 604 | fn hz_late1 m edit ulong 3203584 x ulong pc ulong bit ulong to void |
| 605 | y = add x 512 |
| 606 | r = get m y |
| 607 | put m y or r bit |
| 608 | p = add x 1024 |
| 609 | h = get m p |
| 610 | t = hz_ltag r shr h 32 pc |
| 611 | put m p or and h 4294967295 shl t 32 |
| 612 | end |
| 613 | note The pc tag rules of the C (step and join), each on plain numbers so gpu/nvidia/checks/bwhz can run them. |
| 614 | fn hz_pmin a ulong b ulong to ulong |
| 615 | if eq a 0 |
| 616 | ret b |
| 617 | end |
| 618 | if eq b 0 |
| 619 | ret a |
| 620 | end |
| 621 | if lt a b |
| 622 | ret a |
| 623 | end |
| 624 | ret b |
| 625 | end |
| 626 | note late reader at pc queued on an entry with mask r and tag rt: pmin(rt, pc + 1) if r, else pc + 1 |
| 627 | fn hz_ltag r ulong rt ulong pc ulong to ulong |
| 628 | t = add pc 1 |
| 629 | if ne r 0 |
| 630 | t = hz_pmin rt t |
| 631 | end |
| 632 | ret t |
| 633 | end |
| 634 | note join of a source entry with mask sv and tag st into tag dt: pmin(dt, st) if sv, else dt |
| 635 | fn hz_jtag dt ulong sv ulong st ulong to ulong |
| 636 | if ne sv 0 |
| 637 | ret hz_pmin dt st |
| 638 | end |
| 639 | ret dt |
| 640 | end |
| 641 | note an entry whose mask v a wait left empty drops its tag t |
| 642 | fn hz_wtag v ulong t ulong to ulong |
| 643 | if eq v 0 |
| 644 | ret 0 |
| 645 | end |
| 646 | ret t |
| 647 | end |
| 648 | fn hz_lbit m edit ulong 3203584 dr ulong to ulong |
| 649 | rb = get m add dr 5 |
| 650 | wb = get m add dr 4 |
| 651 | lt8 = get m add dr 8 |
| 652 | if and eq lt8 0 eq rb 7 |
| 653 | ret 0 |
| 654 | end |
| 655 | mm = ulong 0 |
| 656 | if ne rb 7 |
| 657 | mm = shl ulong 1 rb |
| 658 | end |
| 659 | if ne wb 7 |
| 660 | mm = or mm shl ulong 1 wb |
| 661 | end |
| 662 | ret shl ulong 1 mm |
| 663 | end |
| 664 | fn hz_wait m edit ulong 3203584 dr ulong sb ulong to void |
| 665 | wt = get m add dr 6 |
| 666 | if ne wt 0 |
| 667 | k = xor hz_kill wt 18446744073709551615 |
| 668 | for i ulong 512 |
| 669 | x = add sb i |
| 670 | w = and get m x k |
| 671 | put m x w |
| 672 | r = and get m add x 512 k |
| 673 | put m add x 512 r |
| 674 | p = add x 1024 |
| 675 | h = get m p |
| 676 | wt = hz_wtag w and h 4294967295 |
| 677 | rt = hz_wtag r shr h 32 |
| 678 | put m p or wt shl rt 32 |
| 679 | end |
| 680 | end |
| 681 | end |
| 682 | fn hz_step m edit ulong 3203584 dr ulong sb ulong pc ulong rep bool to void |
| 683 | hz_wait m dr sb |
| 684 | nr = get m add dr 9 |
| 685 | for j ulong nr |
| 686 | op = get m add add dr 11 j |
| 687 | hz_raw m op sb pc rep |
| 688 | end |
| 689 | nw = get m add dr 10 |
| 690 | if ne nw 0 |
| 691 | hz_wop m dr sb pc rep |
| 692 | end |
| 693 | bit = hz_lbit m dr |
| 694 | if ne bit 0 |
| 695 | for j ulong nr |
| 696 | op = get m add add dr 11 j |
| 697 | hz_late m op sb pc bit |
| 698 | end |
| 699 | end |
| 700 | end |
| 701 | fn hz_join m edit ulong 3203584 dst ulong src ulong to bool |
| 702 | ch = false |
| 703 | for i ulong 512 |
| 704 | a = hz_j1 m add dst i add src i 0 |
| 705 | b = hz_j1 m add dst i add src i 1 |
| 706 | if or a b |
| 707 | ch = true |
| 708 | end |
| 709 | end |
| 710 | ret ch |
| 711 | end |
| 712 | fn hz_j1 m edit ulong 3203584 d ulong s ulong sel ulong to bool |
| 713 | o = mul sel 512 |
| 714 | sh = mul sel 32 |
| 715 | x = get m add d o |
| 716 | sv = get m add s o |
| 717 | y = or x sv |
| 718 | h = get m add d 1024 |
| 719 | dt = and shr h sh 4294967295 |
| 720 | st = get m add s 1024 |
| 721 | st = and shr st sh 4294967295 |
| 722 | t = hz_jtag dt sv st |
| 723 | if and eq x y eq t dt |
| 724 | ret false |
| 725 | end |
| 726 | put m add d o y |
| 727 | k = shl ulong 4294967295 sh |
| 728 | k = xor k 18446744073709551615 |
| 729 | h = and h k |
| 730 | h = or h shl t sh |
| 731 | put m add d 1024 h |
| 732 | ret true |
| 733 | end |
| 734 | fn hz_copy m edit ulong 3203584 dst ulong src ulong to void |
| 735 | for i ulong 1536 |
| 736 | v = get m add src i |
| 737 | put m add dst i v |
| 738 | end |
| 739 | end |
| 740 | fn hz_zero m edit ulong 3203584 n ulong to void |
| 741 | for b ulong add div n 65536 1 |
| 742 | for i ulong 65536 |
| 743 | x = add mul b 65536 i |
| 744 | if ge x n |
| 745 | ret |
| 746 | end |
| 747 | put m x 0 |
| 748 | end |
| 749 | end |
| 750 | end |
| 751 | fn hz_se n ulong to ulong |
| 752 | ret add 2560 mul n 24 |
| 753 | end |
| 754 | fn hz_in n ulong to ulong |
| 755 | ret add hz_se n mul n 3 |
| 756 | end |
| 757 | fn hz_push m edit ulong 3203584 n ulong s long top ulong to long |
| 758 | if or lt s 0 ge s long n |
| 759 | ret long -1 |
| 760 | end |
| 761 | t = ulong s |
| 762 | qu = add hz_se n n |
| 763 | if eq get m add qu t 0 |
| 764 | put m add qu t 1 |
| 765 | put m add add qu n top t |
| 766 | ret long add top 1 |
| 767 | end |
| 768 | ret long top |
| 769 | end |
| 770 | fn hz_dpc c view uchar 32768 m edit ulong 3203584 pc ulong to long |
| 771 | ins = new uchar 16 0 |
| 772 | rec = new ulong 24 0 |
| 773 | for i ulong 16 |
| 774 | put ins i get c add mul pc 16 i |
| 775 | end |
| 776 | r = hz_dec1 ins rec |
| 777 | dr = add 2560 mul pc 24 |
| 778 | for i ulong 24 |
| 779 | put m add dr i get rec i |
| 780 | end |
| 781 | ret r |
| 782 | end |
| 783 | fn hz_reach c view uchar 32768 m edit ulong 3203584 n ulong to long |
| 784 | qu = add hz_se n n |
| 785 | wk = add qu n |
| 786 | put m wk 0 |
| 787 | put m qu 1 |
| 788 | top = ulong 1 |
| 789 | while gt top 0 bound 999999 |
| 790 | top = sub top 1 |
| 791 | pc = get m add wk top |
| 792 | if ne hz_dpc c m pc 0 |
| 793 | put m 3 pc |
| 794 | ret long -1 |
| 795 | end |
| 796 | put m add hz_se n pc 1 |
| 797 | t = hz_rsuc m n pc top |
| 798 | if lt t 0 |
| 799 | put m 3 pc |
| 800 | ret long -1 |
| 801 | end |
| 802 | top = ulong t |
| 803 | end |
| 804 | ret long 0 |
| 805 | end |
| 806 | fn hz_rsuc m edit ulong 3203584 n ulong pc ulong top ulong to long |
| 807 | dr = add 2560 mul pc 24 |
| 808 | fl = get m add dr 17 |
| 809 | gd = get m add dr 1 |
| 810 | t = long top |
| 811 | if or eq fl 0 ne gd 7 |
| 812 | t = hz_push m n add long pc 1 top |
| 813 | if lt t 0 |
| 814 | ret t |
| 815 | end |
| 816 | end |
| 817 | if eq fl 2 |
| 818 | tg = hz_u2l get m add dr 18 |
| 819 | t = hz_push m n add long pc tg ulong t |
| 820 | end |
| 821 | ret t |
| 822 | end |
| 823 | fn hz_tgt m edit ulong 3203584 pc ulong to ulong |
| 824 | tg = hz_u2l get m add add 2560 mul pc 24 18 |
| 825 | ret ulong add long pc tg |
| 826 | end |
| 827 | fn hz_edge m edit ulong 3203584 n ulong t ulong top ulong to ulong |
| 828 | se = hz_se n |
| 829 | qu = add se n |
| 830 | ch = hz_join m add hz_in n mul t 1536 1024 |
| 831 | sv = get m add se t |
| 832 | qv = get m add qu t |
| 833 | if and or ch eq sv 1 eq qv 0 |
| 834 | put m add qu t 1 |
| 835 | put m add add qu n top t |
| 836 | ret add top 1 |
| 837 | end |
| 838 | ret top |
| 839 | end |
| 840 | fn hz_fix m edit ulong 3203584 n ulong to void |
| 841 | se = hz_se n |
| 842 | qu = add se n |
| 843 | wk = add qu n |
| 844 | put m wk 0 |
| 845 | put m qu 1 |
| 846 | top = ulong 1 |
| 847 | while gt top 0 bound 999999 |
| 848 | top = sub top 1 |
| 849 | pc = get m add wk top |
| 850 | put m add qu pc 0 |
| 851 | put m add se pc 2 |
| 852 | hz_copy m 1024 add hz_in n mul pc 1536 |
| 853 | dr = add 2560 mul pc 24 |
| 854 | hz_step m dr 1024 pc false |
| 855 | fl = get m add dr 17 |
| 856 | gd = get m add dr 1 |
| 857 | if or eq fl 0 ne gd 7 |
| 858 | top = hz_edge m n add pc 1 top |
| 859 | end |
| 860 | if eq fl 2 |
| 861 | top = hz_edge m n hz_tgt m pc top |
| 862 | end |
| 863 | end |
| 864 | end |
| 865 | fn hz_chk c view uchar 32768 lc ulong m edit ulong 3203584 to long |
| 866 | put m 3 18446744073709551615 |
| 867 | if or or eq lc 0 gt lc 32768 ne rem lc 16 0 |
| 868 | ret long -1 |
| 869 | end |
| 870 | n = div lc 16 |
| 871 | need = add hz_in n mul n 1536 |
| 872 | hz_zero m need |
| 873 | put m 3 18446744073709551615 |
| 874 | put m 0 n |
| 875 | if ne hz_reach c m n 0 |
| 876 | ret long -1 |
| 877 | end |
| 878 | se = hz_se n |
| 879 | s = ulong 0 |
| 880 | for i ulong n |
| 881 | if ne get m add se i 0 |
| 882 | s = add s 1 |
| 883 | end |
| 884 | put m add add se n i 0 |
| 885 | end |
| 886 | put m 1 s |
| 887 | hz_fix m n |
| 888 | for pc ulong n |
| 889 | if ne get m add se pc 0 |
| 890 | hz_copy m 1024 add hz_in n mul pc 1536 |
| 891 | hz_step m add 2560 mul pc 24 1024 pc true |
| 892 | end |
| 893 | end |
| 894 | ret long 0 |
| 895 | end |