247175f142ca5653addf7c3378273dc3352ca18c
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>
34 #include "instr-a3xx.h"
36 static enum debug_t debug
;
38 #define printf debug_printf
40 static const char *levels
[] = {
59 static const char *component
= "xyzw";
61 static const char *type
[] = {
76 /* current instruction repeat flag: */
80 static void print_reg(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
81 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
83 const char type
= c
? 'c' : 'r';
85 // XXX I prefer - and || for neg/abs, but preserving format used
86 // by libllvm-a3xx for easy diffing..
89 fprintf(ctx
->out
, "(absneg)");
91 fprintf(ctx
->out
, "(neg)");
93 fprintf(ctx
->out
, "(abs)");
96 fprintf(ctx
->out
, "(r)");
99 fprintf(ctx
->out
, "%d", reg
.iim_val
);
100 } else if (addr_rel
) {
101 /* I would just use %+d but trying to make it diff'able with
105 fprintf(ctx
->out
, "%s%c<a0.x - %d>", full
? "" : "h", type
, -reg
.iim_val
);
106 else if (reg
.iim_val
> 0)
107 fprintf(ctx
->out
, "%s%c<a0.x + %d>", full
? "" : "h", type
, reg
.iim_val
);
109 fprintf(ctx
->out
, "%s%c<a0.x>", full
? "" : "h", type
);
110 } else if ((reg
.num
== REG_A0
) && !c
) {
111 fprintf(ctx
->out
, "a0.%c", component
[reg
.comp
]);
112 } else if ((reg
.num
== REG_P0
) && !c
) {
113 fprintf(ctx
->out
, "p0.%c", component
[reg
.comp
]);
115 fprintf(ctx
->out
, "%s%c%d.%c", full
? "" : "h", type
, reg
.num
& 0x3f, component
[reg
.comp
]);
120 static void print_reg_dst(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool addr_rel
)
122 print_reg(ctx
, reg
, full
, false, false, false, false, false, addr_rel
);
125 static void print_reg_src(struct disasm_ctx
*ctx
, reg_t reg
, bool full
, bool r
,
126 bool c
, bool im
, bool neg
, bool abs
, bool addr_rel
)
128 print_reg(ctx
, reg
, full
, r
, c
, im
, neg
, abs
, addr_rel
);
131 /* TODO switch to using reginfo struct everywhere, since more readable
132 * than passing a bunch of bools to print_reg_src
146 static void print_src(struct disasm_ctx
*ctx
, struct reginfo
*info
)
148 print_reg_src(ctx
, info
->reg
, info
->full
, info
->r
, info
->c
, info
->im
,
149 info
->neg
, info
->abs
, info
->addr_rel
);
152 //static void print_dst(struct disasm_ctx *ctx, struct reginfo *info)
154 // print_reg_dst(ctx, info->reg, info->full, info->addr_rel);
157 static void print_instr_cat0(struct disasm_ctx
*ctx
, instr_t
*instr
)
159 instr_cat0_t
*cat0
= &instr
->cat0
;
163 fprintf(ctx
->out
, " %sp0.%c", cat0
->inv
? "!" : "",
164 component
[cat0
->comp
]);
167 fprintf(ctx
->out
, " %sp0.%c, #%d", cat0
->inv
? "!" : "",
168 component
[cat0
->comp
], cat0
->a3xx
.immed
);
172 fprintf(ctx
->out
, " #%d", cat0
->a3xx
.immed
);
176 if ((debug
& PRINT_VERBOSE
) && (cat0
->dummy2
|cat0
->dummy3
|cat0
->dummy4
))
177 fprintf(ctx
->out
, "\t{0: %x,%x,%x}", cat0
->dummy2
, cat0
->dummy3
, cat0
->dummy4
);
180 static void print_instr_cat1(struct disasm_ctx
*ctx
, instr_t
*instr
)
182 instr_cat1_t
*cat1
= &instr
->cat1
;
185 fprintf(ctx
->out
, "(ul)");
187 if (cat1
->src_type
== cat1
->dst_type
) {
188 if ((cat1
->src_type
== TYPE_S16
) && (((reg_t
)cat1
->dst
).num
== REG_A0
)) {
189 /* special case (nmemonic?): */
190 fprintf(ctx
->out
, "mova");
192 fprintf(ctx
->out
, "mov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
195 fprintf(ctx
->out
, "cov.%s%s", type
[cat1
->src_type
], type
[cat1
->dst_type
]);
198 fprintf(ctx
->out
, " ");
201 fprintf(ctx
->out
, "(even)");
204 fprintf(ctx
->out
, "(pos_infinity)");
206 print_reg_dst(ctx
, (reg_t
)(cat1
->dst
), type_size(cat1
->dst_type
) == 32,
209 fprintf(ctx
->out
, ", ");
211 /* ugg, have to special case this.. vs print_reg().. */
213 if (type_float(cat1
->src_type
))
214 fprintf(ctx
->out
, "(%f)", cat1
->fim_val
);
215 else if (type_uint(cat1
->src_type
))
216 fprintf(ctx
->out
, "0x%08x", cat1
->uim_val
);
218 fprintf(ctx
->out
, "%d", cat1
->iim_val
);
219 } else if (cat1
->src_rel
&& !cat1
->src_c
) {
220 /* I would just use %+d but trying to make it diff'able with
223 char type
= cat1
->src_rel_c
? 'c' : 'r';
225 fprintf(ctx
->out
, "%c<a0.x - %d>", type
, -cat1
->off
);
226 else if (cat1
->off
> 0)
227 fprintf(ctx
->out
, "%c<a0.x + %d>", type
, cat1
->off
);
229 fprintf(ctx
->out
, "%c<a0.x>", type
);
231 print_reg_src(ctx
, (reg_t
)(cat1
->src
), type_size(cat1
->src_type
) == 32,
232 cat1
->src_r
, cat1
->src_c
, cat1
->src_im
, false, false, false);
235 if ((debug
& PRINT_VERBOSE
) && (cat1
->must_be_0
))
236 fprintf(ctx
->out
, "\t{1: %x}", cat1
->must_be_0
);
239 static void print_instr_cat2(struct disasm_ctx
*ctx
, instr_t
*instr
)
241 instr_cat2_t
*cat2
= &instr
->cat2
;
242 static const char *cond
[] = {
252 switch (_OPC(2, cat2
->opc
)) {
259 fprintf(ctx
->out
, ".%s", cond
[cat2
->cond
]);
263 fprintf(ctx
->out
, " ");
265 fprintf(ctx
->out
, "(ei)");
266 print_reg_dst(ctx
, (reg_t
)(cat2
->dst
), cat2
->full
^ cat2
->dst_half
, false);
267 fprintf(ctx
->out
, ", ");
269 if (cat2
->c1
.src1_c
) {
270 print_reg_src(ctx
, (reg_t
)(cat2
->c1
.src1
), cat2
->full
, cat2
->src1_r
,
271 cat2
->c1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
272 cat2
->src1_abs
, false);
273 } else if (cat2
->rel1
.src1_rel
) {
274 print_reg_src(ctx
, (reg_t
)(cat2
->rel1
.src1
), cat2
->full
, cat2
->src1_r
,
275 cat2
->rel1
.src1_c
, cat2
->src1_im
, cat2
->src1_neg
,
276 cat2
->src1_abs
, cat2
->rel1
.src1_rel
);
278 print_reg_src(ctx
, (reg_t
)(cat2
->src1
), cat2
->full
, cat2
->src1_r
,
279 false, cat2
->src1_im
, cat2
->src1_neg
,
280 cat2
->src1_abs
, false);
283 switch (_OPC(2, cat2
->opc
)) {
298 /* these only have one src reg */
301 fprintf(ctx
->out
, ", ");
302 if (cat2
->c2
.src2_c
) {
303 print_reg_src(ctx
, (reg_t
)(cat2
->c2
.src2
), cat2
->full
, cat2
->src2_r
,
304 cat2
->c2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
305 cat2
->src2_abs
, false);
306 } else if (cat2
->rel2
.src2_rel
) {
307 print_reg_src(ctx
, (reg_t
)(cat2
->rel2
.src2
), cat2
->full
, cat2
->src2_r
,
308 cat2
->rel2
.src2_c
, cat2
->src2_im
, cat2
->src2_neg
,
309 cat2
->src2_abs
, cat2
->rel2
.src2_rel
);
311 print_reg_src(ctx
, (reg_t
)(cat2
->src2
), cat2
->full
, cat2
->src2_r
,
312 false, cat2
->src2_im
, cat2
->src2_neg
,
313 cat2
->src2_abs
, false);
319 static void print_instr_cat3(struct disasm_ctx
*ctx
, instr_t
*instr
)
321 instr_cat3_t
*cat3
= &instr
->cat3
;
322 bool full
= instr_cat3_full(cat3
);
324 fprintf(ctx
->out
, " ");
325 print_reg_dst(ctx
, (reg_t
)(cat3
->dst
), full
^ cat3
->dst_half
, false);
326 fprintf(ctx
->out
, ", ");
327 if (cat3
->c1
.src1_c
) {
328 print_reg_src(ctx
, (reg_t
)(cat3
->c1
.src1
), full
,
329 cat3
->src1_r
, cat3
->c1
.src1_c
, false, cat3
->src1_neg
,
331 } else if (cat3
->rel1
.src1_rel
) {
332 print_reg_src(ctx
, (reg_t
)(cat3
->rel1
.src1
), full
,
333 cat3
->src1_r
, cat3
->rel1
.src1_c
, false, cat3
->src1_neg
,
334 false, cat3
->rel1
.src1_rel
);
336 print_reg_src(ctx
, (reg_t
)(cat3
->src1
), full
,
337 cat3
->src1_r
, false, false, cat3
->src1_neg
,
340 fprintf(ctx
->out
, ", ");
341 print_reg_src(ctx
, (reg_t
)cat3
->src2
, full
,
342 cat3
->src2_r
, cat3
->src2_c
, false, cat3
->src2_neg
,
344 fprintf(ctx
->out
, ", ");
345 if (cat3
->c2
.src3_c
) {
346 print_reg_src(ctx
, (reg_t
)(cat3
->c2
.src3
), full
,
347 cat3
->src3_r
, cat3
->c2
.src3_c
, false, cat3
->src3_neg
,
349 } else if (cat3
->rel2
.src3_rel
) {
350 print_reg_src(ctx
, (reg_t
)(cat3
->rel2
.src3
), full
,
351 cat3
->src3_r
, cat3
->rel2
.src3_c
, false, cat3
->src3_neg
,
352 false, cat3
->rel2
.src3_rel
);
354 print_reg_src(ctx
, (reg_t
)(cat3
->src3
), full
,
355 cat3
->src3_r
, false, false, cat3
->src3_neg
,
360 static void print_instr_cat4(struct disasm_ctx
*ctx
, instr_t
*instr
)
362 instr_cat4_t
*cat4
= &instr
->cat4
;
364 fprintf(ctx
->out
, " ");
365 print_reg_dst(ctx
, (reg_t
)(cat4
->dst
), cat4
->full
^ cat4
->dst_half
, false);
366 fprintf(ctx
->out
, ", ");
369 print_reg_src(ctx
, (reg_t
)(cat4
->c
.src
), cat4
->full
,
370 cat4
->src_r
, cat4
->c
.src_c
, cat4
->src_im
,
371 cat4
->src_neg
, cat4
->src_abs
, false);
372 } else if (cat4
->rel
.src_rel
) {
373 print_reg_src(ctx
, (reg_t
)(cat4
->rel
.src
), cat4
->full
,
374 cat4
->src_r
, cat4
->rel
.src_c
, cat4
->src_im
,
375 cat4
->src_neg
, cat4
->src_abs
, cat4
->rel
.src_rel
);
377 print_reg_src(ctx
, (reg_t
)(cat4
->src
), cat4
->full
,
378 cat4
->src_r
, false, cat4
->src_im
,
379 cat4
->src_neg
, cat4
->src_abs
, false);
382 if ((debug
& PRINT_VERBOSE
) && (cat4
->dummy1
|cat4
->dummy2
))
383 fprintf(ctx
->out
, "\t{4: %x,%x}", cat4
->dummy1
, cat4
->dummy2
);
386 static void print_instr_cat5(struct disasm_ctx
*ctx
, instr_t
*instr
)
388 static const struct {
389 bool src1
, src2
, samp
, tex
;
391 [opc_op(OPC_ISAM
)] = { true, false, true, true, },
392 [opc_op(OPC_ISAML
)] = { true, true, true, true, },
393 [opc_op(OPC_ISAMM
)] = { true, false, true, true, },
394 [opc_op(OPC_SAM
)] = { true, false, true, true, },
395 [opc_op(OPC_SAMB
)] = { true, true, true, true, },
396 [opc_op(OPC_SAML
)] = { true, true, true, true, },
397 [opc_op(OPC_SAMGQ
)] = { true, false, true, true, },
398 [opc_op(OPC_GETLOD
)] = { true, false, true, true, },
399 [opc_op(OPC_CONV
)] = { true, true, true, true, },
400 [opc_op(OPC_CONVM
)] = { true, true, true, true, },
401 [opc_op(OPC_GETSIZE
)] = { true, false, false, true, },
402 [opc_op(OPC_GETBUF
)] = { false, false, false, true, },
403 [opc_op(OPC_GETPOS
)] = { true, false, false, true, },
404 [opc_op(OPC_GETINFO
)] = { false, false, false, true, },
405 [opc_op(OPC_DSX
)] = { true, false, false, false, },
406 [opc_op(OPC_DSY
)] = { true, false, false, false, },
407 [opc_op(OPC_GATHER4R
)] = { true, false, true, true, },
408 [opc_op(OPC_GATHER4G
)] = { true, false, true, true, },
409 [opc_op(OPC_GATHER4B
)] = { true, false, true, true, },
410 [opc_op(OPC_GATHER4A
)] = { true, false, true, true, },
411 [opc_op(OPC_SAMGP0
)] = { true, false, true, true, },
412 [opc_op(OPC_SAMGP1
)] = { true, false, true, true, },
413 [opc_op(OPC_SAMGP2
)] = { true, false, true, true, },
414 [opc_op(OPC_SAMGP3
)] = { true, false, true, true, },
415 [opc_op(OPC_DSXPP_1
)] = { true, false, false, false, },
416 [opc_op(OPC_DSYPP_1
)] = { true, false, false, false, },
417 [opc_op(OPC_RGETPOS
)] = { false, false, false, false, },
418 [opc_op(OPC_RGETINFO
)] = { false, false, false, false, },
420 instr_cat5_t
*cat5
= &instr
->cat5
;
423 if (cat5
->is_3d
) fprintf(ctx
->out
, ".3d");
424 if (cat5
->is_a
) fprintf(ctx
->out
, ".a");
425 if (cat5
->is_o
) fprintf(ctx
->out
, ".o");
426 if (cat5
->is_p
) fprintf(ctx
->out
, ".p");
427 if (cat5
->is_s
) fprintf(ctx
->out
, ".s");
428 if (cat5
->is_s2en
) fprintf(ctx
->out
, ".s2en");
430 fprintf(ctx
->out
, " ");
432 switch (_OPC(5, cat5
->opc
)) {
437 fprintf(ctx
->out
, "(%s)", type
[cat5
->type
]);
441 fprintf(ctx
->out
, "(");
442 for (i
= 0; i
< 4; i
++)
443 if (cat5
->wrmask
& (1 << i
))
444 fprintf(ctx
->out
, "%c", "xyzw"[i
]);
445 fprintf(ctx
->out
, ")");
447 print_reg_dst(ctx
, (reg_t
)(cat5
->dst
), type_size(cat5
->type
) == 32, false);
449 if (info
[cat5
->opc
].src1
) {
450 fprintf(ctx
->out
, ", ");
451 print_reg_src(ctx
, (reg_t
)(cat5
->src1
), cat5
->full
, false, false, false,
452 false, false, false);
456 fprintf(ctx
->out
, ", ");
457 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src2
), cat5
->full
, false, false, false,
458 false, false, false);
459 fprintf(ctx
->out
, ", ");
460 print_reg_src(ctx
, (reg_t
)(cat5
->s2en
.src3
), false, false, false, false,
461 false, false, false);
463 if (cat5
->is_o
|| info
[cat5
->opc
].src2
) {
464 fprintf(ctx
->out
, ", ");
465 print_reg_src(ctx
, (reg_t
)(cat5
->norm
.src2
), cat5
->full
,
466 false, false, false, false, false, false);
468 if (info
[cat5
->opc
].samp
)
469 fprintf(ctx
->out
, ", s#%d", cat5
->norm
.samp
);
470 if (info
[cat5
->opc
].tex
)
471 fprintf(ctx
->out
, ", t#%d", cat5
->norm
.tex
);
474 if (debug
& PRINT_VERBOSE
) {
476 if ((debug
& PRINT_VERBOSE
) && (cat5
->s2en
.dummy1
|cat5
->s2en
.dummy2
|cat5
->dummy2
))
477 fprintf(ctx
->out
, "\t{5: %x,%x,%x}", cat5
->s2en
.dummy1
, cat5
->s2en
.dummy2
, cat5
->dummy2
);
479 if ((debug
& PRINT_VERBOSE
) && (cat5
->norm
.dummy1
|cat5
->dummy2
))
480 fprintf(ctx
->out
, "\t{5: %x,%x}", cat5
->norm
.dummy1
, cat5
->dummy2
);
485 static void print_instr_cat6(struct disasm_ctx
*ctx
, instr_t
*instr
)
487 instr_cat6_t
*cat6
= &instr
->cat6
;
488 char sd
= 0, ss
= 0; /* dst/src address space */
490 struct reginfo dst
, src1
, src2
;
491 int src1off
= 0, dstoff
= 0;
493 memset(&dst
, 0, sizeof(dst
));
494 memset(&src1
, 0, sizeof(src1
));
495 memset(&src2
, 0, sizeof(src2
));
497 switch (_OPC(6, cat6
->opc
)) {
500 dst
.full
= type_size(cat6
->type
) == 32;
501 src1
.full
= type_size(cat6
->type
) == 32;
502 src2
.full
= type_size(cat6
->type
) == 32;
517 src1
.full
= type_size(cat6
->type
) == 32;
518 src2
.full
= type_size(cat6
->type
) == 32;
521 dst
.full
= type_size(cat6
->type
) == 32;
527 switch (_OPC(6, cat6
->opc
)) {
531 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
534 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
535 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
536 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
537 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
541 fprintf(ctx
->out
, ".%s", cat6
->stgb
.typed
? "typed" : "untyped");
542 fprintf(ctx
->out
, ".%dd", cat6
->stgb
.d
+ 1);
543 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
544 fprintf(ctx
->out
, ".%d", cat6
->stgb
.type_size
+ 1);
548 case OPC_ATOMIC_XCHG
:
551 case OPC_ATOMIC_CMPXCHG
:
557 ss
= cat6
->g
? 'g' : 'l';
558 fprintf(ctx
->out
, ".%s", cat6
->ldgb
.typed
? "typed" : "untyped");
559 fprintf(ctx
->out
, ".%dd", cat6
->ldgb
.d
+ 1);
560 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
561 fprintf(ctx
->out
, ".%d", cat6
->ldgb
.type_size
+ 1);
562 fprintf(ctx
->out
, ".%c", ss
);
565 dst
.im
= cat6
->g
&& !cat6
->dst_off
;
566 fprintf(ctx
->out
, ".%s", type
[cat6
->type
]);
569 fprintf(ctx
->out
, " ");
571 switch (_OPC(6, cat6
->opc
)) {
612 dst
.full
= false; // XXX or inverts??
616 if ((_OPC(6, cat6
->opc
) == OPC_STGB
) || (_OPC(6, cat6
->opc
) == OPC_STIB
)) {
619 memset(&src3
, 0, sizeof(src3
));
621 src1
.reg
= (reg_t
)(cat6
->stgb
.src1
);
622 src2
.reg
= (reg_t
)(cat6
->stgb
.src2
);
623 src2
.im
= cat6
->stgb
.src2_im
;
624 src3
.reg
= (reg_t
)(cat6
->stgb
.src3
);
625 src3
.im
= cat6
->stgb
.src3_im
;
628 fprintf(ctx
->out
, "g[%u], ", cat6
->stgb
.dst_ssbo
);
629 print_src(ctx
, &src1
);
630 fprintf(ctx
->out
, ", ");
631 print_src(ctx
, &src2
);
632 fprintf(ctx
->out
, ", ");
633 print_src(ctx
, &src3
);
635 if (debug
& PRINT_VERBOSE
)
636 fprintf(ctx
->out
, " (pad0=%x, pad3=%x)", cat6
->stgb
.pad0
, cat6
->stgb
.pad3
);
641 if (is_atomic(_OPC(6, cat6
->opc
))) {
643 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
644 src1
.im
= cat6
->ldgb
.src1_im
;
645 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
646 src2
.im
= cat6
->ldgb
.src2_im
;
647 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
649 print_src(ctx
, &dst
);
650 fprintf(ctx
->out
, ", ");
653 memset(&src3
, 0, sizeof(src3
));
655 src3
.reg
= (reg_t
)(cat6
->ldgb
.src3
);
658 /* For images, the ".typed" variant is used and src2 is
659 * the ivecN coordinates, ie ivec2 for 2d.
661 * For SSBOs, the ".untyped" variant is used and src2 is
662 * a simple dword offset.. src3 appears to be
663 * uvec2(offset * 4, 0). Not sure the point of that.
666 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
667 print_src(ctx
, &src1
); /* value */
668 fprintf(ctx
->out
, ", ");
669 print_src(ctx
, &src2
); /* offset/coords */
670 fprintf(ctx
->out
, ", ");
671 print_src(ctx
, &src3
); /* 64b byte offset.. */
673 if (debug
& PRINT_VERBOSE
) {
674 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
,
675 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
677 } else { /* ss == 'l' */
678 fprintf(ctx
->out
, "l[");
679 print_src(ctx
, &src1
); /* simple byte offset */
680 fprintf(ctx
->out
, "], ");
681 print_src(ctx
, &src2
); /* value */
683 if (debug
& PRINT_VERBOSE
) {
684 fprintf(ctx
->out
, " (src3=%x, pad0=%x, pad3=%x, mustbe0=%x)",
685 cat6
->ldgb
.src3
, cat6
->ldgb
.pad0
,
686 cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
691 } else if (_OPC(6, cat6
->opc
) == OPC_RESINFO
) {
692 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
694 print_src(ctx
, &dst
);
695 fprintf(ctx
->out
, ", ");
696 fprintf(ctx
->out
, "g[%u]", cat6
->ldgb
.src_ssbo
);
699 } else if (_OPC(6, cat6
->opc
) == OPC_LDGB
) {
701 src1
.reg
= (reg_t
)(cat6
->ldgb
.src1
);
702 src1
.im
= cat6
->ldgb
.src1_im
;
703 src2
.reg
= (reg_t
)(cat6
->ldgb
.src2
);
704 src2
.im
= cat6
->ldgb
.src2_im
;
705 dst
.reg
= (reg_t
)(cat6
->ldgb
.dst
);
707 print_src(ctx
, &dst
);
708 fprintf(ctx
->out
, ", ");
709 fprintf(ctx
->out
, "g[%u], ", cat6
->ldgb
.src_ssbo
);
710 print_src(ctx
, &src1
);
711 fprintf(ctx
->out
, ", ");
712 print_src(ctx
, &src2
);
714 if (debug
& PRINT_VERBOSE
)
715 fprintf(ctx
->out
, " (pad0=%x, pad3=%x, mustbe0=%x)", cat6
->ldgb
.pad0
, cat6
->ldgb
.pad3
, cat6
->ldgb
.mustbe0
);
720 dst
.reg
= (reg_t
)(cat6
->c
.dst
);
721 dstoff
= cat6
->c
.off
;
723 dst
.reg
= (reg_t
)(cat6
->d
.dst
);
727 src1
.reg
= (reg_t
)(cat6
->a
.src1
);
728 src1
.im
= cat6
->a
.src1_im
;
729 src2
.reg
= (reg_t
)(cat6
->a
.src2
);
730 src2
.im
= cat6
->a
.src2_im
;
731 src1off
= cat6
->a
.off
;
733 src1
.reg
= (reg_t
)(cat6
->b
.src1
);
734 src1
.im
= cat6
->b
.src1_im
;
735 src2
.reg
= (reg_t
)(cat6
->b
.src2
);
736 src2
.im
= cat6
->b
.src2_im
;
741 fprintf(ctx
->out
, "%c[", sd
);
742 /* note: dst might actually be a src (ie. address to store to) */
743 print_src(ctx
, &dst
);
745 fprintf(ctx
->out
, "%+d", dstoff
);
747 fprintf(ctx
->out
, "]");
748 fprintf(ctx
->out
, ", ");
752 fprintf(ctx
->out
, "%c[", ss
);
754 /* can have a larger than normal immed, so hack: */
756 fprintf(ctx
->out
, "%u", src1
.reg
.dummy13
);
758 print_src(ctx
, &src1
);
762 fprintf(ctx
->out
, "%+d", src1off
);
764 fprintf(ctx
->out
, "]");
766 switch (_OPC(6, cat6
->opc
)) {
771 fprintf(ctx
->out
, ", ");
772 print_src(ctx
, &src2
);
777 static void print_instr_cat7(struct disasm_ctx
*ctx
, instr_t
*instr
)
779 instr_cat7_t
*cat7
= &instr
->cat7
;
782 fprintf(ctx
->out
, ".g");
784 fprintf(ctx
->out
, ".l");
786 if (_OPC(7, cat7
->opc
) == OPC_FENCE
) {
788 fprintf(ctx
->out
, ".r");
790 fprintf(ctx
->out
, ".w");
794 /* size of largest OPC field of all the instruction categories: */
797 static const struct opc_info
{
801 void (*print
)(struct disasm_ctx
*ctx
, instr_t
*instr
);
802 } opcs
[1 << (3+NOPC_BITS
)] = {
803 #define OPC(cat, opc, name) [(opc)] = { (cat), (opc), #name, print_instr_cat##cat }
805 OPC(0, OPC_NOP
, nop
),
807 OPC(0, OPC_JUMP
, jump
),
808 OPC(0, OPC_CALL
, call
),
809 OPC(0, OPC_RET
, ret
),
810 OPC(0, OPC_KILL
, kill
),
811 OPC(0, OPC_END
, end
),
812 OPC(0, OPC_EMIT
, emit
),
813 OPC(0, OPC_CUT
, cut
),
814 OPC(0, OPC_CHMASK
, chmask
),
815 OPC(0, OPC_CHSH
, chsh
),
816 OPC(0, OPC_FLOW_REV
, flow_rev
),
822 OPC(2, OPC_ADD_F
, add
.f
),
823 OPC(2, OPC_MIN_F
, min
.f
),
824 OPC(2, OPC_MAX_F
, max
.f
),
825 OPC(2, OPC_MUL_F
, mul
.f
),
826 OPC(2, OPC_SIGN_F
, sign
.f
),
827 OPC(2, OPC_CMPS_F
, cmps
.f
),
828 OPC(2, OPC_ABSNEG_F
, absneg
.f
),
829 OPC(2, OPC_CMPV_F
, cmpv
.f
),
830 OPC(2, OPC_FLOOR_F
, floor
.f
),
831 OPC(2, OPC_CEIL_F
, ceil
.f
),
832 OPC(2, OPC_RNDNE_F
, rndne
.f
),
833 OPC(2, OPC_RNDAZ_F
, rndaz
.f
),
834 OPC(2, OPC_TRUNC_F
, trunc
.f
),
835 OPC(2, OPC_ADD_U
, add
.u
),
836 OPC(2, OPC_ADD_S
, add
.s
),
837 OPC(2, OPC_SUB_U
, sub
.u
),
838 OPC(2, OPC_SUB_S
, sub
.s
),
839 OPC(2, OPC_CMPS_U
, cmps
.u
),
840 OPC(2, OPC_CMPS_S
, cmps
.s
),
841 OPC(2, OPC_MIN_U
, min
.u
),
842 OPC(2, OPC_MIN_S
, min
.s
),
843 OPC(2, OPC_MAX_U
, max
.u
),
844 OPC(2, OPC_MAX_S
, max
.s
),
845 OPC(2, OPC_ABSNEG_S
, absneg
.s
),
846 OPC(2, OPC_AND_B
, and.b
),
847 OPC(2, OPC_OR_B
, or.b
),
848 OPC(2, OPC_NOT_B
, not.b
),
849 OPC(2, OPC_XOR_B
, xor.b
),
850 OPC(2, OPC_CMPV_U
, cmpv
.u
),
851 OPC(2, OPC_CMPV_S
, cmpv
.s
),
852 OPC(2, OPC_MUL_U
, mul
.u
),
853 OPC(2, OPC_MUL_S
, mul
.s
),
854 OPC(2, OPC_MULL_U
, mull
.u
),
855 OPC(2, OPC_BFREV_B
, bfrev
.b
),
856 OPC(2, OPC_CLZ_S
, clz
.s
),
857 OPC(2, OPC_CLZ_B
, clz
.b
),
858 OPC(2, OPC_SHL_B
, shl
.b
),
859 OPC(2, OPC_SHR_B
, shr
.b
),
860 OPC(2, OPC_ASHR_B
, ashr
.b
),
861 OPC(2, OPC_BARY_F
, bary
.f
),
862 OPC(2, OPC_MGEN_B
, mgen
.b
),
863 OPC(2, OPC_GETBIT_B
, getbit
.b
),
864 OPC(2, OPC_SETRM
, setrm
),
865 OPC(2, OPC_CBITS_B
, cbits
.b
),
866 OPC(2, OPC_SHB
, shb
),
867 OPC(2, OPC_MSAD
, msad
),
870 OPC(3, OPC_MAD_U16
, mad
.u16
),
871 OPC(3, OPC_MADSH_U16
, madsh
.u16
),
872 OPC(3, OPC_MAD_S16
, mad
.s16
),
873 OPC(3, OPC_MADSH_M16
, madsh
.m16
),
874 OPC(3, OPC_MAD_U24
, mad
.u24
),
875 OPC(3, OPC_MAD_S24
, mad
.s24
),
876 OPC(3, OPC_MAD_F16
, mad
.f16
),
877 OPC(3, OPC_MAD_F32
, mad
.f32
),
878 OPC(3, OPC_SEL_B16
, sel
.b16
),
879 OPC(3, OPC_SEL_B32
, sel
.b32
),
880 OPC(3, OPC_SEL_S16
, sel
.s16
),
881 OPC(3, OPC_SEL_S32
, sel
.s32
),
882 OPC(3, OPC_SEL_F16
, sel
.f16
),
883 OPC(3, OPC_SEL_F32
, sel
.f32
),
884 OPC(3, OPC_SAD_S16
, sad
.s16
),
885 OPC(3, OPC_SAD_S32
, sad
.s32
),
888 OPC(4, OPC_RCP
, rcp
),
889 OPC(4, OPC_RSQ
, rsq
),
890 OPC(4, OPC_LOG2
, log2
),
891 OPC(4, OPC_EXP2
, exp2
),
892 OPC(4, OPC_SIN
, sin
),
893 OPC(4, OPC_COS
, cos
),
894 OPC(4, OPC_SQRT
, sqrt
),
897 OPC(5, OPC_ISAM
, isam
),
898 OPC(5, OPC_ISAML
, isaml
),
899 OPC(5, OPC_ISAMM
, isamm
),
900 OPC(5, OPC_SAM
, sam
),
901 OPC(5, OPC_SAMB
, samb
),
902 OPC(5, OPC_SAML
, saml
),
903 OPC(5, OPC_SAMGQ
, samgq
),
904 OPC(5, OPC_GETLOD
, getlod
),
905 OPC(5, OPC_CONV
, conv
),
906 OPC(5, OPC_CONVM
, convm
),
907 OPC(5, OPC_GETSIZE
, getsize
),
908 OPC(5, OPC_GETBUF
, getbuf
),
909 OPC(5, OPC_GETPOS
, getpos
),
910 OPC(5, OPC_GETINFO
, getinfo
),
911 OPC(5, OPC_DSX
, dsx
),
912 OPC(5, OPC_DSY
, dsy
),
913 OPC(5, OPC_GATHER4R
, gather4r
),
914 OPC(5, OPC_GATHER4G
, gather4g
),
915 OPC(5, OPC_GATHER4B
, gather4b
),
916 OPC(5, OPC_GATHER4A
, gather4a
),
917 OPC(5, OPC_SAMGP0
, samgp0
),
918 OPC(5, OPC_SAMGP1
, samgp1
),
919 OPC(5, OPC_SAMGP2
, samgp2
),
920 OPC(5, OPC_SAMGP3
, samgp3
),
921 OPC(5, OPC_DSXPP_1
, dsxpp
.1),
922 OPC(5, OPC_DSYPP_1
, dsypp
.1),
923 OPC(5, OPC_RGETPOS
, rgetpos
),
924 OPC(5, OPC_RGETINFO
, rgetinfo
),
928 OPC(6, OPC_LDG
, ldg
),
929 OPC(6, OPC_LDL
, ldl
),
930 OPC(6, OPC_LDP
, ldp
),
931 OPC(6, OPC_STG
, stg
),
932 OPC(6, OPC_STL
, stl
),
933 OPC(6, OPC_STP
, stp
),
934 OPC(6, OPC_STI
, sti
),
935 OPC(6, OPC_G2L
, g2l
),
936 OPC(6, OPC_L2G
, l2g
),
937 OPC(6, OPC_PREFETCH
, prefetch
),
938 OPC(6, OPC_LDLW
, ldlw
),
939 OPC(6, OPC_STLW
, stlw
),
940 OPC(6, OPC_RESFMT
, resfmt
),
941 OPC(6, OPC_RESINFO
, resinfo
),
942 OPC(6, OPC_ATOMIC_ADD
, atomic
.add
),
943 OPC(6, OPC_ATOMIC_SUB
, atomic
.sub
),
944 OPC(6, OPC_ATOMIC_XCHG
, atomic
.xchg
),
945 OPC(6, OPC_ATOMIC_INC
, atomic
.inc
),
946 OPC(6, OPC_ATOMIC_DEC
, atomic
.dec
),
947 OPC(6, OPC_ATOMIC_CMPXCHG
, atomic
.cmpxchg
),
948 OPC(6, OPC_ATOMIC_MIN
, atomic
.min
),
949 OPC(6, OPC_ATOMIC_MAX
, atomic
.max
),
950 OPC(6, OPC_ATOMIC_AND
, atomic
.and),
951 OPC(6, OPC_ATOMIC_OR
, atomic
.or),
952 OPC(6, OPC_ATOMIC_XOR
, atomic
.xor),
953 OPC(6, OPC_LDGB
, ldgb
),
954 OPC(6, OPC_STGB
, stgb
),
955 OPC(6, OPC_STIB
, stib
),
956 OPC(6, OPC_LDC
, ldc
),
957 OPC(6, OPC_LDLV
, ldlv
),
959 OPC(7, OPC_BAR
, bar
),
960 OPC(7, OPC_FENCE
, fence
),
965 #define GETINFO(instr) (&(opcs[((instr)->opc_cat << NOPC_BITS) | instr_opc(instr)]))
967 // XXX hack.. probably should move this table somewhere common:
969 const char *ir3_instr_name(struct ir3_instruction
*instr
)
971 if (opc_cat(instr
->opc
) == -1) return "??meta??";
972 return opcs
[instr
->opc
].name
;
975 static bool print_instr(struct disasm_ctx
*ctx
, uint32_t *dwords
, int n
)
977 instr_t
*instr
= (instr_t
*)dwords
;
978 uint32_t opc
= instr_opc(instr
);
981 if (debug
& PRINT_VERBOSE
)
982 fprintf(ctx
->out
, "%s%04d[%08xx_%08xx] ", levels
[ctx
->level
], n
, dwords
[1], dwords
[0]);
984 /* NOTE: order flags are printed is a bit fugly.. but for now I
985 * try to match the order in llvm-a3xx disassembler for easy
989 ctx
->repeat
= instr_repeat(instr
);
992 fprintf(ctx
->out
, "(sy)");
993 if (instr
->ss
&& ((instr
->opc_cat
<= 4) || (instr
->opc_cat
== 7)))
994 fprintf(ctx
->out
, "(ss)");
996 fprintf(ctx
->out
, "(jp)");
997 if (instr_sat(instr
))
998 fprintf(ctx
->out
, "(sat)");
1000 fprintf(ctx
->out
, "(rpt%d)", ctx
->repeat
);
1001 if (instr
->ul
&& ((2 <= instr
->opc_cat
) && (instr
->opc_cat
<= 4)))
1002 fprintf(ctx
->out
, "(ul)");
1004 name
= GETINFO(instr
)->name
;
1007 fprintf(ctx
->out
, "%s", name
);
1008 GETINFO(instr
)->print(ctx
, instr
);
1010 fprintf(ctx
->out
, "unknown(%d,%d)", instr
->opc_cat
, opc
);
1013 fprintf(ctx
->out
, "\n");
1015 return (instr
->opc_cat
== 0) && (opc
== OPC_END
);
1018 int disasm_a3xx(uint32_t *dwords
, int sizedwords
, int level
, FILE *out
)
1020 struct disasm_ctx ctx
;
1023 assert((sizedwords
% 2) == 0);
1025 memset(&ctx
, 0, sizeof(ctx
));
1029 for (i
= 0; i
< sizedwords
; i
+= 2)
1030 print_instr(&ctx
, &dwords
[i
], i
/2);