2 #include "aco_builder.h"
5 #include "ac_shader_util.h"
9 static const char *reduce_ops
[] = {
60 static void print_reg_class(const RegClass rc
, FILE *output
)
63 case RegClass::s1
: fprintf(output
, " s1: "); return;
64 case RegClass::s2
: fprintf(output
, " s2: "); return;
65 case RegClass::s3
: fprintf(output
, " s3: "); return;
66 case RegClass::s4
: fprintf(output
, " s4: "); return;
67 case RegClass::s6
: fprintf(output
, " s6: "); return;
68 case RegClass::s8
: fprintf(output
, " s8: "); return;
69 case RegClass::s16
: fprintf(output
, "s16: "); return;
70 case RegClass::v1
: fprintf(output
, " v1: "); return;
71 case RegClass::v2
: fprintf(output
, " v2: "); return;
72 case RegClass::v3
: fprintf(output
, " v3: "); return;
73 case RegClass::v4
: fprintf(output
, " v4: "); return;
74 case RegClass::v5
: fprintf(output
, " v5: "); return;
75 case RegClass::v6
: fprintf(output
, " v6: "); return;
76 case RegClass::v7
: fprintf(output
, " v7: "); return;
77 case RegClass::v8
: fprintf(output
, " v8: "); return;
78 case RegClass::v1b
: fprintf(output
, " v1b: "); return;
79 case RegClass::v2b
: fprintf(output
, " v2b: "); return;
80 case RegClass::v3b
: fprintf(output
, " v3b: "); return;
81 case RegClass::v4b
: fprintf(output
, " v4b: "); return;
82 case RegClass::v6b
: fprintf(output
, " v6b: "); return;
83 case RegClass::v8b
: fprintf(output
, " v8b: "); return;
84 case RegClass::v1_linear
: fprintf(output
, " v1: "); return;
85 case RegClass::v2_linear
: fprintf(output
, " v2: "); return;
89 void print_physReg(PhysReg reg
, unsigned bytes
, FILE *output
)
92 fprintf(output
, ":m0");
93 } else if (reg
== 106) {
94 fprintf(output
, ":vcc");
95 } else if (reg
== 253) {
96 fprintf(output
, ":scc");
97 } else if (reg
== 126) {
98 fprintf(output
, ":exec");
100 bool is_vgpr
= reg
/ 256;
101 unsigned r
= reg
% 256;
102 unsigned size
= DIV_ROUND_UP(bytes
, 4);
103 fprintf(output
, ":%c[%d", is_vgpr
? 'v' : 's', r
);
105 fprintf(output
, "-%d]", r
+ size
-1);
107 fprintf(output
, "]");
108 if (reg
.byte() || bytes
% 4)
109 fprintf(output
, "[%d:%d]", reg
.byte()*8, (reg
.byte()+bytes
) * 8);
113 static void print_constant(uint8_t reg
, FILE *output
)
115 if (reg
>= 128 && reg
<= 192) {
116 fprintf(output
, "%d", reg
- 128);
118 } else if (reg
>= 192 && reg
<= 208) {
119 fprintf(output
, "%d", 192 - reg
);
125 fprintf(output
, "0.5");
128 fprintf(output
, "-0.5");
131 fprintf(output
, "1.0");
134 fprintf(output
, "-1.0");
137 fprintf(output
, "2.0");
140 fprintf(output
, "-2.0");
143 fprintf(output
, "4.0");
146 fprintf(output
, "-4.0");
149 fprintf(output
, "1/(2*PI)");
154 static void print_operand(const Operand
*operand
, FILE *output
)
156 if (operand
->isLiteral()) {
157 fprintf(output
, "0x%x", operand
->constantValue());
158 } else if (operand
->isConstant()) {
159 print_constant(operand
->physReg().reg(), output
);
160 } else if (operand
->isUndefined()) {
161 print_reg_class(operand
->regClass(), output
);
162 fprintf(output
, "undef");
164 if (operand
->isLateKill())
165 fprintf(output
, "(latekill)");
167 fprintf(output
, "%%%d", operand
->tempId());
169 if (operand
->isFixed())
170 print_physReg(operand
->physReg(), operand
->bytes(), output
);
174 static void print_definition(const Definition
*definition
, FILE *output
)
176 print_reg_class(definition
->regClass(), output
);
177 if (definition
->isPrecise())
178 fprintf(output
, "(precise)");
179 fprintf(output
, "%%%d", definition
->tempId());
181 if (definition
->isFixed())
182 print_physReg(definition
->physReg(), definition
->bytes(), output
);
185 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
188 fprintf(output
, " reorder");
190 if (barrier
& barrier_buffer
)
191 fprintf(output
, " buffer");
192 if (barrier
& barrier_image
)
193 fprintf(output
, " image");
194 if (barrier
& barrier_atomic
)
195 fprintf(output
, " atomic");
196 if (barrier
& barrier_shared
)
197 fprintf(output
, " shared");
198 if (barrier
& barrier_gs_data
)
199 fprintf(output
, " gs_data");
200 if (barrier
& barrier_gs_sendmsg
)
201 fprintf(output
, " gs_sendmsg");
204 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
206 switch (instr
->format
) {
208 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
209 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
213 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
214 uint16_t imm
= sopp
->imm
;
215 switch (instr
->opcode
) {
216 case aco_opcode::s_waitcnt
: {
217 /* we usually should check the chip class for vmcnt/lgkm, but
218 * insert_waitcnt() should fill it in regardless. */
219 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
220 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
221 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
222 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
225 case aco_opcode::s_endpgm
:
226 case aco_opcode::s_endpgm_saved
:
227 case aco_opcode::s_endpgm_ordered_ps_done
:
228 case aco_opcode::s_wakeup
:
229 case aco_opcode::s_barrier
:
230 case aco_opcode::s_icache_inv
:
231 case aco_opcode::s_ttracedata
:
232 case aco_opcode::s_set_gpr_idx_off
: {
235 case aco_opcode::s_sendmsg
: {
236 unsigned id
= imm
& sendmsg_id_mask
;
239 fprintf(output
, " sendmsg(MSG_NONE)");
242 fprintf(output
, " sendmsg(gs%s%s, %u)",
243 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
245 case _sendmsg_gs_done
:
246 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
247 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
249 case sendmsg_save_wave
:
250 fprintf(output
, " sendmsg(save_wave)");
252 case sendmsg_stall_wave_gen
:
253 fprintf(output
, " sendmsg(stall_wave_gen)");
255 case sendmsg_halt_waves
:
256 fprintf(output
, " sendmsg(halt_waves)");
258 case sendmsg_ordered_ps_done
:
259 fprintf(output
, " sendmsg(ordered_ps_done)");
261 case sendmsg_early_prim_dealloc
:
262 fprintf(output
, " sendmsg(early_prim_dealloc)");
264 case sendmsg_gs_alloc_req
:
265 fprintf(output
, " sendmsg(gs_alloc_req)");
272 fprintf(output
, " imm:%u", imm
);
276 if (sopp
->block
!= -1)
277 fprintf(output
, " block:BB%d", sopp
->block
);
281 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
283 fprintf(output
, " glc");
285 fprintf(output
, " dlc");
287 fprintf(output
, " nv");
288 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
291 case Format::VINTRP
: {
292 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
293 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
297 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
299 fprintf(output
, " offset0:%u", ds
->offset0
);
301 fprintf(output
, " offset1:%u", ds
->offset1
);
303 fprintf(output
, " gds");
306 case Format::MUBUF
: {
307 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
309 fprintf(output
, " offset:%u", mubuf
->offset
);
311 fprintf(output
, " offen");
313 fprintf(output
, " idxen");
315 fprintf(output
, " addr64");
317 fprintf(output
, " glc");
319 fprintf(output
, " dlc");
321 fprintf(output
, " slc");
323 fprintf(output
, " tfe");
325 fprintf(output
, " lds");
326 if (mubuf
->disable_wqm
)
327 fprintf(output
, " disable_wqm");
328 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
332 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
333 unsigned identity_dmask
= !instr
->definitions
.empty() ?
334 (1 << instr
->definitions
[0].size()) - 1 :
336 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
337 fprintf(output
, " dmask:%s%s%s%s",
338 mimg
->dmask
& 0x1 ? "x" : "",
339 mimg
->dmask
& 0x2 ? "y" : "",
340 mimg
->dmask
& 0x4 ? "z" : "",
341 mimg
->dmask
& 0x8 ? "w" : "");
344 fprintf(output
, " 1d");
347 fprintf(output
, " 2d");
350 fprintf(output
, " 3d");
353 fprintf(output
, " cube");
355 case ac_image_1darray
:
356 fprintf(output
, " 1darray");
358 case ac_image_2darray
:
359 fprintf(output
, " 2darray");
361 case ac_image_2dmsaa
:
362 fprintf(output
, " 2dmsaa");
364 case ac_image_2darraymsaa
:
365 fprintf(output
, " 2darraymsaa");
369 fprintf(output
, " unrm");
371 fprintf(output
, " glc");
373 fprintf(output
, " dlc");
375 fprintf(output
, " slc");
377 fprintf(output
, " tfe");
379 fprintf(output
, " da");
381 fprintf(output
, " lwe");
382 if (mimg
->r128
|| mimg
->a16
)
383 fprintf(output
, " r128/a16");
385 fprintf(output
, " d16");
386 if (mimg
->disable_wqm
)
387 fprintf(output
, " disable_wqm");
388 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
392 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
393 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
394 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
395 fprintf(output
, " en:%c%c%c%c",
396 exp
->enabled_mask
& 0x1 ? 'r' : '*',
397 exp
->enabled_mask
& 0x2 ? 'g' : '*',
398 exp
->enabled_mask
& 0x4 ? 'b' : '*',
399 exp
->enabled_mask
& 0x8 ? 'a' : '*');
401 fprintf(output
, " compr");
403 fprintf(output
, " done");
405 fprintf(output
, " vm");
407 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
408 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
409 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
410 fprintf(output
, " mrtz");
411 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
412 fprintf(output
, " null");
413 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
414 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
415 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
416 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
419 case Format::PSEUDO_BRANCH
: {
420 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
421 /* Note: BB0 cannot be a branch target */
422 if (branch
->target
[0] != 0)
423 fprintf(output
, " BB%d", branch
->target
[0]);
424 if (branch
->target
[1] != 0)
425 fprintf(output
, ", BB%d", branch
->target
[1]);
428 case Format::PSEUDO_REDUCTION
: {
429 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
430 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
431 if (reduce
->cluster_size
)
432 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
437 case Format::SCRATCH
: {
438 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
440 fprintf(output
, " offset:%u", flat
->offset
);
442 fprintf(output
, " glc");
444 fprintf(output
, " dlc");
446 fprintf(output
, " slc");
448 fprintf(output
, " lds");
450 fprintf(output
, " nv");
451 if (flat
->disable_wqm
)
452 fprintf(output
, " disable_wqm");
453 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
456 case Format::MTBUF
: {
457 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
458 fprintf(output
, " dfmt:");
459 switch (mtbuf
->dfmt
) {
460 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
461 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
462 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
463 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
464 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
465 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
466 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
467 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
468 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
469 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
470 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
471 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
472 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
473 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
474 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
476 fprintf(output
, " nfmt:");
477 switch (mtbuf
->nfmt
) {
478 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
479 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
480 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
481 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
482 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
483 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
484 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
485 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
488 fprintf(output
, " offset:%u", mtbuf
->offset
);
490 fprintf(output
, " offen");
492 fprintf(output
, " idxen");
494 fprintf(output
, " glc");
496 fprintf(output
, " dlc");
498 fprintf(output
, " slc");
500 fprintf(output
, " tfe");
501 if (mtbuf
->disable_wqm
)
502 fprintf(output
, " disable_wqm");
503 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
506 case Format::VOP3P
: {
507 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
508 fprintf(output
, " clamp");
515 if (instr
->isVOP3()) {
516 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
517 switch (vop3
->omod
) {
519 fprintf(output
, " *2");
522 fprintf(output
, " *4");
525 fprintf(output
, " *0.5");
529 fprintf(output
, " clamp");
530 if (vop3
->opsel
& (1 << 3))
531 fprintf(output
, " opsel_hi");
532 } else if (instr
->isDPP()) {
533 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
534 if (dpp
->dpp_ctrl
<= 0xff) {
535 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
536 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
537 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
538 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
539 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
540 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
541 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
542 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
543 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
544 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
545 fprintf(output
, " wave_shl:1");
546 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
547 fprintf(output
, " wave_rol:1");
548 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
549 fprintf(output
, " wave_shr:1");
550 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
551 fprintf(output
, " wave_ror:1");
552 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
553 fprintf(output
, " row_mirror");
554 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
555 fprintf(output
, " row_half_mirror");
556 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
557 fprintf(output
, " row_bcast:15");
558 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
559 fprintf(output
, " row_bcast:31");
561 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
563 if (dpp
->row_mask
!= 0xf)
564 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
565 if (dpp
->bank_mask
!= 0xf)
566 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
568 fprintf(output
, " bound_ctrl:1");
569 } else if ((int)instr
->format
& (int)Format::SDWA
) {
570 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
571 switch (sdwa
->omod
) {
573 fprintf(output
, " *2");
576 fprintf(output
, " *4");
579 fprintf(output
, " *0.5");
583 fprintf(output
, " clamp");
584 switch (sdwa
->dst_sel
& sdwa_asuint
) {
591 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
592 sdwa
->dst_sel
& sdwa_bytenum
);
596 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
597 sdwa
->dst_sel
& sdwa_wordnum
);
600 if (sdwa
->dst_preserve
)
601 fprintf(output
, " dst_preserve");
605 void aco_print_instr(const Instruction
*instr
, FILE *output
)
607 if (!instr
->definitions
.empty()) {
608 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
609 print_definition(&instr
->definitions
[i
], output
);
610 if (i
+ 1 != instr
->definitions
.size())
611 fprintf(output
, ", ");
613 fprintf(output
, " = ");
615 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
616 if (instr
->operands
.size()) {
617 bool abs
[instr
->operands
.size()];
618 bool neg
[instr
->operands
.size()];
619 bool opsel
[instr
->operands
.size()];
620 uint8_t sel
[instr
->operands
.size()];
621 if ((int)instr
->format
& (int)Format::VOP3A
) {
622 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
623 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
624 abs
[i
] = vop3
->abs
[i
];
625 neg
[i
] = vop3
->neg
[i
];
626 opsel
[i
] = vop3
->opsel
& (1 << i
);
627 sel
[i
] = sdwa_udword
;
629 } else if (instr
->isDPP()) {
630 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
631 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
632 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
633 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
635 sel
[i
] = sdwa_udword
;
637 } else if (instr
->isSDWA()) {
638 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
639 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
640 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
641 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
643 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
646 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
650 sel
[i
] = sdwa_udword
;
653 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
655 fprintf(output
, ", ");
657 fprintf(output
, " ");
660 fprintf(output
, "-");
662 fprintf(output
, "|");
664 fprintf(output
, "hi(");
665 else if (sel
[i
] & sdwa_sext
)
666 fprintf(output
, "sext(");
667 print_operand(&instr
->operands
[i
], output
);
668 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
669 fprintf(output
, ")");
670 if (!(sel
[i
] & sdwa_isra
)) {
671 if (sel
[i
] & sdwa_udword
) {
673 } else if (sel
[i
] & sdwa_isword
) {
674 unsigned index
= sel
[i
] & sdwa_wordnum
;
675 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
677 unsigned index
= sel
[i
] & sdwa_bytenum
;
678 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
682 fprintf(output
, "|");
684 if (instr
->format
== Format::VOP3P
) {
685 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
686 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
687 fprintf(output
, ".%c%c",
688 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
689 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
691 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
692 fprintf(output
, "*[-1,-1]");
693 else if (vop3
->neg_lo
[i
])
694 fprintf(output
, "*[-1,1]");
695 else if (vop3
->neg_hi
[i
])
696 fprintf(output
, "*[1,-1]");
700 print_instr_format_specific(instr
, output
);
703 static void print_block_kind(uint16_t kind
, FILE *output
)
705 if (kind
& block_kind_uniform
)
706 fprintf(output
, "uniform, ");
707 if (kind
& block_kind_top_level
)
708 fprintf(output
, "top-level, ");
709 if (kind
& block_kind_loop_preheader
)
710 fprintf(output
, "loop-preheader, ");
711 if (kind
& block_kind_loop_header
)
712 fprintf(output
, "loop-header, ");
713 if (kind
& block_kind_loop_exit
)
714 fprintf(output
, "loop-exit, ");
715 if (kind
& block_kind_continue
)
716 fprintf(output
, "continue, ");
717 if (kind
& block_kind_break
)
718 fprintf(output
, "break, ");
719 if (kind
& block_kind_continue_or_break
)
720 fprintf(output
, "continue_or_break, ");
721 if (kind
& block_kind_discard
)
722 fprintf(output
, "discard, ");
723 if (kind
& block_kind_branch
)
724 fprintf(output
, "branch, ");
725 if (kind
& block_kind_merge
)
726 fprintf(output
, "merge, ");
727 if (kind
& block_kind_invert
)
728 fprintf(output
, "invert, ");
729 if (kind
& block_kind_uses_discard_if
)
730 fprintf(output
, "discard_if, ");
731 if (kind
& block_kind_needs_lowering
)
732 fprintf(output
, "needs_lowering, ");
733 if (kind
& block_kind_uses_demote
)
734 fprintf(output
, "uses_demote, ");
735 if (kind
& block_kind_export_end
)
736 fprintf(output
, "export_end, ");
739 static void print_stage(Stage stage
, FILE *output
)
741 fprintf(output
, "ACO shader stage: ");
743 if (stage
== compute_cs
)
744 fprintf(output
, "compute_cs");
745 else if (stage
== fragment_fs
)
746 fprintf(output
, "fragment_fs");
747 else if (stage
== gs_copy_vs
)
748 fprintf(output
, "gs_copy_vs");
749 else if (stage
== vertex_ls
)
750 fprintf(output
, "vertex_ls");
751 else if (stage
== vertex_es
)
752 fprintf(output
, "vertex_es");
753 else if (stage
== vertex_vs
)
754 fprintf(output
, "vertex_vs");
755 else if (stage
== tess_control_hs
)
756 fprintf(output
, "tess_control_hs");
757 else if (stage
== vertex_tess_control_hs
)
758 fprintf(output
, "vertex_tess_control_hs");
759 else if (stage
== tess_eval_es
)
760 fprintf(output
, "tess_eval_es");
761 else if (stage
== tess_eval_vs
)
762 fprintf(output
, "tess_eval_vs");
763 else if (stage
== geometry_gs
)
764 fprintf(output
, "geometry_gs");
765 else if (stage
== vertex_geometry_gs
)
766 fprintf(output
, "vertex_geometry_gs");
767 else if (stage
== tess_eval_geometry_gs
)
768 fprintf(output
, "tess_eval_geometry_gs");
769 else if (stage
== ngg_vertex_gs
)
770 fprintf(output
, "ngg_vertex_gs");
771 else if (stage
== ngg_tess_eval_gs
)
772 fprintf(output
, "ngg_tess_eval_gs");
773 else if (stage
== ngg_vertex_geometry_gs
)
774 fprintf(output
, "ngg_vertex_geometry_gs");
775 else if (stage
== ngg_tess_eval_geometry_gs
)
776 fprintf(output
, "ngg_tess_eval_geometry_gs");
778 fprintf(output
, "unknown");
780 fprintf(output
, "\n");
783 void aco_print_block(const Block
* block
, FILE *output
)
785 fprintf(output
, "BB%d\n", block
->index
);
786 fprintf(output
, "/* logical preds: ");
787 for (unsigned pred
: block
->logical_preds
)
788 fprintf(output
, "BB%d, ", pred
);
789 fprintf(output
, "/ linear preds: ");
790 for (unsigned pred
: block
->linear_preds
)
791 fprintf(output
, "BB%d, ", pred
);
792 fprintf(output
, "/ kind: ");
793 print_block_kind(block
->kind
, output
);
794 fprintf(output
, "*/\n");
795 for (auto const& instr
: block
->instructions
) {
796 fprintf(output
, "\t");
797 aco_print_instr(instr
.get(), output
);
798 fprintf(output
, "\n");
802 void aco_print_program(const Program
*program
, FILE *output
)
804 print_stage(program
->stage
, output
);
806 for (Block
const& block
: program
->blocks
)
807 aco_print_block(&block
, output
);
809 if (program
->constant_data
.size()) {
810 fprintf(output
, "\n/* constant data */\n");
811 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
812 fprintf(output
, "[%06d] ", i
);
813 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
814 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
815 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
817 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
818 fprintf(output
, " %08x", v
);
820 fprintf(output
, "\n");
824 fprintf(output
, "\n");