2 #include "aco_builder.h"
5 #include "ac_shader_util.h"
9 static const char *reduce_ops
[] = {
62 [gfx10_wave64_bpermute
] = "gfx10_wave64_bpermute",
65 static void print_reg_class(const RegClass rc
, FILE *output
)
68 case RegClass::s1
: fprintf(output
, " s1: "); return;
69 case RegClass::s2
: fprintf(output
, " s2: "); return;
70 case RegClass::s3
: fprintf(output
, " s3: "); return;
71 case RegClass::s4
: fprintf(output
, " s4: "); return;
72 case RegClass::s6
: fprintf(output
, " s6: "); return;
73 case RegClass::s8
: fprintf(output
, " s8: "); return;
74 case RegClass::s16
: fprintf(output
, "s16: "); return;
75 case RegClass::v1
: fprintf(output
, " v1: "); return;
76 case RegClass::v2
: fprintf(output
, " v2: "); return;
77 case RegClass::v3
: fprintf(output
, " v3: "); return;
78 case RegClass::v4
: fprintf(output
, " v4: "); return;
79 case RegClass::v5
: fprintf(output
, " v5: "); return;
80 case RegClass::v6
: fprintf(output
, " v6: "); return;
81 case RegClass::v7
: fprintf(output
, " v7: "); return;
82 case RegClass::v8
: fprintf(output
, " v8: "); return;
83 case RegClass::v1b
: fprintf(output
, " v1b: "); return;
84 case RegClass::v2b
: fprintf(output
, " v2b: "); return;
85 case RegClass::v3b
: fprintf(output
, " v3b: "); return;
86 case RegClass::v4b
: fprintf(output
, " v4b: "); return;
87 case RegClass::v6b
: fprintf(output
, " v6b: "); return;
88 case RegClass::v8b
: fprintf(output
, " v8b: "); return;
89 case RegClass::v1_linear
: fprintf(output
, " v1: "); return;
90 case RegClass::v2_linear
: fprintf(output
, " v2: "); return;
94 void print_physReg(PhysReg reg
, unsigned bytes
, FILE *output
)
97 fprintf(output
, ":m0");
98 } else if (reg
== 106) {
99 fprintf(output
, ":vcc");
100 } else if (reg
== 253) {
101 fprintf(output
, ":scc");
102 } else if (reg
== 126) {
103 fprintf(output
, ":exec");
105 bool is_vgpr
= reg
/ 256;
106 unsigned r
= reg
% 256;
107 unsigned size
= DIV_ROUND_UP(bytes
, 4);
108 fprintf(output
, ":%c[%d", is_vgpr
? 'v' : 's', r
);
110 fprintf(output
, "-%d]", r
+ size
-1);
112 fprintf(output
, "]");
113 if (reg
.byte() || bytes
% 4)
114 fprintf(output
, "[%d:%d]", reg
.byte()*8, (reg
.byte()+bytes
) * 8);
118 static void print_constant(uint8_t reg
, FILE *output
)
120 if (reg
>= 128 && reg
<= 192) {
121 fprintf(output
, "%d", reg
- 128);
123 } else if (reg
>= 192 && reg
<= 208) {
124 fprintf(output
, "%d", 192 - reg
);
130 fprintf(output
, "0.5");
133 fprintf(output
, "-0.5");
136 fprintf(output
, "1.0");
139 fprintf(output
, "-1.0");
142 fprintf(output
, "2.0");
145 fprintf(output
, "-2.0");
148 fprintf(output
, "4.0");
151 fprintf(output
, "-4.0");
154 fprintf(output
, "1/(2*PI)");
159 static void print_operand(const Operand
*operand
, FILE *output
)
161 if (operand
->isLiteral()) {
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 fprintf(output
, "%%%d", definition
->tempId());
184 if (definition
->isFixed())
185 print_physReg(definition
->physReg(), definition
->bytes(), output
);
188 static void print_barrier_reorder(bool can_reorder
, barrier_interaction barrier
, FILE *output
)
191 fprintf(output
, " reorder");
193 if (barrier
& barrier_buffer
)
194 fprintf(output
, " buffer");
195 if (barrier
& barrier_image
)
196 fprintf(output
, " image");
197 if (barrier
& barrier_atomic
)
198 fprintf(output
, " atomic");
199 if (barrier
& barrier_shared
)
200 fprintf(output
, " shared");
201 if (barrier
& barrier_gs_data
)
202 fprintf(output
, " gs_data");
203 if (barrier
& barrier_gs_sendmsg
)
204 fprintf(output
, " gs_sendmsg");
207 static void print_instr_format_specific(const Instruction
*instr
, FILE *output
)
209 switch (instr
->format
) {
211 const SOPK_instruction
* sopk
= static_cast<const SOPK_instruction
*>(instr
);
212 fprintf(output
, " imm:%d", sopk
->imm
& 0x8000 ? (sopk
->imm
- 65536) : sopk
->imm
);
216 const SOPP_instruction
* sopp
= static_cast<const SOPP_instruction
*>(instr
);
217 uint16_t imm
= sopp
->imm
;
218 switch (instr
->opcode
) {
219 case aco_opcode::s_waitcnt
: {
220 /* we usually should check the chip class for vmcnt/lgkm, but
221 * insert_waitcnt() should fill it in regardless. */
222 unsigned vmcnt
= (imm
& 0xF) | ((imm
& (0x3 << 14)) >> 10);
223 if (vmcnt
!= 63) fprintf(output
, " vmcnt(%d)", vmcnt
);
224 if (((imm
>> 4) & 0x7) < 0x7) fprintf(output
, " expcnt(%d)", (imm
>> 4) & 0x7);
225 if (((imm
>> 8) & 0x3F) < 0x3F) fprintf(output
, " lgkmcnt(%d)", (imm
>> 8) & 0x3F);
228 case aco_opcode::s_endpgm
:
229 case aco_opcode::s_endpgm_saved
:
230 case aco_opcode::s_endpgm_ordered_ps_done
:
231 case aco_opcode::s_wakeup
:
232 case aco_opcode::s_barrier
:
233 case aco_opcode::s_icache_inv
:
234 case aco_opcode::s_ttracedata
:
235 case aco_opcode::s_set_gpr_idx_off
: {
238 case aco_opcode::s_sendmsg
: {
239 unsigned id
= imm
& sendmsg_id_mask
;
242 fprintf(output
, " sendmsg(MSG_NONE)");
245 fprintf(output
, " sendmsg(gs%s%s, %u)",
246 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
248 case _sendmsg_gs_done
:
249 fprintf(output
, " sendmsg(gs_done%s%s, %u)",
250 imm
& 0x10 ? ", cut" : "", imm
& 0x20 ? ", emit" : "", imm
>> 8);
252 case sendmsg_save_wave
:
253 fprintf(output
, " sendmsg(save_wave)");
255 case sendmsg_stall_wave_gen
:
256 fprintf(output
, " sendmsg(stall_wave_gen)");
258 case sendmsg_halt_waves
:
259 fprintf(output
, " sendmsg(halt_waves)");
261 case sendmsg_ordered_ps_done
:
262 fprintf(output
, " sendmsg(ordered_ps_done)");
264 case sendmsg_early_prim_dealloc
:
265 fprintf(output
, " sendmsg(early_prim_dealloc)");
267 case sendmsg_gs_alloc_req
:
268 fprintf(output
, " sendmsg(gs_alloc_req)");
275 fprintf(output
, " imm:%u", imm
);
279 if (sopp
->block
!= -1)
280 fprintf(output
, " block:BB%d", sopp
->block
);
284 const SMEM_instruction
* smem
= static_cast<const SMEM_instruction
*>(instr
);
286 fprintf(output
, " glc");
288 fprintf(output
, " dlc");
290 fprintf(output
, " nv");
291 print_barrier_reorder(smem
->can_reorder
, smem
->barrier
, output
);
294 case Format::VINTRP
: {
295 const Interp_instruction
* vintrp
= static_cast<const Interp_instruction
*>(instr
);
296 fprintf(output
, " attr%d.%c", vintrp
->attribute
, "xyzw"[vintrp
->component
]);
300 const DS_instruction
* ds
= static_cast<const DS_instruction
*>(instr
);
302 fprintf(output
, " offset0:%u", ds
->offset0
);
304 fprintf(output
, " offset1:%u", ds
->offset1
);
306 fprintf(output
, " gds");
309 case Format::MUBUF
: {
310 const MUBUF_instruction
* mubuf
= static_cast<const MUBUF_instruction
*>(instr
);
312 fprintf(output
, " offset:%u", mubuf
->offset
);
314 fprintf(output
, " offen");
316 fprintf(output
, " idxen");
318 fprintf(output
, " addr64");
320 fprintf(output
, " glc");
322 fprintf(output
, " dlc");
324 fprintf(output
, " slc");
326 fprintf(output
, " tfe");
328 fprintf(output
, " lds");
329 if (mubuf
->disable_wqm
)
330 fprintf(output
, " disable_wqm");
331 print_barrier_reorder(mubuf
->can_reorder
, mubuf
->barrier
, output
);
335 const MIMG_instruction
* mimg
= static_cast<const MIMG_instruction
*>(instr
);
336 unsigned identity_dmask
= !instr
->definitions
.empty() ?
337 (1 << instr
->definitions
[0].size()) - 1 :
339 if ((mimg
->dmask
& identity_dmask
) != identity_dmask
)
340 fprintf(output
, " dmask:%s%s%s%s",
341 mimg
->dmask
& 0x1 ? "x" : "",
342 mimg
->dmask
& 0x2 ? "y" : "",
343 mimg
->dmask
& 0x4 ? "z" : "",
344 mimg
->dmask
& 0x8 ? "w" : "");
347 fprintf(output
, " 1d");
350 fprintf(output
, " 2d");
353 fprintf(output
, " 3d");
356 fprintf(output
, " cube");
358 case ac_image_1darray
:
359 fprintf(output
, " 1darray");
361 case ac_image_2darray
:
362 fprintf(output
, " 2darray");
364 case ac_image_2dmsaa
:
365 fprintf(output
, " 2dmsaa");
367 case ac_image_2darraymsaa
:
368 fprintf(output
, " 2darraymsaa");
372 fprintf(output
, " unrm");
374 fprintf(output
, " glc");
376 fprintf(output
, " dlc");
378 fprintf(output
, " slc");
380 fprintf(output
, " tfe");
382 fprintf(output
, " da");
384 fprintf(output
, " lwe");
385 if (mimg
->r128
|| mimg
->a16
)
386 fprintf(output
, " r128/a16");
388 fprintf(output
, " d16");
389 if (mimg
->disable_wqm
)
390 fprintf(output
, " disable_wqm");
391 print_barrier_reorder(mimg
->can_reorder
, mimg
->barrier
, output
);
395 const Export_instruction
* exp
= static_cast<const Export_instruction
*>(instr
);
396 unsigned identity_mask
= exp
->compressed
? 0x5 : 0xf;
397 if ((exp
->enabled_mask
& identity_mask
) != identity_mask
)
398 fprintf(output
, " en:%c%c%c%c",
399 exp
->enabled_mask
& 0x1 ? 'r' : '*',
400 exp
->enabled_mask
& 0x2 ? 'g' : '*',
401 exp
->enabled_mask
& 0x4 ? 'b' : '*',
402 exp
->enabled_mask
& 0x8 ? 'a' : '*');
404 fprintf(output
, " compr");
406 fprintf(output
, " done");
408 fprintf(output
, " vm");
410 if (exp
->dest
<= V_008DFC_SQ_EXP_MRT
+ 7)
411 fprintf(output
, " mrt%d", exp
->dest
- V_008DFC_SQ_EXP_MRT
);
412 else if (exp
->dest
== V_008DFC_SQ_EXP_MRTZ
)
413 fprintf(output
, " mrtz");
414 else if (exp
->dest
== V_008DFC_SQ_EXP_NULL
)
415 fprintf(output
, " null");
416 else if (exp
->dest
>= V_008DFC_SQ_EXP_POS
&& exp
->dest
<= V_008DFC_SQ_EXP_POS
+ 3)
417 fprintf(output
, " pos%d", exp
->dest
- V_008DFC_SQ_EXP_POS
);
418 else if (exp
->dest
>= V_008DFC_SQ_EXP_PARAM
&& exp
->dest
<= V_008DFC_SQ_EXP_PARAM
+ 31)
419 fprintf(output
, " param%d", exp
->dest
- V_008DFC_SQ_EXP_PARAM
);
422 case Format::PSEUDO_BRANCH
: {
423 const Pseudo_branch_instruction
* branch
= static_cast<const Pseudo_branch_instruction
*>(instr
);
424 /* Note: BB0 cannot be a branch target */
425 if (branch
->target
[0] != 0)
426 fprintf(output
, " BB%d", branch
->target
[0]);
427 if (branch
->target
[1] != 0)
428 fprintf(output
, ", BB%d", branch
->target
[1]);
431 case Format::PSEUDO_REDUCTION
: {
432 const Pseudo_reduction_instruction
* reduce
= static_cast<const Pseudo_reduction_instruction
*>(instr
);
433 fprintf(output
, " op:%s", reduce_ops
[reduce
->reduce_op
]);
434 if (reduce
->cluster_size
)
435 fprintf(output
, " cluster_size:%u", reduce
->cluster_size
);
440 case Format::SCRATCH
: {
441 const FLAT_instruction
* flat
= static_cast<const FLAT_instruction
*>(instr
);
443 fprintf(output
, " offset:%u", flat
->offset
);
445 fprintf(output
, " glc");
447 fprintf(output
, " dlc");
449 fprintf(output
, " slc");
451 fprintf(output
, " lds");
453 fprintf(output
, " nv");
454 if (flat
->disable_wqm
)
455 fprintf(output
, " disable_wqm");
456 print_barrier_reorder(flat
->can_reorder
, flat
->barrier
, output
);
459 case Format::MTBUF
: {
460 const MTBUF_instruction
* mtbuf
= static_cast<const MTBUF_instruction
*>(instr
);
461 fprintf(output
, " dfmt:");
462 switch (mtbuf
->dfmt
) {
463 case V_008F0C_BUF_DATA_FORMAT_8
: fprintf(output
, "8"); break;
464 case V_008F0C_BUF_DATA_FORMAT_16
: fprintf(output
, "16"); break;
465 case V_008F0C_BUF_DATA_FORMAT_8_8
: fprintf(output
, "8_8"); break;
466 case V_008F0C_BUF_DATA_FORMAT_32
: fprintf(output
, "32"); break;
467 case V_008F0C_BUF_DATA_FORMAT_16_16
: fprintf(output
, "16_16"); break;
468 case V_008F0C_BUF_DATA_FORMAT_10_11_11
: fprintf(output
, "10_11_11"); break;
469 case V_008F0C_BUF_DATA_FORMAT_11_11_10
: fprintf(output
, "11_11_10"); break;
470 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2
: fprintf(output
, "10_10_10_2"); break;
471 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10
: fprintf(output
, "2_10_10_10"); break;
472 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8
: fprintf(output
, "8_8_8_8"); break;
473 case V_008F0C_BUF_DATA_FORMAT_32_32
: fprintf(output
, "32_32"); break;
474 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16
: fprintf(output
, "16_16_16_16"); break;
475 case V_008F0C_BUF_DATA_FORMAT_32_32_32
: fprintf(output
, "32_32_32"); break;
476 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32
: fprintf(output
, "32_32_32_32"); break;
477 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15
: fprintf(output
, "reserved15"); break;
479 fprintf(output
, " nfmt:");
480 switch (mtbuf
->nfmt
) {
481 case V_008F0C_BUF_NUM_FORMAT_UNORM
: fprintf(output
, "unorm"); break;
482 case V_008F0C_BUF_NUM_FORMAT_SNORM
: fprintf(output
, "snorm"); break;
483 case V_008F0C_BUF_NUM_FORMAT_USCALED
: fprintf(output
, "uscaled"); break;
484 case V_008F0C_BUF_NUM_FORMAT_SSCALED
: fprintf(output
, "sscaled"); break;
485 case V_008F0C_BUF_NUM_FORMAT_UINT
: fprintf(output
, "uint"); break;
486 case V_008F0C_BUF_NUM_FORMAT_SINT
: fprintf(output
, "sint"); break;
487 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL
: fprintf(output
, "snorm"); break;
488 case V_008F0C_BUF_NUM_FORMAT_FLOAT
: fprintf(output
, "float"); break;
491 fprintf(output
, " offset:%u", mtbuf
->offset
);
493 fprintf(output
, " offen");
495 fprintf(output
, " idxen");
497 fprintf(output
, " glc");
499 fprintf(output
, " dlc");
501 fprintf(output
, " slc");
503 fprintf(output
, " tfe");
504 if (mtbuf
->disable_wqm
)
505 fprintf(output
, " disable_wqm");
506 print_barrier_reorder(mtbuf
->can_reorder
, mtbuf
->barrier
, output
);
509 case Format::VOP3P
: {
510 if (static_cast<const VOP3P_instruction
*>(instr
)->clamp
)
511 fprintf(output
, " clamp");
518 if (instr
->isVOP3()) {
519 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
520 switch (vop3
->omod
) {
522 fprintf(output
, " *2");
525 fprintf(output
, " *4");
528 fprintf(output
, " *0.5");
532 fprintf(output
, " clamp");
533 if (vop3
->opsel
& (1 << 3))
534 fprintf(output
, " opsel_hi");
535 } else if (instr
->isDPP()) {
536 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
537 if (dpp
->dpp_ctrl
<= 0xff) {
538 fprintf(output
, " quad_perm:[%d,%d,%d,%d]",
539 dpp
->dpp_ctrl
& 0x3, (dpp
->dpp_ctrl
>> 2) & 0x3,
540 (dpp
->dpp_ctrl
>> 4) & 0x3, (dpp
->dpp_ctrl
>> 6) & 0x3);
541 } else if (dpp
->dpp_ctrl
>= 0x101 && dpp
->dpp_ctrl
<= 0x10f) {
542 fprintf(output
, " row_shl:%d", dpp
->dpp_ctrl
& 0xf);
543 } else if (dpp
->dpp_ctrl
>= 0x111 && dpp
->dpp_ctrl
<= 0x11f) {
544 fprintf(output
, " row_shr:%d", dpp
->dpp_ctrl
& 0xf);
545 } else if (dpp
->dpp_ctrl
>= 0x121 && dpp
->dpp_ctrl
<= 0x12f) {
546 fprintf(output
, " row_ror:%d", dpp
->dpp_ctrl
& 0xf);
547 } else if (dpp
->dpp_ctrl
== dpp_wf_sl1
) {
548 fprintf(output
, " wave_shl:1");
549 } else if (dpp
->dpp_ctrl
== dpp_wf_rl1
) {
550 fprintf(output
, " wave_rol:1");
551 } else if (dpp
->dpp_ctrl
== dpp_wf_sr1
) {
552 fprintf(output
, " wave_shr:1");
553 } else if (dpp
->dpp_ctrl
== dpp_wf_rr1
) {
554 fprintf(output
, " wave_ror:1");
555 } else if (dpp
->dpp_ctrl
== dpp_row_mirror
) {
556 fprintf(output
, " row_mirror");
557 } else if (dpp
->dpp_ctrl
== dpp_row_half_mirror
) {
558 fprintf(output
, " row_half_mirror");
559 } else if (dpp
->dpp_ctrl
== dpp_row_bcast15
) {
560 fprintf(output
, " row_bcast:15");
561 } else if (dpp
->dpp_ctrl
== dpp_row_bcast31
) {
562 fprintf(output
, " row_bcast:31");
564 fprintf(output
, " dpp_ctrl:0x%.3x", dpp
->dpp_ctrl
);
566 if (dpp
->row_mask
!= 0xf)
567 fprintf(output
, " row_mask:0x%.1x", dpp
->row_mask
);
568 if (dpp
->bank_mask
!= 0xf)
569 fprintf(output
, " bank_mask:0x%.1x", dpp
->bank_mask
);
571 fprintf(output
, " bound_ctrl:1");
572 } else if ((int)instr
->format
& (int)Format::SDWA
) {
573 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
574 switch (sdwa
->omod
) {
576 fprintf(output
, " *2");
579 fprintf(output
, " *4");
582 fprintf(output
, " *0.5");
586 fprintf(output
, " clamp");
587 switch (sdwa
->dst_sel
& sdwa_asuint
) {
594 fprintf(output
, " dst_sel:%sbyte%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
595 sdwa
->dst_sel
& sdwa_bytenum
);
599 fprintf(output
, " dst_sel:%sword%u", sdwa
->dst_sel
& sdwa_sext
? "s" : "u",
600 sdwa
->dst_sel
& sdwa_wordnum
);
603 if (sdwa
->dst_preserve
)
604 fprintf(output
, " dst_preserve");
608 void aco_print_instr(const Instruction
*instr
, FILE *output
)
610 if (!instr
->definitions
.empty()) {
611 for (unsigned i
= 0; i
< instr
->definitions
.size(); ++i
) {
612 print_definition(&instr
->definitions
[i
], output
);
613 if (i
+ 1 != instr
->definitions
.size())
614 fprintf(output
, ", ");
616 fprintf(output
, " = ");
618 fprintf(output
, "%s", instr_info
.name
[(int)instr
->opcode
]);
619 if (instr
->operands
.size()) {
620 bool abs
[instr
->operands
.size()];
621 bool neg
[instr
->operands
.size()];
622 bool opsel
[instr
->operands
.size()];
623 uint8_t sel
[instr
->operands
.size()];
624 if ((int)instr
->format
& (int)Format::VOP3A
) {
625 const VOP3A_instruction
* vop3
= static_cast<const VOP3A_instruction
*>(instr
);
626 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
627 abs
[i
] = vop3
->abs
[i
];
628 neg
[i
] = vop3
->neg
[i
];
629 opsel
[i
] = vop3
->opsel
& (1 << i
);
630 sel
[i
] = sdwa_udword
;
632 } else if (instr
->isDPP()) {
633 const DPP_instruction
* dpp
= static_cast<const DPP_instruction
*>(instr
);
634 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
635 abs
[i
] = i
< 2 ? dpp
->abs
[i
] : false;
636 neg
[i
] = i
< 2 ? dpp
->neg
[i
] : false;
638 sel
[i
] = sdwa_udword
;
640 } else if (instr
->isSDWA()) {
641 const SDWA_instruction
* sdwa
= static_cast<const SDWA_instruction
*>(instr
);
642 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
643 abs
[i
] = i
< 2 ? sdwa
->abs
[i
] : false;
644 neg
[i
] = i
< 2 ? sdwa
->neg
[i
] : false;
646 sel
[i
] = i
< 2 ? sdwa
->sel
[i
] : sdwa_udword
;
649 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
653 sel
[i
] = sdwa_udword
;
656 for (unsigned i
= 0; i
< instr
->operands
.size(); ++i
) {
658 fprintf(output
, ", ");
660 fprintf(output
, " ");
663 fprintf(output
, "-");
665 fprintf(output
, "|");
667 fprintf(output
, "hi(");
668 else if (sel
[i
] & sdwa_sext
)
669 fprintf(output
, "sext(");
670 print_operand(&instr
->operands
[i
], output
);
671 if (opsel
[i
] || (sel
[i
] & sdwa_sext
))
672 fprintf(output
, ")");
673 if (!(sel
[i
] & sdwa_isra
)) {
674 if (sel
[i
] & sdwa_udword
) {
676 } else if (sel
[i
] & sdwa_isword
) {
677 unsigned index
= sel
[i
] & sdwa_wordnum
;
678 fprintf(output
, "[%u:%u]", index
* 16, index
* 16 + 15);
680 unsigned index
= sel
[i
] & sdwa_bytenum
;
681 fprintf(output
, "[%u:%u]", index
* 8, index
* 8 + 7);
685 fprintf(output
, "|");
687 if (instr
->format
== Format::VOP3P
) {
688 const VOP3P_instruction
* vop3
= static_cast<const VOP3P_instruction
*>(instr
);
689 if ((vop3
->opsel_lo
& (1 << i
)) || !(vop3
->opsel_hi
& (1 << i
))) {
690 fprintf(output
, ".%c%c",
691 vop3
->opsel_lo
& (1 << i
) ? 'y' : 'x',
692 vop3
->opsel_hi
& (1 << i
) ? 'y' : 'x');
694 if (vop3
->neg_lo
[i
] && vop3
->neg_hi
[i
])
695 fprintf(output
, "*[-1,-1]");
696 else if (vop3
->neg_lo
[i
])
697 fprintf(output
, "*[-1,1]");
698 else if (vop3
->neg_hi
[i
])
699 fprintf(output
, "*[1,-1]");
703 print_instr_format_specific(instr
, output
);
706 static void print_block_kind(uint16_t kind
, FILE *output
)
708 if (kind
& block_kind_uniform
)
709 fprintf(output
, "uniform, ");
710 if (kind
& block_kind_top_level
)
711 fprintf(output
, "top-level, ");
712 if (kind
& block_kind_loop_preheader
)
713 fprintf(output
, "loop-preheader, ");
714 if (kind
& block_kind_loop_header
)
715 fprintf(output
, "loop-header, ");
716 if (kind
& block_kind_loop_exit
)
717 fprintf(output
, "loop-exit, ");
718 if (kind
& block_kind_continue
)
719 fprintf(output
, "continue, ");
720 if (kind
& block_kind_break
)
721 fprintf(output
, "break, ");
722 if (kind
& block_kind_continue_or_break
)
723 fprintf(output
, "continue_or_break, ");
724 if (kind
& block_kind_discard
)
725 fprintf(output
, "discard, ");
726 if (kind
& block_kind_branch
)
727 fprintf(output
, "branch, ");
728 if (kind
& block_kind_merge
)
729 fprintf(output
, "merge, ");
730 if (kind
& block_kind_invert
)
731 fprintf(output
, "invert, ");
732 if (kind
& block_kind_uses_discard_if
)
733 fprintf(output
, "discard_if, ");
734 if (kind
& block_kind_needs_lowering
)
735 fprintf(output
, "needs_lowering, ");
736 if (kind
& block_kind_uses_demote
)
737 fprintf(output
, "uses_demote, ");
738 if (kind
& block_kind_export_end
)
739 fprintf(output
, "export_end, ");
742 static void print_stage(Stage stage
, FILE *output
)
744 fprintf(output
, "ACO shader stage: ");
746 if (stage
== compute_cs
)
747 fprintf(output
, "compute_cs");
748 else if (stage
== fragment_fs
)
749 fprintf(output
, "fragment_fs");
750 else if (stage
== gs_copy_vs
)
751 fprintf(output
, "gs_copy_vs");
752 else if (stage
== vertex_ls
)
753 fprintf(output
, "vertex_ls");
754 else if (stage
== vertex_es
)
755 fprintf(output
, "vertex_es");
756 else if (stage
== vertex_vs
)
757 fprintf(output
, "vertex_vs");
758 else if (stage
== tess_control_hs
)
759 fprintf(output
, "tess_control_hs");
760 else if (stage
== vertex_tess_control_hs
)
761 fprintf(output
, "vertex_tess_control_hs");
762 else if (stage
== tess_eval_es
)
763 fprintf(output
, "tess_eval_es");
764 else if (stage
== tess_eval_vs
)
765 fprintf(output
, "tess_eval_vs");
766 else if (stage
== geometry_gs
)
767 fprintf(output
, "geometry_gs");
768 else if (stage
== vertex_geometry_gs
)
769 fprintf(output
, "vertex_geometry_gs");
770 else if (stage
== tess_eval_geometry_gs
)
771 fprintf(output
, "tess_eval_geometry_gs");
772 else if (stage
== ngg_vertex_gs
)
773 fprintf(output
, "ngg_vertex_gs");
774 else if (stage
== ngg_tess_eval_gs
)
775 fprintf(output
, "ngg_tess_eval_gs");
776 else if (stage
== ngg_vertex_geometry_gs
)
777 fprintf(output
, "ngg_vertex_geometry_gs");
778 else if (stage
== ngg_tess_eval_geometry_gs
)
779 fprintf(output
, "ngg_tess_eval_geometry_gs");
781 fprintf(output
, "unknown");
783 fprintf(output
, "\n");
786 void aco_print_block(const Block
* block
, FILE *output
)
788 fprintf(output
, "BB%d\n", block
->index
);
789 fprintf(output
, "/* logical preds: ");
790 for (unsigned pred
: block
->logical_preds
)
791 fprintf(output
, "BB%d, ", pred
);
792 fprintf(output
, "/ linear preds: ");
793 for (unsigned pred
: block
->linear_preds
)
794 fprintf(output
, "BB%d, ", pred
);
795 fprintf(output
, "/ kind: ");
796 print_block_kind(block
->kind
, output
);
797 fprintf(output
, "*/\n");
798 for (auto const& instr
: block
->instructions
) {
799 fprintf(output
, "\t");
800 aco_print_instr(instr
.get(), output
);
801 fprintf(output
, "\n");
805 void aco_print_program(const Program
*program
, FILE *output
)
807 print_stage(program
->stage
, output
);
809 for (Block
const& block
: program
->blocks
)
810 aco_print_block(&block
, output
);
812 if (program
->constant_data
.size()) {
813 fprintf(output
, "\n/* constant data */\n");
814 for (unsigned i
= 0; i
< program
->constant_data
.size(); i
+= 32) {
815 fprintf(output
, "[%06d] ", i
);
816 unsigned line_size
= std::min
<size_t>(program
->constant_data
.size() - i
, 32);
817 for (unsigned j
= 0; j
< line_size
; j
+= 4) {
818 unsigned size
= std::min
<size_t>(program
->constant_data
.size() - (i
+ j
), 4);
820 memcpy(&v
, &program
->constant_data
[i
+ j
], size
);
821 fprintf(output
, " %08x", v
);
823 fprintf(output
, "\n");
827 fprintf(output
, "\n");