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
32 #include "instr-a3xx.h"
34 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
36 extern enum debug_t debug
;
38 static const char *levels
[] = {
57 static const char *component
= "xyzw";
59 static const char *type
[] = {
74 uint8_t full
[MAX_REG
/8];
75 uint8_t half
[MAX_REG
/8];
83 struct shader_stats
*stats
;
85 /* we have to process the dst register after src to avoid tripping up
86 * the read-before-write detection
92 /* current instruction repeat flag: */
94 /* current instruction repeat indx/offset (for --expand): */
97 /* tracking for register usage */
100 regmask_t used_merged
;
101 regmask_t rbw
; /* read before write */
102 regmask_t war
; /* write after read */
103 regmask_t cnst
; /* used consts */
107 static const char *float_imms
[] = {
122 static void print_reg(struct disasm_ctx
*ctx
, reg_t reg
, bool full
,
123 bool is_float
, bool r
,
124 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
126 const char type
= c
? 'c' : 'r';
128 // XXX I prefer - and || for neg/abs, but preserving format used
129 // by libllvm-a3xx for easy diffing..
132 fprintf(ctx
->out
, "(absneg)");
134 fprintf(ctx
->out
, "(neg)");
136 fprintf(ctx
->out
, "(abs)");
139 fprintf(ctx
->out
, "(r)");
142 if (is_float
&& full
&& reg
.iim_val
< ARRAY_SIZE(float_imms
)) {
143 fprintf(ctx
->out
, "(%s)", float_imms
[reg
.iim_val
]);
145 fprintf(ctx
->out
, "%d", reg
.iim_val
);
147 } else if (addr_rel
) {
148 /* I would just use %+d but trying to make it diff'able with
152 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
? "" : "h", type
, -reg
.iim_val
);
153 else if (reg
.iim_val
> 0)
154 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
? "" : "h", type
, reg
.iim_val
);
156 fprintf(ctx
->out
, "%s%c<a0.x>", full
? "" : "h", type
);
157 } else if ((reg
.num
== REG_A0
) && !c
) {
158 /* This matches libllvm output, the second (scalar) address register
159 * seems to be called a1.x instead of a0.y.
161 fprintf(ctx
->out
, "a%d.x", reg
.comp
);
162 } else if ((reg
.num
== REG_P0
) && !c
) {
163 fprintf(ctx
->out
, "p0.%c", component
[reg
.comp
]);
165 fprintf(ctx
->out
, "%s%c%d.%c", full
? "" : "h", type
, reg
.num
, component
[reg
.comp
]);
169 /* Tracking for registers used, read-before-write (input), and
170 * write-after-read (output.. but not 100%)..
173 static void regmask_set(regmask_t
*regmask
, unsigned num
, bool full
, unsigned val
)
175 unsigned i
= num
/ 8;
176 unsigned j
= num
% 8;
177 ir3_assert(num
< MAX_REG
);
179 regmask
->full
[i
] = (regmask
->full
[i
] & ~(1 << j
)) | (val
<< j
);
181 regmask
->half
[i
] = (regmask
->half
[i
] & ~(1 << j
)) | (val
<< j
);
185 static unsigned regmask_get(regmask_t
*regmask
, unsigned num
, bool full
)
187 unsigned i
= num
/ 8;
188 unsigned j
= num
% 8;
189 ir3_assert(num
< MAX_REG
);
191 return (regmask
->full
[i
] >> j
) & 0x1;
193 return (regmask
->half
[i
] >> j
) & 0x1;
197 static unsigned regidx(reg_t reg
)
199 return (4 * reg
.num
) + reg
.comp
;
202 static reg_t
idxreg(unsigned idx
)
210 static int print_regs(struct disasm_ctx
*ctx
, regmask_t
*regmask
, bool full
)
212 int num
, max
= 0, cnt
= 0;
215 void print_sequence(void)
217 if (first
!= MAX_REG
) {
219 fprintf(ctx
->out
, " %d", first
);
221 fprintf(ctx
->out
, " %d-%d", first
, last
);
226 first
= last
= MAX_REG
;
228 for (num
= 0; num
< MAX_REG
; num
++) {
229 if (regmask_get(regmask
, num
, full
)) {
230 if (num
!= (last
+ 1)) {
243 fprintf(ctx
->out
, " (cnt=%d, max=%d)", cnt
, max
);
248 static void print_reg_stats(struct disasm_ctx
*ctx
)
250 int fullreg
, halfreg
;
252 fprintf(ctx
->out
, "%sRegister Stats:\n", levels
[ctx
->level
]);
253 fprintf(ctx
->out
, "%s- used (half):", levels
[ctx
->level
]);
254 halfreg
= print_regs(ctx
, &ctx
->regs
.used
, false);
255 fprintf(ctx
->out
, "\n");
256 fprintf(ctx
->out
, "%s- used (full):", levels
[ctx
->level
]);
257 fullreg
= print_regs(ctx
, &ctx
->regs
.used
, true);
258 fprintf(ctx
->out
, "\n");
259 fprintf(ctx
->out
, "%s- used (merged):", levels
[ctx
->level
]);
260 print_regs(ctx
, &ctx
->regs
.used_merged
, false);
261 fprintf(ctx
->out
, "\n");
262 fprintf(ctx
->out
, "%s- input (half):", levels
[ctx
->level
]);
263 print_regs(ctx
, &ctx
->regs
.rbw
, false);
264 fprintf(ctx
->out
, "\n");
265 fprintf(ctx
->out
, "%s- input (full):", levels
[ctx
->level
]);
266 print_regs(ctx
, &ctx
->regs
.rbw
, true);
267 fprintf(ctx
->out
, "\n");
268 fprintf(ctx
->out
, "%s- const (half):", levels
[ctx
->level
]);
269 print_regs(ctx
, &ctx
->regs
.cnst
, false);
270 fprintf(ctx
->out
, "\n");
271 fprintf(ctx
->out
, "%s- const (full):", levels
[ctx
->level
]);
272 print_regs(ctx
, &ctx
->regs
.cnst
, true);
273 fprintf(ctx
->out
, "\n");
274 fprintf(ctx
->out
, "%s- output (half):", levels
[ctx
->level
]);
275 print_regs(ctx
, &ctx
->regs
.war
, false);
276 fprintf(ctx
->out
, " (estimated)\n");
277 fprintf(ctx
->out
, "%s- output (full):", levels
[ctx
->level
]);
278 print_regs(ctx
, &ctx
->regs
.war
, true);
279 fprintf(ctx
->out
, " (estimated)\n");
281 /* convert to vec4, which is the granularity that registers are
282 * assigned to shader:
284 fullreg
= (fullreg
+ 3) / 4;
285 halfreg
= (halfreg
+ 3) / 4;
287 // Note this count of instructions includes rptN, which matches
288 // up to how mesa prints this:
289 fprintf(ctx
->out
, "%s- shaderdb: %d instructions, %d nops, %d non-nops, "
290 "(%d instlen), %d half, %d full\n",
291 levels
[ctx
->level
], ctx
->stats
->instructions
, ctx
->stats
->nops
,
292 ctx
->stats
->instructions
- ctx
->stats
->nops
, ctx
->stats
->instlen
,
294 fprintf(ctx
->out
, "%s- shaderdb: %d (ss), %d (sy)\n", levels
[ctx
->level
],
295 ctx
->stats
->ss
, ctx
->stats
->sy
);
298 static void process_reg_dst(struct disasm_ctx
*ctx
)
302 if (!ctx
->last_dst_valid
)
305 for (i
= 0; i
<= ctx
->repeat
; i
++) {
306 unsigned dst
= ctx
->last_dst
+ i
;
308 regmask_set(&ctx
->regs
.war
, dst
, ctx
->last_dst_full
, 1);
309 regmask_set(&ctx
->regs
.used
, dst
, ctx
->last_dst_full
, 1);
311 if (ctx
->last_dst_full
) {
312 regmask_set(&ctx
->regs
.used_merged
, (dst
*2)+0, false, 1);
313 regmask_set(&ctx
->regs
.used_merged
, (dst
*2)+1, false, 1);
315 regmask_set(&ctx
->regs
.used_merged
, dst
, false, 1);
319 ctx
->last_dst_valid
= false;
322 static void print_reg_dst(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool addr_rel
)
324 /* presumably the special registers a0.c and p0.c don't count.. */
325 if (!(addr_rel
|| (reg
.num
== 61) || (reg
.num
== 62))) {
326 ctx
->last_dst
= regidx(reg
);
327 ctx
->last_dst_full
= full
;
328 ctx
->last_dst_valid
= true;
330 reg
= idxreg(regidx(reg
) + ctx
->repeatidx
);
331 print_reg(ctx
, reg
, full
, false, false, false, false, false, false, addr_rel
);
334 static void print_reg_src(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool f
, bool r
,
335 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
337 /* presumably the special registers a0.c and p0.c don't count.. */
338 if (!(addr_rel
|| c
|| im
|| (reg
.num
== 61) || (reg
.num
== 62))) {
339 int i
, num
= regidx(reg
);
340 for (i
= 0; i
<= ctx
->repeat
; i
++) {
341 unsigned src
= num
+ i
;
343 if (!regmask_get(&ctx
->regs
.used
, src
, full
))
344 regmask_set(&ctx
->regs
.rbw
, src
, full
, 1);
346 regmask_set(&ctx
->regs
.war
, src
, full
, 0);
347 regmask_set(&ctx
->regs
.used
, src
, full
, 1);
350 regmask_set(&ctx
->regs
.used_merged
, (src
*2)+0, false, 1);
351 regmask_set(&ctx
->regs
.used_merged
, (src
*2)+1, false, 1);
353 regmask_set(&ctx
->regs
.used_merged
, src
, false, 1);
360 int i
, num
= regidx(reg
);
361 for (i
= 0; i
<= ctx
->repeat
; i
++) {
362 unsigned src
= num
+ i
;
364 regmask_set(&ctx
->regs
.cnst
, src
, full
, 1);
370 unsigned max
= (num
+ ctx
->repeat
+ 1 + 3) / 4;
371 if (max
> ctx
->stats
->constlen
)
372 ctx
->stats
->constlen
= max
;
376 reg
= idxreg(regidx(reg
) + ctx
->repeatidx
);
378 print_reg(ctx
, reg
, full
, f
, r
, c
, im
, neg
, abs
, addr_rel
);
381 /* TODO switch to using reginfo struct everywhere, since more readable
382 * than passing a bunch of bools to print_reg_src
390 bool f
; /* src reg is interpreted as float, used for printing immediates */
397 static void print_src(struct disasm_ctx
*ctx
, struct reginfo
*info
)
399 reg_t reg
= info
->reg
;
402 reg
= idxreg(regidx(info
->reg
) + ctx
->repeatidx
);
404 print_reg_src(ctx
, reg
, info
->full
, info
->f
, info
->r
, info
->c
, info
->im
,
405 info
->neg
, info
->abs
, info
->addr_rel
);
408 //static void print_dst(struct disasm_ctx *ctx, struct reginfo *info)
410 // print_reg_dst(ctx, info->reg, info->full, info->addr_rel);
413 static void print_instr_cat0(struct disasm_ctx
*ctx
, instr_t
*instr
)
415 static const struct {
420 [BRANCH_PLAIN
] = { "r", 1, false },
421 [BRANCH_OR
] = { "rao", 2, false },
422 [BRANCH_AND
] = { "raa", 2, false },
423 [BRANCH_CONST
] = { "rac", 0, true },
424 [BRANCH_ANY
] = { "any", 1, false },
425 [BRANCH_ALL
] = { "all", 1, false },
426 [BRANCH_X
] = { "rax", 0, false },
428 instr_cat0_t
*cat0
= &instr
->cat0
;
430 switch (instr_opc(instr
, ctx
->gpu_id
)) {
434 fprintf(ctx
->out
, " %sp0.%c", cat0
->inv0
? "!" : "",
435 component
[cat0
->comp0
]);
438 fprintf(ctx
->out
, "%s", brinfo
[cat0
->brtype
].suffix
);
439 if (brinfo
[cat0
->brtype
].idx
) {
440 fprintf(ctx
->out
, ".%u", cat0
->idx
);
442 if (brinfo
[cat0
->brtype
].nsrc
>= 1) {
443 fprintf(ctx
->out
, " %sp0.%c,", cat0
->inv0
? "!" : "",
444 component
[cat0
->comp0
]);
446 if (brinfo
[cat0
->brtype
].nsrc
>= 2) {
447 fprintf(ctx
->out
, " %sp0.%c,", cat0
->inv1
? "!" : "",
448 component
[cat0
->comp1
]);
450 fprintf(ctx
->out
, " #%d", cat0
->a3xx
.immed
);
457 fprintf(ctx
->out
, " #%d", cat0
->a3xx
.immed
);
461 if ((debug
& PRINT_VERBOSE
) && (cat0
->dummy3
|cat0
->dummy4
))
462 fprintf(ctx
->out
, "\t{0: %x,%x}", cat0
->dummy3
, cat0
->dummy4
);
465 static void print_instr_cat1(struct disasm_ctx
*ctx
, instr_t
*instr
)
467 instr_cat1_t
*cat1
= &instr
->cat1
;
470 fprintf(ctx
->out
, "(ul)");
472 if (cat1
->src_type
== cat1
->dst_type
) {
473 if ((cat1
->src_type
== TYPE_S16
) && (((reg_t
)cat1
->dst
).num
== REG_A0
)) {
474 /* special case (nmemonic?): */
475 fprintf(ctx
->out
, "mova");
477 fprintf(ctx
->out
, "mov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
480 fprintf(ctx
->out
, "cov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
483 fprintf(ctx
->out
, " ");
486 fprintf(ctx
->out
, "(even)");
489 fprintf(ctx
->out
, "(pos_infinity)");
491 print_reg_dst(ctx
, (reg_t
)(cat1
->dst
), type_size(cat1
->dst_type
) == 32,
494 fprintf(ctx
->out
, ", ");
496 /* ugg, have to special case this.. vs print_reg().. */
498 if (type_float(cat1
->src_type
))
499 fprintf(ctx
->out
, "(%f)", cat1
->fim_val
);
500 else if (type_uint(cat1
->src_type
))
501 fprintf(ctx
->out
, "0x%08x", cat1
->uim_val
);
503 fprintf(ctx
->out
, "%d", cat1
->iim_val
);
504 } else if (cat1
->src_rel
&& !cat1
->src_c
) {
505 /* I would just use %+d but trying to make it diff'able with
508 char type
= cat1
->src_rel_c
? 'c' : 'r';
509 const char *full
= (type_size(cat1
->src_type
) == 32) ? "" : "h";
511 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
, type
, -cat1
->off
);
512 else if (cat1
->off
> 0)
513 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
, type
, cat1
->off
);
515 fprintf(ctx
->out
, "%s%c<a0.x>", full
, type
);
517 struct reginfo src
= {
518 .reg
= (reg_t
)cat1
->src
,
519 .full
= type_size(cat1
->src_type
) == 32,
524 print_src(ctx
, &src
);
527 if ((debug
& PRINT_VERBOSE
) && (cat1
->must_be_0
))
528 fprintf(ctx
->out
, "\t{1: %x}", cat1
->must_be_0
);
531 static void print_instr_cat2(struct disasm_ctx
*ctx
, instr_t
*instr
)
533 instr_cat2_t
*cat2
= &instr
->cat2
;
534 int opc
= _OPC(2, cat2
->opc
);
535 static const char *cond
[] = {
552 fprintf(ctx
->out
, ".%s", cond
[cat2
->cond
]);
556 fprintf(ctx
->out
, " ");
558 fprintf(ctx
->out
, "(ei)");
559 print_reg_dst(ctx
, (reg_t
)(cat2
->dst
), cat2
->full
^ cat2
->dst_half
, false);
560 fprintf(ctx
->out
, ", ");
562 struct reginfo src1
= {
564 .r
= cat2
->repeat
? cat2
->src1_r
: 0,
565 .f
= is_cat2_float(opc
),
567 .abs
= cat2
->src1_abs
,
568 .neg
= cat2
->src1_neg
,
571 if (cat2
->c1
.src1_c
) {
572 src1
.reg
= (reg_t
)(cat2
->c1
.src1
);
574 } else if (cat2
->rel1
.src1_rel
) {
575 src1
.reg
= (reg_t
)(cat2
->rel1
.src1
);
576 src1
.c
= cat2
->rel1
.src1_c
;
577 src1
.addr_rel
= true;
579 src1
.reg
= (reg_t
)(cat2
->src1
);
581 print_src(ctx
, &src1
);
583 struct reginfo src2
= {
584 .r
= cat2
->repeat
? cat2
->src2_r
: 0,
586 .f
= is_cat2_float(opc
),
587 .abs
= cat2
->src2_abs
,
588 .neg
= cat2
->src2_neg
,
606 /* these only have one src reg */
609 fprintf(ctx
->out
, ", ");
610 if (cat2
->c2
.src2_c
) {
611 src2
.reg
= (reg_t
)(cat2
->c2
.src2
);
613 } else if (cat2
->rel2
.src2_rel
) {
614 src2
.reg
= (reg_t
)(cat2
->rel2
.src2
);
615 src2
.c
= cat2
->rel2
.src2_c
;
616 src2
.addr_rel
= true;
618 src2
.reg
= (reg_t
)(cat2
->src2
);
620 print_src(ctx
, &src2
);
625 static void print_instr_cat3(struct disasm_ctx
*ctx
, instr_t
*instr
)
627 instr_cat3_t
*cat3
= &instr
->cat3
;
628 bool full
= instr_cat3_full(cat3
);
630 fprintf(ctx
->out
, " ");
631 print_reg_dst(ctx
, (reg_t
)(cat3
->dst
), full
^ cat3
->dst_half
, false);
632 fprintf(ctx
->out
, ", ");
634 struct reginfo src1
= {
635 .r
= cat3
->repeat
? cat3
->src1_r
: 0,
637 .neg
= cat3
->src1_neg
,
639 if (cat3
->c1
.src1_c
) {
640 src1
.reg
= (reg_t
)(cat3
->c1
.src1
);
642 } else if (cat3
->rel1
.src1_rel
) {
643 src1
.reg
= (reg_t
)(cat3
->rel1
.src1
);
644 src1
.c
= cat3
->rel1
.src1_c
;
645 src1
.addr_rel
= true;
647 src1
.reg
= (reg_t
)(cat3
->src1
);
649 print_src(ctx
, &src1
);
651 fprintf(ctx
->out
, ", ");
652 struct reginfo src2
= {
653 .reg
= (reg_t
)cat3
->src2
,
655 .r
= cat3
->repeat
? cat3
->src2_r
: 0,
657 .neg
= cat3
->src2_neg
,
659 print_src(ctx
, &src2
);
661 fprintf(ctx
->out
, ", ");
662 struct reginfo src3
= {
665 .neg
= cat3
->src3_neg
,
667 if (cat3
->c2
.src3_c
) {
668 src3
.reg
= (reg_t
)(cat3
->c2
.src3
);
670 } else if (cat3
->rel2
.src3_rel
) {
671 src3
.reg
= (reg_t
)(cat3
->rel2
.src3
);
672 src3
.c
= cat3
->rel2
.src3_c
;
673 src3
.addr_rel
= true;
675 src3
.reg
= (reg_t
)(cat3
->src3
);
677 print_src(ctx
, &src3
);
680 static void print_instr_cat4(struct disasm_ctx
*ctx
, instr_t
*instr
)
682 instr_cat4_t
*cat4
= &instr
->cat4
;
684 fprintf(ctx
->out
, " ");
685 print_reg_dst(ctx
, (reg_t
)(cat4
->dst
), cat4
->full
^ cat4
->dst_half
, false);
686 fprintf(ctx
->out
, ", ");
688 struct reginfo src
= {
692 .neg
= cat4
->src_neg
,
693 .abs
= cat4
->src_abs
,
696 src
.reg
= (reg_t
)(cat4
->c
.src
);
698 } else if (cat4
->rel
.src_rel
) {
699 src
.reg
= (reg_t
)(cat4
->rel
.src
);
700 src
.c
= cat4
->rel
.src_c
;
703 src
.reg
= (reg_t
)(cat4
->src
);
705 print_src(ctx
, &src
);
707 if ((debug
& PRINT_VERBOSE
) && (cat4
->dummy1
|cat4
->dummy2
))
708 fprintf(ctx
->out
, "\t{4: %x,%x}", cat4
->dummy1
, cat4
->dummy2
);
711 static void print_instr_cat5(struct disasm_ctx
*ctx
, instr_t
*instr
)
713 static const struct {
714 bool src1
, src2
, samp
, tex
;
716 [opc_op(OPC_ISAM
)] = { true, false, true, true, },
717 [opc_op(OPC_ISAML
)] = { true, true, true, true, },
718 [opc_op(OPC_ISAMM
)] = { true, false, true, true, },
719 [opc_op(OPC_SAM
)] = { true, false, true, true, },
720 [opc_op(OPC_SAMB
)] = { true, true, true, true, },
721 [opc_op(OPC_SAML
)] = { true, true, true, true, },
722 [opc_op(OPC_SAMGQ
)] = { true, false, true, true, },
723 [opc_op(OPC_GETLOD
)] = { true, false, true, true, },
724 [opc_op(OPC_CONV
)] = { true, true, true, true, },
725 [opc_op(OPC_CONVM
)] = { true, true, true, true, },
726 [opc_op(OPC_GETSIZE
)] = { true, false, false, true, },
727 [opc_op(OPC_GETBUF
)] = { false, false, false, true, },
728 [opc_op(OPC_GETPOS
)] = { true, false, false, true, },
729 [opc_op(OPC_GETINFO
)] = { false, false, false, true, },
730 [opc_op(OPC_DSX
)] = { true, false, false, false, },
731 [opc_op(OPC_DSY
)] = { true, false, false, false, },
732 [opc_op(OPC_GATHER4R
)] = { true, false, true, true, },
733 [opc_op(OPC_GATHER4G
)] = { true, false, true, true, },
734 [opc_op(OPC_GATHER4B
)] = { true, false, true, true, },
735 [opc_op(OPC_GATHER4A
)] = { true, false, true, true, },
736 [opc_op(OPC_SAMGP0
)] = { true, false, true, true, },
737 [opc_op(OPC_SAMGP1
)] = { true, false, true, true, },
738 [opc_op(OPC_SAMGP2
)] = { true, false, true, true, },
739 [opc_op(OPC_SAMGP3
)] = { true, false, true, true, },
740 [opc_op(OPC_DSXPP_1
)] = { true, false, false, false, },
741 [opc_op(OPC_DSYPP_1
)] = { true, false, false, false, },
742 [opc_op(OPC_RGETPOS
)] = { true, false, false, false, },
743 [opc_op(OPC_RGETINFO
)] = { false, false, false, false, },
746 static const struct {
751 } desc_features
[8] = {
752 [CAT5_NONUNIFORM
] = { .indirect
= true, },
753 [CAT5_UNIFORM
] = { .indirect
= true, .uniform
= true, },
754 [CAT5_BINDLESS_IMM
] = { .bindless
= true, },
755 [CAT5_BINDLESS_UNIFORM
] = {
760 [CAT5_BINDLESS_NONUNIFORM
] = {
764 [CAT5_BINDLESS_A1_IMM
] = {
768 [CAT5_BINDLESS_A1_UNIFORM
] = {
774 [CAT5_BINDLESS_A1_NONUNIFORM
] = {
781 instr_cat5_t
*cat5
= &instr
->cat5
;
785 cat5
->is_s2en_bindless
&&
786 desc_features
[cat5
->s2en_bindless
.desc_mode
].indirect
;
788 cat5
->is_s2en_bindless
&&
789 desc_features
[cat5
->s2en_bindless
.desc_mode
].bindless
;
791 cat5
->is_s2en_bindless
&&
792 desc_features
[cat5
->s2en_bindless
.desc_mode
].use_a1
;
794 cat5
->is_s2en_bindless
&&
795 desc_features
[cat5
->s2en_bindless
.desc_mode
].uniform
;
797 if (cat5
->is_3d
) fprintf(ctx
->out
, ".3d");
798 if (cat5
->is_a
) fprintf(ctx
->out
, ".a");
799 if (cat5
->is_o
) fprintf(ctx
->out
, ".o");
800 if (cat5
->is_p
) fprintf(ctx
->out
, ".p");
801 if (cat5
->is_s
) fprintf(ctx
->out
, ".s");
802 if (desc_indirect
) fprintf(ctx
->out
, ".s2en");
803 if (uniform
) fprintf(ctx
->out
, ".uniform");
806 unsigned base
= (cat5
->s2en_bindless
.base_hi
<< 1) | cat5
->base_lo
;
807 fprintf(ctx
->out
, ".base%d", base
);
810 fprintf(ctx
->out
, " ");
812 switch (_OPC(5, cat5
->opc
)) {
817 fprintf(ctx
->out
, "(%s)", type
[cat5
->type
]);
821 fprintf(ctx
->out
, "(");
822 for (i
= 0; i
< 4; i
++)
823 if (cat5
->wrmask
& (1 << i
))
824 fprintf(ctx
->out
, "%c", "xyzw"[i
]);
825 fprintf(ctx
->out
, ")");
827 print_reg_dst(ctx
, (reg_t
)(cat5
->dst
), type_size(cat5
->type
) == 32, false);
829 if (info
[cat5
->opc
].src1
) {
830 fprintf(ctx
->out
, ", ");
831 struct reginfo src
= { .reg
= (reg_t
)(cat5
->src1
), .full
= cat5
->full
};
832 print_src(ctx
, &src
);
835 if (cat5
->is_o
|| info
[cat5
->opc
].src2
) {
836 fprintf(ctx
->out
, ", ");
837 struct reginfo src
= { .reg
= (reg_t
)(cat5
->src2
), .full
= cat5
->full
};
838 print_src(ctx
, &src
);
840 if (cat5
->is_s2en_bindless
) {
841 if (!desc_indirect
) {
842 if (info
[cat5
->opc
].samp
) {
844 fprintf(ctx
->out
, ", s#%d", cat5
->s2en_bindless
.src3
);
846 fprintf(ctx
->out
, ", s#%d", cat5
->s2en_bindless
.src3
& 0xf);
849 if (info
[cat5
->opc
].tex
&& !use_a1
) {
850 fprintf(ctx
->out
, ", t#%d", cat5
->s2en_bindless
.src3
>> 4);
854 if (info
[cat5
->opc
].samp
)
855 fprintf(ctx
->out
, ", s#%d", cat5
->norm
.samp
);
856 if (info
[cat5
->opc
].tex
)
857 fprintf(ctx
->out
, ", t#%d", cat5
->norm
.tex
);
861 fprintf(ctx
->out
, ", ");
862 struct reginfo src
= { .reg
= (reg_t
)(cat5
->s2en_bindless
.src3
), .full
= bindless
};
863 print_src(ctx
, &src
);
867 fprintf(ctx
->out
, ", a1.x");
869 if (debug
& PRINT_VERBOSE
) {
870 if (cat5
->is_s2en_bindless
) {
871 if ((debug
& PRINT_VERBOSE
) && cat5
->s2en_bindless
.dummy1
)
872 fprintf(ctx
->out
, "\t{5: %x}", cat5
->s2en_bindless
.dummy1
);
874 if ((debug
& PRINT_VERBOSE
) && cat5
->norm
.dummy1
)
875 fprintf(ctx
->out
, "\t{5: %x}", cat5
->norm
.dummy1
);
880 static void print_instr_cat6_a3xx(struct disasm_ctx
*ctx
, instr_t
*instr
)
882 instr_cat6_t
*cat6
= &instr
->cat6
;
883 char sd
= 0, ss
= 0; /* dst/src address space */
885 struct reginfo dst
, src1
, src2
;
886 int src1off
= 0, dstoff
= 0;
888 memset(&dst
, 0, sizeof(dst
));
889 memset(&src1
, 0, sizeof(src1
));
890 memset(&src2
, 0, sizeof(src2
));
892 switch (_OPC(6, cat6
->opc
)) {
895 dst
.full
= type_size(cat6
->type
) == 32;
896 src1
.full
= type_size(cat6
->type
) == 32;
897 src2
.full
= type_size(cat6
->type
) == 32;
910 dst
.full
= type_size(cat6
->type
) == 32;
911 src1
.full
= type_size(cat6
->type
) == 32;
912 src2
.full
= type_size(cat6
->type
) == 32;
915 dst
.full
= type_size(cat6
->type
) == 32;
921 switch (_OPC(6, cat6
->opc
)) {
925 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
928 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
929 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
930 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
931 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
935 fprintf(ctx
->out
, ".%s", cat6
->stgb
.typed
? "typed" : "untyped");
936 fprintf(ctx
->out
, ".%dd", cat6
->stgb
.d
+ 1);
937 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
938 fprintf(ctx
->out
, ".%d", cat6
->stgb
.type_size
+ 1);
942 case OPC_ATOMIC_XCHG
:
945 case OPC_ATOMIC_CMPXCHG
:
951 ss
= cat6
->g
? 'g' : 'l';
952 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
953 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
954 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
955 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
956 fprintf(ctx
->out
, ".%c", ss
);
959 dst
.im
= cat6
->g
&& !cat6
->dst_off
;
960 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
963 fprintf(ctx
->out
, " ");
965 switch (_OPC(6, cat6
->opc
)) {
1006 if ((_OPC(6, cat6
->opc
) == OPC_STGB
) || (_OPC(6, cat6
->opc
) == OPC_STIB
)) {
1007 struct reginfo src3
;
1009 memset(&src3
, 0, sizeof(src3
));
1011 src1
.reg
= (reg_t
)(cat6
->stgb
.src1
);
1012 src2
.reg
= (reg_t
)(cat6
->stgb
.src2
);
1013 src2
.im
= cat6
->stgb
.src2_im
;
1014 src3
.reg
= (reg_t
)(cat6
->stgb
.src3
);
1015 src3
.im
= cat6
->stgb
.src3_im
;
1018 fprintf(ctx
->out
, "g[%u], ", cat6
->stgb
.dst_ssbo
);
1019 print_src(ctx
, &src1
);
1020 fprintf(ctx
->out
, ", ");
1021 print_src(ctx
, &src2
);
1022 fprintf(ctx
->out
, ", ");
1023 print_src(ctx
, &src3
);
1025 if (debug
& PRINT_VERBOSE
)
1026 fprintf(ctx
->out
, " (pad0=%x, pad3=%x)", cat6
->stgb
.pad0
, cat6
->stgb
.pad3
);
1031 if (is_atomic(_OPC(6, cat6
->opc
))) {
1033 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
1034 src1
.im
= cat6
->ldgb
.src1_im
;
1035 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
1036 src2
.im
= cat6
->ldgb
.src2_im
;
1037 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
1039 print_src(ctx
, &dst
);
1040 fprintf(ctx
->out
, ", ");
1042 struct reginfo src3
;
1043 memset(&src3
, 0, sizeof(src3
));
1045 src3
.reg
= (reg_t
)(cat6
->ldgb
.src3
);
1048 /* For images, the ".typed" variant is used and src2 is
1049 * the ivecN coordinates, ie ivec2 for 2d.
1051 * For SSBOs, the ".untyped" variant is used and src2 is
1052 * a simple dword offset.. src3 appears to be
1053 * uvec2(offset * 4, 0). Not sure the point of that.
1056 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
1057 print_src(ctx
, &src1
); /* value */
1058 fprintf(ctx
->out
, ", ");
1059 print_src(ctx
, &src2
); /* offset/coords */
1060 fprintf(ctx
->out
, ", ");
1061 print_src(ctx
, &src3
); /* 64b byte offset.. */
1063 if (debug
& PRINT_VERBOSE
) {
1064 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
,
1065 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
1067 } else { /* ss == 'l' */
1068 fprintf(ctx
->out
, "l[");
1069 print_src(ctx
, &src1
); /* simple byte offset */
1070 fprintf(ctx
->out
, "], ");
1071 print_src(ctx
, &src2
); /* value */
1073 if (debug
& PRINT_VERBOSE
) {
1074 fprintf(ctx
->out
, " (src3=%x, pad0=%x, pad3=%x, mustbe0=%x)",
1075 cat6
->ldgb
.src3
, cat6
->ldgb
.pad0
,
1076 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
1081 } else if (_OPC(6, cat6
->opc
) == OPC_RESINFO
) {
1082 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
1084 print_src(ctx
, &dst
);
1085 fprintf(ctx
->out
, ", ");
1086 fprintf(ctx
->out
, "g[%u]", cat6
->ldgb
.src_ssbo
);
1089 } else if (_OPC(6, cat6
->opc
) == OPC_LDGB
) {
1091 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
1092 src1
.im
= cat6
->ldgb
.src1_im
;
1093 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
1094 src2
.im
= cat6
->ldgb
.src2_im
;
1095 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
1097 print_src(ctx
, &dst
);
1098 fprintf(ctx
->out
, ", ");
1099 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
1100 print_src(ctx
, &src1
);
1101 fprintf(ctx
->out
, ", ");
1102 print_src(ctx
, &src2
);
1104 if (debug
& PRINT_VERBOSE
)
1105 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
, cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
1108 } else if (_OPC(6, cat6
->opc
) == OPC_LDG
&& cat6
->a
.src1_im
&& cat6
->a
.src2_im
) {
1109 struct reginfo src3
;
1111 memset(&src3
, 0, sizeof(src3
));
1112 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
1113 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
1114 src2
.im
= cat6
->a
.src2_im
;
1115 src3
.reg
= (reg_t
)(cat6
->a
.off
);
1117 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
1119 print_src(ctx
, &dst
);
1120 fprintf(ctx
->out
, ", g[");
1121 print_src(ctx
, &src1
);
1122 fprintf(ctx
->out
, "+");
1123 print_src(ctx
, &src3
);
1124 fprintf(ctx
->out
, "], ");
1125 print_src(ctx
, &src2
);
1129 if (cat6
->dst_off
) {
1130 dst
.reg
= (reg_t
)(cat6
->c
.dst
);
1131 dstoff
= cat6
->c
.off
;
1133 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
1136 if (cat6
->src_off
) {
1137 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
1138 src1
.im
= cat6
->a
.src1_im
;
1139 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
1140 src2
.im
= cat6
->a
.src2_im
;
1141 src1off
= cat6
->a
.off
;
1143 src1
.reg
= (reg_t
)(cat6
->b
.src1
);
1144 src1
.im
= cat6
->b
.src1_im
;
1145 src2
.reg
= (reg_t
)(cat6
->b
.src2
);
1146 src2
.im
= cat6
->b
.src2_im
;
1151 fprintf(ctx
->out
, "%c[", sd
);
1152 /* note: dst might actually be a src (ie. address to store to) */
1153 print_src(ctx
, &dst
);
1154 if (cat6
->dst_off
&& cat6
->g
) {
1155 struct reginfo dstoff_reg
= {0};
1156 dstoff_reg
.reg
= (reg_t
) cat6
->c
.off
;
1157 dstoff_reg
.full
= true;
1158 fprintf(ctx
->out
, "+");
1159 print_src(ctx
, &dstoff_reg
);
1161 fprintf(ctx
->out
, "%+d", dstoff
);
1163 fprintf(ctx
->out
, "]");
1164 fprintf(ctx
->out
, ", ");
1168 fprintf(ctx
->out
, "%c[", ss
);
1170 /* can have a larger than normal immed, so hack: */
1172 fprintf(ctx
->out
, "%u", src1
.reg
.dummy13
);
1174 print_src(ctx
, &src1
);
1177 if (cat6
->src_off
&& cat6
->g
)
1178 print_src(ctx
, &src2
);
1180 fprintf(ctx
->out
, "%+d", src1off
);
1182 fprintf(ctx
->out
, "]");
1184 switch (_OPC(6, cat6
->opc
)) {
1189 fprintf(ctx
->out
, ", ");
1190 print_src(ctx
, &src2
);
1195 static void print_instr_cat6_a6xx(struct disasm_ctx
*ctx
, instr_t
*instr
)
1197 instr_cat6_a6xx_t
*cat6
= &instr
->cat6_a6xx
;
1198 struct reginfo src1
, src2
, ssbo
;
1199 bool uses_type
= _OPC(6, cat6
->opc
) != OPC_LDC
;
1201 static const struct {
1205 } desc_features
[8] = {
1213 [CAT6_NONUNIFORM
] = {
1215 .name
= "nonuniform"
1217 [CAT6_BINDLESS_IMM
] = {
1221 [CAT6_BINDLESS_UNIFORM
] = {
1226 [CAT6_BINDLESS_NONUNIFORM
] = {
1229 .name
= "nonuniform"
1233 bool indirect_ssbo
= desc_features
[cat6
->desc_mode
].indirect
;
1234 bool bindless
= desc_features
[cat6
->desc_mode
].bindless
;
1235 bool type_full
= cat6
->type
!= TYPE_U16
;
1238 memset(&src1
, 0, sizeof(src1
));
1239 memset(&src2
, 0, sizeof(src2
));
1240 memset(&ssbo
, 0, sizeof(ssbo
));
1243 fprintf(ctx
->out
, ".%s", cat6
->typed
? "typed" : "untyped");
1244 fprintf(ctx
->out
, ".%dd", cat6
->d
+ 1);
1245 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
1247 fprintf(ctx
->out
, ".offset%d", cat6
->d
);
1249 fprintf(ctx
->out
, ".%u", cat6
->type_size
+ 1);
1251 fprintf(ctx
->out
, ".%s", desc_features
[cat6
->desc_mode
].name
);
1253 fprintf(ctx
->out
, ".base%d", cat6
->base
);
1254 fprintf(ctx
->out
, " ");
1256 src2
.reg
= (reg_t
)(cat6
->src2
);
1257 src2
.full
= type_full
;
1258 print_src(ctx
, &src2
);
1259 fprintf(ctx
->out
, ", ");
1261 src1
.reg
= (reg_t
)(cat6
->src1
);
1262 src1
.full
= true; // XXX
1263 print_src(ctx
, &src1
);
1264 fprintf(ctx
->out
, ", ");
1265 ssbo
.reg
= (reg_t
)(cat6
->ssbo
);
1266 ssbo
.im
= !indirect_ssbo
;
1268 print_src(ctx
, &ssbo
);
1270 if (debug
& PRINT_VERBOSE
) {
1271 fprintf(ctx
->out
, " (pad1=%x, pad2=%x, pad3=%x, pad4=%x, pad5=%x)",
1272 cat6
->pad1
, cat6
->pad2
, cat6
->pad3
, cat6
->pad4
, cat6
->pad5
);
1276 static void print_instr_cat6(struct disasm_ctx
*ctx
, instr_t
*instr
)
1278 if (!is_cat6_legacy(instr
, ctx
->gpu_id
)) {
1279 print_instr_cat6_a6xx(ctx
, instr
);
1280 if (debug
& PRINT_VERBOSE
)
1281 fprintf(ctx
->out
, " NEW");
1283 print_instr_cat6_a3xx(ctx
, instr
);
1284 if (debug
& PRINT_VERBOSE
)
1285 fprintf(ctx
->out
, " LEGACY");
1288 static void print_instr_cat7(struct disasm_ctx
*ctx
, instr_t
*instr
)
1290 instr_cat7_t
*cat7
= &instr
->cat7
;
1293 fprintf(ctx
->out
, ".g");
1295 fprintf(ctx
->out
, ".l");
1297 if (_OPC(7, cat7
->opc
) == OPC_FENCE
) {
1299 fprintf(ctx
->out
, ".r");
1301 fprintf(ctx
->out
, ".w");
1305 /* size of largest OPC field of all the instruction categories: */
1308 static const struct opc_info
{
1312 void (*print
)(struct disasm_ctx
*ctx
, instr_t
*instr
);
1313 } opcs
[1 << (3+NOPC_BITS
)] = {
1314 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat }
1316 OPC(0, OPC_NOP
, nop
),
1318 OPC(0, OPC_JUMP
, jump
),
1319 OPC(0, OPC_CALL
, call
),
1320 OPC(0, OPC_RET
, ret
),
1321 OPC(0, OPC_KILL
, kill
),
1322 OPC(0, OPC_END
, end
),
1323 OPC(0, OPC_EMIT
, emit
),
1324 OPC(0, OPC_CUT
, cut
),
1325 OPC(0, OPC_CHMASK
, chmask
),
1326 OPC(0, OPC_CHSH
, chsh
),
1327 OPC(0, OPC_FLOW_REV
, flow_rev
),
1328 OPC(0, OPC_PREDT
, predt
),
1329 OPC(0, OPC_PREDF
, predf
),
1330 OPC(0, OPC_PREDE
, prede
),
1331 OPC(0, OPC_BKT
, bkt
),
1332 OPC(0, OPC_STKS
, stks
),
1333 OPC(0, OPC_STKR
, stkr
),
1334 OPC(0, OPC_XSET
, xset
),
1335 OPC(0, OPC_XCLR
, xclr
),
1336 OPC(0, OPC_GETONE
, getone
),
1337 OPC(0, OPC_DBG
, dbg
),
1338 OPC(0, OPC_SHPS
, shps
),
1339 OPC(0, OPC_SHPE
, shpe
),
1345 OPC(2, OPC_ADD_F
, add
.f
),
1346 OPC(2, OPC_MIN_F
, min
.f
),
1347 OPC(2, OPC_MAX_F
, max
.f
),
1348 OPC(2, OPC_MUL_F
, mul
.f
),
1349 OPC(2, OPC_SIGN_F
, sign
.f
),
1350 OPC(2, OPC_CMPS_F
, cmps
.f
),
1351 OPC(2, OPC_ABSNEG_F
, absneg
.f
),
1352 OPC(2, OPC_CMPV_F
, cmpv
.f
),
1353 OPC(2, OPC_FLOOR_F
, floor
.f
),
1354 OPC(2, OPC_CEIL_F
, ceil
.f
),
1355 OPC(2, OPC_RNDNE_F
, rndne
.f
),
1356 OPC(2, OPC_RNDAZ_F
, rndaz
.f
),
1357 OPC(2, OPC_TRUNC_F
, trunc
.f
),
1358 OPC(2, OPC_ADD_U
, add
.u
),
1359 OPC(2, OPC_ADD_S
, add
.s
),
1360 OPC(2, OPC_SUB_U
, sub
.u
),
1361 OPC(2, OPC_SUB_S
, sub
.s
),
1362 OPC(2, OPC_CMPS_U
, cmps
.u
),
1363 OPC(2, OPC_CMPS_S
, cmps
.s
),
1364 OPC(2, OPC_MIN_U
, min
.u
),
1365 OPC(2, OPC_MIN_S
, min
.s
),
1366 OPC(2, OPC_MAX_U
, max
.u
),
1367 OPC(2, OPC_MAX_S
, max
.s
),
1368 OPC(2, OPC_ABSNEG_S
, absneg
.s
),
1369 OPC(2, OPC_AND_B
, and.b
),
1370 OPC(2, OPC_OR_B
, or.b
),
1371 OPC(2, OPC_NOT_B
, not.b
),
1372 OPC(2, OPC_XOR_B
, xor.b
),
1373 OPC(2, OPC_CMPV_U
, cmpv
.u
),
1374 OPC(2, OPC_CMPV_S
, cmpv
.s
),
1375 OPC(2, OPC_MUL_U24
, mul
.u24
),
1376 OPC(2, OPC_MUL_S24
, mul
.s24
),
1377 OPC(2, OPC_MULL_U
, mull
.u
),
1378 OPC(2, OPC_BFREV_B
, bfrev
.b
),
1379 OPC(2, OPC_CLZ_S
, clz
.s
),
1380 OPC(2, OPC_CLZ_B
, clz
.b
),
1381 OPC(2, OPC_SHL_B
, shl
.b
),
1382 OPC(2, OPC_SHR_B
, shr
.b
),
1383 OPC(2, OPC_ASHR_B
, ashr
.b
),
1384 OPC(2, OPC_BARY_F
, bary
.f
),
1385 OPC(2, OPC_MGEN_B
, mgen
.b
),
1386 OPC(2, OPC_GETBIT_B
, getbit
.b
),
1387 OPC(2, OPC_SETRM
, setrm
),
1388 OPC(2, OPC_CBITS_B
, cbits
.b
),
1389 OPC(2, OPC_SHB
, shb
),
1390 OPC(2, OPC_MSAD
, msad
),
1393 OPC(3, OPC_MAD_U16
, mad
.u16
),
1394 OPC(3, OPC_MADSH_U16
, madsh
.u16
),
1395 OPC(3, OPC_MAD_S16
, mad
.s16
),
1396 OPC(3, OPC_MADSH_M16
, madsh
.m16
),
1397 OPC(3, OPC_MAD_U24
, mad
.u24
),
1398 OPC(3, OPC_MAD_S24
, mad
.s24
),
1399 OPC(3, OPC_MAD_F16
, mad
.f16
),
1400 OPC(3, OPC_MAD_F32
, mad
.f32
),
1401 OPC(3, OPC_SEL_B16
, sel
.b16
),
1402 OPC(3, OPC_SEL_B32
, sel
.b32
),
1403 OPC(3, OPC_SEL_S16
, sel
.s16
),
1404 OPC(3, OPC_SEL_S32
, sel
.s32
),
1405 OPC(3, OPC_SEL_F16
, sel
.f16
),
1406 OPC(3, OPC_SEL_F32
, sel
.f32
),
1407 OPC(3, OPC_SAD_S16
, sad
.s16
),
1408 OPC(3, OPC_SAD_S32
, sad
.s32
),
1411 OPC(4, OPC_RCP
, rcp
),
1412 OPC(4, OPC_RSQ
, rsq
),
1413 OPC(4, OPC_LOG2
, log2
),
1414 OPC(4, OPC_EXP2
, exp2
),
1415 OPC(4, OPC_SIN
, sin
),
1416 OPC(4, OPC_COS
, cos
),
1417 OPC(4, OPC_SQRT
, sqrt
),
1418 OPC(4, OPC_HRSQ
, hrsq
),
1419 OPC(4, OPC_HLOG2
, hlog2
),
1420 OPC(4, OPC_HEXP2
, hexp2
),
1423 OPC(5, OPC_ISAM
, isam
),
1424 OPC(5, OPC_ISAML
, isaml
),
1425 OPC(5, OPC_ISAMM
, isamm
),
1426 OPC(5, OPC_SAM
, sam
),
1427 OPC(5, OPC_SAMB
, samb
),
1428 OPC(5, OPC_SAML
, saml
),
1429 OPC(5, OPC_SAMGQ
, samgq
),
1430 OPC(5, OPC_GETLOD
, getlod
),
1431 OPC(5, OPC_CONV
, conv
),
1432 OPC(5, OPC_CONVM
, convm
),
1433 OPC(5, OPC_GETSIZE
, getsize
),
1434 OPC(5, OPC_GETBUF
, getbuf
),
1435 OPC(5, OPC_GETPOS
, getpos
),
1436 OPC(5, OPC_GETINFO
, getinfo
),
1437 OPC(5, OPC_DSX
, dsx
),
1438 OPC(5, OPC_DSY
, dsy
),
1439 OPC(5, OPC_GATHER4R
, gather4r
),
1440 OPC(5, OPC_GATHER4G
, gather4g
),
1441 OPC(5, OPC_GATHER4B
, gather4b
),
1442 OPC(5, OPC_GATHER4A
, gather4a
),
1443 OPC(5, OPC_SAMGP0
, samgp0
),
1444 OPC(5, OPC_SAMGP1
, samgp1
),
1445 OPC(5, OPC_SAMGP2
, samgp2
),
1446 OPC(5, OPC_SAMGP3
, samgp3
),
1447 OPC(5, OPC_DSXPP_1
, dsxpp
.1),
1448 OPC(5, OPC_DSYPP_1
, dsypp
.1),
1449 OPC(5, OPC_RGETPOS
, rgetpos
),
1450 OPC(5, OPC_RGETINFO
, rgetinfo
),
1454 OPC(6, OPC_LDG
, ldg
),
1455 OPC(6, OPC_LDL
, ldl
),
1456 OPC(6, OPC_LDP
, ldp
),
1457 OPC(6, OPC_STG
, stg
),
1458 OPC(6, OPC_STL
, stl
),
1459 OPC(6, OPC_STP
, stp
),
1460 OPC(6, OPC_LDIB
, ldib
),
1461 OPC(6, OPC_G2L
, g2l
),
1462 OPC(6, OPC_L2G
, l2g
),
1463 OPC(6, OPC_PREFETCH
, prefetch
),
1464 OPC(6, OPC_LDLW
, ldlw
),
1465 OPC(6, OPC_STLW
, stlw
),
1466 OPC(6, OPC_RESFMT
, resfmt
),
1467 OPC(6, OPC_RESINFO
, resinfo
),
1468 OPC(6, OPC_ATOMIC_ADD
, atomic
.add
),
1469 OPC(6, OPC_ATOMIC_SUB
, atomic
.sub
),
1470 OPC(6, OPC_ATOMIC_XCHG
, atomic
.xchg
),
1471 OPC(6, OPC_ATOMIC_INC
, atomic
.inc
),
1472 OPC(6, OPC_ATOMIC_DEC
, atomic
.dec
),
1473 OPC(6, OPC_ATOMIC_CMPXCHG
, atomic
.cmpxchg
),
1474 OPC(6, OPC_ATOMIC_MIN
, atomic
.min
),
1475 OPC(6, OPC_ATOMIC_MAX
, atomic
.max
),
1476 OPC(6, OPC_ATOMIC_AND
, atomic
.and),
1477 OPC(6, OPC_ATOMIC_OR
, atomic
.or),
1478 OPC(6, OPC_ATOMIC_XOR
, atomic
.xor),
1479 OPC(6, OPC_LDGB
, ldgb
),
1480 OPC(6, OPC_STGB
, stgb
),
1481 OPC(6, OPC_STIB
, stib
),
1482 OPC(6, OPC_LDC
, ldc
),
1483 OPC(6, OPC_LDLV
, ldlv
),
1485 OPC(7, OPC_BAR
, bar
),
1486 OPC(7, OPC_FENCE
, fence
),
1492 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr, ctx->gpu_id)]))
1494 static void print_single_instr(struct disasm_ctx
*ctx
, instr_t
*instr
)
1496 const char *name
= GETINFO(instr
)->name
;
1497 uint32_t opc
= instr_opc(instr
, ctx
->gpu_id
);
1500 fprintf(ctx
->out
, "%s", name
);
1501 GETINFO(instr
)->print(ctx
, instr
);
1503 fprintf(ctx
->out
, "unknown(%d,%d)", instr
->opc_cat
, opc
);
1505 switch (instr
->opc_cat
) {
1506 case 0: print_instr_cat0(ctx
, instr
); break;
1507 case 1: print_instr_cat1(ctx
, instr
); break;
1508 case 2: print_instr_cat2(ctx
, instr
); break;
1509 case 3: print_instr_cat3(ctx
, instr
); break;
1510 case 4: print_instr_cat4(ctx
, instr
); break;
1511 case 5: print_instr_cat5(ctx
, instr
); break;
1512 case 6: print_instr_cat6(ctx
, instr
); break;
1513 case 7: print_instr_cat7(ctx
, instr
); break;
1518 static bool print_instr(struct disasm_ctx
*ctx
, uint32_t *dwords
, int n
)
1520 instr_t
*instr
= (instr_t
*)dwords
;
1521 uint32_t opc
= instr_opc(instr
, ctx
->gpu_id
);
1523 unsigned cycles
= ctx
->stats
->instructions
;
1525 fprintf(ctx
->out
, "%s:%d:%04d:%04d[%08xx_%08xx] ", levels
[ctx
->level
],
1526 instr
->opc_cat
, n
, cycles
++, dwords
[1], dwords
[0]);
1529 /* print unknown bits: */
1530 if (debug
& PRINT_RAW
)
1531 fprintf(ctx
->out
, "[%08xx_%08xx] ", dwords
[1] & 0x001ff800, dwords
[0] & 0x00000000);
1533 if (debug
& PRINT_VERBOSE
)
1534 fprintf(ctx
->out
, "%d,%02d ", instr
->opc_cat
, opc
);
1537 /* NOTE: order flags are printed is a bit fugly.. but for now I
1538 * try to match the order in llvm-a3xx disassembler for easy
1542 ctx
->repeat
= instr_repeat(instr
);
1543 ctx
->stats
->instructions
+= 1 + ctx
->repeat
;
1544 ctx
->stats
->instlen
++;
1547 fprintf(ctx
->out
, "(sy)");
1550 if (instr
->ss
&& ((instr
->opc_cat
<= 4) || (instr
->opc_cat
== 7))) {
1551 fprintf(ctx
->out
, "(ss)");
1555 fprintf(ctx
->out
, "(jp)");
1556 if ((instr
->opc_cat
== 0) && instr
->cat0
.eq
)
1557 fprintf(ctx
->out
, "(eq)");
1558 if (instr_sat(instr
))
1559 fprintf(ctx
->out
, "(sat)");
1561 fprintf(ctx
->out
, "(rpt%d)", ctx
->repeat
);
1562 else if ((instr
->opc_cat
== 2) && (instr
->cat2
.src1_r
|| instr
->cat2
.src2_r
))
1563 nop
= (instr
->cat2
.src2_r
* 2) + instr
->cat2
.src1_r
;
1564 else if ((instr
->opc_cat
== 3) && (instr
->cat3
.src1_r
|| instr
->cat3
.src2_r
))
1565 nop
= (instr
->cat3
.src2_r
* 2) + instr
->cat3
.src1_r
;
1566 ctx
->stats
->instructions
+= nop
;
1567 ctx
->stats
->nops
+= nop
;
1569 ctx
->stats
->nops
+= 1 + ctx
->repeat
;
1571 fprintf(ctx
->out
, "(nop%d) ", nop
);
1573 if (instr
->ul
&& ((2 <= instr
->opc_cat
) && (instr
->opc_cat
<= 4)))
1574 fprintf(ctx
->out
, "(ul)");
1576 print_single_instr(ctx
, instr
);
1577 fprintf(ctx
->out
, "\n");
1579 process_reg_dst(ctx
);
1581 if ((instr
->opc_cat
<= 4) && (debug
& EXPAND_REPEAT
)) {
1583 for (i
= 0; i
< nop
; i
++) {
1584 fprintf(ctx
->out
, "%s:%d:%04d:%04d[ ] ",
1585 levels
[ctx
->level
], instr
->opc_cat
, n
, cycles
++);
1586 fprintf(ctx
->out
, "nop\n");
1588 for (i
= 0; i
< ctx
->repeat
; i
++) {
1589 ctx
->repeatidx
= i
+ 1;
1590 fprintf(ctx
->out
, "%s:%d:%04d:%04d[ ] ",
1591 levels
[ctx
->level
], instr
->opc_cat
, n
, cycles
++);
1593 print_single_instr(ctx
, instr
);
1594 fprintf(ctx
->out
, "\n");
1599 return (instr
->opc_cat
== 0) &&
1600 ((opc
== OPC_END
) || (opc
== OPC_CHSH
));
1603 int disasm_a3xx(uint32_t *dwords
, int sizedwords
, int level
, FILE *out
, unsigned gpu_id
)
1605 struct shader_stats stats
;
1606 return disasm_a3xx_stat(dwords
, sizedwords
, level
, out
, gpu_id
, &stats
);
1609 int disasm_a3xx_stat(uint32_t *dwords
, int sizedwords
, int level
, FILE *out
,
1610 unsigned gpu_id
, struct shader_stats
*stats
)
1612 struct disasm_ctx ctx
;
1615 bool has_end
= false;
1617 // ir3_assert((sizedwords % 2) == 0);
1619 memset(&ctx
, 0, sizeof(ctx
));
1622 ctx
.gpu_id
= gpu_id
;
1624 memset(ctx
.stats
, 0, sizeof(*ctx
.stats
));
1626 for (i
= 0; i
< sizedwords
; i
+= 2) {
1627 has_end
|= print_instr(&ctx
, &dwords
[i
], i
/2);
1630 if (dwords
[i
] == 0 && dwords
[i
+ 1] == 0)
1638 print_reg_stats(&ctx
);