2 #include "aco_builder.h"
5 #include "ac_shader_util.h"
9 static const char *reduce_ops
[] = {
58 [gfx10_wave64_bpermute
] = "gfx10_wave64_bpermute",
61 static void print_reg_class(const RegClass rc
, FILE *output
)
64 case RegClass::s1
: fprintf(output
, " s1: "); return;
65 case RegClass::s2
: fprintf(output
, " s2: "); return;
66 case RegClass::s3
: fprintf(output
, " s3: "); return;
67 case RegClass::s4
: fprintf(output
, " s4: "); return;
68 case RegClass::s6
: fprintf(output
, " s6: "); return;
69 case RegClass::s8
: fprintf(output
, " s8: "); return;
70 case RegClass::s16
: fprintf(output
, "s16: "); return;
71 case RegClass::v1
: fprintf(output
, " v1: "); return;
72 case RegClass::v2
: fprintf(output
, " v2: "); return;
73 case RegClass::v3
: fprintf(output
, " v3: "); return;
74 case RegClass::v4
: fprintf(output
, " v4: "); return;
75 case RegClass::v5
: fprintf(output
, " v5: "); return;
76 case RegClass::v6
: fprintf(output
, " v6: "); return;
77 case RegClass::v7
: fprintf(output
, " v7: "); return;
78 case RegClass::v8
: fprintf(output
, " v8: "); return;
79 case RegClass::v1b
: fprintf(output
, " v1b: "); return;
80 case RegClass::v2b
: fprintf(output
, " v2b: "); return;
81 case RegClass::v3b
: fprintf(output
, " v3b: "); return;
82 case RegClass::v4b
: fprintf(output
, " v4b: "); return;
83 case RegClass::v6b
: fprintf(output
, " v6b: "); return;
84 case RegClass::v8b
: fprintf(output
, " v8b: "); return;
85 case RegClass::v1_linear
: fprintf(output
, " v1: "); return;
86 case RegClass::v2_linear
: fprintf(output
, " v2: "); return;
90 void print_physReg(PhysReg reg
, unsigned bytes
, FILE *output
)
93 fprintf(output
, ":m0");
94 } else if (reg
== 106) {
95 fprintf(output
, ":vcc");
96 } else if (reg
== 253) {
97 fprintf(output
, ":scc");
98 } else if (reg
== 126) {
99 fprintf(output
, ":exec");
101 bool is_vgpr
= reg
/ 256;
102 unsigned r
= reg
% 256;
103 unsigned size
= DIV_ROUND_UP(bytes
, 4);
104 fprintf(output
, ":%c[%d", is_vgpr
? 'v' : 's', r
);
106 fprintf(output
, "-%d]", r
+ size
-1);
108 fprintf(output
, "]");
109 if (reg
.byte() || bytes
% 4)
110 fprintf(output
, "[%d:%d]", reg
.byte()*8, (reg
.byte()+bytes
) * 8);
114 static void print_constant(uint8_t reg
, FILE *output
)
116 if (reg
>= 128 && reg
<= 192) {
117 fprintf(output
, "%d", reg
- 128);
119 } else if (reg
>= 192 && reg
<= 208) {
120 fprintf(output
, "%d", 192 - reg
);
126 fprintf(output
, "0.5");
129 fprintf(output
, "-0.5");
132 fprintf(output
, "1.0");
135 fprintf(output
, "-1.0");
138 fprintf(output
, "2.0");
141 fprintf(output
, "-2.0");
144 fprintf(output
, "4.0");
147 fprintf(output
, "-4.0");
150 fprintf(output
, "1/(2*PI)");
155 static void print_operand(const Operand
*operand
, FILE *output
)
157 if (operand
->isLiteral()) {
158 fprintf(output
, "0x%x", operand
->constantValue());
159 } else if (operand
->isConstant()) {
160 print_constant(operand
->physReg().reg(), output
);
161 } else if (operand
->isUndefined()) {
162 print_reg_class(operand
->regClass(), output
);
163 fprintf(output
, "undef");
165 if (operand
->isLateKill())
166 fprintf(output
, "(latekill)");
168 fprintf(output
, "%%%d", operand
->tempId());
170 if (operand
->isFixed())
171 print_physReg(operand
->physReg(), operand
->bytes(), output
);
175 static void print_definition(const Definition
*definition
, FILE *output
)
177 print_reg_class(definition
->regClass(), output
);
178 fprintf(output
, "%%%d", definition
->tempId());
180 if (definition
->isFixed())
181 print_physReg(definition
->physReg(), definition
->bytes(), output
);
184 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
187 fprintf(output
, " reorder");
189 if (barrier
& barrier_buffer
)
190 fprintf(output
, " buffer");
191 if (barrier
& barrier_image
)
192 fprintf(output
, " image");
193 if (barrier
& barrier_atomic
)
194 fprintf(output
, " atomic");
195 if (barrier
& barrier_shared
)
196 fprintf(output
, " shared");
197 if (barrier
& barrier_gs_data
)
198 fprintf(output
, " gs_data");
199 if (barrier
& barrier_gs_sendmsg
)
200 fprintf(output
, " gs_sendmsg");
203 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
205 switch (instr
->format
) {
207 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
208 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
212 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
213 uint16_t imm
= sopp
->imm
;
214 switch (instr
->opcode
) {
215 case aco_opcode::s_waitcnt
: {
216 /* we usually should check the chip class for vmcnt/lgkm, but
217 * insert_waitcnt() should fill it in regardless. */
218 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
219 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
220 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
221 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
224 case aco_opcode::s_endpgm
:
225 case aco_opcode::s_endpgm_saved
:
226 case aco_opcode::s_endpgm_ordered_ps_done
:
227 case aco_opcode::s_wakeup
:
228 case aco_opcode::s_barrier
:
229 case aco_opcode::s_icache_inv
:
230 case aco_opcode::s_ttracedata
:
231 case aco_opcode::s_set_gpr_idx_off
: {
234 case aco_opcode::s_sendmsg
: {
235 unsigned id
= imm
& sendmsg_id_mask
;
238 fprintf(output
, " sendmsg(MSG_NONE)");
241 fprintf(output
, " sendmsg(gs%s%s, %u)",
242 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
244 case _sendmsg_gs_done
:
245 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
246 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
248 case sendmsg_save_wave
:
249 fprintf(output
, " sendmsg(save_wave)");
251 case sendmsg_stall_wave_gen
:
252 fprintf(output
, " sendmsg(stall_wave_gen)");
254 case sendmsg_halt_waves
:
255 fprintf(output
, " sendmsg(halt_waves)");
257 case sendmsg_ordered_ps_done
:
258 fprintf(output
, " sendmsg(ordered_ps_done)");
260 case sendmsg_early_prim_dealloc
:
261 fprintf(output
, " sendmsg(early_prim_dealloc)");
263 case sendmsg_gs_alloc_req
:
264 fprintf(output
, " sendmsg(gs_alloc_req)");
271 fprintf(output
, " imm:%u", imm
);
275 if (sopp
->block
!= -1)
276 fprintf(output
, " block:BB%d", sopp
->block
);
280 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
282 fprintf(output
, " glc");
284 fprintf(output
, " dlc");
286 fprintf(output
, " nv");
287 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
290 case Format::VINTRP
: {
291 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
292 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
296 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
298 fprintf(output
, " offset0:%u", ds
->offset0
);
300 fprintf(output
, " offset1:%u", ds
->offset1
);
302 fprintf(output
, " gds");
305 case Format::MUBUF
: {
306 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
308 fprintf(output
, " offset:%u", mubuf
->offset
);
310 fprintf(output
, " offen");
312 fprintf(output
, " idxen");
314 fprintf(output
, " addr64");
316 fprintf(output
, " glc");
318 fprintf(output
, " dlc");
320 fprintf(output
, " slc");
322 fprintf(output
, " tfe");
324 fprintf(output
, " lds");
325 if (mubuf
->disable_wqm
)
326 fprintf(output
, " disable_wqm");
327 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
331 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
332 unsigned identity_dmask
= !instr
->definitions
.empty() ?
333 (1 << instr
->definitions
[0].size()) - 1 :
335 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
336 fprintf(output
, " dmask:%s%s%s%s",
337 mimg
->dmask
& 0x1 ? "x" : "",
338 mimg
->dmask
& 0x2 ? "y" : "",
339 mimg
->dmask
& 0x4 ? "z" : "",
340 mimg
->dmask
& 0x8 ? "w" : "");
343 fprintf(output
, " 1d");
346 fprintf(output
, " 2d");
349 fprintf(output
, " 3d");
352 fprintf(output
, " cube");
354 case ac_image_1darray
:
355 fprintf(output
, " 1darray");
357 case ac_image_2darray
:
358 fprintf(output
, " 2darray");
360 case ac_image_2dmsaa
:
361 fprintf(output
, " 2dmsaa");
363 case ac_image_2darraymsaa
:
364 fprintf(output
, " 2darraymsaa");
368 fprintf(output
, " unrm");
370 fprintf(output
, " glc");
372 fprintf(output
, " dlc");
374 fprintf(output
, " slc");
376 fprintf(output
, " tfe");
378 fprintf(output
, " da");
380 fprintf(output
, " lwe");
381 if (mimg
->r128
|| mimg
->a16
)
382 fprintf(output
, " r128/a16");
384 fprintf(output
, " d16");
385 if (mimg
->disable_wqm
)
386 fprintf(output
, " disable_wqm");
387 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
391 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
392 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
393 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
394 fprintf(output
, " en:%c%c%c%c",
395 exp
->enabled_mask
& 0x1 ? 'r' : '*',
396 exp
->enabled_mask
& 0x2 ? 'g' : '*',
397 exp
->enabled_mask
& 0x4 ? 'b' : '*',
398 exp
->enabled_mask
& 0x8 ? 'a' : '*');
400 fprintf(output
, " compr");
402 fprintf(output
, " done");
404 fprintf(output
, " vm");
406 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
407 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
408 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
409 fprintf(output
, " mrtz");
410 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
411 fprintf(output
, " null");
412 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
413 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
414 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
415 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
418 case Format::PSEUDO_BRANCH
: {
419 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
420 /* Note: BB0 cannot be a branch target */
421 if (branch
->target
[0] != 0)
422 fprintf(output
, " BB%d", branch
->target
[0]);
423 if (branch
->target
[1] != 0)
424 fprintf(output
, ", BB%d", branch
->target
[1]);
427 case Format::PSEUDO_REDUCTION
: {
428 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
429 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
430 if (reduce
->cluster_size
)
431 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
436 case Format::SCRATCH
: {
437 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
439 fprintf(output
, " offset:%u", flat
->offset
);
441 fprintf(output
, " glc");
443 fprintf(output
, " dlc");
445 fprintf(output
, " slc");
447 fprintf(output
, " lds");
449 fprintf(output
, " nv");
450 if (flat
->disable_wqm
)
451 fprintf(output
, " disable_wqm");
452 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
455 case Format::MTBUF
: {
456 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
457 fprintf(output
, " dfmt:");
458 switch (mtbuf
->dfmt
) {
459 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
460 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
461 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
462 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
463 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
464 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
465 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
466 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
467 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
468 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
469 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
470 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
471 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
472 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
473 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
475 fprintf(output
, " nfmt:");
476 switch (mtbuf
->nfmt
) {
477 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
478 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
479 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
480 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
481 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
482 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
483 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
484 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
487 fprintf(output
, " offset:%u", mtbuf
->offset
);
489 fprintf(output
, " offen");
491 fprintf(output
, " idxen");
493 fprintf(output
, " glc");
495 fprintf(output
, " dlc");
497 fprintf(output
, " slc");
499 fprintf(output
, " tfe");
500 if (mtbuf
->disable_wqm
)
501 fprintf(output
, " disable_wqm");
502 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
505 case Format::VOP3P
: {
506 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
507 fprintf(output
, " clamp");
514 if (instr
->isVOP3()) {
515 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
516 switch (vop3
->omod
) {
518 fprintf(output
, " *2");
521 fprintf(output
, " *4");
524 fprintf(output
, " *0.5");
528 fprintf(output
, " clamp");
529 if (vop3
->opsel
& (1 << 3))
530 fprintf(output
, " opsel_hi");
531 } else if (instr
->isDPP()) {
532 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
533 if (dpp
->dpp_ctrl
<= 0xff) {
534 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
535 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
536 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
537 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
538 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
539 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
540 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
541 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
542 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
543 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
544 fprintf(output
, " wave_shl:1");
545 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
546 fprintf(output
, " wave_rol:1");
547 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
548 fprintf(output
, " wave_shr:1");
549 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
550 fprintf(output
, " wave_ror:1");
551 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
552 fprintf(output
, " row_mirror");
553 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
554 fprintf(output
, " row_half_mirror");
555 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
556 fprintf(output
, " row_bcast:15");
557 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
558 fprintf(output
, " row_bcast:31");
560 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
562 if (dpp
->row_mask
!= 0xf)
563 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
564 if (dpp
->bank_mask
!= 0xf)
565 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
567 fprintf(output
, " bound_ctrl:1");
568 } else if ((int)instr
->format
& (int)Format::SDWA
) {
569 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
570 switch (sdwa
->omod
) {
572 fprintf(output
, " *2");
575 fprintf(output
, " *4");
578 fprintf(output
, " *0.5");
582 fprintf(output
, " clamp");
583 switch (sdwa
->dst_sel
& sdwa_asuint
) {
590 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
591 sdwa
->dst_sel
& sdwa_bytenum
);
595 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
596 sdwa
->dst_sel
& sdwa_wordnum
);
599 if (sdwa
->dst_preserve
)
600 fprintf(output
, " dst_preserve");
604 void aco_print_instr(const Instruction
*instr
, FILE *output
)
606 if (!instr
->definitions
.empty()) {
607 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
608 print_definition(&instr
->definitions
[i
], output
);
609 if (i
+ 1 != instr
->definitions
.size())
610 fprintf(output
, ", ");
612 fprintf(output
, " = ");
614 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
615 if (instr
->operands
.size()) {
616 bool abs
[instr
->operands
.size()];
617 bool neg
[instr
->operands
.size()];
618 bool opsel
[instr
->operands
.size()];
619 uint8_t sel
[instr
->operands
.size()];
620 if ((int)instr
->format
& (int)Format::VOP3A
) {
621 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
622 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
623 abs
[i
] = vop3
->abs
[i
];
624 neg
[i
] = vop3
->neg
[i
];
625 opsel
[i
] = vop3
->opsel
& (1 << i
);
626 sel
[i
] = sdwa_udword
;
628 } else if (instr
->isDPP()) {
629 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
630 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
631 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
632 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
634 sel
[i
] = sdwa_udword
;
636 } else if (instr
->isSDWA()) {
637 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
638 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
639 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
640 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
642 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
645 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
649 sel
[i
] = sdwa_udword
;
652 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
654 fprintf(output
, ", ");
656 fprintf(output
, " ");
659 fprintf(output
, "-");
661 fprintf(output
, "|");
663 fprintf(output
, "hi(");
664 else if (sel
[i
] & sdwa_sext
)
665 fprintf(output
, "sext(");
666 print_operand(&instr
->operands
[i
], output
);
667 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
668 fprintf(output
, ")");
669 if (!(sel
[i
] & sdwa_isra
)) {
670 if (sel
[i
] & sdwa_udword
) {
672 } else if (sel
[i
] & sdwa_isword
) {
673 unsigned index
= sel
[i
] & sdwa_wordnum
;
674 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
676 unsigned index
= sel
[i
] & sdwa_bytenum
;
677 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
681 fprintf(output
, "|");
683 if (instr
->format
== Format::VOP3P
) {
684 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
685 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
686 fprintf(output
, ".%c%c",
687 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
688 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
690 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
691 fprintf(output
, "*[-1,-1]");
692 else if (vop3
->neg_lo
[i
])
693 fprintf(output
, "*[-1,1]");
694 else if (vop3
->neg_hi
[i
])
695 fprintf(output
, "*[1,-1]");
699 print_instr_format_specific(instr
, output
);
702 static void print_block_kind(uint16_t kind
, FILE *output
)
704 if (kind
& block_kind_uniform
)
705 fprintf(output
, "uniform, ");
706 if (kind
& block_kind_top_level
)
707 fprintf(output
, "top-level, ");
708 if (kind
& block_kind_loop_preheader
)
709 fprintf(output
, "loop-preheader, ");
710 if (kind
& block_kind_loop_header
)
711 fprintf(output
, "loop-header, ");
712 if (kind
& block_kind_loop_exit
)
713 fprintf(output
, "loop-exit, ");
714 if (kind
& block_kind_continue
)
715 fprintf(output
, "continue, ");
716 if (kind
& block_kind_break
)
717 fprintf(output
, "break, ");
718 if (kind
& block_kind_continue_or_break
)
719 fprintf(output
, "continue_or_break, ");
720 if (kind
& block_kind_discard
)
721 fprintf(output
, "discard, ");
722 if (kind
& block_kind_branch
)
723 fprintf(output
, "branch, ");
724 if (kind
& block_kind_merge
)
725 fprintf(output
, "merge, ");
726 if (kind
& block_kind_invert
)
727 fprintf(output
, "invert, ");
728 if (kind
& block_kind_uses_discard_if
)
729 fprintf(output
, "discard_if, ");
730 if (kind
& block_kind_needs_lowering
)
731 fprintf(output
, "needs_lowering, ");
732 if (kind
& block_kind_uses_demote
)
733 fprintf(output
, "uses_demote, ");
734 if (kind
& block_kind_export_end
)
735 fprintf(output
, "export_end, ");
738 static void print_stage(Stage stage
, FILE *output
)
740 fprintf(output
, "ACO shader stage: ");
742 if (stage
== compute_cs
)
743 fprintf(output
, "compute_cs");
744 else if (stage
== fragment_fs
)
745 fprintf(output
, "fragment_fs");
746 else if (stage
== gs_copy_vs
)
747 fprintf(output
, "gs_copy_vs");
748 else if (stage
== vertex_ls
)
749 fprintf(output
, "vertex_ls");
750 else if (stage
== vertex_es
)
751 fprintf(output
, "vertex_es");
752 else if (stage
== vertex_vs
)
753 fprintf(output
, "vertex_vs");
754 else if (stage
== tess_control_hs
)
755 fprintf(output
, "tess_control_hs");
756 else if (stage
== vertex_tess_control_hs
)
757 fprintf(output
, "vertex_tess_control_hs");
758 else if (stage
== tess_eval_es
)
759 fprintf(output
, "tess_eval_es");
760 else if (stage
== tess_eval_vs
)
761 fprintf(output
, "tess_eval_vs");
762 else if (stage
== geometry_gs
)
763 fprintf(output
, "geometry_gs");
764 else if (stage
== vertex_geometry_gs
)
765 fprintf(output
, "vertex_geometry_gs");
766 else if (stage
== tess_eval_geometry_gs
)
767 fprintf(output
, "tess_eval_geometry_gs");
768 else if (stage
== ngg_vertex_gs
)
769 fprintf(output
, "ngg_vertex_gs");
770 else if (stage
== ngg_tess_eval_gs
)
771 fprintf(output
, "ngg_tess_eval_gs");
772 else if (stage
== ngg_vertex_geometry_gs
)
773 fprintf(output
, "ngg_vertex_geometry_gs");
774 else if (stage
== ngg_tess_eval_geometry_gs
)
775 fprintf(output
, "ngg_tess_eval_geometry_gs");
777 fprintf(output
, "unknown");
779 fprintf(output
, "\n");
782 void aco_print_block(const Block
* block
, FILE *output
)
784 fprintf(output
, "BB%d\n", block
->index
);
785 fprintf(output
, "/* logical preds: ");
786 for (unsigned pred
: block
->logical_preds
)
787 fprintf(output
, "BB%d, ", pred
);
788 fprintf(output
, "/ linear preds: ");
789 for (unsigned pred
: block
->linear_preds
)
790 fprintf(output
, "BB%d, ", pred
);
791 fprintf(output
, "/ kind: ");
792 print_block_kind(block
->kind
, output
);
793 fprintf(output
, "*/\n");
794 for (auto const& instr
: block
->instructions
) {
795 fprintf(output
, "\t");
796 aco_print_instr(instr
.get(), output
);
797 fprintf(output
, "\n");
801 void aco_print_program(const Program
*program
, FILE *output
)
803 print_stage(program
->stage
, output
);
805 for (Block
const& block
: program
->blocks
)
806 aco_print_block(&block
, output
);
808 if (program
->constant_data
.size()) {
809 fprintf(output
, "\n/* constant data */\n");
810 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
811 fprintf(output
, "[%06d] ", i
);
812 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
813 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
814 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
816 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
817 fprintf(output
, " %08x", v
);
819 fprintf(output
, "\n");
823 fprintf(output
, "\n");