1 /* 2 * Copyright (c) 2013 Rob Clark <robdclark (at) gmail.com> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <stdint.h> 27 #include <string.h> 28 #include <assert.h> 29 30 #include <util/u_debug.h> 31 32 #include "disasm.h" 33 #include "instr-a3xx.h" 34 35 static enum debug_t debug; 36 37 #define printf debug_printf 38 39 static const char *levels[] = { 40 "", 41 "\t", 42 "\t\t", 43 "\t\t\t", 44 "\t\t\t\t", 45 "\t\t\t\t\t", 46 "\t\t\t\t\t\t", 47 "\t\t\t\t\t\t\t", 48 "\t\t\t\t\t\t\t\t", 49 "\t\t\t\t\t\t\t\t\t", 50 "x", 51 "x", 52 "x", 53 "x", 54 "x", 55 "x", 56 }; 57 58 static const char *component = "xyzw"; 59 60 static const char *type[] = { 61 [TYPE_F16] = "f16", 62 [TYPE_F32] = "f32", 63 [TYPE_U16] = "u16", 64 [TYPE_U32] = "u32", 65 [TYPE_S16] = "s16", 66 [TYPE_S32] = "s32", 67 [TYPE_U8] = "u8", 68 [TYPE_S8] = "s8", 69 }; 70 71 static void print_reg(reg_t reg, bool full, bool r, bool c, bool im, 72 bool neg, bool abs, bool addr_rel) 73 { 74 const char type = c ? 'c' : 'r'; 75 76 // XXX I prefer - and || for neg/abs, but preserving format used 77 // by libllvm-a3xx for easy diffing.. 78 79 if (abs && neg) 80 printf("(absneg)"); 81 else if (neg) 82 printf("(neg)"); 83 else if (abs) 84 printf("(abs)"); 85 86 if (r) 87 printf("(r)"); 88 89 if (im) { 90 printf("%d", reg.iim_val); 91 } else if (addr_rel) { 92 /* I would just use %+d but trying to make it diff'able with 93 * libllvm-a3xx... 94 */ 95 if (reg.iim_val < 0) 96 printf("%s%c<a0.x - %d>", full ? "" : "h", type, -reg.iim_val); 97 else if (reg.iim_val > 0) 98 printf("%s%c<a0.x + %d>", full ? "" : "h", type, reg.iim_val); 99 else 100 printf("%s%c<a0.x>", full ? "" : "h", type); 101 } else if ((reg.num == REG_A0) && !c) { 102 printf("a0.%c", component[reg.comp]); 103 } else if ((reg.num == REG_P0) && !c) { 104 printf("p0.%c", component[reg.comp]); 105 } else { 106 printf("%s%c%d.%c", full ? "" : "h", type, reg.num & 0x3f, component[reg.comp]); 107 } 108 } 109 110 111 /* current instruction repeat flag: */ 112 static unsigned repeat; 113 114 static void print_reg_dst(reg_t reg, bool full, bool addr_rel) 115 { 116 print_reg(reg, full, false, false, false, false, false, addr_rel); 117 } 118 119 static void print_reg_src(reg_t reg, bool full, bool r, bool c, bool im, 120 bool neg, bool abs, bool addr_rel) 121 { 122 print_reg(reg, full, r, c, im, neg, abs, addr_rel); 123 } 124 125 /* TODO switch to using reginfo struct everywhere, since more readable 126 * than passing a bunch of bools to print_reg_src 127 */ 128 129 struct reginfo { 130 reg_t reg; 131 bool full; 132 bool r; 133 bool c; 134 bool im; 135 bool neg; 136 bool abs; 137 bool addr_rel; 138 }; 139 140 static void print_src(struct reginfo *info) 141 { 142 print_reg_src(info->reg, info->full, info->r, info->c, info->im, 143 info->neg, info->abs, info->addr_rel); 144 } 145 146 //static void print_dst(struct reginfo *info) 147 //{ 148 // print_reg_dst(info->reg, info->full, info->addr_rel); 149 //} 150 151 static void print_instr_cat0(instr_t *instr) 152 { 153 instr_cat0_t *cat0 = &instr->cat0; 154 155 switch (cat0->opc) { 156 case OPC_KILL: 157 printf(" %sp0.%c", cat0->inv ? "!" : "", 158 component[cat0->comp]); 159 break; 160 case OPC_BR: 161 printf(" %sp0.%c, #%d", cat0->inv ? "!" : "", 162 component[cat0->comp], cat0->a3xx.immed); 163 break; 164 case OPC_JUMP: 165 case OPC_CALL: 166 printf(" #%d", cat0->a3xx.immed); 167 break; 168 } 169 170 if ((debug & PRINT_VERBOSE) && (cat0->a3xx.dummy1|cat0->dummy2|cat0->dummy3|cat0->dummy4)) 171 printf("\t{0: %x,%x,%x,%x}", cat0->a3xx.dummy1, cat0->dummy2, cat0->dummy3, cat0->dummy4); 172 } 173 174 static void print_instr_cat1(instr_t *instr) 175 { 176 instr_cat1_t *cat1 = &instr->cat1; 177 178 if (cat1->ul) 179 printf("(ul)"); 180 181 if (cat1->src_type == cat1->dst_type) { 182 if ((cat1->src_type == TYPE_S16) && (((reg_t)cat1->dst).num == REG_A0)) { 183 /* special case (nmemonic?): */ 184 printf("mova"); 185 } else { 186 printf("mov.%s%s", type[cat1->src_type], type[cat1->dst_type]); 187 } 188 } else { 189 printf("cov.%s%s", type[cat1->src_type], type[cat1->dst_type]); 190 } 191 192 printf(" "); 193 194 if (cat1->even) 195 printf("(even)"); 196 197 if (cat1->pos_inf) 198 printf("(pos_infinity)"); 199 200 print_reg_dst((reg_t)(cat1->dst), type_size(cat1->dst_type) == 32, 201 cat1->dst_rel); 202 203 printf(", "); 204 205 /* ugg, have to special case this.. vs print_reg().. */ 206 if (cat1->src_im) { 207 if (type_float(cat1->src_type)) 208 printf("(%f)", cat1->fim_val); 209 else if (type_uint(cat1->src_type)) 210 printf("0x%08x", cat1->uim_val); 211 else 212 printf("%d", cat1->iim_val); 213 } else if (cat1->src_rel && !cat1->src_c) { 214 /* I would just use %+d but trying to make it diff'able with 215 * libllvm-a3xx... 216 */ 217 char type = cat1->src_rel_c ? 'c' : 'r'; 218 if (cat1->off < 0) 219 printf("%c<a0.x - %d>", type, -cat1->off); 220 else if (cat1->off > 0) 221 printf("%c<a0.x + %d>", type, cat1->off); 222 else 223 printf("%c<a0.x>", type); 224 } else { 225 print_reg_src((reg_t)(cat1->src), type_size(cat1->src_type) == 32, 226 cat1->src_r, cat1->src_c, cat1->src_im, false, false, false); 227 } 228 229 if ((debug & PRINT_VERBOSE) && (cat1->must_be_0)) 230 printf("\t{1: %x}", cat1->must_be_0); 231 } 232 233 static void print_instr_cat2(instr_t *instr) 234 { 235 instr_cat2_t *cat2 = &instr->cat2; 236 static const char *cond[] = { 237 "lt", 238 "le", 239 "gt", 240 "ge", 241 "eq", 242 "ne", 243 "?6?", 244 }; 245 246 switch (_OPC(2, cat2->opc)) { 247 case OPC_CMPS_F: 248 case OPC_CMPS_U: 249 case OPC_CMPS_S: 250 case OPC_CMPV_F: 251 case OPC_CMPV_U: 252 case OPC_CMPV_S: 253 printf(".%s", cond[cat2->cond]); 254 break; 255 } 256 257 printf(" "); 258 if (cat2->ei) 259 printf("(ei)"); 260 print_reg_dst((reg_t)(cat2->dst), cat2->full ^ cat2->dst_half, false); 261 printf(", "); 262 263 if (cat2->c1.src1_c) { 264 print_reg_src((reg_t)(cat2->c1.src1), cat2->full, cat2->src1_r, 265 cat2->c1.src1_c, cat2->src1_im, cat2->src1_neg, 266 cat2->src1_abs, false); 267 } else if (cat2->rel1.src1_rel) { 268 print_reg_src((reg_t)(cat2->rel1.src1), cat2->full, cat2->src1_r, 269 cat2->rel1.src1_c, cat2->src1_im, cat2->src1_neg, 270 cat2->src1_abs, cat2->rel1.src1_rel); 271 } else { 272 print_reg_src((reg_t)(cat2->src1), cat2->full, cat2->src1_r, 273 false, cat2->src1_im, cat2->src1_neg, 274 cat2->src1_abs, false); 275 } 276 277 switch (_OPC(2, cat2->opc)) { 278 case OPC_ABSNEG_F: 279 case OPC_ABSNEG_S: 280 case OPC_CLZ_B: 281 case OPC_CLZ_S: 282 case OPC_SIGN_F: 283 case OPC_FLOOR_F: 284 case OPC_CEIL_F: 285 case OPC_RNDNE_F: 286 case OPC_RNDAZ_F: 287 case OPC_TRUNC_F: 288 case OPC_NOT_B: 289 case OPC_BFREV_B: 290 case OPC_SETRM: 291 case OPC_CBITS_B: 292 /* these only have one src reg */ 293 break; 294 default: 295 printf(", "); 296 if (cat2->c2.src2_c) { 297 print_reg_src((reg_t)(cat2->c2.src2), cat2->full, cat2->src2_r, 298 cat2->c2.src2_c, cat2->src2_im, cat2->src2_neg, 299 cat2->src2_abs, false); 300 } else if (cat2->rel2.src2_rel) { 301 print_reg_src((reg_t)(cat2->rel2.src2), cat2->full, cat2->src2_r, 302 cat2->rel2.src2_c, cat2->src2_im, cat2->src2_neg, 303 cat2->src2_abs, cat2->rel2.src2_rel); 304 } else { 305 print_reg_src((reg_t)(cat2->src2), cat2->full, cat2->src2_r, 306 false, cat2->src2_im, cat2->src2_neg, 307 cat2->src2_abs, false); 308 } 309 break; 310 } 311 } 312 313 static void print_instr_cat3(instr_t *instr) 314 { 315 instr_cat3_t *cat3 = &instr->cat3; 316 bool full = instr_cat3_full(cat3); 317 318 printf(" "); 319 print_reg_dst((reg_t)(cat3->dst), full ^ cat3->dst_half, false); 320 printf(", "); 321 if (cat3->c1.src1_c) { 322 print_reg_src((reg_t)(cat3->c1.src1), full, 323 cat3->src1_r, cat3->c1.src1_c, false, cat3->src1_neg, 324 false, false); 325 } else if (cat3->rel1.src1_rel) { 326 print_reg_src((reg_t)(cat3->rel1.src1), full, 327 cat3->src1_r, cat3->rel1.src1_c, false, cat3->src1_neg, 328 false, cat3->rel1.src1_rel); 329 } else { 330 print_reg_src((reg_t)(cat3->src1), full, 331 cat3->src1_r, false, false, cat3->src1_neg, 332 false, false); 333 } 334 printf(", "); 335 print_reg_src((reg_t)cat3->src2, full, 336 cat3->src2_r, cat3->src2_c, false, cat3->src2_neg, 337 false, false); 338 printf(", "); 339 if (cat3->c2.src3_c) { 340 print_reg_src((reg_t)(cat3->c2.src3), full, 341 cat3->src3_r, cat3->c2.src3_c, false, cat3->src3_neg, 342 false, false); 343 } else if (cat3->rel2.src3_rel) { 344 print_reg_src((reg_t)(cat3->rel2.src3), full, 345 cat3->src3_r, cat3->rel2.src3_c, false, cat3->src3_neg, 346 false, cat3->rel2.src3_rel); 347 } else { 348 print_reg_src((reg_t)(cat3->src3), full, 349 cat3->src3_r, false, false, cat3->src3_neg, 350 false, false); 351 } 352 } 353 354 static void print_instr_cat4(instr_t *instr) 355 { 356 instr_cat4_t *cat4 = &instr->cat4; 357 358 printf(" "); 359 print_reg_dst((reg_t)(cat4->dst), cat4->full ^ cat4->dst_half, false); 360 printf(", "); 361 362 if (cat4->c.src_c) { 363 print_reg_src((reg_t)(cat4->c.src), cat4->full, 364 cat4->src_r, cat4->c.src_c, cat4->src_im, 365 cat4->src_neg, cat4->src_abs, false); 366 } else if (cat4->rel.src_rel) { 367 print_reg_src((reg_t)(cat4->rel.src), cat4->full, 368 cat4->src_r, cat4->rel.src_c, cat4->src_im, 369 cat4->src_neg, cat4->src_abs, cat4->rel.src_rel); 370 } else { 371 print_reg_src((reg_t)(cat4->src), cat4->full, 372 cat4->src_r, false, cat4->src_im, 373 cat4->src_neg, cat4->src_abs, false); 374 } 375 376 if ((debug & PRINT_VERBOSE) && (cat4->dummy1|cat4->dummy2)) 377 printf("\t{4: %x,%x}", cat4->dummy1, cat4->dummy2); 378 } 379 380 static void print_instr_cat5(instr_t *instr) 381 { 382 static const struct { 383 bool src1, src2, samp, tex; 384 } info[0x1f] = { 385 [opc_op(OPC_ISAM)] = { true, false, true, true, }, 386 [opc_op(OPC_ISAML)] = { true, true, true, true, }, 387 [opc_op(OPC_ISAMM)] = { true, false, true, true, }, 388 [opc_op(OPC_SAM)] = { true, false, true, true, }, 389 [opc_op(OPC_SAMB)] = { true, true, true, true, }, 390 [opc_op(OPC_SAML)] = { true, true, true, true, }, 391 [opc_op(OPC_SAMGQ)] = { true, false, true, true, }, 392 [opc_op(OPC_GETLOD)] = { true, false, true, true, }, 393 [opc_op(OPC_CONV)] = { true, true, true, true, }, 394 [opc_op(OPC_CONVM)] = { true, true, true, true, }, 395 [opc_op(OPC_GETSIZE)] = { true, false, false, true, }, 396 [opc_op(OPC_GETBUF)] = { false, false, false, true, }, 397 [opc_op(OPC_GETPOS)] = { true, false, false, true, }, 398 [opc_op(OPC_GETINFO)] = { false, false, false, true, }, 399 [opc_op(OPC_DSX)] = { true, false, false, false, }, 400 [opc_op(OPC_DSY)] = { true, false, false, false, }, 401 [opc_op(OPC_GATHER4R)] = { true, false, true, true, }, 402 [opc_op(OPC_GATHER4G)] = { true, false, true, true, }, 403 [opc_op(OPC_GATHER4B)] = { true, false, true, true, }, 404 [opc_op(OPC_GATHER4A)] = { true, false, true, true, }, 405 [opc_op(OPC_SAMGP0)] = { true, false, true, true, }, 406 [opc_op(OPC_SAMGP1)] = { true, false, true, true, }, 407 [opc_op(OPC_SAMGP2)] = { true, false, true, true, }, 408 [opc_op(OPC_SAMGP3)] = { true, false, true, true, }, 409 [opc_op(OPC_DSXPP_1)] = { true, false, false, false, }, 410 [opc_op(OPC_DSYPP_1)] = { true, false, false, false, }, 411 [opc_op(OPC_RGETPOS)] = { false, false, false, false, }, 412 [opc_op(OPC_RGETINFO)] = { false, false, false, false, }, 413 }; 414 instr_cat5_t *cat5 = &instr->cat5; 415 int i; 416 417 if (cat5->is_3d) printf(".3d"); 418 if (cat5->is_a) printf(".a"); 419 if (cat5->is_o) printf(".o"); 420 if (cat5->is_p) printf(".p"); 421 if (cat5->is_s) printf(".s"); 422 if (cat5->is_s2en) printf(".s2en"); 423 424 printf(" "); 425 426 switch (_OPC(5, cat5->opc)) { 427 case OPC_DSXPP_1: 428 case OPC_DSYPP_1: 429 break; 430 default: 431 printf("(%s)", type[cat5->type]); 432 break; 433 } 434 435 printf("("); 436 for (i = 0; i < 4; i++) 437 if (cat5->wrmask & (1 << i)) 438 printf("%c", "xyzw"[i]); 439 printf(")"); 440 441 print_reg_dst((reg_t)(cat5->dst), type_size(cat5->type) == 32, false); 442 443 if (info[cat5->opc].src1) { 444 printf(", "); 445 print_reg_src((reg_t)(cat5->src1), cat5->full, false, false, false, 446 false, false, false); 447 } 448 449 if (cat5->is_s2en) { 450 printf(", "); 451 print_reg_src((reg_t)(cat5->s2en.src2), cat5->full, false, false, false, 452 false, false, false); 453 printf(", "); 454 print_reg_src((reg_t)(cat5->s2en.src3), false, false, false, false, 455 false, false, false); 456 } else { 457 if (cat5->is_o || info[cat5->opc].src2) { 458 printf(", "); 459 print_reg_src((reg_t)(cat5->norm.src2), cat5->full, 460 false, false, false, false, false, false); 461 } 462 if (info[cat5->opc].samp) 463 printf(", s#%d", cat5->norm.samp); 464 if (info[cat5->opc].tex) 465 printf(", t#%d", cat5->norm.tex); 466 } 467 468 if (debug & PRINT_VERBOSE) { 469 if (cat5->is_s2en) { 470 if ((debug & PRINT_VERBOSE) && (cat5->s2en.dummy1|cat5->s2en.dummy2|cat5->dummy2)) 471 printf("\t{5: %x,%x,%x}", cat5->s2en.dummy1, cat5->s2en.dummy2, cat5->dummy2); 472 } else { 473 if ((debug & PRINT_VERBOSE) && (cat5->norm.dummy1|cat5->dummy2)) 474 printf("\t{5: %x,%x}", cat5->norm.dummy1, cat5->dummy2); 475 } 476 } 477 } 478 479 static void print_instr_cat6(instr_t *instr) 480 { 481 instr_cat6_t *cat6 = &instr->cat6; 482 char sd = 0, ss = 0; /* dst/src address space */ 483 bool nodst = false; 484 struct reginfo dst, src1, src2; 485 int src1off = 0, dstoff = 0; 486 487 memset(&dst, 0, sizeof(dst)); 488 memset(&src1, 0, sizeof(src1)); 489 memset(&src2, 0, sizeof(src2)); 490 491 switch (_OPC(6, cat6->opc)) { 492 case OPC_RESINFO: 493 case OPC_RESFMT: 494 dst.full = type_size(cat6->type) == 32; 495 src1.full = type_size(cat6->type) == 32; 496 src2.full = type_size(cat6->type) == 32; 497 break; 498 case OPC_L2G: 499 case OPC_G2L: 500 dst.full = true; 501 src1.full = true; 502 src2.full = true; 503 break; 504 case OPC_STG: 505 case OPC_STL: 506 case OPC_STP: 507 case OPC_STI: 508 case OPC_STLW: 509 case OPC_STGB_4D_4: 510 case OPC_STIB: 511 dst.full = true; 512 src1.full = type_size(cat6->type) == 32; 513 src2.full = type_size(cat6->type) == 32; 514 break; 515 default: 516 dst.full = type_size(cat6->type) == 32; 517 src1.full = true; 518 src2.full = true; 519 break; 520 } 521 522 switch (_OPC(6, cat6->opc)) { 523 case OPC_PREFETCH: 524 case OPC_RESINFO: 525 break; 526 case OPC_ATOMIC_ADD: 527 case OPC_ATOMIC_SUB: 528 case OPC_ATOMIC_XCHG: 529 case OPC_ATOMIC_INC: 530 case OPC_ATOMIC_DEC: 531 case OPC_ATOMIC_CMPXCHG: 532 case OPC_ATOMIC_MIN: 533 case OPC_ATOMIC_MAX: 534 case OPC_ATOMIC_AND: 535 case OPC_ATOMIC_OR: 536 case OPC_ATOMIC_XOR: 537 ss = cat6->g ? 'g' : 'l'; 538 printf(".%c", ss); 539 printf(".%s", type[cat6->type]); 540 break; 541 default: 542 dst.im = cat6->g && !cat6->dst_off; 543 printf(".%s", type[cat6->type]); 544 break; 545 } 546 printf(" "); 547 548 switch (_OPC(6, cat6->opc)) { 549 case OPC_STG: 550 sd = 'g'; 551 break; 552 case OPC_STP: 553 sd = 'p'; 554 break; 555 case OPC_STL: 556 case OPC_STLW: 557 sd = 'l'; 558 break; 559 560 case OPC_LDG: 561 ss = 'g'; 562 break; 563 case OPC_LDP: 564 ss = 'p'; 565 break; 566 case OPC_LDL: 567 case OPC_LDLW: 568 case OPC_LDLV: 569 ss = 'l'; 570 break; 571 572 case OPC_L2G: 573 ss = 'l'; 574 sd = 'g'; 575 break; 576 577 case OPC_G2L: 578 ss = 'g'; 579 sd = 'l'; 580 break; 581 582 case OPC_PREFETCH: 583 ss = 'g'; 584 nodst = true; 585 break; 586 587 case OPC_STI: 588 dst.full = false; // XXX or inverts?? 589 break; 590 } 591 592 if (cat6->dst_off) { 593 dst.reg = (reg_t)(cat6->c.dst); 594 dstoff = cat6->c.off; 595 } else { 596 dst.reg = (reg_t)(cat6->d.dst); 597 } 598 599 if (cat6->src_off) { 600 src1.reg = (reg_t)(cat6->a.src1); 601 src1.im = cat6->a.src1_im; 602 src2.reg = (reg_t)(cat6->a.src2); 603 src2.im = cat6->a.src2_im; 604 src1off = cat6->a.off; 605 } else { 606 src1.reg = (reg_t)(cat6->b.src1); 607 src1.im = cat6->b.src1_im; 608 src2.reg = (reg_t)(cat6->b.src2); 609 src2.im = cat6->b.src2_im; 610 } 611 612 if (!nodst) { 613 if (sd) 614 printf("%c[", sd); 615 /* note: dst might actually be a src (ie. address to store to) */ 616 print_src(&dst); 617 if (dstoff) 618 printf("%+d", dstoff); 619 if (sd) 620 printf("]"); 621 printf(", "); 622 } 623 624 if (ss) 625 printf("%c[", ss); 626 627 /* can have a larger than normal immed, so hack: */ 628 if (src1.im) { 629 printf("%u", src1.reg.dummy13); 630 } else { 631 print_src(&src1); 632 } 633 634 if (src1off) 635 printf("%+d", src1off); 636 if (ss) 637 printf("]"); 638 639 switch (_OPC(6, cat6->opc)) { 640 case OPC_RESINFO: 641 case OPC_RESFMT: 642 break; 643 default: 644 printf(", "); 645 print_src(&src2); 646 break; 647 } 648 } 649 650 /* size of largest OPC field of all the instruction categories: */ 651 #define NOPC_BITS 6 652 653 static const struct opc_info { 654 uint16_t cat; 655 uint16_t opc; 656 const char *name; 657 void (*print)(instr_t *instr); 658 } opcs[1 << (3+NOPC_BITS)] = { 659 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat } 660 /* category 0: */ 661 OPC(0, OPC_NOP, nop), 662 OPC(0, OPC_BR, br), 663 OPC(0, OPC_JUMP, jump), 664 OPC(0, OPC_CALL, call), 665 OPC(0, OPC_RET, ret), 666 OPC(0, OPC_KILL, kill), 667 OPC(0, OPC_END, end), 668 OPC(0, OPC_EMIT, emit), 669 OPC(0, OPC_CUT, cut), 670 OPC(0, OPC_CHMASK, chmask), 671 OPC(0, OPC_CHSH, chsh), 672 OPC(0, OPC_FLOW_REV, flow_rev), 673 674 /* category 1: */ 675 OPC(1, OPC_MOV, ), 676 677 /* category 2: */ 678 OPC(2, OPC_ADD_F, add.f), 679 OPC(2, OPC_MIN_F, min.f), 680 OPC(2, OPC_MAX_F, max.f), 681 OPC(2, OPC_MUL_F, mul.f), 682 OPC(2, OPC_SIGN_F, sign.f), 683 OPC(2, OPC_CMPS_F, cmps.f), 684 OPC(2, OPC_ABSNEG_F, absneg.f), 685 OPC(2, OPC_CMPV_F, cmpv.f), 686 OPC(2, OPC_FLOOR_F, floor.f), 687 OPC(2, OPC_CEIL_F, ceil.f), 688 OPC(2, OPC_RNDNE_F, rndne.f), 689 OPC(2, OPC_RNDAZ_F, rndaz.f), 690 OPC(2, OPC_TRUNC_F, trunc.f), 691 OPC(2, OPC_ADD_U, add.u), 692 OPC(2, OPC_ADD_S, add.s), 693 OPC(2, OPC_SUB_U, sub.u), 694 OPC(2, OPC_SUB_S, sub.s), 695 OPC(2, OPC_CMPS_U, cmps.u), 696 OPC(2, OPC_CMPS_S, cmps.s), 697 OPC(2, OPC_MIN_U, min.u), 698 OPC(2, OPC_MIN_S, min.s), 699 OPC(2, OPC_MAX_U, max.u), 700 OPC(2, OPC_MAX_S, max.s), 701 OPC(2, OPC_ABSNEG_S, absneg.s), 702 OPC(2, OPC_AND_B, and.b), 703 OPC(2, OPC_OR_B, or.b), 704 OPC(2, OPC_NOT_B, not.b), 705 OPC(2, OPC_XOR_B, xor.b), 706 OPC(2, OPC_CMPV_U, cmpv.u), 707 OPC(2, OPC_CMPV_S, cmpv.s), 708 OPC(2, OPC_MUL_U, mul.u), 709 OPC(2, OPC_MUL_S, mul.s), 710 OPC(2, OPC_MULL_U, mull.u), 711 OPC(2, OPC_BFREV_B, bfrev.b), 712 OPC(2, OPC_CLZ_S, clz.s), 713 OPC(2, OPC_CLZ_B, clz.b), 714 OPC(2, OPC_SHL_B, shl.b), 715 OPC(2, OPC_SHR_B, shr.b), 716 OPC(2, OPC_ASHR_B, ashr.b), 717 OPC(2, OPC_BARY_F, bary.f), 718 OPC(2, OPC_MGEN_B, mgen.b), 719 OPC(2, OPC_GETBIT_B, getbit.b), 720 OPC(2, OPC_SETRM, setrm), 721 OPC(2, OPC_CBITS_B, cbits.b), 722 OPC(2, OPC_SHB, shb), 723 OPC(2, OPC_MSAD, msad), 724 725 /* category 3: */ 726 OPC(3, OPC_MAD_U16, mad.u16), 727 OPC(3, OPC_MADSH_U16, madsh.u16), 728 OPC(3, OPC_MAD_S16, mad.s16), 729 OPC(3, OPC_MADSH_M16, madsh.m16), 730 OPC(3, OPC_MAD_U24, mad.u24), 731 OPC(3, OPC_MAD_S24, mad.s24), 732 OPC(3, OPC_MAD_F16, mad.f16), 733 OPC(3, OPC_MAD_F32, mad.f32), 734 OPC(3, OPC_SEL_B16, sel.b16), 735 OPC(3, OPC_SEL_B32, sel.b32), 736 OPC(3, OPC_SEL_S16, sel.s16), 737 OPC(3, OPC_SEL_S32, sel.s32), 738 OPC(3, OPC_SEL_F16, sel.f16), 739 OPC(3, OPC_SEL_F32, sel.f32), 740 OPC(3, OPC_SAD_S16, sad.s16), 741 OPC(3, OPC_SAD_S32, sad.s32), 742 743 /* category 4: */ 744 OPC(4, OPC_RCP, rcp), 745 OPC(4, OPC_RSQ, rsq), 746 OPC(4, OPC_LOG2, log2), 747 OPC(4, OPC_EXP2, exp2), 748 OPC(4, OPC_SIN, sin), 749 OPC(4, OPC_COS, cos), 750 OPC(4, OPC_SQRT, sqrt), 751 752 /* category 5: */ 753 OPC(5, OPC_ISAM, isam), 754 OPC(5, OPC_ISAML, isaml), 755 OPC(5, OPC_ISAMM, isamm), 756 OPC(5, OPC_SAM, sam), 757 OPC(5, OPC_SAMB, samb), 758 OPC(5, OPC_SAML, saml), 759 OPC(5, OPC_SAMGQ, samgq), 760 OPC(5, OPC_GETLOD, getlod), 761 OPC(5, OPC_CONV, conv), 762 OPC(5, OPC_CONVM, convm), 763 OPC(5, OPC_GETSIZE, getsize), 764 OPC(5, OPC_GETBUF, getbuf), 765 OPC(5, OPC_GETPOS, getpos), 766 OPC(5, OPC_GETINFO, getinfo), 767 OPC(5, OPC_DSX, dsx), 768 OPC(5, OPC_DSY, dsy), 769 OPC(5, OPC_GATHER4R, gather4r), 770 OPC(5, OPC_GATHER4G, gather4g), 771 OPC(5, OPC_GATHER4B, gather4b), 772 OPC(5, OPC_GATHER4A, gather4a), 773 OPC(5, OPC_SAMGP0, samgp0), 774 OPC(5, OPC_SAMGP1, samgp1), 775 OPC(5, OPC_SAMGP2, samgp2), 776 OPC(5, OPC_SAMGP3, samgp3), 777 OPC(5, OPC_DSXPP_1, dsxpp.1), 778 OPC(5, OPC_DSYPP_1, dsypp.1), 779 OPC(5, OPC_RGETPOS, rgetpos), 780 OPC(5, OPC_RGETINFO, rgetinfo), 781 782 783 /* category 6: */ 784 OPC(6, OPC_LDG, ldg), 785 OPC(6, OPC_LDL, ldl), 786 OPC(6, OPC_LDP, ldp), 787 OPC(6, OPC_STG, stg), 788 OPC(6, OPC_STL, stl), 789 OPC(6, OPC_STP, stp), 790 OPC(6, OPC_STI, sti), 791 OPC(6, OPC_G2L, g2l), 792 OPC(6, OPC_L2G, l2g), 793 OPC(6, OPC_PREFETCH, prefetch), 794 OPC(6, OPC_LDLW, ldlw), 795 OPC(6, OPC_STLW, stlw), 796 OPC(6, OPC_RESFMT, resfmt), 797 OPC(6, OPC_RESINFO, resinfo), 798 OPC(6, OPC_ATOMIC_ADD, atomic.add), 799 OPC(6, OPC_ATOMIC_SUB, atomic.sub), 800 OPC(6, OPC_ATOMIC_XCHG, atomic.xchg), 801 OPC(6, OPC_ATOMIC_INC, atomic.inc), 802 OPC(6, OPC_ATOMIC_DEC, atomic.dec), 803 OPC(6, OPC_ATOMIC_CMPXCHG, atomic.cmpxchg), 804 OPC(6, OPC_ATOMIC_MIN, atomic.min), 805 OPC(6, OPC_ATOMIC_MAX, atomic.max), 806 OPC(6, OPC_ATOMIC_AND, atomic.and), 807 OPC(6, OPC_ATOMIC_OR, atomic.or), 808 OPC(6, OPC_ATOMIC_XOR, atomic.xor), 809 OPC(6, OPC_LDGB_TYPED_4D, ldgb.typed.3d), 810 OPC(6, OPC_STGB_4D_4, stgb.4d.4), 811 OPC(6, OPC_STIB, stib), 812 OPC(6, OPC_LDC_4, ldc.4), 813 OPC(6, OPC_LDLV, ldlv), 814 815 816 #undef OPC 817 }; 818 819 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr)])) 820 821 // XXX hack.. probably should move this table somewhere common: 822 #include "ir3.h" 823 const char *ir3_instr_name(struct ir3_instruction *instr) 824 { 825 if (opc_cat(instr->opc) == -1) return "??meta??"; 826 return opcs[instr->opc].name; 827 } 828 829 static void print_instr(uint32_t *dwords, int level, int n) 830 { 831 instr_t *instr = (instr_t *)dwords; 832 uint32_t opc = instr_opc(instr); 833 const char *name; 834 835 if (debug & PRINT_VERBOSE) 836 printf("%s%04d[%08xx_%08xx] ", levels[level], n, dwords[1], dwords[0]); 837 838 /* NOTE: order flags are printed is a bit fugly.. but for now I 839 * try to match the order in llvm-a3xx disassembler for easy 840 * diff'ing.. 841 */ 842 843 if (instr->sync) 844 printf("(sy)"); 845 if (instr->ss && (instr->opc_cat <= 4)) 846 printf("(ss)"); 847 if (instr->jmp_tgt) 848 printf("(jp)"); 849 if (instr->repeat && (instr->opc_cat <= 4)) { 850 printf("(rpt%d)", instr->repeat); 851 repeat = instr->repeat; 852 } else { 853 repeat = 0; 854 } 855 if (instr->ul && ((2 <= instr->opc_cat) && (instr->opc_cat <= 4))) 856 printf("(ul)"); 857 858 name = GETINFO(instr)->name; 859 860 if (name) { 861 printf("%s", name); 862 GETINFO(instr)->print(instr); 863 } else { 864 printf("unknown(%d,%d)", instr->opc_cat, opc); 865 } 866 867 printf("\n"); 868 } 869 870 int disasm_a3xx(uint32_t *dwords, int sizedwords, int level, enum shader_t type) 871 { 872 int i; 873 874 assert((sizedwords % 2) == 0); 875 876 for (i = 0; i < sizedwords; i += 2) 877 print_instr(&dwords[i], level, i/2); 878 879 return 0; 880 } 881