freedreno: Fix printing of unused src in disasm of cat6 RESINFO.
[mesa.git] / src / freedreno / ir3 / disasm-a3xx.c
1 /*
2 * Copyright (c) 2013 Rob Clark <robdclark@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 <stdbool.h>
28 #include <string.h>
29 #include <assert.h>
30
31 #include <util/u_debug.h>
32
33 #include "instr-a3xx.h"
34
35 /* bitmask of debug flags */
36 enum debug_t {
37 PRINT_RAW = 0x1, /* dump raw hexdump */
38 PRINT_VERBOSE = 0x2,
39 EXPAND_REPEAT = 0x4,
40 };
41
42 static enum debug_t debug;
43
44 #define printf debug_printf
45
46 static const char *levels[] = {
47 "",
48 "\t",
49 "\t\t",
50 "\t\t\t",
51 "\t\t\t\t",
52 "\t\t\t\t\t",
53 "\t\t\t\t\t\t",
54 "\t\t\t\t\t\t\t",
55 "\t\t\t\t\t\t\t\t",
56 "\t\t\t\t\t\t\t\t\t",
57 "x",
58 "x",
59 "x",
60 "x",
61 "x",
62 "x",
63 };
64
65 static const char *component = "xyzw";
66
67 static const char *type[] = {
68 [TYPE_F16] = "f16",
69 [TYPE_F32] = "f32",
70 [TYPE_U16] = "u16",
71 [TYPE_U32] = "u32",
72 [TYPE_S16] = "s16",
73 [TYPE_S32] = "s32",
74 [TYPE_U8] = "u8",
75 [TYPE_S8] = "s8",
76 };
77
78 struct disasm_ctx {
79 FILE *out;
80 int level;
81 unsigned gpu_id;
82
83 /* current instruction repeat flag: */
84 unsigned repeat;
85 /* current instruction repeat indx/offset (for --expand): */
86 unsigned repeatidx;
87
88 unsigned instructions;
89 };
90
91 static const char *float_imms[] = {
92 "0.0",
93 "0.5",
94 "1.0",
95 "2.0",
96 "e",
97 "pi",
98 "1/pi",
99 "1/log2(e)",
100 "log2(e)",
101 "1/log2(10)",
102 "log2(10)",
103 "4.0",
104 };
105
106 static void print_reg(struct disasm_ctx *ctx, reg_t reg, bool full,
107 bool is_float, bool r,
108 bool c, bool im, bool neg, bool abs, bool addr_rel)
109 {
110 const char type = c ? 'c' : 'r';
111
112 // XXX I prefer - and || for neg/abs, but preserving format used
113 // by libllvm-a3xx for easy diffing..
114
115 if (abs && neg)
116 fprintf(ctx->out, "(absneg)");
117 else if (neg)
118 fprintf(ctx->out, "(neg)");
119 else if (abs)
120 fprintf(ctx->out, "(abs)");
121
122 if (r)
123 fprintf(ctx->out, "(r)");
124
125 if (im) {
126 if (is_float && full && reg.iim_val < ARRAY_SIZE(float_imms)) {
127 fprintf(ctx->out, "(%s)", float_imms[reg.iim_val]);
128 } else {
129 fprintf(ctx->out, "%d", reg.iim_val);
130 }
131 } else if (addr_rel) {
132 /* I would just use %+d but trying to make it diff'able with
133 * libllvm-a3xx...
134 */
135 if (reg.iim_val < 0)
136 fprintf(ctx->out, "%s%c<a0.x - %d>", full ? "" : "h", type, -reg.iim_val);
137 else if (reg.iim_val > 0)
138 fprintf(ctx->out, "%s%c<a0.x + %d>", full ? "" : "h", type, reg.iim_val);
139 else
140 fprintf(ctx->out, "%s%c<a0.x>", full ? "" : "h", type);
141 } else if ((reg.num == REG_A0) && !c) {
142 /* This matches libllvm output, the second (scalar) address register
143 * seems to be called a1.x instead of a0.y.
144 */
145 fprintf(ctx->out, "a%d.x", reg.comp);
146 } else if ((reg.num == REG_P0) && !c) {
147 fprintf(ctx->out, "p0.%c", component[reg.comp]);
148 } else {
149 fprintf(ctx->out, "%s%c%d.%c", full ? "" : "h", type, reg.num, component[reg.comp]);
150 }
151 }
152
153 static unsigned regidx(reg_t reg)
154 {
155 return (4 * reg.num) + reg.comp;
156 }
157
158 static reg_t idxreg(unsigned idx)
159 {
160 return (reg_t){
161 .comp = idx & 0x3,
162 .num = idx >> 2,
163 };
164 }
165
166 static void print_reg_dst(struct disasm_ctx *ctx, reg_t reg, bool full, bool addr_rel)
167 {
168 reg = idxreg(regidx(reg) + ctx->repeatidx);
169 print_reg(ctx, reg, full, false, false, false, false, false, false, addr_rel);
170 }
171
172 /* TODO switch to using reginfo struct everywhere, since more readable
173 * than passing a bunch of bools to print_reg_src
174 */
175
176 struct reginfo {
177 reg_t reg;
178 bool full;
179 bool r;
180 bool c;
181 bool f; /* src reg is interpreted as float, used for printing immediates */
182 bool im;
183 bool neg;
184 bool abs;
185 bool addr_rel;
186 };
187
188 static void print_src(struct disasm_ctx *ctx, struct reginfo *info)
189 {
190 reg_t reg = info->reg;
191
192 if (info->r)
193 reg = idxreg(regidx(info->reg) + ctx->repeatidx);
194
195 print_reg(ctx, reg, info->full, info->f, info->r, info->c, info->im,
196 info->neg, info->abs, info->addr_rel);
197 }
198
199 //static void print_dst(struct disasm_ctx *ctx, struct reginfo *info)
200 //{
201 // print_reg_dst(ctx, info->reg, info->full, info->addr_rel);
202 //}
203
204 static void print_instr_cat0(struct disasm_ctx *ctx, instr_t *instr)
205 {
206 static const struct {
207 const char *suffix;
208 int nsrc;
209 bool idx;
210 } brinfo[7] = {
211 [BRANCH_PLAIN] = { "r", 1, false },
212 [BRANCH_OR] = { "rao", 2, false },
213 [BRANCH_AND] = { "raa", 2, false },
214 [BRANCH_CONST] = { "rac", 0, true },
215 [BRANCH_ANY] = { "any", 1, false },
216 [BRANCH_ALL] = { "all", 1, false },
217 [BRANCH_X] = { "rax", 0, false },
218 };
219 instr_cat0_t *cat0 = &instr->cat0;
220
221 switch (instr_opc(instr, ctx->gpu_id)) {
222 case OPC_KILL:
223 case OPC_PREDT:
224 case OPC_PREDF:
225 fprintf(ctx->out, " %sp0.%c", cat0->inv0 ? "!" : "",
226 component[cat0->comp0]);
227 break;
228 case OPC_B:
229 fprintf(ctx->out, "%s", brinfo[cat0->brtype].suffix);
230 if (brinfo[cat0->brtype].idx) {
231 fprintf(ctx->out, ".%u", cat0->idx);
232 }
233 if (brinfo[cat0->brtype].nsrc >= 1) {
234 fprintf(ctx->out, " %sp0.%c,", cat0->inv0 ? "!" : "",
235 component[cat0->comp0]);
236 }
237 if (brinfo[cat0->brtype].nsrc >= 2) {
238 fprintf(ctx->out, " %sp0.%c,", cat0->inv1 ? "!" : "",
239 component[cat0->comp1]);
240 }
241 fprintf(ctx->out, " #%d", cat0->a3xx.immed);
242 break;
243 case OPC_JUMP:
244 case OPC_CALL:
245 case OPC_BKT:
246 case OPC_GETONE:
247 case OPC_SHPS:
248 fprintf(ctx->out, " #%d", cat0->a3xx.immed);
249 break;
250 }
251
252 if ((debug & PRINT_VERBOSE) && (cat0->dummy3|cat0->dummy4))
253 fprintf(ctx->out, "\t{0: %x,%x}", cat0->dummy3, cat0->dummy4);
254 }
255
256 static void print_instr_cat1(struct disasm_ctx *ctx, instr_t *instr)
257 {
258 instr_cat1_t *cat1 = &instr->cat1;
259
260 if (cat1->ul)
261 fprintf(ctx->out, "(ul)");
262
263 if (cat1->src_type == cat1->dst_type) {
264 if ((cat1->src_type == TYPE_S16) && (((reg_t)cat1->dst).num == REG_A0)) {
265 /* special case (nmemonic?): */
266 fprintf(ctx->out, "mova");
267 } else {
268 fprintf(ctx->out, "mov.%s%s", type[cat1->src_type], type[cat1->dst_type]);
269 }
270 } else {
271 fprintf(ctx->out, "cov.%s%s", type[cat1->src_type], type[cat1->dst_type]);
272 }
273
274 fprintf(ctx->out, " ");
275
276 if (cat1->even)
277 fprintf(ctx->out, "(even)");
278
279 if (cat1->pos_inf)
280 fprintf(ctx->out, "(pos_infinity)");
281
282 print_reg_dst(ctx, (reg_t)(cat1->dst), type_size(cat1->dst_type) == 32,
283 cat1->dst_rel);
284
285 fprintf(ctx->out, ", ");
286
287 /* ugg, have to special case this.. vs print_reg().. */
288 if (cat1->src_im) {
289 if (type_float(cat1->src_type))
290 fprintf(ctx->out, "(%f)", cat1->fim_val);
291 else if (type_uint(cat1->src_type))
292 fprintf(ctx->out, "0x%08x", cat1->uim_val);
293 else
294 fprintf(ctx->out, "%d", cat1->iim_val);
295 } else if (cat1->src_rel && !cat1->src_c) {
296 /* I would just use %+d but trying to make it diff'able with
297 * libllvm-a3xx...
298 */
299 char type = cat1->src_rel_c ? 'c' : 'r';
300 const char *full = (type_size(cat1->src_type) == 32) ? "" : "h";
301 if (cat1->off < 0)
302 fprintf(ctx->out, "%s%c<a0.x - %d>", full, type, -cat1->off);
303 else if (cat1->off > 0)
304 fprintf(ctx->out, "%s%c<a0.x + %d>", full, type, cat1->off);
305 else
306 fprintf(ctx->out, "%s%c<a0.x>", full, type);
307 } else {
308 struct reginfo src = {
309 .reg = (reg_t)cat1->src,
310 .full = type_size(cat1->src_type) == 32,
311 .r = cat1->src_r,
312 .c = cat1->src_c,
313 .im = cat1->src_im,
314 };
315 print_src(ctx, &src);
316 }
317
318 if ((debug & PRINT_VERBOSE) && (cat1->must_be_0))
319 fprintf(ctx->out, "\t{1: %x}", cat1->must_be_0);
320 }
321
322 static void print_instr_cat2(struct disasm_ctx *ctx, instr_t *instr)
323 {
324 instr_cat2_t *cat2 = &instr->cat2;
325 int opc = _OPC(2, cat2->opc);
326 static const char *cond[] = {
327 "lt",
328 "le",
329 "gt",
330 "ge",
331 "eq",
332 "ne",
333 "?6?",
334 };
335
336 switch (opc) {
337 case OPC_CMPS_F:
338 case OPC_CMPS_U:
339 case OPC_CMPS_S:
340 case OPC_CMPV_F:
341 case OPC_CMPV_U:
342 case OPC_CMPV_S:
343 fprintf(ctx->out, ".%s", cond[cat2->cond]);
344 break;
345 }
346
347 fprintf(ctx->out, " ");
348 if (cat2->ei)
349 fprintf(ctx->out, "(ei)");
350 print_reg_dst(ctx, (reg_t)(cat2->dst), cat2->full ^ cat2->dst_half, false);
351 fprintf(ctx->out, ", ");
352
353 struct reginfo src1 = {
354 .full = cat2->full,
355 .r = cat2->repeat ? cat2->src1_r : 0,
356 .f = is_cat2_float(opc),
357 .im = cat2->src1_im,
358 .abs = cat2->src1_abs,
359 .neg = cat2->src1_neg,
360 };
361
362 if (cat2->c1.src1_c) {
363 src1.reg = (reg_t)(cat2->c1.src1);
364 src1.c = true;
365 } else if (cat2->rel1.src1_rel) {
366 src1.reg = (reg_t)(cat2->rel1.src1);
367 src1.c = cat2->rel1.src1_c;
368 src1.addr_rel = true;
369 } else {
370 src1.reg = (reg_t)(cat2->src1);
371 }
372 print_src(ctx, &src1);
373
374 struct reginfo src2 = {
375 .r = cat2->repeat ? cat2->src2_r : 0,
376 .full = cat2->full,
377 .f = is_cat2_float(opc),
378 .abs = cat2->src2_abs,
379 .neg = cat2->src2_neg,
380 .im = cat2->src2_im,
381 };
382 switch (opc) {
383 case OPC_ABSNEG_F:
384 case OPC_ABSNEG_S:
385 case OPC_CLZ_B:
386 case OPC_CLZ_S:
387 case OPC_SIGN_F:
388 case OPC_FLOOR_F:
389 case OPC_CEIL_F:
390 case OPC_RNDNE_F:
391 case OPC_RNDAZ_F:
392 case OPC_TRUNC_F:
393 case OPC_NOT_B:
394 case OPC_BFREV_B:
395 case OPC_SETRM:
396 case OPC_CBITS_B:
397 /* these only have one src reg */
398 break;
399 default:
400 fprintf(ctx->out, ", ");
401 if (cat2->c2.src2_c) {
402 src2.reg = (reg_t)(cat2->c2.src2);
403 src2.c = true;
404 } else if (cat2->rel2.src2_rel) {
405 src2.reg = (reg_t)(cat2->rel2.src2);
406 src2.c = cat2->rel2.src2_c;
407 src2.addr_rel = true;
408 } else {
409 src2.reg = (reg_t)(cat2->src2);
410 }
411 print_src(ctx, &src2);
412 break;
413 }
414 }
415
416 static void print_instr_cat3(struct disasm_ctx *ctx, instr_t *instr)
417 {
418 instr_cat3_t *cat3 = &instr->cat3;
419 bool full = instr_cat3_full(cat3);
420
421 fprintf(ctx->out, " ");
422 print_reg_dst(ctx, (reg_t)(cat3->dst), full ^ cat3->dst_half, false);
423 fprintf(ctx->out, ", ");
424
425 struct reginfo src1 = {
426 .r = cat3->repeat ? cat3->src1_r : 0,
427 .full = full,
428 .neg = cat3->src1_neg,
429 };
430 if (cat3->c1.src1_c) {
431 src1.reg = (reg_t)(cat3->c1.src1);
432 src1.c = true;
433 } else if (cat3->rel1.src1_rel) {
434 src1.reg = (reg_t)(cat3->rel1.src1);
435 src1.c = cat3->rel1.src1_c;
436 src1.addr_rel = true;
437 } else {
438 src1.reg = (reg_t)(cat3->src1);
439 }
440 print_src(ctx, &src1);
441
442 fprintf(ctx->out, ", ");
443 struct reginfo src2 = {
444 .reg = (reg_t)cat3->src2,
445 .full = full,
446 .r = cat3->repeat ? cat3->src2_r : 0,
447 .c = cat3->src2_c,
448 .neg = cat3->src2_neg,
449 };
450 print_src(ctx, &src2);
451
452 fprintf(ctx->out, ", ");
453 struct reginfo src3 = {
454 .r = cat3->src3_r,
455 .full = full,
456 .neg = cat3->src3_neg,
457 };
458 if (cat3->c2.src3_c) {
459 src3.reg = (reg_t)(cat3->c2.src3);
460 src3.c = true;
461 } else if (cat3->rel2.src3_rel) {
462 src3.reg = (reg_t)(cat3->rel2.src3);
463 src3.c = cat3->rel2.src3_c;
464 src3.addr_rel = true;
465 } else {
466 src3.reg = (reg_t)(cat3->src3);
467 }
468 print_src(ctx, &src3);
469 }
470
471 static void print_instr_cat4(struct disasm_ctx *ctx, instr_t *instr)
472 {
473 instr_cat4_t *cat4 = &instr->cat4;
474
475 fprintf(ctx->out, " ");
476 print_reg_dst(ctx, (reg_t)(cat4->dst), cat4->full ^ cat4->dst_half, false);
477 fprintf(ctx->out, ", ");
478
479 struct reginfo src = {
480 .r = cat4->src_r,
481 .im = cat4->src_im,
482 .full = cat4->full,
483 .neg = cat4->src_neg,
484 .abs = cat4->src_abs,
485 };
486 if (cat4->c.src_c) {
487 src.reg = (reg_t)(cat4->c.src);
488 src.c = true;
489 } else if (cat4->rel.src_rel) {
490 src.reg = (reg_t)(cat4->rel.src);
491 src.c = cat4->rel.src_c;
492 src.addr_rel = true;
493 } else {
494 src.reg = (reg_t)(cat4->src);
495 }
496 print_src(ctx, &src);
497
498 if ((debug & PRINT_VERBOSE) && (cat4->dummy1|cat4->dummy2))
499 fprintf(ctx->out, "\t{4: %x,%x}", cat4->dummy1, cat4->dummy2);
500 }
501
502 static void print_instr_cat5(struct disasm_ctx *ctx, instr_t *instr)
503 {
504 static const struct {
505 bool src1, src2, samp, tex;
506 } info[0x1f] = {
507 [opc_op(OPC_ISAM)] = { true, false, true, true, },
508 [opc_op(OPC_ISAML)] = { true, true, true, true, },
509 [opc_op(OPC_ISAMM)] = { true, false, true, true, },
510 [opc_op(OPC_SAM)] = { true, false, true, true, },
511 [opc_op(OPC_SAMB)] = { true, true, true, true, },
512 [opc_op(OPC_SAML)] = { true, true, true, true, },
513 [opc_op(OPC_SAMGQ)] = { true, false, true, true, },
514 [opc_op(OPC_GETLOD)] = { true, false, true, true, },
515 [opc_op(OPC_CONV)] = { true, true, true, true, },
516 [opc_op(OPC_CONVM)] = { true, true, true, true, },
517 [opc_op(OPC_GETSIZE)] = { true, false, false, true, },
518 [opc_op(OPC_GETBUF)] = { false, false, false, true, },
519 [opc_op(OPC_GETPOS)] = { true, false, false, true, },
520 [opc_op(OPC_GETINFO)] = { false, false, false, true, },
521 [opc_op(OPC_DSX)] = { true, false, false, false, },
522 [opc_op(OPC_DSY)] = { true, false, false, false, },
523 [opc_op(OPC_GATHER4R)] = { true, false, true, true, },
524 [opc_op(OPC_GATHER4G)] = { true, false, true, true, },
525 [opc_op(OPC_GATHER4B)] = { true, false, true, true, },
526 [opc_op(OPC_GATHER4A)] = { true, false, true, true, },
527 [opc_op(OPC_SAMGP0)] = { true, false, true, true, },
528 [opc_op(OPC_SAMGP1)] = { true, false, true, true, },
529 [opc_op(OPC_SAMGP2)] = { true, false, true, true, },
530 [opc_op(OPC_SAMGP3)] = { true, false, true, true, },
531 [opc_op(OPC_DSXPP_1)] = { true, false, false, false, },
532 [opc_op(OPC_DSYPP_1)] = { true, false, false, false, },
533 [opc_op(OPC_RGETPOS)] = { true, false, false, false, },
534 [opc_op(OPC_RGETINFO)] = { false, false, false, false, },
535 };
536
537 static const struct {
538 bool indirect;
539 bool bindless;
540 bool use_a1;
541 bool uniform;
542 } desc_features[8] = {
543 [CAT5_NONUNIFORM] = { .indirect = true, },
544 [CAT5_UNIFORM] = { .indirect = true, .uniform = true, },
545 [CAT5_BINDLESS_IMM] = { .bindless = true, },
546 [CAT5_BINDLESS_UNIFORM] = {
547 .bindless = true,
548 .indirect = true,
549 .uniform = true,
550 },
551 [CAT5_BINDLESS_NONUNIFORM] = {
552 .bindless = true,
553 .indirect = true,
554 },
555 [CAT5_BINDLESS_A1_IMM] = {
556 .bindless = true,
557 .use_a1 = true,
558 },
559 [CAT5_BINDLESS_A1_UNIFORM] = {
560 .bindless = true,
561 .indirect = true,
562 .uniform = true,
563 .use_a1 = true,
564 },
565 [CAT5_BINDLESS_A1_NONUNIFORM] = {
566 .bindless = true,
567 .indirect = true,
568 .use_a1 = true,
569 },
570 };
571
572 instr_cat5_t *cat5 = &instr->cat5;
573 int i;
574
575 bool desc_indirect =
576 cat5->is_s2en_bindless &&
577 desc_features[cat5->s2en_bindless.desc_mode].indirect;
578 bool bindless =
579 cat5->is_s2en_bindless &&
580 desc_features[cat5->s2en_bindless.desc_mode].bindless;
581 bool use_a1 =
582 cat5->is_s2en_bindless &&
583 desc_features[cat5->s2en_bindless.desc_mode].use_a1;
584 bool uniform =
585 cat5->is_s2en_bindless &&
586 desc_features[cat5->s2en_bindless.desc_mode].uniform;
587
588 if (cat5->is_3d) fprintf(ctx->out, ".3d");
589 if (cat5->is_a) fprintf(ctx->out, ".a");
590 if (cat5->is_o) fprintf(ctx->out, ".o");
591 if (cat5->is_p) fprintf(ctx->out, ".p");
592 if (cat5->is_s) fprintf(ctx->out, ".s");
593 if (desc_indirect) fprintf(ctx->out, ".s2en");
594 if (uniform) fprintf(ctx->out, ".uniform");
595
596 if (bindless) {
597 unsigned base = (cat5->s2en_bindless.base_hi << 1) | cat5->base_lo;
598 fprintf(ctx->out, ".base%d", base);
599 }
600
601 fprintf(ctx->out, " ");
602
603 switch (_OPC(5, cat5->opc)) {
604 case OPC_DSXPP_1:
605 case OPC_DSYPP_1:
606 break;
607 default:
608 fprintf(ctx->out, "(%s)", type[cat5->type]);
609 break;
610 }
611
612 fprintf(ctx->out, "(");
613 for (i = 0; i < 4; i++)
614 if (cat5->wrmask & (1 << i))
615 fprintf(ctx->out, "%c", "xyzw"[i]);
616 fprintf(ctx->out, ")");
617
618 print_reg_dst(ctx, (reg_t)(cat5->dst), type_size(cat5->type) == 32, false);
619
620 if (info[cat5->opc].src1) {
621 fprintf(ctx->out, ", ");
622 struct reginfo src = { .reg = (reg_t)(cat5->src1), .full = cat5->full };
623 print_src(ctx, &src);
624 }
625
626 if (cat5->is_o || info[cat5->opc].src2) {
627 fprintf(ctx->out, ", ");
628 struct reginfo src = { .reg = (reg_t)(cat5->src2), .full = cat5->full };
629 print_src(ctx, &src);
630 }
631 if (cat5->is_s2en_bindless) {
632 if (!desc_indirect) {
633 if (info[cat5->opc].samp) {
634 if (use_a1)
635 fprintf(ctx->out, ", s#%d", cat5->s2en_bindless.src3);
636 else
637 fprintf(ctx->out, ", s#%d", cat5->s2en_bindless.src3 & 0xf);
638 }
639
640 if (info[cat5->opc].tex && !use_a1) {
641 fprintf(ctx->out, ", t#%d", cat5->s2en_bindless.src3 >> 4);
642 }
643 }
644 } else {
645 if (info[cat5->opc].samp)
646 fprintf(ctx->out, ", s#%d", cat5->norm.samp);
647 if (info[cat5->opc].tex)
648 fprintf(ctx->out, ", t#%d", cat5->norm.tex);
649 }
650
651 if (desc_indirect) {
652 fprintf(ctx->out, ", ");
653 struct reginfo src = { .reg = (reg_t)(cat5->s2en_bindless.src3), .full = bindless };
654 print_src(ctx, &src);
655 }
656
657 if (use_a1)
658 fprintf(ctx->out, ", a1.x");
659
660 if (debug & PRINT_VERBOSE) {
661 if (cat5->is_s2en_bindless) {
662 if ((debug & PRINT_VERBOSE) && cat5->s2en_bindless.dummy1)
663 fprintf(ctx->out, "\t{5: %x}", cat5->s2en_bindless.dummy1);
664 } else {
665 if ((debug & PRINT_VERBOSE) && cat5->norm.dummy1)
666 fprintf(ctx->out, "\t{5: %x}", cat5->norm.dummy1);
667 }
668 }
669 }
670
671 static void print_instr_cat6_a3xx(struct disasm_ctx *ctx, instr_t *instr)
672 {
673 instr_cat6_t *cat6 = &instr->cat6;
674 char sd = 0, ss = 0; /* dst/src address space */
675 bool nodst = false;
676 struct reginfo dst, src1, src2;
677 int src1off = 0, dstoff = 0;
678
679 memset(&dst, 0, sizeof(dst));
680 memset(&src1, 0, sizeof(src1));
681 memset(&src2, 0, sizeof(src2));
682
683 switch (_OPC(6, cat6->opc)) {
684 case OPC_RESINFO:
685 case OPC_RESFMT:
686 dst.full = type_size(cat6->type) == 32;
687 src1.full = type_size(cat6->type) == 32;
688 src2.full = type_size(cat6->type) == 32;
689 break;
690 case OPC_L2G:
691 case OPC_G2L:
692 dst.full = true;
693 src1.full = true;
694 src2.full = true;
695 break;
696 case OPC_STG:
697 case OPC_STL:
698 case OPC_STP:
699 case OPC_STLW:
700 case OPC_STIB:
701 dst.full = type_size(cat6->type) == 32;
702 src1.full = type_size(cat6->type) == 32;
703 src2.full = type_size(cat6->type) == 32;
704 break;
705 default:
706 dst.full = type_size(cat6->type) == 32;
707 src1.full = true;
708 src2.full = true;
709 break;
710 }
711
712 switch (_OPC(6, cat6->opc)) {
713 case OPC_PREFETCH:
714 break;
715 case OPC_RESINFO:
716 fprintf(ctx->out, ".%dd", cat6->ldgb.d + 1);
717 break;
718 case OPC_LDGB:
719 fprintf(ctx->out, ".%s", cat6->ldgb.typed ? "typed" : "untyped");
720 fprintf(ctx->out, ".%dd", cat6->ldgb.d + 1);
721 fprintf(ctx->out, ".%s", type[cat6->type]);
722 fprintf(ctx->out, ".%d", cat6->ldgb.type_size + 1);
723 break;
724 case OPC_STGB:
725 case OPC_STIB:
726 fprintf(ctx->out, ".%s", cat6->stgb.typed ? "typed" : "untyped");
727 fprintf(ctx->out, ".%dd", cat6->stgb.d + 1);
728 fprintf(ctx->out, ".%s", type[cat6->type]);
729 fprintf(ctx->out, ".%d", cat6->stgb.type_size + 1);
730 break;
731 case OPC_ATOMIC_ADD:
732 case OPC_ATOMIC_SUB:
733 case OPC_ATOMIC_XCHG:
734 case OPC_ATOMIC_INC:
735 case OPC_ATOMIC_DEC:
736 case OPC_ATOMIC_CMPXCHG:
737 case OPC_ATOMIC_MIN:
738 case OPC_ATOMIC_MAX:
739 case OPC_ATOMIC_AND:
740 case OPC_ATOMIC_OR:
741 case OPC_ATOMIC_XOR:
742 ss = cat6->g ? 'g' : 'l';
743 fprintf(ctx->out, ".%s", cat6->ldgb.typed ? "typed" : "untyped");
744 fprintf(ctx->out, ".%dd", cat6->ldgb.d + 1);
745 fprintf(ctx->out, ".%s", type[cat6->type]);
746 fprintf(ctx->out, ".%d", cat6->ldgb.type_size + 1);
747 fprintf(ctx->out, ".%c", ss);
748 break;
749 default:
750 dst.im = cat6->g && !cat6->dst_off;
751 fprintf(ctx->out, ".%s", type[cat6->type]);
752 break;
753 }
754 fprintf(ctx->out, " ");
755
756 switch (_OPC(6, cat6->opc)) {
757 case OPC_STG:
758 sd = 'g';
759 break;
760 case OPC_STP:
761 sd = 'p';
762 break;
763 case OPC_STL:
764 case OPC_STLW:
765 sd = 'l';
766 break;
767
768 case OPC_LDG:
769 case OPC_LDC:
770 ss = 'g';
771 break;
772 case OPC_LDP:
773 ss = 'p';
774 break;
775 case OPC_LDL:
776 case OPC_LDLW:
777 case OPC_LDLV:
778 ss = 'l';
779 break;
780
781 case OPC_L2G:
782 ss = 'l';
783 sd = 'g';
784 break;
785
786 case OPC_G2L:
787 ss = 'g';
788 sd = 'l';
789 break;
790
791 case OPC_PREFETCH:
792 ss = 'g';
793 nodst = true;
794 break;
795 }
796
797 if ((_OPC(6, cat6->opc) == OPC_STGB) || (_OPC(6, cat6->opc) == OPC_STIB)) {
798 struct reginfo src3;
799
800 memset(&src3, 0, sizeof(src3));
801
802 src1.reg = (reg_t)(cat6->stgb.src1);
803 src2.reg = (reg_t)(cat6->stgb.src2);
804 src2.im = cat6->stgb.src2_im;
805 src3.reg = (reg_t)(cat6->stgb.src3);
806 src3.im = cat6->stgb.src3_im;
807 src3.full = true;
808
809 fprintf(ctx->out, "g[%u], ", cat6->stgb.dst_ssbo);
810 print_src(ctx, &src1);
811 fprintf(ctx->out, ", ");
812 print_src(ctx, &src2);
813 fprintf(ctx->out, ", ");
814 print_src(ctx, &src3);
815
816 if (debug & PRINT_VERBOSE)
817 fprintf(ctx->out, " (pad0=%x, pad3=%x)", cat6->stgb.pad0, cat6->stgb.pad3);
818
819 return;
820 }
821
822 if (is_atomic(_OPC(6, cat6->opc))) {
823
824 src1.reg = (reg_t)(cat6->ldgb.src1);
825 src1.im = cat6->ldgb.src1_im;
826 src2.reg = (reg_t)(cat6->ldgb.src2);
827 src2.im = cat6->ldgb.src2_im;
828 dst.reg = (reg_t)(cat6->ldgb.dst);
829
830 print_src(ctx, &dst);
831 fprintf(ctx->out, ", ");
832 if (ss == 'g') {
833 struct reginfo src3;
834 memset(&src3, 0, sizeof(src3));
835
836 src3.reg = (reg_t)(cat6->ldgb.src3);
837 src3.full = true;
838
839 /* For images, the ".typed" variant is used and src2 is
840 * the ivecN coordinates, ie ivec2 for 2d.
841 *
842 * For SSBOs, the ".untyped" variant is used and src2 is
843 * a simple dword offset.. src3 appears to be
844 * uvec2(offset * 4, 0). Not sure the point of that.
845 */
846
847 fprintf(ctx->out, "g[%u], ", cat6->ldgb.src_ssbo);
848 print_src(ctx, &src1); /* value */
849 fprintf(ctx->out, ", ");
850 print_src(ctx, &src2); /* offset/coords */
851 fprintf(ctx->out, ", ");
852 print_src(ctx, &src3); /* 64b byte offset.. */
853
854 if (debug & PRINT_VERBOSE) {
855 fprintf(ctx->out, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6->ldgb.pad0,
856 cat6->ldgb.pad3, cat6->ldgb.mustbe0);
857 }
858 } else { /* ss == 'l' */
859 fprintf(ctx->out, "l[");
860 print_src(ctx, &src1); /* simple byte offset */
861 fprintf(ctx->out, "], ");
862 print_src(ctx, &src2); /* value */
863
864 if (debug & PRINT_VERBOSE) {
865 fprintf(ctx->out, " (src3=%x, pad0=%x, pad3=%x, mustbe0=%x)",
866 cat6->ldgb.src3, cat6->ldgb.pad0,
867 cat6->ldgb.pad3, cat6->ldgb.mustbe0);
868 }
869 }
870
871 return;
872 } else if (_OPC(6, cat6->opc) == OPC_RESINFO) {
873 dst.reg = (reg_t)(cat6->ldgb.dst);
874
875 print_src(ctx, &dst);
876 fprintf(ctx->out, ", ");
877 fprintf(ctx->out, "g[%u]", cat6->ldgb.src_ssbo);
878
879 return;
880 } else if (_OPC(6, cat6->opc) == OPC_LDGB) {
881
882 src1.reg = (reg_t)(cat6->ldgb.src1);
883 src1.im = cat6->ldgb.src1_im;
884 src2.reg = (reg_t)(cat6->ldgb.src2);
885 src2.im = cat6->ldgb.src2_im;
886 dst.reg = (reg_t)(cat6->ldgb.dst);
887
888 print_src(ctx, &dst);
889 fprintf(ctx->out, ", ");
890 fprintf(ctx->out, "g[%u], ", cat6->ldgb.src_ssbo);
891 print_src(ctx, &src1);
892 fprintf(ctx->out, ", ");
893 print_src(ctx, &src2);
894
895 if (debug & PRINT_VERBOSE)
896 fprintf(ctx->out, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6->ldgb.pad0, cat6->ldgb.pad3, cat6->ldgb.mustbe0);
897
898 return;
899 } else if (_OPC(6, cat6->opc) == OPC_LDG && cat6->a.src1_im && cat6->a.src2_im) {
900 struct reginfo src3;
901
902 memset(&src3, 0, sizeof(src3));
903 src1.reg = (reg_t)(cat6->a.src1);
904 src2.reg = (reg_t)(cat6->a.src2);
905 src2.im = cat6->a.src2_im;
906 src3.reg = (reg_t)(cat6->a.off);
907 src3.full = true;
908 dst.reg = (reg_t)(cat6->d.dst);
909
910 print_src(ctx, &dst);
911 fprintf(ctx->out, ", g[");
912 print_src(ctx, &src1);
913 fprintf(ctx->out, "+");
914 print_src(ctx, &src3);
915 fprintf(ctx->out, "], ");
916 print_src(ctx, &src2);
917
918 return;
919 }
920 if (cat6->dst_off) {
921 dst.reg = (reg_t)(cat6->c.dst);
922 dstoff = cat6->c.off;
923 } else {
924 dst.reg = (reg_t)(cat6->d.dst);
925 }
926
927 if (cat6->src_off) {
928 src1.reg = (reg_t)(cat6->a.src1);
929 src1.im = cat6->a.src1_im;
930 src2.reg = (reg_t)(cat6->a.src2);
931 src2.im = cat6->a.src2_im;
932 src1off = cat6->a.off;
933 } else {
934 src1.reg = (reg_t)(cat6->b.src1);
935 src1.im = cat6->b.src1_im;
936 src2.reg = (reg_t)(cat6->b.src2);
937 src2.im = cat6->b.src2_im;
938 }
939
940 if (!nodst) {
941 if (sd)
942 fprintf(ctx->out, "%c[", sd);
943 /* note: dst might actually be a src (ie. address to store to) */
944 print_src(ctx, &dst);
945 if (cat6->dst_off && cat6->g) {
946 struct reginfo dstoff_reg = {0};
947 dstoff_reg.reg = (reg_t) cat6->c.off;
948 dstoff_reg.full = true;
949 fprintf(ctx->out, "+");
950 print_src(ctx, &dstoff_reg);
951 } else if (dstoff)
952 fprintf(ctx->out, "%+d", dstoff);
953 if (sd)
954 fprintf(ctx->out, "]");
955 fprintf(ctx->out, ", ");
956 }
957
958 if (ss)
959 fprintf(ctx->out, "%c[", ss);
960
961 /* can have a larger than normal immed, so hack: */
962 if (src1.im) {
963 fprintf(ctx->out, "%u", src1.reg.dummy13);
964 } else {
965 print_src(ctx, &src1);
966 }
967
968 if (cat6->src_off && cat6->g)
969 print_src(ctx, &src2);
970 else if (src1off)
971 fprintf(ctx->out, "%+d", src1off);
972 if (ss)
973 fprintf(ctx->out, "]");
974
975 switch (_OPC(6, cat6->opc)) {
976 case OPC_RESINFO:
977 case OPC_RESFMT:
978 break;
979 default:
980 fprintf(ctx->out, ", ");
981 print_src(ctx, &src2);
982 break;
983 }
984 }
985
986 static void print_instr_cat6_a6xx(struct disasm_ctx *ctx, instr_t *instr)
987 {
988 instr_cat6_a6xx_t *cat6 = &instr->cat6_a6xx;
989 struct reginfo src1, src2, ssbo;
990 uint32_t opc = _OPC(6, cat6->opc);
991 bool uses_type = opc != OPC_LDC;
992
993 static const struct {
994 bool indirect;
995 bool bindless;
996 const char *name;
997 } desc_features[8] = {
998 [CAT6_IMM] = {
999 .name = "imm"
1000 },
1001 [CAT6_UNIFORM] = {
1002 .indirect = true,
1003 .name = "uniform"
1004 },
1005 [CAT6_NONUNIFORM] = {
1006 .indirect = true,
1007 .name = "nonuniform"
1008 },
1009 [CAT6_BINDLESS_IMM] = {
1010 .bindless = true,
1011 .name = "imm"
1012 },
1013 [CAT6_BINDLESS_UNIFORM] = {
1014 .bindless = true,
1015 .indirect = true,
1016 .name = "uniform"
1017 },
1018 [CAT6_BINDLESS_NONUNIFORM] = {
1019 .bindless = true,
1020 .indirect = true,
1021 .name = "nonuniform"
1022 },
1023 };
1024
1025 bool indirect_ssbo = desc_features[cat6->desc_mode].indirect;
1026 bool bindless = desc_features[cat6->desc_mode].bindless;
1027 bool type_full = cat6->type != TYPE_U16;
1028
1029
1030 memset(&src1, 0, sizeof(src1));
1031 memset(&src2, 0, sizeof(src2));
1032 memset(&ssbo, 0, sizeof(ssbo));
1033
1034 if (uses_type) {
1035 fprintf(ctx->out, ".%s", cat6->typed ? "typed" : "untyped");
1036 fprintf(ctx->out, ".%dd", cat6->d + 1);
1037 fprintf(ctx->out, ".%s", type[cat6->type]);
1038 } else {
1039 fprintf(ctx->out, ".offset%d", cat6->d);
1040 }
1041 fprintf(ctx->out, ".%u", cat6->type_size + 1);
1042
1043 fprintf(ctx->out, ".%s", desc_features[cat6->desc_mode].name);
1044 if (bindless)
1045 fprintf(ctx->out, ".base%d", cat6->base);
1046 fprintf(ctx->out, " ");
1047
1048 src2.reg = (reg_t)(cat6->src2);
1049 src2.full = type_full;
1050 print_src(ctx, &src2);
1051 fprintf(ctx->out, ", ");
1052
1053 if (opc != OPC_RESINFO) {
1054 src1.reg = (reg_t)(cat6->src1);
1055 src1.full = true; // XXX
1056 print_src(ctx, &src1);
1057 fprintf(ctx->out, ", ");
1058 }
1059
1060 ssbo.reg = (reg_t)(cat6->ssbo);
1061 ssbo.im = !indirect_ssbo;
1062 ssbo.full = true;
1063 print_src(ctx, &ssbo);
1064
1065 if (debug & PRINT_VERBOSE) {
1066 fprintf(ctx->out, " (pad1=%x, pad2=%x, pad3=%x, pad4=%x, pad5=%x)",
1067 cat6->pad1, cat6->pad2, cat6->pad3, cat6->pad4, cat6->pad5);
1068 }
1069 }
1070
1071 static void print_instr_cat6(struct disasm_ctx *ctx, instr_t *instr)
1072 {
1073 if (!is_cat6_legacy(instr, ctx->gpu_id)) {
1074 print_instr_cat6_a6xx(ctx, instr);
1075 if (debug & PRINT_VERBOSE)
1076 fprintf(ctx->out, " NEW");
1077 } else {
1078 print_instr_cat6_a3xx(ctx, instr);
1079 if (debug & PRINT_VERBOSE)
1080 fprintf(ctx->out, " LEGACY");
1081 }
1082 }
1083 static void print_instr_cat7(struct disasm_ctx *ctx, instr_t *instr)
1084 {
1085 instr_cat7_t *cat7 = &instr->cat7;
1086
1087 if (cat7->g)
1088 fprintf(ctx->out, ".g");
1089 if (cat7->l)
1090 fprintf(ctx->out, ".l");
1091
1092 if (_OPC(7, cat7->opc) == OPC_FENCE) {
1093 if (cat7->r)
1094 fprintf(ctx->out, ".r");
1095 if (cat7->w)
1096 fprintf(ctx->out, ".w");
1097 }
1098 }
1099
1100 /* size of largest OPC field of all the instruction categories: */
1101 #define NOPC_BITS 6
1102
1103 static const struct opc_info {
1104 uint16_t cat;
1105 uint16_t opc;
1106 const char *name;
1107 void (*print)(struct disasm_ctx *ctx, instr_t *instr);
1108 } opcs[1 << (3+NOPC_BITS)] = {
1109 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat }
1110 /* category 0: */
1111 OPC(0, OPC_NOP, nop),
1112 OPC(0, OPC_B, b),
1113 OPC(0, OPC_JUMP, jump),
1114 OPC(0, OPC_CALL, call),
1115 OPC(0, OPC_RET, ret),
1116 OPC(0, OPC_KILL, kill),
1117 OPC(0, OPC_END, end),
1118 OPC(0, OPC_EMIT, emit),
1119 OPC(0, OPC_CUT, cut),
1120 OPC(0, OPC_CHMASK, chmask),
1121 OPC(0, OPC_CHSH, chsh),
1122 OPC(0, OPC_FLOW_REV, flow_rev),
1123 OPC(0, OPC_PREDT, predt),
1124 OPC(0, OPC_PREDF, predf),
1125 OPC(0, OPC_PREDE, prede),
1126 OPC(0, OPC_BKT, bkt),
1127 OPC(0, OPC_STKS, stks),
1128 OPC(0, OPC_STKR, stkr),
1129 OPC(0, OPC_XSET, xset),
1130 OPC(0, OPC_XCLR, xclr),
1131 OPC(0, OPC_GETONE, getone),
1132 OPC(0, OPC_DBG, dbg),
1133 OPC(0, OPC_SHPS, shps),
1134 OPC(0, OPC_SHPE, shpe),
1135
1136 /* category 1: */
1137 OPC(1, OPC_MOV, ),
1138
1139 /* category 2: */
1140 OPC(2, OPC_ADD_F, add.f),
1141 OPC(2, OPC_MIN_F, min.f),
1142 OPC(2, OPC_MAX_F, max.f),
1143 OPC(2, OPC_MUL_F, mul.f),
1144 OPC(2, OPC_SIGN_F, sign.f),
1145 OPC(2, OPC_CMPS_F, cmps.f),
1146 OPC(2, OPC_ABSNEG_F, absneg.f),
1147 OPC(2, OPC_CMPV_F, cmpv.f),
1148 OPC(2, OPC_FLOOR_F, floor.f),
1149 OPC(2, OPC_CEIL_F, ceil.f),
1150 OPC(2, OPC_RNDNE_F, rndne.f),
1151 OPC(2, OPC_RNDAZ_F, rndaz.f),
1152 OPC(2, OPC_TRUNC_F, trunc.f),
1153 OPC(2, OPC_ADD_U, add.u),
1154 OPC(2, OPC_ADD_S, add.s),
1155 OPC(2, OPC_SUB_U, sub.u),
1156 OPC(2, OPC_SUB_S, sub.s),
1157 OPC(2, OPC_CMPS_U, cmps.u),
1158 OPC(2, OPC_CMPS_S, cmps.s),
1159 OPC(2, OPC_MIN_U, min.u),
1160 OPC(2, OPC_MIN_S, min.s),
1161 OPC(2, OPC_MAX_U, max.u),
1162 OPC(2, OPC_MAX_S, max.s),
1163 OPC(2, OPC_ABSNEG_S, absneg.s),
1164 OPC(2, OPC_AND_B, and.b),
1165 OPC(2, OPC_OR_B, or.b),
1166 OPC(2, OPC_NOT_B, not.b),
1167 OPC(2, OPC_XOR_B, xor.b),
1168 OPC(2, OPC_CMPV_U, cmpv.u),
1169 OPC(2, OPC_CMPV_S, cmpv.s),
1170 OPC(2, OPC_MUL_U24, mul.u24),
1171 OPC(2, OPC_MUL_S24, mul.s24),
1172 OPC(2, OPC_MULL_U, mull.u),
1173 OPC(2, OPC_BFREV_B, bfrev.b),
1174 OPC(2, OPC_CLZ_S, clz.s),
1175 OPC(2, OPC_CLZ_B, clz.b),
1176 OPC(2, OPC_SHL_B, shl.b),
1177 OPC(2, OPC_SHR_B, shr.b),
1178 OPC(2, OPC_ASHR_B, ashr.b),
1179 OPC(2, OPC_BARY_F, bary.f),
1180 OPC(2, OPC_MGEN_B, mgen.b),
1181 OPC(2, OPC_GETBIT_B, getbit.b),
1182 OPC(2, OPC_SETRM, setrm),
1183 OPC(2, OPC_CBITS_B, cbits.b),
1184 OPC(2, OPC_SHB, shb),
1185 OPC(2, OPC_MSAD, msad),
1186
1187 /* category 3: */
1188 OPC(3, OPC_MAD_U16, mad.u16),
1189 OPC(3, OPC_MADSH_U16, madsh.u16),
1190 OPC(3, OPC_MAD_S16, mad.s16),
1191 OPC(3, OPC_MADSH_M16, madsh.m16),
1192 OPC(3, OPC_MAD_U24, mad.u24),
1193 OPC(3, OPC_MAD_S24, mad.s24),
1194 OPC(3, OPC_MAD_F16, mad.f16),
1195 OPC(3, OPC_MAD_F32, mad.f32),
1196 OPC(3, OPC_SEL_B16, sel.b16),
1197 OPC(3, OPC_SEL_B32, sel.b32),
1198 OPC(3, OPC_SEL_S16, sel.s16),
1199 OPC(3, OPC_SEL_S32, sel.s32),
1200 OPC(3, OPC_SEL_F16, sel.f16),
1201 OPC(3, OPC_SEL_F32, sel.f32),
1202 OPC(3, OPC_SAD_S16, sad.s16),
1203 OPC(3, OPC_SAD_S32, sad.s32),
1204
1205 /* category 4: */
1206 OPC(4, OPC_RCP, rcp),
1207 OPC(4, OPC_RSQ, rsq),
1208 OPC(4, OPC_LOG2, log2),
1209 OPC(4, OPC_EXP2, exp2),
1210 OPC(4, OPC_SIN, sin),
1211 OPC(4, OPC_COS, cos),
1212 OPC(4, OPC_SQRT, sqrt),
1213 OPC(4, OPC_HRSQ, hrsq),
1214 OPC(4, OPC_HLOG2, hlog2),
1215 OPC(4, OPC_HEXP2, hexp2),
1216
1217 /* category 5: */
1218 OPC(5, OPC_ISAM, isam),
1219 OPC(5, OPC_ISAML, isaml),
1220 OPC(5, OPC_ISAMM, isamm),
1221 OPC(5, OPC_SAM, sam),
1222 OPC(5, OPC_SAMB, samb),
1223 OPC(5, OPC_SAML, saml),
1224 OPC(5, OPC_SAMGQ, samgq),
1225 OPC(5, OPC_GETLOD, getlod),
1226 OPC(5, OPC_CONV, conv),
1227 OPC(5, OPC_CONVM, convm),
1228 OPC(5, OPC_GETSIZE, getsize),
1229 OPC(5, OPC_GETBUF, getbuf),
1230 OPC(5, OPC_GETPOS, getpos),
1231 OPC(5, OPC_GETINFO, getinfo),
1232 OPC(5, OPC_DSX, dsx),
1233 OPC(5, OPC_DSY, dsy),
1234 OPC(5, OPC_GATHER4R, gather4r),
1235 OPC(5, OPC_GATHER4G, gather4g),
1236 OPC(5, OPC_GATHER4B, gather4b),
1237 OPC(5, OPC_GATHER4A, gather4a),
1238 OPC(5, OPC_SAMGP0, samgp0),
1239 OPC(5, OPC_SAMGP1, samgp1),
1240 OPC(5, OPC_SAMGP2, samgp2),
1241 OPC(5, OPC_SAMGP3, samgp3),
1242 OPC(5, OPC_DSXPP_1, dsxpp.1),
1243 OPC(5, OPC_DSYPP_1, dsypp.1),
1244 OPC(5, OPC_RGETPOS, rgetpos),
1245 OPC(5, OPC_RGETINFO, rgetinfo),
1246
1247
1248 /* category 6: */
1249 OPC(6, OPC_LDG, ldg),
1250 OPC(6, OPC_LDL, ldl),
1251 OPC(6, OPC_LDP, ldp),
1252 OPC(6, OPC_STG, stg),
1253 OPC(6, OPC_STL, stl),
1254 OPC(6, OPC_STP, stp),
1255 OPC(6, OPC_LDIB, ldib),
1256 OPC(6, OPC_G2L, g2l),
1257 OPC(6, OPC_L2G, l2g),
1258 OPC(6, OPC_PREFETCH, prefetch),
1259 OPC(6, OPC_LDLW, ldlw),
1260 OPC(6, OPC_STLW, stlw),
1261 OPC(6, OPC_RESFMT, resfmt),
1262 OPC(6, OPC_RESINFO, resinfo),
1263 OPC(6, OPC_ATOMIC_ADD, atomic.add),
1264 OPC(6, OPC_ATOMIC_SUB, atomic.sub),
1265 OPC(6, OPC_ATOMIC_XCHG, atomic.xchg),
1266 OPC(6, OPC_ATOMIC_INC, atomic.inc),
1267 OPC(6, OPC_ATOMIC_DEC, atomic.dec),
1268 OPC(6, OPC_ATOMIC_CMPXCHG, atomic.cmpxchg),
1269 OPC(6, OPC_ATOMIC_MIN, atomic.min),
1270 OPC(6, OPC_ATOMIC_MAX, atomic.max),
1271 OPC(6, OPC_ATOMIC_AND, atomic.and),
1272 OPC(6, OPC_ATOMIC_OR, atomic.or),
1273 OPC(6, OPC_ATOMIC_XOR, atomic.xor),
1274 OPC(6, OPC_LDGB, ldgb),
1275 OPC(6, OPC_STGB, stgb),
1276 OPC(6, OPC_STIB, stib),
1277 OPC(6, OPC_LDC, ldc),
1278 OPC(6, OPC_LDLV, ldlv),
1279
1280 OPC(7, OPC_BAR, bar),
1281 OPC(7, OPC_FENCE, fence),
1282
1283 #undef OPC
1284 };
1285
1286 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr, ctx->gpu_id)]))
1287
1288 // XXX hack.. probably should move this table somewhere common:
1289 #include "ir3.h"
1290 const char *ir3_instr_name(struct ir3_instruction *instr)
1291 {
1292 if (opc_cat(instr->opc) == -1) return "??meta??";
1293 return opcs[instr->opc].name;
1294 }
1295
1296 static void print_single_instr(struct disasm_ctx *ctx, instr_t *instr)
1297 {
1298 const char *name = GETINFO(instr)->name;
1299 uint32_t opc = instr_opc(instr, ctx->gpu_id);
1300
1301 if (name) {
1302 fprintf(ctx->out, "%s", name);
1303 GETINFO(instr)->print(ctx, instr);
1304 } else {
1305 fprintf(ctx->out, "unknown(%d,%d)", instr->opc_cat, opc);
1306
1307 switch (instr->opc_cat) {
1308 case 0: print_instr_cat0(ctx, instr); break;
1309 case 1: print_instr_cat1(ctx, instr); break;
1310 case 2: print_instr_cat2(ctx, instr); break;
1311 case 3: print_instr_cat3(ctx, instr); break;
1312 case 4: print_instr_cat4(ctx, instr); break;
1313 case 5: print_instr_cat5(ctx, instr); break;
1314 case 6: print_instr_cat6(ctx, instr); break;
1315 case 7: print_instr_cat7(ctx, instr); break;
1316 }
1317 }
1318 }
1319
1320 static bool print_instr(struct disasm_ctx *ctx, uint32_t *dwords, int n)
1321 {
1322 instr_t *instr = (instr_t *)dwords;
1323 uint32_t opc = instr_opc(instr, ctx->gpu_id);
1324 unsigned nop = 0;
1325 unsigned cycles = ctx->instructions;
1326
1327 if (debug & PRINT_VERBOSE) {
1328 fprintf(ctx->out, "%s%04d:%04d[%08xx_%08xx] ", levels[ctx->level],
1329 n, cycles++, dwords[1], dwords[0]);
1330 }
1331
1332 /* NOTE: order flags are printed is a bit fugly.. but for now I
1333 * try to match the order in llvm-a3xx disassembler for easy
1334 * diff'ing..
1335 */
1336
1337 ctx->repeat = instr_repeat(instr);
1338 ctx->instructions += 1 + ctx->repeat;
1339
1340 if (instr->sync) {
1341 fprintf(ctx->out, "(sy)");
1342 }
1343 if (instr->ss && ((instr->opc_cat <= 4) || (instr->opc_cat == 7))) {
1344 fprintf(ctx->out, "(ss)");
1345 }
1346 if (instr->jmp_tgt)
1347 fprintf(ctx->out, "(jp)");
1348 if ((instr->opc_cat == 0) && instr->cat0.eq)
1349 fprintf(ctx->out, "(eq)");
1350 if (instr_sat(instr))
1351 fprintf(ctx->out, "(sat)");
1352 if (ctx->repeat)
1353 fprintf(ctx->out, "(rpt%d)", ctx->repeat);
1354 else if ((instr->opc_cat == 2) && (instr->cat2.src1_r || instr->cat2.src2_r))
1355 nop = (instr->cat2.src2_r * 2) + instr->cat2.src1_r;
1356 else if ((instr->opc_cat == 3) && (instr->cat3.src1_r || instr->cat3.src2_r))
1357 nop = (instr->cat3.src2_r * 2) + instr->cat3.src1_r;
1358 ctx->instructions += nop;
1359 if (nop)
1360 fprintf(ctx->out, "(nop%d) ", nop);
1361
1362 if (instr->ul && ((2 <= instr->opc_cat) && (instr->opc_cat <= 4)))
1363 fprintf(ctx->out, "(ul)");
1364
1365 print_single_instr(ctx, instr);
1366 fprintf(ctx->out, "\n");
1367
1368 if ((instr->opc_cat <= 4) && (debug & EXPAND_REPEAT)) {
1369 int i;
1370 for (i = 0; i < nop; i++) {
1371 if (debug & PRINT_VERBOSE) {
1372 fprintf(ctx->out, "%s%04d:%04d[ ] ",
1373 levels[ctx->level], n, cycles++);
1374 }
1375 fprintf(ctx->out, "nop\n");
1376 }
1377 for (i = 0; i < ctx->repeat; i++) {
1378 ctx->repeatidx = i + 1;
1379 if (debug & PRINT_VERBOSE) {
1380 fprintf(ctx->out, "%s%04d:%04d[ ] ",
1381 levels[ctx->level], n, cycles++);
1382 }
1383 print_single_instr(ctx, instr);
1384 fprintf(ctx->out, "\n");
1385 }
1386 ctx->repeatidx = 0;
1387 }
1388
1389 return (instr->opc_cat == 0) && (opc == OPC_END);
1390 }
1391
1392 int disasm_a3xx(uint32_t *dwords, int sizedwords, int level, FILE *out, unsigned gpu_id)
1393 {
1394 struct disasm_ctx ctx;
1395 int i;
1396 int nop_count = 0;
1397
1398 assert((sizedwords % 2) == 0);
1399
1400 memset(&ctx, 0, sizeof(ctx));
1401 ctx.out = out;
1402 ctx.level = level;
1403 ctx.gpu_id = gpu_id;
1404
1405 for (i = 0; i < sizedwords; i += 2) {
1406 print_instr(&ctx, &dwords[i], i/2);
1407 if (dwords[i] == 0 && dwords[i + 1] == 0)
1408 nop_count++;
1409 else
1410 nop_count = 0;
1411 if (nop_count > 3)
1412 break;
1413 }
1414
1415 return 0;
1416 }