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