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 fprintf(output
, "%%%d", definition
->tempId());
179 if (definition
->isFixed())
180 print_physReg(definition
->physReg(), definition
->bytes(), output
);
183 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
186 fprintf(output
, " reorder");
188 if (barrier
& barrier_buffer
)
189 fprintf(output
, " buffer");
190 if (barrier
& barrier_image
)
191 fprintf(output
, " image");
192 if (barrier
& barrier_atomic
)
193 fprintf(output
, " atomic");
194 if (barrier
& barrier_shared
)
195 fprintf(output
, " shared");
196 if (barrier
& barrier_gs_data
)
197 fprintf(output
, " gs_data");
198 if (barrier
& barrier_gs_sendmsg
)
199 fprintf(output
, " gs_sendmsg");
202 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
204 switch (instr
->format
) {
206 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
207 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
211 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
212 uint16_t imm
= sopp
->imm
;
213 switch (instr
->opcode
) {
214 case aco_opcode::s_waitcnt
: {
215 /* we usually should check the chip class for vmcnt/lgkm, but
216 * insert_waitcnt() should fill it in regardless. */
217 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
218 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
219 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
220 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
223 case aco_opcode::s_endpgm
:
224 case aco_opcode::s_endpgm_saved
:
225 case aco_opcode::s_endpgm_ordered_ps_done
:
226 case aco_opcode::s_wakeup
:
227 case aco_opcode::s_barrier
:
228 case aco_opcode::s_icache_inv
:
229 case aco_opcode::s_ttracedata
:
230 case aco_opcode::s_set_gpr_idx_off
: {
233 case aco_opcode::s_sendmsg
: {
234 unsigned id
= imm
& sendmsg_id_mask
;
237 fprintf(output
, " sendmsg(MSG_NONE)");
240 fprintf(output
, " sendmsg(gs%s%s, %u)",
241 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
243 case _sendmsg_gs_done
:
244 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
245 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
247 case sendmsg_save_wave
:
248 fprintf(output
, " sendmsg(save_wave)");
250 case sendmsg_stall_wave_gen
:
251 fprintf(output
, " sendmsg(stall_wave_gen)");
253 case sendmsg_halt_waves
:
254 fprintf(output
, " sendmsg(halt_waves)");
256 case sendmsg_ordered_ps_done
:
257 fprintf(output
, " sendmsg(ordered_ps_done)");
259 case sendmsg_early_prim_dealloc
:
260 fprintf(output
, " sendmsg(early_prim_dealloc)");
262 case sendmsg_gs_alloc_req
:
263 fprintf(output
, " sendmsg(gs_alloc_req)");
270 fprintf(output
, " imm:%u", imm
);
274 if (sopp
->block
!= -1)
275 fprintf(output
, " block:BB%d", sopp
->block
);
279 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
281 fprintf(output
, " glc");
283 fprintf(output
, " dlc");
285 fprintf(output
, " nv");
286 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
289 case Format::VINTRP
: {
290 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
291 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
295 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
297 fprintf(output
, " offset0:%u", ds
->offset0
);
299 fprintf(output
, " offset1:%u", ds
->offset1
);
301 fprintf(output
, " gds");
304 case Format::MUBUF
: {
305 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
307 fprintf(output
, " offset:%u", mubuf
->offset
);
309 fprintf(output
, " offen");
311 fprintf(output
, " idxen");
313 fprintf(output
, " addr64");
315 fprintf(output
, " glc");
317 fprintf(output
, " dlc");
319 fprintf(output
, " slc");
321 fprintf(output
, " tfe");
323 fprintf(output
, " lds");
324 if (mubuf
->disable_wqm
)
325 fprintf(output
, " disable_wqm");
326 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
330 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
331 unsigned identity_dmask
= !instr
->definitions
.empty() ?
332 (1 << instr
->definitions
[0].size()) - 1 :
334 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
335 fprintf(output
, " dmask:%s%s%s%s",
336 mimg
->dmask
& 0x1 ? "x" : "",
337 mimg
->dmask
& 0x2 ? "y" : "",
338 mimg
->dmask
& 0x4 ? "z" : "",
339 mimg
->dmask
& 0x8 ? "w" : "");
342 fprintf(output
, " 1d");
345 fprintf(output
, " 2d");
348 fprintf(output
, " 3d");
351 fprintf(output
, " cube");
353 case ac_image_1darray
:
354 fprintf(output
, " 1darray");
356 case ac_image_2darray
:
357 fprintf(output
, " 2darray");
359 case ac_image_2dmsaa
:
360 fprintf(output
, " 2dmsaa");
362 case ac_image_2darraymsaa
:
363 fprintf(output
, " 2darraymsaa");
367 fprintf(output
, " unrm");
369 fprintf(output
, " glc");
371 fprintf(output
, " dlc");
373 fprintf(output
, " slc");
375 fprintf(output
, " tfe");
377 fprintf(output
, " da");
379 fprintf(output
, " lwe");
380 if (mimg
->r128
|| mimg
->a16
)
381 fprintf(output
, " r128/a16");
383 fprintf(output
, " d16");
384 if (mimg
->disable_wqm
)
385 fprintf(output
, " disable_wqm");
386 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
390 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
391 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
392 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
393 fprintf(output
, " en:%c%c%c%c",
394 exp
->enabled_mask
& 0x1 ? 'r' : '*',
395 exp
->enabled_mask
& 0x2 ? 'g' : '*',
396 exp
->enabled_mask
& 0x4 ? 'b' : '*',
397 exp
->enabled_mask
& 0x8 ? 'a' : '*');
399 fprintf(output
, " compr");
401 fprintf(output
, " done");
403 fprintf(output
, " vm");
405 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
406 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
407 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
408 fprintf(output
, " mrtz");
409 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
410 fprintf(output
, " null");
411 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
412 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
413 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
414 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
417 case Format::PSEUDO_BRANCH
: {
418 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
419 /* Note: BB0 cannot be a branch target */
420 if (branch
->target
[0] != 0)
421 fprintf(output
, " BB%d", branch
->target
[0]);
422 if (branch
->target
[1] != 0)
423 fprintf(output
, ", BB%d", branch
->target
[1]);
426 case Format::PSEUDO_REDUCTION
: {
427 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
428 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
429 if (reduce
->cluster_size
)
430 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
435 case Format::SCRATCH
: {
436 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
438 fprintf(output
, " offset:%u", flat
->offset
);
440 fprintf(output
, " glc");
442 fprintf(output
, " dlc");
444 fprintf(output
, " slc");
446 fprintf(output
, " lds");
448 fprintf(output
, " nv");
449 if (flat
->disable_wqm
)
450 fprintf(output
, " disable_wqm");
451 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
454 case Format::MTBUF
: {
455 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
456 fprintf(output
, " dfmt:");
457 switch (mtbuf
->dfmt
) {
458 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
459 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
460 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
461 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
462 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
463 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
464 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
465 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
466 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
467 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
468 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
469 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
470 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
471 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
472 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
474 fprintf(output
, " nfmt:");
475 switch (mtbuf
->nfmt
) {
476 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
477 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
478 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
479 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
480 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
481 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
482 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
483 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
486 fprintf(output
, " offset:%u", mtbuf
->offset
);
488 fprintf(output
, " offen");
490 fprintf(output
, " idxen");
492 fprintf(output
, " glc");
494 fprintf(output
, " dlc");
496 fprintf(output
, " slc");
498 fprintf(output
, " tfe");
499 if (mtbuf
->disable_wqm
)
500 fprintf(output
, " disable_wqm");
501 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
504 case Format::VOP3P
: {
505 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
506 fprintf(output
, " clamp");
513 if (instr
->isVOP3()) {
514 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
515 switch (vop3
->omod
) {
517 fprintf(output
, " *2");
520 fprintf(output
, " *4");
523 fprintf(output
, " *0.5");
527 fprintf(output
, " clamp");
528 if (vop3
->opsel
& (1 << 3))
529 fprintf(output
, " opsel_hi");
530 } else if (instr
->isDPP()) {
531 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
532 if (dpp
->dpp_ctrl
<= 0xff) {
533 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
534 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
535 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
536 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
537 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
538 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
539 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
540 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
541 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
542 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
543 fprintf(output
, " wave_shl:1");
544 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
545 fprintf(output
, " wave_rol:1");
546 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
547 fprintf(output
, " wave_shr:1");
548 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
549 fprintf(output
, " wave_ror:1");
550 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
551 fprintf(output
, " row_mirror");
552 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
553 fprintf(output
, " row_half_mirror");
554 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
555 fprintf(output
, " row_bcast:15");
556 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
557 fprintf(output
, " row_bcast:31");
559 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
561 if (dpp
->row_mask
!= 0xf)
562 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
563 if (dpp
->bank_mask
!= 0xf)
564 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
566 fprintf(output
, " bound_ctrl:1");
567 } else if ((int)instr
->format
& (int)Format::SDWA
) {
568 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
569 switch (sdwa
->omod
) {
571 fprintf(output
, " *2");
574 fprintf(output
, " *4");
577 fprintf(output
, " *0.5");
581 fprintf(output
, " clamp");
582 switch (sdwa
->dst_sel
& sdwa_asuint
) {
589 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
590 sdwa
->dst_sel
& sdwa_bytenum
);
594 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
595 sdwa
->dst_sel
& sdwa_wordnum
);
598 if (sdwa
->dst_preserve
)
599 fprintf(output
, " dst_preserve");
603 void aco_print_instr(const Instruction
*instr
, FILE *output
)
605 if (!instr
->definitions
.empty()) {
606 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
607 print_definition(&instr
->definitions
[i
], output
);
608 if (i
+ 1 != instr
->definitions
.size())
609 fprintf(output
, ", ");
611 fprintf(output
, " = ");
613 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
614 if (instr
->operands
.size()) {
615 bool abs
[instr
->operands
.size()];
616 bool neg
[instr
->operands
.size()];
617 bool opsel
[instr
->operands
.size()];
618 uint8_t sel
[instr
->operands
.size()];
619 if ((int)instr
->format
& (int)Format::VOP3A
) {
620 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
621 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
622 abs
[i
] = vop3
->abs
[i
];
623 neg
[i
] = vop3
->neg
[i
];
624 opsel
[i
] = vop3
->opsel
& (1 << i
);
625 sel
[i
] = sdwa_udword
;
627 } else if (instr
->isDPP()) {
628 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
629 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
630 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
631 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
633 sel
[i
] = sdwa_udword
;
635 } else if (instr
->isSDWA()) {
636 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
637 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
638 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
639 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
641 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
644 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
648 sel
[i
] = sdwa_udword
;
651 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
653 fprintf(output
, ", ");
655 fprintf(output
, " ");
658 fprintf(output
, "-");
660 fprintf(output
, "|");
662 fprintf(output
, "hi(");
663 else if (sel
[i
] & sdwa_sext
)
664 fprintf(output
, "sext(");
665 print_operand(&instr
->operands
[i
], output
);
666 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
667 fprintf(output
, ")");
668 if (!(sel
[i
] & sdwa_isra
)) {
669 if (sel
[i
] & sdwa_udword
) {
671 } else if (sel
[i
] & sdwa_isword
) {
672 unsigned index
= sel
[i
] & sdwa_wordnum
;
673 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
675 unsigned index
= sel
[i
] & sdwa_bytenum
;
676 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
680 fprintf(output
, "|");
682 if (instr
->format
== Format::VOP3P
) {
683 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
684 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
685 fprintf(output
, ".%c%c",
686 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
687 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
689 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
690 fprintf(output
, "*[-1,-1]");
691 else if (vop3
->neg_lo
[i
])
692 fprintf(output
, "*[-1,1]");
693 else if (vop3
->neg_hi
[i
])
694 fprintf(output
, "*[1,-1]");
698 print_instr_format_specific(instr
, output
);
701 static void print_block_kind(uint16_t kind
, FILE *output
)
703 if (kind
& block_kind_uniform
)
704 fprintf(output
, "uniform, ");
705 if (kind
& block_kind_top_level
)
706 fprintf(output
, "top-level, ");
707 if (kind
& block_kind_loop_preheader
)
708 fprintf(output
, "loop-preheader, ");
709 if (kind
& block_kind_loop_header
)
710 fprintf(output
, "loop-header, ");
711 if (kind
& block_kind_loop_exit
)
712 fprintf(output
, "loop-exit, ");
713 if (kind
& block_kind_continue
)
714 fprintf(output
, "continue, ");
715 if (kind
& block_kind_break
)
716 fprintf(output
, "break, ");
717 if (kind
& block_kind_continue_or_break
)
718 fprintf(output
, "continue_or_break, ");
719 if (kind
& block_kind_discard
)
720 fprintf(output
, "discard, ");
721 if (kind
& block_kind_branch
)
722 fprintf(output
, "branch, ");
723 if (kind
& block_kind_merge
)
724 fprintf(output
, "merge, ");
725 if (kind
& block_kind_invert
)
726 fprintf(output
, "invert, ");
727 if (kind
& block_kind_uses_discard_if
)
728 fprintf(output
, "discard_if, ");
729 if (kind
& block_kind_needs_lowering
)
730 fprintf(output
, "needs_lowering, ");
731 if (kind
& block_kind_uses_demote
)
732 fprintf(output
, "uses_demote, ");
733 if (kind
& block_kind_export_end
)
734 fprintf(output
, "export_end, ");
737 static void print_stage(Stage stage
, FILE *output
)
739 fprintf(output
, "ACO shader stage: ");
741 if (stage
== compute_cs
)
742 fprintf(output
, "compute_cs");
743 else if (stage
== fragment_fs
)
744 fprintf(output
, "fragment_fs");
745 else if (stage
== gs_copy_vs
)
746 fprintf(output
, "gs_copy_vs");
747 else if (stage
== vertex_ls
)
748 fprintf(output
, "vertex_ls");
749 else if (stage
== vertex_es
)
750 fprintf(output
, "vertex_es");
751 else if (stage
== vertex_vs
)
752 fprintf(output
, "vertex_vs");
753 else if (stage
== tess_control_hs
)
754 fprintf(output
, "tess_control_hs");
755 else if (stage
== vertex_tess_control_hs
)
756 fprintf(output
, "vertex_tess_control_hs");
757 else if (stage
== tess_eval_es
)
758 fprintf(output
, "tess_eval_es");
759 else if (stage
== tess_eval_vs
)
760 fprintf(output
, "tess_eval_vs");
761 else if (stage
== geometry_gs
)
762 fprintf(output
, "geometry_gs");
763 else if (stage
== vertex_geometry_gs
)
764 fprintf(output
, "vertex_geometry_gs");
765 else if (stage
== tess_eval_geometry_gs
)
766 fprintf(output
, "tess_eval_geometry_gs");
767 else if (stage
== ngg_vertex_gs
)
768 fprintf(output
, "ngg_vertex_gs");
769 else if (stage
== ngg_tess_eval_gs
)
770 fprintf(output
, "ngg_tess_eval_gs");
771 else if (stage
== ngg_vertex_geometry_gs
)
772 fprintf(output
, "ngg_vertex_geometry_gs");
773 else if (stage
== ngg_tess_eval_geometry_gs
)
774 fprintf(output
, "ngg_tess_eval_geometry_gs");
776 fprintf(output
, "unknown");
778 fprintf(output
, "\n");
781 void aco_print_block(const Block
* block
, FILE *output
)
783 fprintf(output
, "BB%d\n", block
->index
);
784 fprintf(output
, "/* logical preds: ");
785 for (unsigned pred
: block
->logical_preds
)
786 fprintf(output
, "BB%d, ", pred
);
787 fprintf(output
, "/ linear preds: ");
788 for (unsigned pred
: block
->linear_preds
)
789 fprintf(output
, "BB%d, ", pred
);
790 fprintf(output
, "/ kind: ");
791 print_block_kind(block
->kind
, output
);
792 fprintf(output
, "*/\n");
793 for (auto const& instr
: block
->instructions
) {
794 fprintf(output
, "\t");
795 aco_print_instr(instr
.get(), output
);
796 fprintf(output
, "\n");
800 void aco_print_program(const Program
*program
, FILE *output
)
802 print_stage(program
->stage
, output
);
804 for (Block
const& block
: program
->blocks
)
805 aco_print_block(&block
, output
);
807 if (program
->constant_data
.size()) {
808 fprintf(output
, "\n/* constant data */\n");
809 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
810 fprintf(output
, "[%06d] ", i
);
811 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
812 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
813 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
815 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
816 fprintf(output
, " %08x", v
);
818 fprintf(output
, "\n");
822 fprintf(output
, "\n");