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() || (operand
->isConstant() && operand
->bytes() == 1)) {
157 if (operand
->bytes() == 1)
158 fprintf(output
, "0x%.2x", operand
->constantValue());
159 else if (operand
->bytes() == 2)
160 fprintf(output
, "0x%.4x", operand
->constantValue());
162 fprintf(output
, "0x%x", operand
->constantValue());
163 } else if (operand
->isConstant()) {
164 print_constant(operand
->physReg().reg(), output
);
165 } else if (operand
->isUndefined()) {
166 print_reg_class(operand
->regClass(), output
);
167 fprintf(output
, "undef");
169 if (operand
->isLateKill())
170 fprintf(output
, "(latekill)");
172 fprintf(output
, "%%%d", operand
->tempId());
174 if (operand
->isFixed())
175 print_physReg(operand
->physReg(), operand
->bytes(), output
);
179 static void print_definition(const Definition
*definition
, FILE *output
)
181 print_reg_class(definition
->regClass(), output
);
182 if (definition
->isPrecise())
183 fprintf(output
, "(precise)");
184 fprintf(output
, "%%%d", definition
->tempId());
186 if (definition
->isFixed())
187 print_physReg(definition
->physReg(), definition
->bytes(), output
);
190 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
193 fprintf(output
, " reorder");
195 if (barrier
& barrier_buffer
)
196 fprintf(output
, " buffer");
197 if (barrier
& barrier_image
)
198 fprintf(output
, " image");
199 if (barrier
& barrier_atomic
)
200 fprintf(output
, " atomic");
201 if (barrier
& barrier_shared
)
202 fprintf(output
, " shared");
203 if (barrier
& barrier_gs_data
)
204 fprintf(output
, " gs_data");
205 if (barrier
& barrier_gs_sendmsg
)
206 fprintf(output
, " gs_sendmsg");
209 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
211 switch (instr
->format
) {
213 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
214 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
218 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
219 uint16_t imm
= sopp
->imm
;
220 switch (instr
->opcode
) {
221 case aco_opcode::s_waitcnt
: {
222 /* we usually should check the chip class for vmcnt/lgkm, but
223 * insert_waitcnt() should fill it in regardless. */
224 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
225 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
226 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
227 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
230 case aco_opcode::s_endpgm
:
231 case aco_opcode::s_endpgm_saved
:
232 case aco_opcode::s_endpgm_ordered_ps_done
:
233 case aco_opcode::s_wakeup
:
234 case aco_opcode::s_barrier
:
235 case aco_opcode::s_icache_inv
:
236 case aco_opcode::s_ttracedata
:
237 case aco_opcode::s_set_gpr_idx_off
: {
240 case aco_opcode::s_sendmsg
: {
241 unsigned id
= imm
& sendmsg_id_mask
;
244 fprintf(output
, " sendmsg(MSG_NONE)");
247 fprintf(output
, " sendmsg(gs%s%s, %u)",
248 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
250 case _sendmsg_gs_done
:
251 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
252 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
254 case sendmsg_save_wave
:
255 fprintf(output
, " sendmsg(save_wave)");
257 case sendmsg_stall_wave_gen
:
258 fprintf(output
, " sendmsg(stall_wave_gen)");
260 case sendmsg_halt_waves
:
261 fprintf(output
, " sendmsg(halt_waves)");
263 case sendmsg_ordered_ps_done
:
264 fprintf(output
, " sendmsg(ordered_ps_done)");
266 case sendmsg_early_prim_dealloc
:
267 fprintf(output
, " sendmsg(early_prim_dealloc)");
269 case sendmsg_gs_alloc_req
:
270 fprintf(output
, " sendmsg(gs_alloc_req)");
277 fprintf(output
, " imm:%u", imm
);
281 if (sopp
->block
!= -1)
282 fprintf(output
, " block:BB%d", sopp
->block
);
286 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
288 fprintf(output
, " glc");
290 fprintf(output
, " dlc");
292 fprintf(output
, " nv");
293 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
296 case Format::VINTRP
: {
297 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
298 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
302 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
304 fprintf(output
, " offset0:%u", ds
->offset0
);
306 fprintf(output
, " offset1:%u", ds
->offset1
);
308 fprintf(output
, " gds");
311 case Format::MUBUF
: {
312 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
314 fprintf(output
, " offset:%u", mubuf
->offset
);
316 fprintf(output
, " offen");
318 fprintf(output
, " idxen");
320 fprintf(output
, " addr64");
322 fprintf(output
, " glc");
324 fprintf(output
, " dlc");
326 fprintf(output
, " slc");
328 fprintf(output
, " tfe");
330 fprintf(output
, " lds");
331 if (mubuf
->disable_wqm
)
332 fprintf(output
, " disable_wqm");
333 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
337 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
338 unsigned identity_dmask
= !instr
->definitions
.empty() ?
339 (1 << instr
->definitions
[0].size()) - 1 :
341 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
342 fprintf(output
, " dmask:%s%s%s%s",
343 mimg
->dmask
& 0x1 ? "x" : "",
344 mimg
->dmask
& 0x2 ? "y" : "",
345 mimg
->dmask
& 0x4 ? "z" : "",
346 mimg
->dmask
& 0x8 ? "w" : "");
349 fprintf(output
, " 1d");
352 fprintf(output
, " 2d");
355 fprintf(output
, " 3d");
358 fprintf(output
, " cube");
360 case ac_image_1darray
:
361 fprintf(output
, " 1darray");
363 case ac_image_2darray
:
364 fprintf(output
, " 2darray");
366 case ac_image_2dmsaa
:
367 fprintf(output
, " 2dmsaa");
369 case ac_image_2darraymsaa
:
370 fprintf(output
, " 2darraymsaa");
374 fprintf(output
, " unrm");
376 fprintf(output
, " glc");
378 fprintf(output
, " dlc");
380 fprintf(output
, " slc");
382 fprintf(output
, " tfe");
384 fprintf(output
, " da");
386 fprintf(output
, " lwe");
387 if (mimg
->r128
|| mimg
->a16
)
388 fprintf(output
, " r128/a16");
390 fprintf(output
, " d16");
391 if (mimg
->disable_wqm
)
392 fprintf(output
, " disable_wqm");
393 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
397 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
398 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
399 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
400 fprintf(output
, " en:%c%c%c%c",
401 exp
->enabled_mask
& 0x1 ? 'r' : '*',
402 exp
->enabled_mask
& 0x2 ? 'g' : '*',
403 exp
->enabled_mask
& 0x4 ? 'b' : '*',
404 exp
->enabled_mask
& 0x8 ? 'a' : '*');
406 fprintf(output
, " compr");
408 fprintf(output
, " done");
410 fprintf(output
, " vm");
412 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
413 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
414 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
415 fprintf(output
, " mrtz");
416 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
417 fprintf(output
, " null");
418 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
419 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
420 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
421 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
424 case Format::PSEUDO_BRANCH
: {
425 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
426 /* Note: BB0 cannot be a branch target */
427 if (branch
->target
[0] != 0)
428 fprintf(output
, " BB%d", branch
->target
[0]);
429 if (branch
->target
[1] != 0)
430 fprintf(output
, ", BB%d", branch
->target
[1]);
433 case Format::PSEUDO_REDUCTION
: {
434 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
435 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
436 if (reduce
->cluster_size
)
437 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
442 case Format::SCRATCH
: {
443 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
445 fprintf(output
, " offset:%u", flat
->offset
);
447 fprintf(output
, " glc");
449 fprintf(output
, " dlc");
451 fprintf(output
, " slc");
453 fprintf(output
, " lds");
455 fprintf(output
, " nv");
456 if (flat
->disable_wqm
)
457 fprintf(output
, " disable_wqm");
458 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
461 case Format::MTBUF
: {
462 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
463 fprintf(output
, " dfmt:");
464 switch (mtbuf
->dfmt
) {
465 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
466 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
467 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
468 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
469 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
470 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
471 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
472 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
473 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
474 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
475 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
476 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
477 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
478 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
479 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
481 fprintf(output
, " nfmt:");
482 switch (mtbuf
->nfmt
) {
483 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
484 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
485 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
486 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
487 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
488 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
489 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
490 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
493 fprintf(output
, " offset:%u", mtbuf
->offset
);
495 fprintf(output
, " offen");
497 fprintf(output
, " idxen");
499 fprintf(output
, " glc");
501 fprintf(output
, " dlc");
503 fprintf(output
, " slc");
505 fprintf(output
, " tfe");
506 if (mtbuf
->disable_wqm
)
507 fprintf(output
, " disable_wqm");
508 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
511 case Format::VOP3P
: {
512 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
513 fprintf(output
, " clamp");
520 if (instr
->isVOP3()) {
521 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
522 switch (vop3
->omod
) {
524 fprintf(output
, " *2");
527 fprintf(output
, " *4");
530 fprintf(output
, " *0.5");
534 fprintf(output
, " clamp");
535 if (vop3
->opsel
& (1 << 3))
536 fprintf(output
, " opsel_hi");
537 } else if (instr
->isDPP()) {
538 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
539 if (dpp
->dpp_ctrl
<= 0xff) {
540 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
541 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
542 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
543 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
544 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
545 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
546 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
547 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
548 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
549 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
550 fprintf(output
, " wave_shl:1");
551 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
552 fprintf(output
, " wave_rol:1");
553 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
554 fprintf(output
, " wave_shr:1");
555 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
556 fprintf(output
, " wave_ror:1");
557 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
558 fprintf(output
, " row_mirror");
559 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
560 fprintf(output
, " row_half_mirror");
561 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
562 fprintf(output
, " row_bcast:15");
563 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
564 fprintf(output
, " row_bcast:31");
566 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
568 if (dpp
->row_mask
!= 0xf)
569 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
570 if (dpp
->bank_mask
!= 0xf)
571 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
573 fprintf(output
, " bound_ctrl:1");
574 } else if ((int)instr
->format
& (int)Format::SDWA
) {
575 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
576 switch (sdwa
->omod
) {
578 fprintf(output
, " *2");
581 fprintf(output
, " *4");
584 fprintf(output
, " *0.5");
588 fprintf(output
, " clamp");
589 switch (sdwa
->dst_sel
& sdwa_asuint
) {
596 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
597 sdwa
->dst_sel
& sdwa_bytenum
);
601 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
602 sdwa
->dst_sel
& sdwa_wordnum
);
605 if (sdwa
->dst_preserve
)
606 fprintf(output
, " dst_preserve");
610 void aco_print_instr(const Instruction
*instr
, FILE *output
)
612 if (!instr
->definitions
.empty()) {
613 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
614 print_definition(&instr
->definitions
[i
], output
);
615 if (i
+ 1 != instr
->definitions
.size())
616 fprintf(output
, ", ");
618 fprintf(output
, " = ");
620 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
621 if (instr
->operands
.size()) {
622 bool abs
[instr
->operands
.size()];
623 bool neg
[instr
->operands
.size()];
624 bool opsel
[instr
->operands
.size()];
625 uint8_t sel
[instr
->operands
.size()];
626 if ((int)instr
->format
& (int)Format::VOP3A
) {
627 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
628 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
629 abs
[i
] = vop3
->abs
[i
];
630 neg
[i
] = vop3
->neg
[i
];
631 opsel
[i
] = vop3
->opsel
& (1 << i
);
632 sel
[i
] = sdwa_udword
;
634 } else if (instr
->isDPP()) {
635 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
636 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
637 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
638 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
640 sel
[i
] = sdwa_udword
;
642 } else if (instr
->isSDWA()) {
643 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
644 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
645 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
646 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
648 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
651 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
655 sel
[i
] = sdwa_udword
;
658 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
660 fprintf(output
, ", ");
662 fprintf(output
, " ");
665 fprintf(output
, "-");
667 fprintf(output
, "|");
669 fprintf(output
, "hi(");
670 else if (sel
[i
] & sdwa_sext
)
671 fprintf(output
, "sext(");
672 print_operand(&instr
->operands
[i
], output
);
673 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
674 fprintf(output
, ")");
675 if (!(sel
[i
] & sdwa_isra
)) {
676 if (sel
[i
] & sdwa_udword
) {
678 } else if (sel
[i
] & sdwa_isword
) {
679 unsigned index
= sel
[i
] & sdwa_wordnum
;
680 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
682 unsigned index
= sel
[i
] & sdwa_bytenum
;
683 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
687 fprintf(output
, "|");
689 if (instr
->format
== Format::VOP3P
) {
690 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
691 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
692 fprintf(output
, ".%c%c",
693 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
694 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
696 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
697 fprintf(output
, "*[-1,-1]");
698 else if (vop3
->neg_lo
[i
])
699 fprintf(output
, "*[-1,1]");
700 else if (vop3
->neg_hi
[i
])
701 fprintf(output
, "*[1,-1]");
705 print_instr_format_specific(instr
, output
);
708 static void print_block_kind(uint16_t kind
, FILE *output
)
710 if (kind
& block_kind_uniform
)
711 fprintf(output
, "uniform, ");
712 if (kind
& block_kind_top_level
)
713 fprintf(output
, "top-level, ");
714 if (kind
& block_kind_loop_preheader
)
715 fprintf(output
, "loop-preheader, ");
716 if (kind
& block_kind_loop_header
)
717 fprintf(output
, "loop-header, ");
718 if (kind
& block_kind_loop_exit
)
719 fprintf(output
, "loop-exit, ");
720 if (kind
& block_kind_continue
)
721 fprintf(output
, "continue, ");
722 if (kind
& block_kind_break
)
723 fprintf(output
, "break, ");
724 if (kind
& block_kind_continue_or_break
)
725 fprintf(output
, "continue_or_break, ");
726 if (kind
& block_kind_discard
)
727 fprintf(output
, "discard, ");
728 if (kind
& block_kind_branch
)
729 fprintf(output
, "branch, ");
730 if (kind
& block_kind_merge
)
731 fprintf(output
, "merge, ");
732 if (kind
& block_kind_invert
)
733 fprintf(output
, "invert, ");
734 if (kind
& block_kind_uses_discard_if
)
735 fprintf(output
, "discard_if, ");
736 if (kind
& block_kind_needs_lowering
)
737 fprintf(output
, "needs_lowering, ");
738 if (kind
& block_kind_uses_demote
)
739 fprintf(output
, "uses_demote, ");
740 if (kind
& block_kind_export_end
)
741 fprintf(output
, "export_end, ");
744 static void print_stage(Stage stage
, FILE *output
)
746 fprintf(output
, "ACO shader stage: ");
748 if (stage
== compute_cs
)
749 fprintf(output
, "compute_cs");
750 else if (stage
== fragment_fs
)
751 fprintf(output
, "fragment_fs");
752 else if (stage
== gs_copy_vs
)
753 fprintf(output
, "gs_copy_vs");
754 else if (stage
== vertex_ls
)
755 fprintf(output
, "vertex_ls");
756 else if (stage
== vertex_es
)
757 fprintf(output
, "vertex_es");
758 else if (stage
== vertex_vs
)
759 fprintf(output
, "vertex_vs");
760 else if (stage
== tess_control_hs
)
761 fprintf(output
, "tess_control_hs");
762 else if (stage
== vertex_tess_control_hs
)
763 fprintf(output
, "vertex_tess_control_hs");
764 else if (stage
== tess_eval_es
)
765 fprintf(output
, "tess_eval_es");
766 else if (stage
== tess_eval_vs
)
767 fprintf(output
, "tess_eval_vs");
768 else if (stage
== geometry_gs
)
769 fprintf(output
, "geometry_gs");
770 else if (stage
== vertex_geometry_gs
)
771 fprintf(output
, "vertex_geometry_gs");
772 else if (stage
== tess_eval_geometry_gs
)
773 fprintf(output
, "tess_eval_geometry_gs");
774 else if (stage
== ngg_vertex_gs
)
775 fprintf(output
, "ngg_vertex_gs");
776 else if (stage
== ngg_tess_eval_gs
)
777 fprintf(output
, "ngg_tess_eval_gs");
778 else if (stage
== ngg_vertex_geometry_gs
)
779 fprintf(output
, "ngg_vertex_geometry_gs");
780 else if (stage
== ngg_tess_eval_geometry_gs
)
781 fprintf(output
, "ngg_tess_eval_geometry_gs");
783 fprintf(output
, "unknown");
785 fprintf(output
, "\n");
788 void aco_print_block(const Block
* block
, FILE *output
)
790 fprintf(output
, "BB%d\n", block
->index
);
791 fprintf(output
, "/* logical preds: ");
792 for (unsigned pred
: block
->logical_preds
)
793 fprintf(output
, "BB%d, ", pred
);
794 fprintf(output
, "/ linear preds: ");
795 for (unsigned pred
: block
->linear_preds
)
796 fprintf(output
, "BB%d, ", pred
);
797 fprintf(output
, "/ kind: ");
798 print_block_kind(block
->kind
, output
);
799 fprintf(output
, "*/\n");
800 for (auto const& instr
: block
->instructions
) {
801 fprintf(output
, "\t");
802 aco_print_instr(instr
.get(), output
);
803 fprintf(output
, "\n");
807 void aco_print_program(const Program
*program
, FILE *output
)
809 print_stage(program
->stage
, output
);
811 for (Block
const& block
: program
->blocks
)
812 aco_print_block(&block
, output
);
814 if (program
->constant_data
.size()) {
815 fprintf(output
, "\n/* constant data */\n");
816 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
817 fprintf(output
, "[%06d] ", i
);
818 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
819 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
820 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
822 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
823 fprintf(output
, " %08x", v
);
825 fprintf(output
, "\n");
829 fprintf(output
, "\n");