2 * Copyright (c) 2013 Rob Clark <robdclark@gmail.com>
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:
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
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
31 #include <util/u_debug.h>
33 #include "instr-a3xx.h"
35 /* bitmask of debug flags */
37 PRINT_RAW
= 0x1, /* dump raw hexdump */
42 static enum debug_t debug
;
44 #define printf debug_printf
46 static const char *levels
[] = {
65 static const char *component
= "xyzw";
67 static const char *type
[] = {
83 /* current instruction repeat flag: */
85 /* current instruction repeat indx/offset (for --expand): */
89 static void print_reg(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
90 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
92 const char type
= c
? 'c' : 'r';
94 // XXX I prefer - and || for neg/abs, but preserving format used
95 // by libllvm-a3xx for easy diffing..
98 fprintf(ctx
->out
, "(absneg)");
100 fprintf(ctx
->out
, "(neg)");
102 fprintf(ctx
->out
, "(abs)");
105 fprintf(ctx
->out
, "(r)");
108 fprintf(ctx
->out
, "%d", reg
.iim_val
);
109 } else if (addr_rel
) {
110 /* I would just use %+d but trying to make it diff'able with
114 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
? "" : "h", type
, -reg
.iim_val
);
115 else if (reg
.iim_val
> 0)
116 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
? "" : "h", type
, reg
.iim_val
);
118 fprintf(ctx
->out
, "%s%c<a0.x>", full
? "" : "h", type
);
119 } else if ((reg
.num
== REG_A0
) && !c
) {
120 fprintf(ctx
->out
, "a0.%c", component
[reg
.comp
]);
121 } else if ((reg
.num
== REG_P0
) && !c
) {
122 fprintf(ctx
->out
, "p0.%c", component
[reg
.comp
]);
124 fprintf(ctx
->out
, "%s%c%d.%c", full
? "" : "h", type
, reg
.num
, component
[reg
.comp
]);
128 static unsigned regidx(reg_t reg
)
130 return (4 * reg
.num
) + reg
.comp
;
133 static reg_t
idxreg(unsigned idx
)
141 static void print_reg_dst(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool addr_rel
)
143 reg
= idxreg(regidx(reg
) + ctx
->repeatidx
);
144 print_reg(ctx
, reg
, full
, false, false, false, false, false, addr_rel
);
147 static void print_reg_src(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
148 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
151 reg
= idxreg(regidx(reg
) + ctx
->repeatidx
);
153 print_reg(ctx
, reg
, full
, r
, c
, im
, neg
, abs
, addr_rel
);
156 /* TODO switch to using reginfo struct everywhere, since more readable
157 * than passing a bunch of bools to print_reg_src
171 static void print_src(struct disasm_ctx
*ctx
, struct reginfo
*info
)
173 print_reg_src(ctx
, info
->reg
, info
->full
, info
->r
, info
->c
, info
->im
,
174 info
->neg
, info
->abs
, info
->addr_rel
);
177 //static void print_dst(struct disasm_ctx *ctx, struct reginfo *info)
179 // print_reg_dst(ctx, info->reg, info->full, info->addr_rel);
182 static void print_instr_cat0(struct disasm_ctx
*ctx
, instr_t
*instr
)
184 instr_cat0_t
*cat0
= &instr
->cat0
;
189 fprintf(ctx
->out
, " %sp0.%c", cat0
->inv
? "!" : "",
190 component
[cat0
->comp
]);
193 fprintf(ctx
->out
, " %sp0.%c, #%d", cat0
->inv
? "!" : "",
194 component
[cat0
->comp
], cat0
->a3xx
.immed
);
198 fprintf(ctx
->out
, " #%d", cat0
->a3xx
.immed
);
202 if ((debug
& PRINT_VERBOSE
) && (cat0
->dummy2
|cat0
->dummy3
|cat0
->dummy4
))
203 fprintf(ctx
->out
, "\t{0: %x,%x,%x}", cat0
->dummy2
, cat0
->dummy3
, cat0
->dummy4
);
206 static void print_instr_cat1(struct disasm_ctx
*ctx
, instr_t
*instr
)
208 instr_cat1_t
*cat1
= &instr
->cat1
;
211 fprintf(ctx
->out
, "(ul)");
213 if (cat1
->src_type
== cat1
->dst_type
) {
214 if ((cat1
->src_type
== TYPE_S16
) && (((reg_t
)cat1
->dst
).num
== REG_A0
)) {
215 /* special case (nmemonic?): */
216 fprintf(ctx
->out
, "mova");
218 fprintf(ctx
->out
, "mov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
221 fprintf(ctx
->out
, "cov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
224 fprintf(ctx
->out
, " ");
227 fprintf(ctx
->out
, "(even)");
230 fprintf(ctx
->out
, "(pos_infinity)");
232 print_reg_dst(ctx
, (reg_t
)(cat1
->dst
), type_size(cat1
->dst_type
) == 32,
235 fprintf(ctx
->out
, ", ");
237 /* ugg, have to special case this.. vs print_reg().. */
239 if (type_float(cat1
->src_type
))
240 fprintf(ctx
->out
, "(%f)", cat1
->fim_val
);
241 else if (type_uint(cat1
->src_type
))
242 fprintf(ctx
->out
, "0x%08x", cat1
->uim_val
);
244 fprintf(ctx
->out
, "%d", cat1
->iim_val
);
245 } else if (cat1
->src_rel
&& !cat1
->src_c
) {
246 /* I would just use %+d but trying to make it diff'able with
249 char type
= cat1
->src_rel_c
? 'c' : 'r';
250 const char *full
= (type_size(cat1
->src_type
) == 32) ? "" : "h";
252 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
, type
, -cat1
->off
);
253 else if (cat1
->off
> 0)
254 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
, type
, cat1
->off
);
256 fprintf(ctx
->out
, "%s%c<a0.x>", full
, type
);
258 print_reg_src(ctx
, (reg_t
)(cat1
->src
), type_size(cat1
->src_type
) == 32,
259 cat1
->src_r
, cat1
->src_c
, cat1
->src_im
, false, false, false);
262 if ((debug
& PRINT_VERBOSE
) && (cat1
->must_be_0
))
263 fprintf(ctx
->out
, "\t{1: %x}", cat1
->must_be_0
);
266 static void print_instr_cat2(struct disasm_ctx
*ctx
, instr_t
*instr
)
268 instr_cat2_t
*cat2
= &instr
->cat2
;
269 static const char *cond
[] = {
279 switch (_OPC(2, cat2
->opc
)) {
286 fprintf(ctx
->out
, ".%s", cond
[cat2
->cond
]);
290 fprintf(ctx
->out
, " ");
292 fprintf(ctx
->out
, "(ei)");
293 print_reg_dst(ctx
, (reg_t
)(cat2
->dst
), cat2
->full
^ cat2
->dst_half
, false);
294 fprintf(ctx
->out
, ", ");
296 unsigned src1_r
= cat2
->repeat
? cat2
->src1_r
: 0;
297 if (cat2
->c1
.src1_c
) {
298 print_reg_src(ctx
, (reg_t
)(cat2
->c1
.src1
), cat2
->full
, src1_r
,
299 cat2
->c1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
300 cat2
->src1_abs
, false);
301 } else if (cat2
->rel1
.src1_rel
) {
302 print_reg_src(ctx
, (reg_t
)(cat2
->rel1
.src1
), cat2
->full
, src1_r
,
303 cat2
->rel1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
304 cat2
->src1_abs
, cat2
->rel1
.src1_rel
);
306 print_reg_src(ctx
, (reg_t
)(cat2
->src1
), cat2
->full
, src1_r
,
307 false, cat2
->src1_im
, cat2
->src1_neg
,
308 cat2
->src1_abs
, false);
311 unsigned src2_r
= cat2
->repeat
? cat2
->src2_r
: 0;
312 switch (_OPC(2, cat2
->opc
)) {
327 /* these only have one src reg */
330 fprintf(ctx
->out
, ", ");
331 if (cat2
->c2
.src2_c
) {
332 print_reg_src(ctx
, (reg_t
)(cat2
->c2
.src2
), cat2
->full
, src2_r
,
333 cat2
->c2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
334 cat2
->src2_abs
, false);
335 } else if (cat2
->rel2
.src2_rel
) {
336 print_reg_src(ctx
, (reg_t
)(cat2
->rel2
.src2
), cat2
->full
, src2_r
,
337 cat2
->rel2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
338 cat2
->src2_abs
, cat2
->rel2
.src2_rel
);
340 print_reg_src(ctx
, (reg_t
)(cat2
->src2
), cat2
->full
, src2_r
,
341 false, cat2
->src2_im
, cat2
->src2_neg
,
342 cat2
->src2_abs
, false);
348 static void print_instr_cat3(struct disasm_ctx
*ctx
, instr_t
*instr
)
350 instr_cat3_t
*cat3
= &instr
->cat3
;
351 bool full
= instr_cat3_full(cat3
);
353 fprintf(ctx
->out
, " ");
354 print_reg_dst(ctx
, (reg_t
)(cat3
->dst
), full
^ cat3
->dst_half
, false);
355 fprintf(ctx
->out
, ", ");
356 unsigned src1_r
= cat3
->repeat
? cat3
->src1_r
: 0;
357 if (cat3
->c1
.src1_c
) {
358 print_reg_src(ctx
, (reg_t
)(cat3
->c1
.src1
), full
,
359 src1_r
, cat3
->c1
.src1_c
, false, cat3
->src1_neg
,
361 } else if (cat3
->rel1
.src1_rel
) {
362 print_reg_src(ctx
, (reg_t
)(cat3
->rel1
.src1
), full
,
363 src1_r
, cat3
->rel1
.src1_c
, false, cat3
->src1_neg
,
364 false, cat3
->rel1
.src1_rel
);
366 print_reg_src(ctx
, (reg_t
)(cat3
->src1
), full
,
367 src1_r
, false, false, cat3
->src1_neg
,
370 fprintf(ctx
->out
, ", ");
371 unsigned src2_r
= cat3
->repeat
? cat3
->src2_r
: 0;
372 print_reg_src(ctx
, (reg_t
)cat3
->src2
, full
,
373 src2_r
, cat3
->src2_c
, false, cat3
->src2_neg
,
375 fprintf(ctx
->out
, ", ");
376 if (cat3
->c2
.src3_c
) {
377 print_reg_src(ctx
, (reg_t
)(cat3
->c2
.src3
), full
,
378 cat3
->src3_r
, cat3
->c2
.src3_c
, false, cat3
->src3_neg
,
380 } else if (cat3
->rel2
.src3_rel
) {
381 print_reg_src(ctx
, (reg_t
)(cat3
->rel2
.src3
), full
,
382 cat3
->src3_r
, cat3
->rel2
.src3_c
, false, cat3
->src3_neg
,
383 false, cat3
->rel2
.src3_rel
);
385 print_reg_src(ctx
, (reg_t
)(cat3
->src3
), full
,
386 cat3
->src3_r
, false, false, cat3
->src3_neg
,
391 static void print_instr_cat4(struct disasm_ctx
*ctx
, instr_t
*instr
)
393 instr_cat4_t
*cat4
= &instr
->cat4
;
395 fprintf(ctx
->out
, " ");
396 print_reg_dst(ctx
, (reg_t
)(cat4
->dst
), cat4
->full
^ cat4
->dst_half
, false);
397 fprintf(ctx
->out
, ", ");
400 print_reg_src(ctx
, (reg_t
)(cat4
->c
.src
), cat4
->full
,
401 cat4
->src_r
, cat4
->c
.src_c
, cat4
->src_im
,
402 cat4
->src_neg
, cat4
->src_abs
, false);
403 } else if (cat4
->rel
.src_rel
) {
404 print_reg_src(ctx
, (reg_t
)(cat4
->rel
.src
), cat4
->full
,
405 cat4
->src_r
, cat4
->rel
.src_c
, cat4
->src_im
,
406 cat4
->src_neg
, cat4
->src_abs
, cat4
->rel
.src_rel
);
408 print_reg_src(ctx
, (reg_t
)(cat4
->src
), cat4
->full
,
409 cat4
->src_r
, false, cat4
->src_im
,
410 cat4
->src_neg
, cat4
->src_abs
, false);
413 if ((debug
& PRINT_VERBOSE
) && (cat4
->dummy1
|cat4
->dummy2
))
414 fprintf(ctx
->out
, "\t{4: %x,%x}", cat4
->dummy1
, cat4
->dummy2
);
417 static void print_instr_cat5(struct disasm_ctx
*ctx
, instr_t
*instr
)
419 static const struct {
420 bool src1
, src2
, samp
, tex
;
422 [opc_op(OPC_ISAM
)] = { true, false, true, true, },
423 [opc_op(OPC_ISAML
)] = { true, true, true, true, },
424 [opc_op(OPC_ISAMM
)] = { true, false, true, true, },
425 [opc_op(OPC_SAM
)] = { true, false, true, true, },
426 [opc_op(OPC_SAMB
)] = { true, true, true, true, },
427 [opc_op(OPC_SAML
)] = { true, true, true, true, },
428 [opc_op(OPC_SAMGQ
)] = { true, false, true, true, },
429 [opc_op(OPC_GETLOD
)] = { true, false, true, true, },
430 [opc_op(OPC_CONV
)] = { true, true, true, true, },
431 [opc_op(OPC_CONVM
)] = { true, true, true, true, },
432 [opc_op(OPC_GETSIZE
)] = { true, false, false, true, },
433 [opc_op(OPC_GETBUF
)] = { false, false, false, true, },
434 [opc_op(OPC_GETPOS
)] = { true, false, false, true, },
435 [opc_op(OPC_GETINFO
)] = { false, false, false, true, },
436 [opc_op(OPC_DSX
)] = { true, false, false, false, },
437 [opc_op(OPC_DSY
)] = { true, false, false, false, },
438 [opc_op(OPC_GATHER4R
)] = { true, false, true, true, },
439 [opc_op(OPC_GATHER4G
)] = { true, false, true, true, },
440 [opc_op(OPC_GATHER4B
)] = { true, false, true, true, },
441 [opc_op(OPC_GATHER4A
)] = { true, false, true, true, },
442 [opc_op(OPC_SAMGP0
)] = { true, false, true, true, },
443 [opc_op(OPC_SAMGP1
)] = { true, false, true, true, },
444 [opc_op(OPC_SAMGP2
)] = { true, false, true, true, },
445 [opc_op(OPC_SAMGP3
)] = { true, false, true, true, },
446 [opc_op(OPC_DSXPP_1
)] = { true, false, false, false, },
447 [opc_op(OPC_DSYPP_1
)] = { true, false, false, false, },
448 [opc_op(OPC_RGETPOS
)] = { true, false, false, false, },
449 [opc_op(OPC_RGETINFO
)] = { false, false, false, false, },
451 instr_cat5_t
*cat5
= &instr
->cat5
;
454 if (cat5
->is_3d
) fprintf(ctx
->out
, ".3d");
455 if (cat5
->is_a
) fprintf(ctx
->out
, ".a");
456 if (cat5
->is_o
) fprintf(ctx
->out
, ".o");
457 if (cat5
->is_p
) fprintf(ctx
->out
, ".p");
458 if (cat5
->is_s
) fprintf(ctx
->out
, ".s");
459 if (cat5
->is_s2en
) fprintf(ctx
->out
, ".s2en");
461 fprintf(ctx
->out
, " ");
463 switch (_OPC(5, cat5
->opc
)) {
468 fprintf(ctx
->out
, "(%s)", type
[cat5
->type
]);
472 fprintf(ctx
->out
, "(");
473 for (i
= 0; i
< 4; i
++)
474 if (cat5
->wrmask
& (1 << i
))
475 fprintf(ctx
->out
, "%c", "xyzw"[i
]);
476 fprintf(ctx
->out
, ")");
478 print_reg_dst(ctx
, (reg_t
)(cat5
->dst
), type_size(cat5
->type
) == 32, false);
480 if (info
[cat5
->opc
].src1
) {
481 fprintf(ctx
->out
, ", ");
482 print_reg_src(ctx
, (reg_t
)(cat5
->src1
), cat5
->full
, false, false, false,
483 false, false, false);
487 if (cat5
->is_o
|| info
[cat5
->opc
].src2
) {
488 fprintf(ctx
->out
, ", ");
489 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src2
), cat5
->full
,
490 false, false, false, false, false, false);
492 fprintf(ctx
->out
, ", ");
493 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src3
), false, false, false, false,
494 false, false, false);
496 if (cat5
->is_o
|| info
[cat5
->opc
].src2
) {
497 fprintf(ctx
->out
, ", ");
498 print_reg_src(ctx
, (reg_t
)(cat5
->norm
.src2
), cat5
->full
,
499 false, false, false, false, false, false);
501 if (info
[cat5
->opc
].samp
)
502 fprintf(ctx
->out
, ", s#%d", cat5
->norm
.samp
);
503 if (info
[cat5
->opc
].tex
)
504 fprintf(ctx
->out
, ", t#%d", cat5
->norm
.tex
);
507 if (debug
& PRINT_VERBOSE
) {
509 if ((debug
& PRINT_VERBOSE
) && (cat5
->s2en
.dummy1
|cat5
->s2en
.dummy2
|cat5
->dummy2
))
510 fprintf(ctx
->out
, "\t{5: %x,%x,%x}", cat5
->s2en
.dummy1
, cat5
->s2en
.dummy2
, cat5
->dummy2
);
512 if ((debug
& PRINT_VERBOSE
) && (cat5
->norm
.dummy1
|cat5
->dummy2
))
513 fprintf(ctx
->out
, "\t{5: %x,%x}", cat5
->norm
.dummy1
, cat5
->dummy2
);
518 static void print_instr_cat6_a3xx(struct disasm_ctx
*ctx
, instr_t
*instr
)
520 instr_cat6_t
*cat6
= &instr
->cat6
;
521 char sd
= 0, ss
= 0; /* dst/src address space */
523 struct reginfo dst
, src1
, src2
;
524 int src1off
= 0, dstoff
= 0;
526 memset(&dst
, 0, sizeof(dst
));
527 memset(&src1
, 0, sizeof(src1
));
528 memset(&src2
, 0, sizeof(src2
));
530 switch (_OPC(6, cat6
->opc
)) {
533 dst
.full
= type_size(cat6
->type
) == 32;
534 src1
.full
= type_size(cat6
->type
) == 32;
535 src2
.full
= type_size(cat6
->type
) == 32;
549 src1
.full
= type_size(cat6
->type
) == 32;
550 src2
.full
= type_size(cat6
->type
) == 32;
553 dst
.full
= type_size(cat6
->type
) == 32;
559 switch (_OPC(6, cat6
->opc
)) {
563 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
566 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
567 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
568 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
569 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
573 fprintf(ctx
->out
, ".%s", cat6
->stgb
.typed
? "typed" : "untyped");
574 fprintf(ctx
->out
, ".%dd", cat6
->stgb
.d
+ 1);
575 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
576 fprintf(ctx
->out
, ".%d", cat6
->stgb
.type_size
+ 1);
580 case OPC_ATOMIC_XCHG
:
583 case OPC_ATOMIC_CMPXCHG
:
589 ss
= cat6
->g
? 'g' : 'l';
590 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
591 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
592 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
593 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
594 fprintf(ctx
->out
, ".%c", ss
);
597 dst
.im
= cat6
->g
&& !cat6
->dst_off
;
598 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
601 fprintf(ctx
->out
, " ");
603 switch (_OPC(6, cat6
->opc
)) {
644 if ((_OPC(6, cat6
->opc
) == OPC_STGB
) || (_OPC(6, cat6
->opc
) == OPC_STIB
)) {
647 memset(&src3
, 0, sizeof(src3
));
649 src1
.reg
= (reg_t
)(cat6
->stgb
.src1
);
650 src2
.reg
= (reg_t
)(cat6
->stgb
.src2
);
651 src2
.im
= cat6
->stgb
.src2_im
;
652 src3
.reg
= (reg_t
)(cat6
->stgb
.src3
);
653 src3
.im
= cat6
->stgb
.src3_im
;
656 fprintf(ctx
->out
, "g[%u], ", cat6
->stgb
.dst_ssbo
);
657 print_src(ctx
, &src1
);
658 fprintf(ctx
->out
, ", ");
659 print_src(ctx
, &src2
);
660 fprintf(ctx
->out
, ", ");
661 print_src(ctx
, &src3
);
663 if (debug
& PRINT_VERBOSE
)
664 fprintf(ctx
->out
, " (pad0=%x, pad3=%x)", cat6
->stgb
.pad0
, cat6
->stgb
.pad3
);
669 if (is_atomic(_OPC(6, cat6
->opc
))) {
671 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
672 src1
.im
= cat6
->ldgb
.src1_im
;
673 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
674 src2
.im
= cat6
->ldgb
.src2_im
;
675 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
677 print_src(ctx
, &dst
);
678 fprintf(ctx
->out
, ", ");
681 memset(&src3
, 0, sizeof(src3
));
683 src3
.reg
= (reg_t
)(cat6
->ldgb
.src3
);
686 /* For images, the ".typed" variant is used and src2 is
687 * the ivecN coordinates, ie ivec2 for 2d.
689 * For SSBOs, the ".untyped" variant is used and src2 is
690 * a simple dword offset.. src3 appears to be
691 * uvec2(offset * 4, 0). Not sure the point of that.
694 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
695 print_src(ctx
, &src1
); /* value */
696 fprintf(ctx
->out
, ", ");
697 print_src(ctx
, &src2
); /* offset/coords */
698 fprintf(ctx
->out
, ", ");
699 print_src(ctx
, &src3
); /* 64b byte offset.. */
701 if (debug
& PRINT_VERBOSE
) {
702 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
,
703 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
705 } else { /* ss == 'l' */
706 fprintf(ctx
->out
, "l[");
707 print_src(ctx
, &src1
); /* simple byte offset */
708 fprintf(ctx
->out
, "], ");
709 print_src(ctx
, &src2
); /* value */
711 if (debug
& PRINT_VERBOSE
) {
712 fprintf(ctx
->out
, " (src3=%x, pad0=%x, pad3=%x, mustbe0=%x)",
713 cat6
->ldgb
.src3
, cat6
->ldgb
.pad0
,
714 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
719 } else if (_OPC(6, cat6
->opc
) == OPC_RESINFO
) {
720 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
722 print_src(ctx
, &dst
);
723 fprintf(ctx
->out
, ", ");
724 fprintf(ctx
->out
, "g[%u]", cat6
->ldgb
.src_ssbo
);
727 } else if (_OPC(6, cat6
->opc
) == OPC_LDGB
) {
729 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
730 src1
.im
= cat6
->ldgb
.src1_im
;
731 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
732 src2
.im
= cat6
->ldgb
.src2_im
;
733 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
735 print_src(ctx
, &dst
);
736 fprintf(ctx
->out
, ", ");
737 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
738 print_src(ctx
, &src1
);
739 fprintf(ctx
->out
, ", ");
740 print_src(ctx
, &src2
);
742 if (debug
& PRINT_VERBOSE
)
743 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
, cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
746 } else if (_OPC(6, cat6
->opc
) == OPC_LDG
&& cat6
->a
.src1_im
&& cat6
->a
.src2_im
) {
749 memset(&src3
, 0, sizeof(src3
));
750 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
751 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
752 src2
.im
= cat6
->a
.src2_im
;
753 src3
.reg
= (reg_t
)(cat6
->a
.off
);
755 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
757 print_src(ctx
, &dst
);
758 fprintf(ctx
->out
, ", g[");
759 print_src(ctx
, &src1
);
760 fprintf(ctx
->out
, "+");
761 print_src(ctx
, &src3
);
762 fprintf(ctx
->out
, "], ");
763 print_src(ctx
, &src2
);
768 dst
.reg
= (reg_t
)(cat6
->c
.dst
);
769 dstoff
= cat6
->c
.off
;
771 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
775 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
776 src1
.im
= cat6
->a
.src1_im
;
777 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
778 src2
.im
= cat6
->a
.src2_im
;
779 src1off
= cat6
->a
.off
;
781 src1
.reg
= (reg_t
)(cat6
->b
.src1
);
782 src1
.im
= cat6
->b
.src1_im
;
783 src2
.reg
= (reg_t
)(cat6
->b
.src2
);
784 src2
.im
= cat6
->b
.src2_im
;
789 fprintf(ctx
->out
, "%c[", sd
);
790 /* note: dst might actually be a src (ie. address to store to) */
791 print_src(ctx
, &dst
);
792 if (cat6
->dst_off
&& cat6
->g
) {
793 struct reginfo dstoff_reg
= {0};
794 dstoff_reg
.reg
= (reg_t
) cat6
->c
.off
;
795 dstoff_reg
.full
= true;
796 fprintf(ctx
->out
, "+");
797 print_src(ctx
, &dstoff_reg
);
799 fprintf(ctx
->out
, "%+d", dstoff
);
801 fprintf(ctx
->out
, "]");
802 fprintf(ctx
->out
, ", ");
806 fprintf(ctx
->out
, "%c[", ss
);
808 /* can have a larger than normal immed, so hack: */
810 fprintf(ctx
->out
, "%u", src1
.reg
.dummy13
);
812 print_src(ctx
, &src1
);
815 if (cat6
->src_off
&& cat6
->g
)
816 print_src(ctx
, &src2
);
818 fprintf(ctx
->out
, "%+d", src1off
);
820 fprintf(ctx
->out
, "]");
822 switch (_OPC(6, cat6
->opc
)) {
827 fprintf(ctx
->out
, ", ");
828 print_src(ctx
, &src2
);
833 static void print_instr_cat6_a6xx(struct disasm_ctx
*ctx
, instr_t
*instr
)
835 instr_cat6_a6xx_t
*cat6
= &instr
->cat6_a6xx
;
836 struct reginfo src1
, src2
;
837 bool has_dest
= _OPC(6, cat6
->opc
) == OPC_LDIB
;
840 memset(&src1
, 0, sizeof(src1
));
841 memset(&src2
, 0, sizeof(src2
));
843 fprintf(ctx
->out
, ".%s", cat6
->typed
? "typed" : "untyped");
844 fprintf(ctx
->out
, ".%dd", cat6
->d
+ 1);
845 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
846 fprintf(ctx
->out
, ".%u ", cat6
->type_size
+ 1);
849 src2
.reg
= (reg_t
)(cat6
->src2
);
850 src2
.full
= true; // XXX
851 print_src(ctx
, &src2
);
853 fprintf(ctx
->out
, ", ");
856 /* NOTE: blob seems to use old encoding for ldl/stl (local memory) */
859 fprintf(ctx
->out
, "%c[%u", ss
, cat6
->ssbo
);
860 fprintf(ctx
->out
, "] + ");
861 src1
.reg
= (reg_t
)(cat6
->src1
);
862 src1
.full
= true; // XXX
863 print_src(ctx
, &src1
);
866 fprintf(ctx
->out
, ", ");
868 src2
.reg
= (reg_t
)(cat6
->src2
);
869 src2
.full
= true; // XXX
870 print_src(ctx
, &src2
);
873 if (debug
& PRINT_VERBOSE
) {
874 fprintf(ctx
->out
, " (pad1=%x, pad2=%x, pad3=%x, pad4=%x)", cat6
->pad1
,
875 cat6
->pad2
, cat6
->pad3
, cat6
->pad4
);
879 static void print_instr_cat6(struct disasm_ctx
*ctx
, instr_t
*instr
)
881 if (!is_cat6_legacy(instr
, ctx
->gpu_id
)) {
882 print_instr_cat6_a6xx(ctx
, instr
);
883 if (debug
& PRINT_VERBOSE
)
884 fprintf(ctx
->out
, " NEW");
886 print_instr_cat6_a3xx(ctx
, instr
);
887 if (debug
& PRINT_VERBOSE
)
888 fprintf(ctx
->out
, " LEGACY");
891 static void print_instr_cat7(struct disasm_ctx
*ctx
, instr_t
*instr
)
893 instr_cat7_t
*cat7
= &instr
->cat7
;
896 fprintf(ctx
->out
, ".g");
898 fprintf(ctx
->out
, ".l");
900 if (_OPC(7, cat7
->opc
) == OPC_FENCE
) {
902 fprintf(ctx
->out
, ".r");
904 fprintf(ctx
->out
, ".w");
908 /* size of largest OPC field of all the instruction categories: */
911 static const struct opc_info
{
915 void (*print
)(struct disasm_ctx
*ctx
, instr_t
*instr
);
916 } opcs
[1 << (3+NOPC_BITS
)] = {
917 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat }
919 OPC(0, OPC_NOP
, nop
),
921 OPC(0, OPC_JUMP
, jump
),
922 OPC(0, OPC_CALL
, call
),
923 OPC(0, OPC_RET
, ret
),
924 OPC(0, OPC_KILL
, kill
),
925 OPC(0, OPC_END
, end
),
926 OPC(0, OPC_EMIT
, emit
),
927 OPC(0, OPC_CUT
, cut
),
928 OPC(0, OPC_CHMASK
, chmask
),
929 OPC(0, OPC_CHSH
, chsh
),
930 OPC(0, OPC_FLOW_REV
, flow_rev
),
932 OPC(0, OPC_ELSE
, else),
933 OPC(0, OPC_ENDIF
, endif
),
939 OPC(2, OPC_ADD_F
, add
.f
),
940 OPC(2, OPC_MIN_F
, min
.f
),
941 OPC(2, OPC_MAX_F
, max
.f
),
942 OPC(2, OPC_MUL_F
, mul
.f
),
943 OPC(2, OPC_SIGN_F
, sign
.f
),
944 OPC(2, OPC_CMPS_F
, cmps
.f
),
945 OPC(2, OPC_ABSNEG_F
, absneg
.f
),
946 OPC(2, OPC_CMPV_F
, cmpv
.f
),
947 OPC(2, OPC_FLOOR_F
, floor
.f
),
948 OPC(2, OPC_CEIL_F
, ceil
.f
),
949 OPC(2, OPC_RNDNE_F
, rndne
.f
),
950 OPC(2, OPC_RNDAZ_F
, rndaz
.f
),
951 OPC(2, OPC_TRUNC_F
, trunc
.f
),
952 OPC(2, OPC_ADD_U
, add
.u
),
953 OPC(2, OPC_ADD_S
, add
.s
),
954 OPC(2, OPC_SUB_U
, sub
.u
),
955 OPC(2, OPC_SUB_S
, sub
.s
),
956 OPC(2, OPC_CMPS_U
, cmps
.u
),
957 OPC(2, OPC_CMPS_S
, cmps
.s
),
958 OPC(2, OPC_MIN_U
, min
.u
),
959 OPC(2, OPC_MIN_S
, min
.s
),
960 OPC(2, OPC_MAX_U
, max
.u
),
961 OPC(2, OPC_MAX_S
, max
.s
),
962 OPC(2, OPC_ABSNEG_S
, absneg
.s
),
963 OPC(2, OPC_AND_B
, and.b
),
964 OPC(2, OPC_OR_B
, or.b
),
965 OPC(2, OPC_NOT_B
, not.b
),
966 OPC(2, OPC_XOR_B
, xor.b
),
967 OPC(2, OPC_CMPV_U
, cmpv
.u
),
968 OPC(2, OPC_CMPV_S
, cmpv
.s
),
969 OPC(2, OPC_MUL_U24
, mul
.u24
),
970 OPC(2, OPC_MUL_S24
, mul
.s24
),
971 OPC(2, OPC_MULL_U
, mull
.u
),
972 OPC(2, OPC_BFREV_B
, bfrev
.b
),
973 OPC(2, OPC_CLZ_S
, clz
.s
),
974 OPC(2, OPC_CLZ_B
, clz
.b
),
975 OPC(2, OPC_SHL_B
, shl
.b
),
976 OPC(2, OPC_SHR_B
, shr
.b
),
977 OPC(2, OPC_ASHR_B
, ashr
.b
),
978 OPC(2, OPC_BARY_F
, bary
.f
),
979 OPC(2, OPC_MGEN_B
, mgen
.b
),
980 OPC(2, OPC_GETBIT_B
, getbit
.b
),
981 OPC(2, OPC_SETRM
, setrm
),
982 OPC(2, OPC_CBITS_B
, cbits
.b
),
983 OPC(2, OPC_SHB
, shb
),
984 OPC(2, OPC_MSAD
, msad
),
987 OPC(3, OPC_MAD_U16
, mad
.u16
),
988 OPC(3, OPC_MADSH_U16
, madsh
.u16
),
989 OPC(3, OPC_MAD_S16
, mad
.s16
),
990 OPC(3, OPC_MADSH_M16
, madsh
.m16
),
991 OPC(3, OPC_MAD_U24
, mad
.u24
),
992 OPC(3, OPC_MAD_S24
, mad
.s24
),
993 OPC(3, OPC_MAD_F16
, mad
.f16
),
994 OPC(3, OPC_MAD_F32
, mad
.f32
),
995 OPC(3, OPC_SEL_B16
, sel
.b16
),
996 OPC(3, OPC_SEL_B32
, sel
.b32
),
997 OPC(3, OPC_SEL_S16
, sel
.s16
),
998 OPC(3, OPC_SEL_S32
, sel
.s32
),
999 OPC(3, OPC_SEL_F16
, sel
.f16
),
1000 OPC(3, OPC_SEL_F32
, sel
.f32
),
1001 OPC(3, OPC_SAD_S16
, sad
.s16
),
1002 OPC(3, OPC_SAD_S32
, sad
.s32
),
1005 OPC(4, OPC_RCP
, rcp
),
1006 OPC(4, OPC_RSQ
, rsq
),
1007 OPC(4, OPC_LOG2
, log2
),
1008 OPC(4, OPC_EXP2
, exp2
),
1009 OPC(4, OPC_SIN
, sin
),
1010 OPC(4, OPC_COS
, cos
),
1011 OPC(4, OPC_SQRT
, sqrt
),
1012 OPC(4, OPC_HRSQ
, hrsq
),
1013 OPC(4, OPC_HLOG2
, hlog2
),
1014 OPC(4, OPC_HEXP2
, hexp2
),
1017 OPC(5, OPC_ISAM
, isam
),
1018 OPC(5, OPC_ISAML
, isaml
),
1019 OPC(5, OPC_ISAMM
, isamm
),
1020 OPC(5, OPC_SAM
, sam
),
1021 OPC(5, OPC_SAMB
, samb
),
1022 OPC(5, OPC_SAML
, saml
),
1023 OPC(5, OPC_SAMGQ
, samgq
),
1024 OPC(5, OPC_GETLOD
, getlod
),
1025 OPC(5, OPC_CONV
, conv
),
1026 OPC(5, OPC_CONVM
, convm
),
1027 OPC(5, OPC_GETSIZE
, getsize
),
1028 OPC(5, OPC_GETBUF
, getbuf
),
1029 OPC(5, OPC_GETPOS
, getpos
),
1030 OPC(5, OPC_GETINFO
, getinfo
),
1031 OPC(5, OPC_DSX
, dsx
),
1032 OPC(5, OPC_DSY
, dsy
),
1033 OPC(5, OPC_GATHER4R
, gather4r
),
1034 OPC(5, OPC_GATHER4G
, gather4g
),
1035 OPC(5, OPC_GATHER4B
, gather4b
),
1036 OPC(5, OPC_GATHER4A
, gather4a
),
1037 OPC(5, OPC_SAMGP0
, samgp0
),
1038 OPC(5, OPC_SAMGP1
, samgp1
),
1039 OPC(5, OPC_SAMGP2
, samgp2
),
1040 OPC(5, OPC_SAMGP3
, samgp3
),
1041 OPC(5, OPC_DSXPP_1
, dsxpp
.1),
1042 OPC(5, OPC_DSYPP_1
, dsypp
.1),
1043 OPC(5, OPC_RGETPOS
, rgetpos
),
1044 OPC(5, OPC_RGETINFO
, rgetinfo
),
1048 OPC(6, OPC_LDG
, ldg
),
1049 OPC(6, OPC_LDL
, ldl
),
1050 OPC(6, OPC_LDP
, ldp
),
1051 OPC(6, OPC_STG
, stg
),
1052 OPC(6, OPC_STL
, stl
),
1053 OPC(6, OPC_STP
, stp
),
1054 OPC(6, OPC_LDIB
, ldib
),
1055 OPC(6, OPC_G2L
, g2l
),
1056 OPC(6, OPC_L2G
, l2g
),
1057 OPC(6, OPC_PREFETCH
, prefetch
),
1058 OPC(6, OPC_LDLW
, ldlw
),
1059 OPC(6, OPC_STLW
, stlw
),
1060 OPC(6, OPC_RESFMT
, resfmt
),
1061 OPC(6, OPC_RESINFO
, resinfo
),
1062 OPC(6, OPC_ATOMIC_ADD
, atomic
.add
),
1063 OPC(6, OPC_ATOMIC_SUB
, atomic
.sub
),
1064 OPC(6, OPC_ATOMIC_XCHG
, atomic
.xchg
),
1065 OPC(6, OPC_ATOMIC_INC
, atomic
.inc
),
1066 OPC(6, OPC_ATOMIC_DEC
, atomic
.dec
),
1067 OPC(6, OPC_ATOMIC_CMPXCHG
, atomic
.cmpxchg
),
1068 OPC(6, OPC_ATOMIC_MIN
, atomic
.min
),
1069 OPC(6, OPC_ATOMIC_MAX
, atomic
.max
),
1070 OPC(6, OPC_ATOMIC_AND
, atomic
.and),
1071 OPC(6, OPC_ATOMIC_OR
, atomic
.or),
1072 OPC(6, OPC_ATOMIC_XOR
, atomic
.xor),
1073 OPC(6, OPC_LDGB
, ldgb
),
1074 OPC(6, OPC_STGB
, stgb
),
1075 OPC(6, OPC_STIB
, stib
),
1076 OPC(6, OPC_LDC
, ldc
),
1077 OPC(6, OPC_LDLV
, ldlv
),
1079 OPC(7, OPC_BAR
, bar
),
1080 OPC(7, OPC_FENCE
, fence
),
1085 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr, ctx->gpu_id)]))
1087 // XXX hack.. probably should move this table somewhere common:
1089 const char *ir3_instr_name(struct ir3_instruction
*instr
)
1091 if (opc_cat(instr
->opc
) == -1) return "??meta??";
1092 return opcs
[instr
->opc
].name
;
1095 static void print_single_instr(struct disasm_ctx
*ctx
, instr_t
*instr
)
1097 const char *name
= GETINFO(instr
)->name
;
1098 uint32_t opc
= instr_opc(instr
, ctx
->gpu_id
);
1101 fprintf(ctx
->out
, "%s", name
);
1102 GETINFO(instr
)->print(ctx
, instr
);
1104 fprintf(ctx
->out
, "unknown(%d,%d)", instr
->opc_cat
, opc
);
1106 switch (instr
->opc_cat
) {
1107 case 0: print_instr_cat0(ctx
, instr
); break;
1108 case 1: print_instr_cat1(ctx
, instr
); break;
1109 case 2: print_instr_cat2(ctx
, instr
); break;
1110 case 3: print_instr_cat3(ctx
, instr
); break;
1111 case 4: print_instr_cat4(ctx
, instr
); break;
1112 case 5: print_instr_cat5(ctx
, instr
); break;
1113 case 6: print_instr_cat6(ctx
, instr
); break;
1114 case 7: print_instr_cat7(ctx
, instr
); break;
1119 static bool print_instr(struct disasm_ctx
*ctx
, uint32_t *dwords
, int n
)
1121 instr_t
*instr
= (instr_t
*)dwords
;
1122 uint32_t opc
= instr_opc(instr
, ctx
->gpu_id
);
1125 if (debug
& PRINT_VERBOSE
)
1126 fprintf(ctx
->out
, "%s%04d[%08xx_%08xx] ", levels
[ctx
->level
], n
, dwords
[1], dwords
[0]);
1128 /* NOTE: order flags are printed is a bit fugly.. but for now I
1129 * try to match the order in llvm-a3xx disassembler for easy
1133 ctx
->repeat
= instr_repeat(instr
);
1136 fprintf(ctx
->out
, "(sy)");
1138 if (instr
->ss
&& ((instr
->opc_cat
<= 4) || (instr
->opc_cat
== 7))) {
1139 fprintf(ctx
->out
, "(ss)");
1142 fprintf(ctx
->out
, "(jp)");
1143 if (instr_sat(instr
))
1144 fprintf(ctx
->out
, "(sat)");
1146 fprintf(ctx
->out
, "(rpt%d)", ctx
->repeat
);
1147 else if ((instr
->opc_cat
== 2) && (instr
->cat2
.src1_r
|| instr
->cat2
.src2_r
))
1148 nop
= (instr
->cat2
.src2_r
* 2) + instr
->cat2
.src1_r
;
1149 else if ((instr
->opc_cat
== 3) && (instr
->cat3
.src1_r
|| instr
->cat3
.src2_r
))
1150 nop
= (instr
->cat3
.src2_r
* 2) + instr
->cat3
.src1_r
;
1152 fprintf(ctx
->out
, "(nop%d)", nop
);
1154 if (instr
->ul
&& ((2 <= instr
->opc_cat
) && (instr
->opc_cat
<= 4)))
1155 fprintf(ctx
->out
, "(ul)");
1157 print_single_instr(ctx
, instr
);
1158 fprintf(ctx
->out
, "\n");
1160 if ((instr
->opc_cat
<= 4) && (debug
& EXPAND_REPEAT
)) {
1162 for (i
= 0; i
< nop
; i
++) {
1163 fprintf(ctx
->out
, "%s%04d[ ] ", levels
[ctx
->level
], n
);
1164 fprintf(ctx
->out
, "nop\n");
1166 for (i
= 0; i
< ctx
->repeat
; i
++) {
1167 ctx
->repeatidx
= i
+ 1;
1168 fprintf(ctx
->out
, "%s%04d[ ] ", levels
[ctx
->level
], n
);
1170 print_single_instr(ctx
, instr
);
1171 fprintf(ctx
->out
, "\n");
1176 return (instr
->opc_cat
== 0) && (opc
== OPC_END
);
1179 int disasm_a3xx(uint32_t *dwords
, int sizedwords
, int level
, FILE *out
, unsigned gpu_id
)
1181 struct disasm_ctx ctx
;
1185 assert((sizedwords
% 2) == 0);
1187 memset(&ctx
, 0, sizeof(ctx
));
1190 ctx
.gpu_id
= gpu_id
;
1192 for (i
= 0; i
< sizedwords
; i
+= 2) {
1193 print_instr(&ctx
, &dwords
[i
], i
/2);
1194 if (dwords
[i
] == 0 && dwords
[i
+ 1] == 0)