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 if (definition
->isNUW())
185 fprintf(output
, "(nuw)");
186 fprintf(output
, "%%%d", definition
->tempId());
188 if (definition
->isFixed())
189 print_physReg(definition
->physReg(), definition
->bytes(), output
);
192 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
195 fprintf(output
, " reorder");
197 if (barrier
& barrier_buffer
)
198 fprintf(output
, " buffer");
199 if (barrier
& barrier_image
)
200 fprintf(output
, " image");
201 if (barrier
& barrier_atomic
)
202 fprintf(output
, " atomic");
203 if (barrier
& barrier_shared
)
204 fprintf(output
, " shared");
205 if (barrier
& barrier_gs_data
)
206 fprintf(output
, " gs_data");
207 if (barrier
& barrier_gs_sendmsg
)
208 fprintf(output
, " gs_sendmsg");
211 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
213 switch (instr
->format
) {
215 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
216 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
220 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
221 uint16_t imm
= sopp
->imm
;
222 switch (instr
->opcode
) {
223 case aco_opcode::s_waitcnt
: {
224 /* we usually should check the chip class for vmcnt/lgkm, but
225 * insert_waitcnt() should fill it in regardless. */
226 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
227 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
228 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
229 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
232 case aco_opcode::s_endpgm
:
233 case aco_opcode::s_endpgm_saved
:
234 case aco_opcode::s_endpgm_ordered_ps_done
:
235 case aco_opcode::s_wakeup
:
236 case aco_opcode::s_barrier
:
237 case aco_opcode::s_icache_inv
:
238 case aco_opcode::s_ttracedata
:
239 case aco_opcode::s_set_gpr_idx_off
: {
242 case aco_opcode::s_sendmsg
: {
243 unsigned id
= imm
& sendmsg_id_mask
;
246 fprintf(output
, " sendmsg(MSG_NONE)");
249 fprintf(output
, " sendmsg(gs%s%s, %u)",
250 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
252 case _sendmsg_gs_done
:
253 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
254 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
256 case sendmsg_save_wave
:
257 fprintf(output
, " sendmsg(save_wave)");
259 case sendmsg_stall_wave_gen
:
260 fprintf(output
, " sendmsg(stall_wave_gen)");
262 case sendmsg_halt_waves
:
263 fprintf(output
, " sendmsg(halt_waves)");
265 case sendmsg_ordered_ps_done
:
266 fprintf(output
, " sendmsg(ordered_ps_done)");
268 case sendmsg_early_prim_dealloc
:
269 fprintf(output
, " sendmsg(early_prim_dealloc)");
271 case sendmsg_gs_alloc_req
:
272 fprintf(output
, " sendmsg(gs_alloc_req)");
279 fprintf(output
, " imm:%u", imm
);
283 if (sopp
->block
!= -1)
284 fprintf(output
, " block:BB%d", sopp
->block
);
288 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
290 fprintf(output
, " glc");
292 fprintf(output
, " dlc");
294 fprintf(output
, " nv");
295 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
298 case Format::VINTRP
: {
299 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
300 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
304 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
306 fprintf(output
, " offset0:%u", ds
->offset0
);
308 fprintf(output
, " offset1:%u", ds
->offset1
);
310 fprintf(output
, " gds");
313 case Format::MUBUF
: {
314 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
316 fprintf(output
, " offset:%u", mubuf
->offset
);
318 fprintf(output
, " offen");
320 fprintf(output
, " idxen");
322 fprintf(output
, " addr64");
324 fprintf(output
, " glc");
326 fprintf(output
, " dlc");
328 fprintf(output
, " slc");
330 fprintf(output
, " tfe");
332 fprintf(output
, " lds");
333 if (mubuf
->disable_wqm
)
334 fprintf(output
, " disable_wqm");
335 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
339 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
340 unsigned identity_dmask
= !instr
->definitions
.empty() ?
341 (1 << instr
->definitions
[0].size()) - 1 :
343 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
344 fprintf(output
, " dmask:%s%s%s%s",
345 mimg
->dmask
& 0x1 ? "x" : "",
346 mimg
->dmask
& 0x2 ? "y" : "",
347 mimg
->dmask
& 0x4 ? "z" : "",
348 mimg
->dmask
& 0x8 ? "w" : "");
351 fprintf(output
, " 1d");
354 fprintf(output
, " 2d");
357 fprintf(output
, " 3d");
360 fprintf(output
, " cube");
362 case ac_image_1darray
:
363 fprintf(output
, " 1darray");
365 case ac_image_2darray
:
366 fprintf(output
, " 2darray");
368 case ac_image_2dmsaa
:
369 fprintf(output
, " 2dmsaa");
371 case ac_image_2darraymsaa
:
372 fprintf(output
, " 2darraymsaa");
376 fprintf(output
, " unrm");
378 fprintf(output
, " glc");
380 fprintf(output
, " dlc");
382 fprintf(output
, " slc");
384 fprintf(output
, " tfe");
386 fprintf(output
, " da");
388 fprintf(output
, " lwe");
389 if (mimg
->r128
|| mimg
->a16
)
390 fprintf(output
, " r128/a16");
392 fprintf(output
, " d16");
393 if (mimg
->disable_wqm
)
394 fprintf(output
, " disable_wqm");
395 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
399 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
400 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
401 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
402 fprintf(output
, " en:%c%c%c%c",
403 exp
->enabled_mask
& 0x1 ? 'r' : '*',
404 exp
->enabled_mask
& 0x2 ? 'g' : '*',
405 exp
->enabled_mask
& 0x4 ? 'b' : '*',
406 exp
->enabled_mask
& 0x8 ? 'a' : '*');
408 fprintf(output
, " compr");
410 fprintf(output
, " done");
412 fprintf(output
, " vm");
414 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
415 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
416 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
417 fprintf(output
, " mrtz");
418 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
419 fprintf(output
, " null");
420 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
421 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
422 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
423 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
426 case Format::PSEUDO_BRANCH
: {
427 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
428 /* Note: BB0 cannot be a branch target */
429 if (branch
->target
[0] != 0)
430 fprintf(output
, " BB%d", branch
->target
[0]);
431 if (branch
->target
[1] != 0)
432 fprintf(output
, ", BB%d", branch
->target
[1]);
435 case Format::PSEUDO_REDUCTION
: {
436 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
437 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
438 if (reduce
->cluster_size
)
439 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
444 case Format::SCRATCH
: {
445 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
447 fprintf(output
, " offset:%u", flat
->offset
);
449 fprintf(output
, " glc");
451 fprintf(output
, " dlc");
453 fprintf(output
, " slc");
455 fprintf(output
, " lds");
457 fprintf(output
, " nv");
458 if (flat
->disable_wqm
)
459 fprintf(output
, " disable_wqm");
460 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
463 case Format::MTBUF
: {
464 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
465 fprintf(output
, " dfmt:");
466 switch (mtbuf
->dfmt
) {
467 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
468 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
469 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
470 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
471 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
472 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
473 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
474 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
475 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
476 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
477 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
478 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
479 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
480 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
481 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
483 fprintf(output
, " nfmt:");
484 switch (mtbuf
->nfmt
) {
485 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
486 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
487 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
488 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
489 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
490 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
491 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
492 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
495 fprintf(output
, " offset:%u", mtbuf
->offset
);
497 fprintf(output
, " offen");
499 fprintf(output
, " idxen");
501 fprintf(output
, " glc");
503 fprintf(output
, " dlc");
505 fprintf(output
, " slc");
507 fprintf(output
, " tfe");
508 if (mtbuf
->disable_wqm
)
509 fprintf(output
, " disable_wqm");
510 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
513 case Format::VOP3P
: {
514 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
515 fprintf(output
, " clamp");
522 if (instr
->isVOP3()) {
523 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
524 switch (vop3
->omod
) {
526 fprintf(output
, " *2");
529 fprintf(output
, " *4");
532 fprintf(output
, " *0.5");
536 fprintf(output
, " clamp");
537 if (vop3
->opsel
& (1 << 3))
538 fprintf(output
, " opsel_hi");
539 } else if (instr
->isDPP()) {
540 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
541 if (dpp
->dpp_ctrl
<= 0xff) {
542 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
543 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
544 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
545 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
546 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
547 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
548 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
549 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
550 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
551 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
552 fprintf(output
, " wave_shl:1");
553 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
554 fprintf(output
, " wave_rol:1");
555 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
556 fprintf(output
, " wave_shr:1");
557 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
558 fprintf(output
, " wave_ror:1");
559 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
560 fprintf(output
, " row_mirror");
561 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
562 fprintf(output
, " row_half_mirror");
563 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
564 fprintf(output
, " row_bcast:15");
565 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
566 fprintf(output
, " row_bcast:31");
568 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
570 if (dpp
->row_mask
!= 0xf)
571 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
572 if (dpp
->bank_mask
!= 0xf)
573 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
575 fprintf(output
, " bound_ctrl:1");
576 } else if ((int)instr
->format
& (int)Format::SDWA
) {
577 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
578 switch (sdwa
->omod
) {
580 fprintf(output
, " *2");
583 fprintf(output
, " *4");
586 fprintf(output
, " *0.5");
590 fprintf(output
, " clamp");
591 switch (sdwa
->dst_sel
& sdwa_asuint
) {
598 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
599 sdwa
->dst_sel
& sdwa_bytenum
);
603 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
604 sdwa
->dst_sel
& sdwa_wordnum
);
607 if (sdwa
->dst_preserve
)
608 fprintf(output
, " dst_preserve");
612 void aco_print_instr(const Instruction
*instr
, FILE *output
)
614 if (!instr
->definitions
.empty()) {
615 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
616 print_definition(&instr
->definitions
[i
], output
);
617 if (i
+ 1 != instr
->definitions
.size())
618 fprintf(output
, ", ");
620 fprintf(output
, " = ");
622 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
623 if (instr
->operands
.size()) {
624 bool abs
[instr
->operands
.size()];
625 bool neg
[instr
->operands
.size()];
626 bool opsel
[instr
->operands
.size()];
627 uint8_t sel
[instr
->operands
.size()];
628 if ((int)instr
->format
& (int)Format::VOP3A
) {
629 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
630 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
631 abs
[i
] = vop3
->abs
[i
];
632 neg
[i
] = vop3
->neg
[i
];
633 opsel
[i
] = vop3
->opsel
& (1 << i
);
634 sel
[i
] = sdwa_udword
;
636 } else if (instr
->isDPP()) {
637 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
638 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
639 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
640 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
642 sel
[i
] = sdwa_udword
;
644 } else if (instr
->isSDWA()) {
645 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
646 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
647 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
648 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
650 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
653 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
657 sel
[i
] = sdwa_udword
;
660 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
662 fprintf(output
, ", ");
664 fprintf(output
, " ");
667 fprintf(output
, "-");
669 fprintf(output
, "|");
671 fprintf(output
, "hi(");
672 else if (sel
[i
] & sdwa_sext
)
673 fprintf(output
, "sext(");
674 print_operand(&instr
->operands
[i
], output
);
675 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
676 fprintf(output
, ")");
677 if (!(sel
[i
] & sdwa_isra
)) {
678 if (sel
[i
] & sdwa_udword
) {
680 } else if (sel
[i
] & sdwa_isword
) {
681 unsigned index
= sel
[i
] & sdwa_wordnum
;
682 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
684 unsigned index
= sel
[i
] & sdwa_bytenum
;
685 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
689 fprintf(output
, "|");
691 if (instr
->format
== Format::VOP3P
) {
692 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
693 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
694 fprintf(output
, ".%c%c",
695 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
696 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
698 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
699 fprintf(output
, "*[-1,-1]");
700 else if (vop3
->neg_lo
[i
])
701 fprintf(output
, "*[-1,1]");
702 else if (vop3
->neg_hi
[i
])
703 fprintf(output
, "*[1,-1]");
707 print_instr_format_specific(instr
, output
);
710 static void print_block_kind(uint16_t kind
, FILE *output
)
712 if (kind
& block_kind_uniform
)
713 fprintf(output
, "uniform, ");
714 if (kind
& block_kind_top_level
)
715 fprintf(output
, "top-level, ");
716 if (kind
& block_kind_loop_preheader
)
717 fprintf(output
, "loop-preheader, ");
718 if (kind
& block_kind_loop_header
)
719 fprintf(output
, "loop-header, ");
720 if (kind
& block_kind_loop_exit
)
721 fprintf(output
, "loop-exit, ");
722 if (kind
& block_kind_continue
)
723 fprintf(output
, "continue, ");
724 if (kind
& block_kind_break
)
725 fprintf(output
, "break, ");
726 if (kind
& block_kind_continue_or_break
)
727 fprintf(output
, "continue_or_break, ");
728 if (kind
& block_kind_discard
)
729 fprintf(output
, "discard, ");
730 if (kind
& block_kind_branch
)
731 fprintf(output
, "branch, ");
732 if (kind
& block_kind_merge
)
733 fprintf(output
, "merge, ");
734 if (kind
& block_kind_invert
)
735 fprintf(output
, "invert, ");
736 if (kind
& block_kind_uses_discard_if
)
737 fprintf(output
, "discard_if, ");
738 if (kind
& block_kind_needs_lowering
)
739 fprintf(output
, "needs_lowering, ");
740 if (kind
& block_kind_uses_demote
)
741 fprintf(output
, "uses_demote, ");
742 if (kind
& block_kind_export_end
)
743 fprintf(output
, "export_end, ");
746 static void print_stage(Stage stage
, FILE *output
)
748 fprintf(output
, "ACO shader stage: ");
750 if (stage
== compute_cs
)
751 fprintf(output
, "compute_cs");
752 else if (stage
== fragment_fs
)
753 fprintf(output
, "fragment_fs");
754 else if (stage
== gs_copy_vs
)
755 fprintf(output
, "gs_copy_vs");
756 else if (stage
== vertex_ls
)
757 fprintf(output
, "vertex_ls");
758 else if (stage
== vertex_es
)
759 fprintf(output
, "vertex_es");
760 else if (stage
== vertex_vs
)
761 fprintf(output
, "vertex_vs");
762 else if (stage
== tess_control_hs
)
763 fprintf(output
, "tess_control_hs");
764 else if (stage
== vertex_tess_control_hs
)
765 fprintf(output
, "vertex_tess_control_hs");
766 else if (stage
== tess_eval_es
)
767 fprintf(output
, "tess_eval_es");
768 else if (stage
== tess_eval_vs
)
769 fprintf(output
, "tess_eval_vs");
770 else if (stage
== geometry_gs
)
771 fprintf(output
, "geometry_gs");
772 else if (stage
== vertex_geometry_gs
)
773 fprintf(output
, "vertex_geometry_gs");
774 else if (stage
== tess_eval_geometry_gs
)
775 fprintf(output
, "tess_eval_geometry_gs");
776 else if (stage
== ngg_vertex_gs
)
777 fprintf(output
, "ngg_vertex_gs");
778 else if (stage
== ngg_tess_eval_gs
)
779 fprintf(output
, "ngg_tess_eval_gs");
780 else if (stage
== ngg_vertex_geometry_gs
)
781 fprintf(output
, "ngg_vertex_geometry_gs");
782 else if (stage
== ngg_tess_eval_geometry_gs
)
783 fprintf(output
, "ngg_tess_eval_geometry_gs");
785 fprintf(output
, "unknown");
787 fprintf(output
, "\n");
790 void aco_print_block(const Block
* block
, FILE *output
)
792 fprintf(output
, "BB%d\n", block
->index
);
793 fprintf(output
, "/* logical preds: ");
794 for (unsigned pred
: block
->logical_preds
)
795 fprintf(output
, "BB%d, ", pred
);
796 fprintf(output
, "/ linear preds: ");
797 for (unsigned pred
: block
->linear_preds
)
798 fprintf(output
, "BB%d, ", pred
);
799 fprintf(output
, "/ kind: ");
800 print_block_kind(block
->kind
, output
);
801 fprintf(output
, "*/\n");
802 for (auto const& instr
: block
->instructions
) {
803 fprintf(output
, "\t");
804 aco_print_instr(instr
.get(), output
);
805 fprintf(output
, "\n");
809 void aco_print_program(const Program
*program
, FILE *output
)
811 print_stage(program
->stage
, output
);
813 for (Block
const& block
: program
->blocks
)
814 aco_print_block(&block
, output
);
816 if (program
->constant_data
.size()) {
817 fprintf(output
, "\n/* constant data */\n");
818 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
819 fprintf(output
, "[%06d] ", i
);
820 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
821 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
822 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
824 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
825 fprintf(output
, " %08x", v
);
827 fprintf(output
, "\n");
831 fprintf(output
, "\n");