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 */
41 static enum debug_t debug
;
43 #define printf debug_printf
45 static const char *levels
[] = {
64 static const char *component
= "xyzw";
66 static const char *type
[] = {
81 /* current instruction repeat flag: */
85 static void print_reg(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
86 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
88 const char type
= c
? 'c' : 'r';
90 // XXX I prefer - and || for neg/abs, but preserving format used
91 // by libllvm-a3xx for easy diffing..
94 fprintf(ctx
->out
, "(absneg)");
96 fprintf(ctx
->out
, "(neg)");
98 fprintf(ctx
->out
, "(abs)");
101 fprintf(ctx
->out
, "(r)");
104 fprintf(ctx
->out
, "%d", reg
.iim_val
);
105 } else if (addr_rel
) {
106 /* I would just use %+d but trying to make it diff'able with
110 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
? "" : "h", type
, -reg
.iim_val
);
111 else if (reg
.iim_val
> 0)
112 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
? "" : "h", type
, reg
.iim_val
);
114 fprintf(ctx
->out
, "%s%c<a0.x>", full
? "" : "h", type
);
115 } else if ((reg
.num
== REG_A0
) && !c
) {
116 fprintf(ctx
->out
, "a0.%c", component
[reg
.comp
]);
117 } else if ((reg
.num
== REG_P0
) && !c
) {
118 fprintf(ctx
->out
, "p0.%c", component
[reg
.comp
]);
120 fprintf(ctx
->out
, "%s%c%d.%c", full
? "" : "h", type
, reg
.num
& 0x3f, component
[reg
.comp
]);
125 static void print_reg_dst(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool addr_rel
)
127 print_reg(ctx
, reg
, full
, false, false, false, false, false, addr_rel
);
130 static void print_reg_src(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
131 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
133 print_reg(ctx
, reg
, full
, r
, c
, im
, neg
, abs
, addr_rel
);
136 /* TODO switch to using reginfo struct everywhere, since more readable
137 * than passing a bunch of bools to print_reg_src
151 static void print_src(struct disasm_ctx
*ctx
, struct reginfo
*info
)
153 print_reg_src(ctx
, info
->reg
, info
->full
, info
->r
, info
->c
, info
->im
,
154 info
->neg
, info
->abs
, info
->addr_rel
);
157 //static void print_dst(struct disasm_ctx *ctx, struct reginfo *info)
159 // print_reg_dst(ctx, info->reg, info->full, info->addr_rel);
162 static void print_instr_cat0(struct disasm_ctx
*ctx
, instr_t
*instr
)
164 instr_cat0_t
*cat0
= &instr
->cat0
;
168 fprintf(ctx
->out
, " %sp0.%c", cat0
->inv
? "!" : "",
169 component
[cat0
->comp
]);
172 fprintf(ctx
->out
, " %sp0.%c, #%d", cat0
->inv
? "!" : "",
173 component
[cat0
->comp
], cat0
->a3xx
.immed
);
177 fprintf(ctx
->out
, " #%d", cat0
->a3xx
.immed
);
181 if ((debug
& PRINT_VERBOSE
) && (cat0
->dummy2
|cat0
->dummy3
|cat0
->dummy4
))
182 fprintf(ctx
->out
, "\t{0: %x,%x,%x}", cat0
->dummy2
, cat0
->dummy3
, cat0
->dummy4
);
185 static void print_instr_cat1(struct disasm_ctx
*ctx
, instr_t
*instr
)
187 instr_cat1_t
*cat1
= &instr
->cat1
;
190 fprintf(ctx
->out
, "(ul)");
192 if (cat1
->src_type
== cat1
->dst_type
) {
193 if ((cat1
->src_type
== TYPE_S16
) && (((reg_t
)cat1
->dst
).num
== REG_A0
)) {
194 /* special case (nmemonic?): */
195 fprintf(ctx
->out
, "mova");
197 fprintf(ctx
->out
, "mov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
200 fprintf(ctx
->out
, "cov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
203 fprintf(ctx
->out
, " ");
206 fprintf(ctx
->out
, "(even)");
209 fprintf(ctx
->out
, "(pos_infinity)");
211 print_reg_dst(ctx
, (reg_t
)(cat1
->dst
), type_size(cat1
->dst_type
) == 32,
214 fprintf(ctx
->out
, ", ");
216 /* ugg, have to special case this.. vs print_reg().. */
218 if (type_float(cat1
->src_type
))
219 fprintf(ctx
->out
, "(%f)", cat1
->fim_val
);
220 else if (type_uint(cat1
->src_type
))
221 fprintf(ctx
->out
, "0x%08x", cat1
->uim_val
);
223 fprintf(ctx
->out
, "%d", cat1
->iim_val
);
224 } else if (cat1
->src_rel
&& !cat1
->src_c
) {
225 /* I would just use %+d but trying to make it diff'able with
228 char type
= cat1
->src_rel_c
? 'c' : 'r';
230 fprintf(ctx
->out
, "%c<a0.x - %d>", type
, -cat1
->off
);
231 else if (cat1
->off
> 0)
232 fprintf(ctx
->out
, "%c<a0.x + %d>", type
, cat1
->off
);
234 fprintf(ctx
->out
, "%c<a0.x>", type
);
236 print_reg_src(ctx
, (reg_t
)(cat1
->src
), type_size(cat1
->src_type
) == 32,
237 cat1
->src_r
, cat1
->src_c
, cat1
->src_im
, false, false, false);
240 if ((debug
& PRINT_VERBOSE
) && (cat1
->must_be_0
))
241 fprintf(ctx
->out
, "\t{1: %x}", cat1
->must_be_0
);
244 static void print_instr_cat2(struct disasm_ctx
*ctx
, instr_t
*instr
)
246 instr_cat2_t
*cat2
= &instr
->cat2
;
247 static const char *cond
[] = {
257 switch (_OPC(2, cat2
->opc
)) {
264 fprintf(ctx
->out
, ".%s", cond
[cat2
->cond
]);
268 fprintf(ctx
->out
, " ");
270 fprintf(ctx
->out
, "(ei)");
271 print_reg_dst(ctx
, (reg_t
)(cat2
->dst
), cat2
->full
^ cat2
->dst_half
, false);
272 fprintf(ctx
->out
, ", ");
274 if (cat2
->c1
.src1_c
) {
275 print_reg_src(ctx
, (reg_t
)(cat2
->c1
.src1
), cat2
->full
, cat2
->src1_r
,
276 cat2
->c1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
277 cat2
->src1_abs
, false);
278 } else if (cat2
->rel1
.src1_rel
) {
279 print_reg_src(ctx
, (reg_t
)(cat2
->rel1
.src1
), cat2
->full
, cat2
->src1_r
,
280 cat2
->rel1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
281 cat2
->src1_abs
, cat2
->rel1
.src1_rel
);
283 print_reg_src(ctx
, (reg_t
)(cat2
->src1
), cat2
->full
, cat2
->src1_r
,
284 false, cat2
->src1_im
, cat2
->src1_neg
,
285 cat2
->src1_abs
, false);
288 switch (_OPC(2, cat2
->opc
)) {
303 /* these only have one src reg */
306 fprintf(ctx
->out
, ", ");
307 if (cat2
->c2
.src2_c
) {
308 print_reg_src(ctx
, (reg_t
)(cat2
->c2
.src2
), cat2
->full
, cat2
->src2_r
,
309 cat2
->c2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
310 cat2
->src2_abs
, false);
311 } else if (cat2
->rel2
.src2_rel
) {
312 print_reg_src(ctx
, (reg_t
)(cat2
->rel2
.src2
), cat2
->full
, cat2
->src2_r
,
313 cat2
->rel2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
314 cat2
->src2_abs
, cat2
->rel2
.src2_rel
);
316 print_reg_src(ctx
, (reg_t
)(cat2
->src2
), cat2
->full
, cat2
->src2_r
,
317 false, cat2
->src2_im
, cat2
->src2_neg
,
318 cat2
->src2_abs
, false);
324 static void print_instr_cat3(struct disasm_ctx
*ctx
, instr_t
*instr
)
326 instr_cat3_t
*cat3
= &instr
->cat3
;
327 bool full
= instr_cat3_full(cat3
);
329 fprintf(ctx
->out
, " ");
330 print_reg_dst(ctx
, (reg_t
)(cat3
->dst
), full
^ cat3
->dst_half
, false);
331 fprintf(ctx
->out
, ", ");
332 if (cat3
->c1
.src1_c
) {
333 print_reg_src(ctx
, (reg_t
)(cat3
->c1
.src1
), full
,
334 cat3
->src1_r
, cat3
->c1
.src1_c
, false, cat3
->src1_neg
,
336 } else if (cat3
->rel1
.src1_rel
) {
337 print_reg_src(ctx
, (reg_t
)(cat3
->rel1
.src1
), full
,
338 cat3
->src1_r
, cat3
->rel1
.src1_c
, false, cat3
->src1_neg
,
339 false, cat3
->rel1
.src1_rel
);
341 print_reg_src(ctx
, (reg_t
)(cat3
->src1
), full
,
342 cat3
->src1_r
, false, false, cat3
->src1_neg
,
345 fprintf(ctx
->out
, ", ");
346 print_reg_src(ctx
, (reg_t
)cat3
->src2
, full
,
347 cat3
->src2_r
, cat3
->src2_c
, false, cat3
->src2_neg
,
349 fprintf(ctx
->out
, ", ");
350 if (cat3
->c2
.src3_c
) {
351 print_reg_src(ctx
, (reg_t
)(cat3
->c2
.src3
), full
,
352 cat3
->src3_r
, cat3
->c2
.src3_c
, false, cat3
->src3_neg
,
354 } else if (cat3
->rel2
.src3_rel
) {
355 print_reg_src(ctx
, (reg_t
)(cat3
->rel2
.src3
), full
,
356 cat3
->src3_r
, cat3
->rel2
.src3_c
, false, cat3
->src3_neg
,
357 false, cat3
->rel2
.src3_rel
);
359 print_reg_src(ctx
, (reg_t
)(cat3
->src3
), full
,
360 cat3
->src3_r
, false, false, cat3
->src3_neg
,
365 static void print_instr_cat4(struct disasm_ctx
*ctx
, instr_t
*instr
)
367 instr_cat4_t
*cat4
= &instr
->cat4
;
369 fprintf(ctx
->out
, " ");
370 print_reg_dst(ctx
, (reg_t
)(cat4
->dst
), cat4
->full
^ cat4
->dst_half
, false);
371 fprintf(ctx
->out
, ", ");
374 print_reg_src(ctx
, (reg_t
)(cat4
->c
.src
), cat4
->full
,
375 cat4
->src_r
, cat4
->c
.src_c
, cat4
->src_im
,
376 cat4
->src_neg
, cat4
->src_abs
, false);
377 } else if (cat4
->rel
.src_rel
) {
378 print_reg_src(ctx
, (reg_t
)(cat4
->rel
.src
), cat4
->full
,
379 cat4
->src_r
, cat4
->rel
.src_c
, cat4
->src_im
,
380 cat4
->src_neg
, cat4
->src_abs
, cat4
->rel
.src_rel
);
382 print_reg_src(ctx
, (reg_t
)(cat4
->src
), cat4
->full
,
383 cat4
->src_r
, false, cat4
->src_im
,
384 cat4
->src_neg
, cat4
->src_abs
, false);
387 if ((debug
& PRINT_VERBOSE
) && (cat4
->dummy1
|cat4
->dummy2
))
388 fprintf(ctx
->out
, "\t{4: %x,%x}", cat4
->dummy1
, cat4
->dummy2
);
391 static void print_instr_cat5(struct disasm_ctx
*ctx
, instr_t
*instr
)
393 static const struct {
394 bool src1
, src2
, samp
, tex
;
396 [opc_op(OPC_ISAM
)] = { true, false, true, true, },
397 [opc_op(OPC_ISAML
)] = { true, true, true, true, },
398 [opc_op(OPC_ISAMM
)] = { true, false, true, true, },
399 [opc_op(OPC_SAM
)] = { true, false, true, true, },
400 [opc_op(OPC_SAMB
)] = { true, true, true, true, },
401 [opc_op(OPC_SAML
)] = { true, true, true, true, },
402 [opc_op(OPC_SAMGQ
)] = { true, false, true, true, },
403 [opc_op(OPC_GETLOD
)] = { true, false, true, true, },
404 [opc_op(OPC_CONV
)] = { true, true, true, true, },
405 [opc_op(OPC_CONVM
)] = { true, true, true, true, },
406 [opc_op(OPC_GETSIZE
)] = { true, false, false, true, },
407 [opc_op(OPC_GETBUF
)] = { false, false, false, true, },
408 [opc_op(OPC_GETPOS
)] = { true, false, false, true, },
409 [opc_op(OPC_GETINFO
)] = { false, false, false, true, },
410 [opc_op(OPC_DSX
)] = { true, false, false, false, },
411 [opc_op(OPC_DSY
)] = { true, false, false, false, },
412 [opc_op(OPC_GATHER4R
)] = { true, false, true, true, },
413 [opc_op(OPC_GATHER4G
)] = { true, false, true, true, },
414 [opc_op(OPC_GATHER4B
)] = { true, false, true, true, },
415 [opc_op(OPC_GATHER4A
)] = { true, false, true, true, },
416 [opc_op(OPC_SAMGP0
)] = { true, false, true, true, },
417 [opc_op(OPC_SAMGP1
)] = { true, false, true, true, },
418 [opc_op(OPC_SAMGP2
)] = { true, false, true, true, },
419 [opc_op(OPC_SAMGP3
)] = { true, false, true, true, },
420 [opc_op(OPC_DSXPP_1
)] = { true, false, false, false, },
421 [opc_op(OPC_DSYPP_1
)] = { true, false, false, false, },
422 [opc_op(OPC_RGETPOS
)] = { false, false, false, false, },
423 [opc_op(OPC_RGETINFO
)] = { false, false, false, false, },
425 instr_cat5_t
*cat5
= &instr
->cat5
;
428 if (cat5
->is_3d
) fprintf(ctx
->out
, ".3d");
429 if (cat5
->is_a
) fprintf(ctx
->out
, ".a");
430 if (cat5
->is_o
) fprintf(ctx
->out
, ".o");
431 if (cat5
->is_p
) fprintf(ctx
->out
, ".p");
432 if (cat5
->is_s
) fprintf(ctx
->out
, ".s");
433 if (cat5
->is_s2en
) fprintf(ctx
->out
, ".s2en");
435 fprintf(ctx
->out
, " ");
437 switch (_OPC(5, cat5
->opc
)) {
442 fprintf(ctx
->out
, "(%s)", type
[cat5
->type
]);
446 fprintf(ctx
->out
, "(");
447 for (i
= 0; i
< 4; i
++)
448 if (cat5
->wrmask
& (1 << i
))
449 fprintf(ctx
->out
, "%c", "xyzw"[i
]);
450 fprintf(ctx
->out
, ")");
452 print_reg_dst(ctx
, (reg_t
)(cat5
->dst
), type_size(cat5
->type
) == 32, false);
454 if (info
[cat5
->opc
].src1
) {
455 fprintf(ctx
->out
, ", ");
456 print_reg_src(ctx
, (reg_t
)(cat5
->src1
), cat5
->full
, false, false, false,
457 false, false, false);
461 fprintf(ctx
->out
, ", ");
462 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src2
), cat5
->full
, false, false, false,
463 false, false, false);
464 fprintf(ctx
->out
, ", ");
465 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src3
), false, false, false, false,
466 false, false, false);
468 if (cat5
->is_o
|| info
[cat5
->opc
].src2
) {
469 fprintf(ctx
->out
, ", ");
470 print_reg_src(ctx
, (reg_t
)(cat5
->norm
.src2
), cat5
->full
,
471 false, false, false, false, false, false);
473 if (info
[cat5
->opc
].samp
)
474 fprintf(ctx
->out
, ", s#%d", cat5
->norm
.samp
);
475 if (info
[cat5
->opc
].tex
)
476 fprintf(ctx
->out
, ", t#%d", cat5
->norm
.tex
);
479 if (debug
& PRINT_VERBOSE
) {
481 if ((debug
& PRINT_VERBOSE
) && (cat5
->s2en
.dummy1
|cat5
->s2en
.dummy2
|cat5
->dummy2
))
482 fprintf(ctx
->out
, "\t{5: %x,%x,%x}", cat5
->s2en
.dummy1
, cat5
->s2en
.dummy2
, cat5
->dummy2
);
484 if ((debug
& PRINT_VERBOSE
) && (cat5
->norm
.dummy1
|cat5
->dummy2
))
485 fprintf(ctx
->out
, "\t{5: %x,%x}", cat5
->norm
.dummy1
, cat5
->dummy2
);
490 static void print_instr_cat6(struct disasm_ctx
*ctx
, instr_t
*instr
)
492 instr_cat6_t
*cat6
= &instr
->cat6
;
493 char sd
= 0, ss
= 0; /* dst/src address space */
495 struct reginfo dst
, src1
, src2
;
496 int src1off
= 0, dstoff
= 0;
498 memset(&dst
, 0, sizeof(dst
));
499 memset(&src1
, 0, sizeof(src1
));
500 memset(&src2
, 0, sizeof(src2
));
502 switch (_OPC(6, cat6
->opc
)) {
505 dst
.full
= type_size(cat6
->type
) == 32;
506 src1
.full
= type_size(cat6
->type
) == 32;
507 src2
.full
= type_size(cat6
->type
) == 32;
522 src1
.full
= type_size(cat6
->type
) == 32;
523 src2
.full
= type_size(cat6
->type
) == 32;
526 dst
.full
= type_size(cat6
->type
) == 32;
532 switch (_OPC(6, cat6
->opc
)) {
536 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
539 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
540 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
541 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
542 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
546 fprintf(ctx
->out
, ".%s", cat6
->stgb
.typed
? "typed" : "untyped");
547 fprintf(ctx
->out
, ".%dd", cat6
->stgb
.d
+ 1);
548 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
549 fprintf(ctx
->out
, ".%d", cat6
->stgb
.type_size
+ 1);
553 case OPC_ATOMIC_XCHG
:
556 case OPC_ATOMIC_CMPXCHG
:
562 ss
= cat6
->g
? 'g' : 'l';
563 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
564 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
565 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
566 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
567 fprintf(ctx
->out
, ".%c", ss
);
570 dst
.im
= cat6
->g
&& !cat6
->dst_off
;
571 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
574 fprintf(ctx
->out
, " ");
576 switch (_OPC(6, cat6
->opc
)) {
617 dst
.full
= false; // XXX or inverts??
621 if ((_OPC(6, cat6
->opc
) == OPC_STGB
) || (_OPC(6, cat6
->opc
) == OPC_STIB
)) {
624 memset(&src3
, 0, sizeof(src3
));
626 src1
.reg
= (reg_t
)(cat6
->stgb
.src1
);
627 src2
.reg
= (reg_t
)(cat6
->stgb
.src2
);
628 src2
.im
= cat6
->stgb
.src2_im
;
629 src3
.reg
= (reg_t
)(cat6
->stgb
.src3
);
630 src3
.im
= cat6
->stgb
.src3_im
;
633 fprintf(ctx
->out
, "g[%u], ", cat6
->stgb
.dst_ssbo
);
634 print_src(ctx
, &src1
);
635 fprintf(ctx
->out
, ", ");
636 print_src(ctx
, &src2
);
637 fprintf(ctx
->out
, ", ");
638 print_src(ctx
, &src3
);
640 if (debug
& PRINT_VERBOSE
)
641 fprintf(ctx
->out
, " (pad0=%x, pad3=%x)", cat6
->stgb
.pad0
, cat6
->stgb
.pad3
);
646 if (is_atomic(_OPC(6, cat6
->opc
))) {
648 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
649 src1
.im
= cat6
->ldgb
.src1_im
;
650 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
651 src2
.im
= cat6
->ldgb
.src2_im
;
652 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
654 print_src(ctx
, &dst
);
655 fprintf(ctx
->out
, ", ");
658 memset(&src3
, 0, sizeof(src3
));
660 src3
.reg
= (reg_t
)(cat6
->ldgb
.src3
);
663 /* For images, the ".typed" variant is used and src2 is
664 * the ivecN coordinates, ie ivec2 for 2d.
666 * For SSBOs, the ".untyped" variant is used and src2 is
667 * a simple dword offset.. src3 appears to be
668 * uvec2(offset * 4, 0). Not sure the point of that.
671 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
672 print_src(ctx
, &src1
); /* value */
673 fprintf(ctx
->out
, ", ");
674 print_src(ctx
, &src2
); /* offset/coords */
675 fprintf(ctx
->out
, ", ");
676 print_src(ctx
, &src3
); /* 64b byte offset.. */
678 if (debug
& PRINT_VERBOSE
) {
679 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
,
680 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
682 } else { /* ss == 'l' */
683 fprintf(ctx
->out
, "l[");
684 print_src(ctx
, &src1
); /* simple byte offset */
685 fprintf(ctx
->out
, "], ");
686 print_src(ctx
, &src2
); /* value */
688 if (debug
& PRINT_VERBOSE
) {
689 fprintf(ctx
->out
, " (src3=%x, pad0=%x, pad3=%x, mustbe0=%x)",
690 cat6
->ldgb
.src3
, cat6
->ldgb
.pad0
,
691 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
696 } else if (_OPC(6, cat6
->opc
) == OPC_RESINFO
) {
697 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
699 print_src(ctx
, &dst
);
700 fprintf(ctx
->out
, ", ");
701 fprintf(ctx
->out
, "g[%u]", cat6
->ldgb
.src_ssbo
);
704 } else if (_OPC(6, cat6
->opc
) == OPC_LDGB
) {
706 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
707 src1
.im
= cat6
->ldgb
.src1_im
;
708 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
709 src2
.im
= cat6
->ldgb
.src2_im
;
710 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
712 print_src(ctx
, &dst
);
713 fprintf(ctx
->out
, ", ");
714 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
715 print_src(ctx
, &src1
);
716 fprintf(ctx
->out
, ", ");
717 print_src(ctx
, &src2
);
719 if (debug
& PRINT_VERBOSE
)
720 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
, cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
725 dst
.reg
= (reg_t
)(cat6
->c
.dst
);
726 dstoff
= cat6
->c
.off
;
728 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
732 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
733 src1
.im
= cat6
->a
.src1_im
;
734 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
735 src2
.im
= cat6
->a
.src2_im
;
736 src1off
= cat6
->a
.off
;
738 src1
.reg
= (reg_t
)(cat6
->b
.src1
);
739 src1
.im
= cat6
->b
.src1_im
;
740 src2
.reg
= (reg_t
)(cat6
->b
.src2
);
741 src2
.im
= cat6
->b
.src2_im
;
746 fprintf(ctx
->out
, "%c[", sd
);
747 /* note: dst might actually be a src (ie. address to store to) */
748 print_src(ctx
, &dst
);
750 fprintf(ctx
->out
, "%+d", dstoff
);
752 fprintf(ctx
->out
, "]");
753 fprintf(ctx
->out
, ", ");
757 fprintf(ctx
->out
, "%c[", ss
);
759 /* can have a larger than normal immed, so hack: */
761 fprintf(ctx
->out
, "%u", src1
.reg
.dummy13
);
763 print_src(ctx
, &src1
);
767 fprintf(ctx
->out
, "%+d", src1off
);
769 fprintf(ctx
->out
, "]");
771 switch (_OPC(6, cat6
->opc
)) {
776 fprintf(ctx
->out
, ", ");
777 print_src(ctx
, &src2
);
782 static void print_instr_cat7(struct disasm_ctx
*ctx
, instr_t
*instr
)
784 instr_cat7_t
*cat7
= &instr
->cat7
;
787 fprintf(ctx
->out
, ".g");
789 fprintf(ctx
->out
, ".l");
791 if (_OPC(7, cat7
->opc
) == OPC_FENCE
) {
793 fprintf(ctx
->out
, ".r");
795 fprintf(ctx
->out
, ".w");
799 /* size of largest OPC field of all the instruction categories: */
802 static const struct opc_info
{
806 void (*print
)(struct disasm_ctx
*ctx
, instr_t
*instr
);
807 } opcs
[1 << (3+NOPC_BITS
)] = {
808 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat }
810 OPC(0, OPC_NOP
, nop
),
812 OPC(0, OPC_JUMP
, jump
),
813 OPC(0, OPC_CALL
, call
),
814 OPC(0, OPC_RET
, ret
),
815 OPC(0, OPC_KILL
, kill
),
816 OPC(0, OPC_END
, end
),
817 OPC(0, OPC_EMIT
, emit
),
818 OPC(0, OPC_CUT
, cut
),
819 OPC(0, OPC_CHMASK
, chmask
),
820 OPC(0, OPC_CHSH
, chsh
),
821 OPC(0, OPC_FLOW_REV
, flow_rev
),
827 OPC(2, OPC_ADD_F
, add
.f
),
828 OPC(2, OPC_MIN_F
, min
.f
),
829 OPC(2, OPC_MAX_F
, max
.f
),
830 OPC(2, OPC_MUL_F
, mul
.f
),
831 OPC(2, OPC_SIGN_F
, sign
.f
),
832 OPC(2, OPC_CMPS_F
, cmps
.f
),
833 OPC(2, OPC_ABSNEG_F
, absneg
.f
),
834 OPC(2, OPC_CMPV_F
, cmpv
.f
),
835 OPC(2, OPC_FLOOR_F
, floor
.f
),
836 OPC(2, OPC_CEIL_F
, ceil
.f
),
837 OPC(2, OPC_RNDNE_F
, rndne
.f
),
838 OPC(2, OPC_RNDAZ_F
, rndaz
.f
),
839 OPC(2, OPC_TRUNC_F
, trunc
.f
),
840 OPC(2, OPC_ADD_U
, add
.u
),
841 OPC(2, OPC_ADD_S
, add
.s
),
842 OPC(2, OPC_SUB_U
, sub
.u
),
843 OPC(2, OPC_SUB_S
, sub
.s
),
844 OPC(2, OPC_CMPS_U
, cmps
.u
),
845 OPC(2, OPC_CMPS_S
, cmps
.s
),
846 OPC(2, OPC_MIN_U
, min
.u
),
847 OPC(2, OPC_MIN_S
, min
.s
),
848 OPC(2, OPC_MAX_U
, max
.u
),
849 OPC(2, OPC_MAX_S
, max
.s
),
850 OPC(2, OPC_ABSNEG_S
, absneg
.s
),
851 OPC(2, OPC_AND_B
, and.b
),
852 OPC(2, OPC_OR_B
, or.b
),
853 OPC(2, OPC_NOT_B
, not.b
),
854 OPC(2, OPC_XOR_B
, xor.b
),
855 OPC(2, OPC_CMPV_U
, cmpv
.u
),
856 OPC(2, OPC_CMPV_S
, cmpv
.s
),
857 OPC(2, OPC_MUL_U
, mul
.u
),
858 OPC(2, OPC_MUL_S
, mul
.s
),
859 OPC(2, OPC_MULL_U
, mull
.u
),
860 OPC(2, OPC_BFREV_B
, bfrev
.b
),
861 OPC(2, OPC_CLZ_S
, clz
.s
),
862 OPC(2, OPC_CLZ_B
, clz
.b
),
863 OPC(2, OPC_SHL_B
, shl
.b
),
864 OPC(2, OPC_SHR_B
, shr
.b
),
865 OPC(2, OPC_ASHR_B
, ashr
.b
),
866 OPC(2, OPC_BARY_F
, bary
.f
),
867 OPC(2, OPC_MGEN_B
, mgen
.b
),
868 OPC(2, OPC_GETBIT_B
, getbit
.b
),
869 OPC(2, OPC_SETRM
, setrm
),
870 OPC(2, OPC_CBITS_B
, cbits
.b
),
871 OPC(2, OPC_SHB
, shb
),
872 OPC(2, OPC_MSAD
, msad
),
875 OPC(3, OPC_MAD_U16
, mad
.u16
),
876 OPC(3, OPC_MADSH_U16
, madsh
.u16
),
877 OPC(3, OPC_MAD_S16
, mad
.s16
),
878 OPC(3, OPC_MADSH_M16
, madsh
.m16
),
879 OPC(3, OPC_MAD_U24
, mad
.u24
),
880 OPC(3, OPC_MAD_S24
, mad
.s24
),
881 OPC(3, OPC_MAD_F16
, mad
.f16
),
882 OPC(3, OPC_MAD_F32
, mad
.f32
),
883 OPC(3, OPC_SEL_B16
, sel
.b16
),
884 OPC(3, OPC_SEL_B32
, sel
.b32
),
885 OPC(3, OPC_SEL_S16
, sel
.s16
),
886 OPC(3, OPC_SEL_S32
, sel
.s32
),
887 OPC(3, OPC_SEL_F16
, sel
.f16
),
888 OPC(3, OPC_SEL_F32
, sel
.f32
),
889 OPC(3, OPC_SAD_S16
, sad
.s16
),
890 OPC(3, OPC_SAD_S32
, sad
.s32
),
893 OPC(4, OPC_RCP
, rcp
),
894 OPC(4, OPC_RSQ
, rsq
),
895 OPC(4, OPC_LOG2
, log2
),
896 OPC(4, OPC_EXP2
, exp2
),
897 OPC(4, OPC_SIN
, sin
),
898 OPC(4, OPC_COS
, cos
),
899 OPC(4, OPC_SQRT
, sqrt
),
902 OPC(5, OPC_ISAM
, isam
),
903 OPC(5, OPC_ISAML
, isaml
),
904 OPC(5, OPC_ISAMM
, isamm
),
905 OPC(5, OPC_SAM
, sam
),
906 OPC(5, OPC_SAMB
, samb
),
907 OPC(5, OPC_SAML
, saml
),
908 OPC(5, OPC_SAMGQ
, samgq
),
909 OPC(5, OPC_GETLOD
, getlod
),
910 OPC(5, OPC_CONV
, conv
),
911 OPC(5, OPC_CONVM
, convm
),
912 OPC(5, OPC_GETSIZE
, getsize
),
913 OPC(5, OPC_GETBUF
, getbuf
),
914 OPC(5, OPC_GETPOS
, getpos
),
915 OPC(5, OPC_GETINFO
, getinfo
),
916 OPC(5, OPC_DSX
, dsx
),
917 OPC(5, OPC_DSY
, dsy
),
918 OPC(5, OPC_GATHER4R
, gather4r
),
919 OPC(5, OPC_GATHER4G
, gather4g
),
920 OPC(5, OPC_GATHER4B
, gather4b
),
921 OPC(5, OPC_GATHER4A
, gather4a
),
922 OPC(5, OPC_SAMGP0
, samgp0
),
923 OPC(5, OPC_SAMGP1
, samgp1
),
924 OPC(5, OPC_SAMGP2
, samgp2
),
925 OPC(5, OPC_SAMGP3
, samgp3
),
926 OPC(5, OPC_DSXPP_1
, dsxpp
.1),
927 OPC(5, OPC_DSYPP_1
, dsypp
.1),
928 OPC(5, OPC_RGETPOS
, rgetpos
),
929 OPC(5, OPC_RGETINFO
, rgetinfo
),
933 OPC(6, OPC_LDG
, ldg
),
934 OPC(6, OPC_LDL
, ldl
),
935 OPC(6, OPC_LDP
, ldp
),
936 OPC(6, OPC_STG
, stg
),
937 OPC(6, OPC_STL
, stl
),
938 OPC(6, OPC_STP
, stp
),
939 OPC(6, OPC_STI
, sti
),
940 OPC(6, OPC_G2L
, g2l
),
941 OPC(6, OPC_L2G
, l2g
),
942 OPC(6, OPC_PREFETCH
, prefetch
),
943 OPC(6, OPC_LDLW
, ldlw
),
944 OPC(6, OPC_STLW
, stlw
),
945 OPC(6, OPC_RESFMT
, resfmt
),
946 OPC(6, OPC_RESINFO
, resinfo
),
947 OPC(6, OPC_ATOMIC_ADD
, atomic
.add
),
948 OPC(6, OPC_ATOMIC_SUB
, atomic
.sub
),
949 OPC(6, OPC_ATOMIC_XCHG
, atomic
.xchg
),
950 OPC(6, OPC_ATOMIC_INC
, atomic
.inc
),
951 OPC(6, OPC_ATOMIC_DEC
, atomic
.dec
),
952 OPC(6, OPC_ATOMIC_CMPXCHG
, atomic
.cmpxchg
),
953 OPC(6, OPC_ATOMIC_MIN
, atomic
.min
),
954 OPC(6, OPC_ATOMIC_MAX
, atomic
.max
),
955 OPC(6, OPC_ATOMIC_AND
, atomic
.and),
956 OPC(6, OPC_ATOMIC_OR
, atomic
.or),
957 OPC(6, OPC_ATOMIC_XOR
, atomic
.xor),
958 OPC(6, OPC_LDGB
, ldgb
),
959 OPC(6, OPC_STGB
, stgb
),
960 OPC(6, OPC_STIB
, stib
),
961 OPC(6, OPC_LDC
, ldc
),
962 OPC(6, OPC_LDLV
, ldlv
),
964 OPC(7, OPC_BAR
, bar
),
965 OPC(7, OPC_FENCE
, fence
),
970 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr)]))
972 // XXX hack.. probably should move this table somewhere common:
974 const char *ir3_instr_name(struct ir3_instruction
*instr
)
976 if (opc_cat(instr
->opc
) == -1) return "??meta??";
977 return opcs
[instr
->opc
].name
;
980 static bool print_instr(struct disasm_ctx
*ctx
, uint32_t *dwords
, int n
)
982 instr_t
*instr
= (instr_t
*)dwords
;
983 uint32_t opc
= instr_opc(instr
);
986 if (debug
& PRINT_VERBOSE
)
987 fprintf(ctx
->out
, "%s%04d[%08xx_%08xx] ", levels
[ctx
->level
], n
, dwords
[1], dwords
[0]);
989 /* NOTE: order flags are printed is a bit fugly.. but for now I
990 * try to match the order in llvm-a3xx disassembler for easy
994 ctx
->repeat
= instr_repeat(instr
);
997 fprintf(ctx
->out
, "(sy)");
998 if (instr
->ss
&& ((instr
->opc_cat
<= 4) || (instr
->opc_cat
== 7)))
999 fprintf(ctx
->out
, "(ss)");
1001 fprintf(ctx
->out
, "(jp)");
1002 if (instr_sat(instr
))
1003 fprintf(ctx
->out
, "(sat)");
1005 fprintf(ctx
->out
, "(rpt%d)", ctx
->repeat
);
1006 if (instr
->ul
&& ((2 <= instr
->opc_cat
) && (instr
->opc_cat
<= 4)))
1007 fprintf(ctx
->out
, "(ul)");
1009 name
= GETINFO(instr
)->name
;
1012 fprintf(ctx
->out
, "%s", name
);
1013 GETINFO(instr
)->print(ctx
, instr
);
1015 fprintf(ctx
->out
, "unknown(%d,%d)", instr
->opc_cat
, opc
);
1018 fprintf(ctx
->out
, "\n");
1020 return (instr
->opc_cat
== 0) && (opc
== OPC_END
);
1023 int disasm_a3xx(uint32_t *dwords
, int sizedwords
, int level
, FILE *out
)
1025 struct disasm_ctx ctx
;
1028 assert((sizedwords
% 2) == 0);
1030 memset(&ctx
, 0, sizeof(ctx
));
1034 for (i
= 0; i
< sizedwords
; i
+= 2)
1035 print_instr(&ctx
, &dwords
[i
], i
/2);