1 //===-- AMDGPUInstPrinter.cpp - AMDGPU MC Inst -> ASM ---------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "AMDGPUInstPrinter.h"
11 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
12 #include "SIDefines.h"
13 #include "SIRegisterInfo.h"
14 #include "Utils/AMDGPUAsmUtils.h"
15 #include "Utils/AMDGPUBaseInfo.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrDesc.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/TargetParser.h"
25 using namespace llvm::AMDGPU
;
27 static cl::opt
<bool> Keep16BitSuffixes(
28 "amdgpu-keep-16-bit-reg-suffixes",
29 cl::desc("Keep .l and .h suffixes in asm for debugging purposes"),
33 void AMDGPUInstPrinter::printRegName(raw_ostream
&OS
, unsigned RegNo
) const {
34 // FIXME: The current implementation of
35 // AsmParser::parseRegisterOrRegisterNumber in MC implies we either emit this
36 // as an integer or we provide a name which represents a physical register.
37 // For CFI instructions we really want to emit a name for the DWARF register
38 // instead, because there may be multiple DWARF registers corresponding to a
39 // single physical register. One case where this problem manifests is with
40 // wave32/wave64 where using the physical register name is ambiguous: if we
41 // write e.g. `.cfi_undefined v0` we lose information about the wavefront
42 // size which we need to encode the register in the final DWARF. Ideally we
43 // would extend MC to support parsing DWARF register names so we could do
44 // something like `.cfi_undefined dwarf_wave32_v0`. For now we just live with
45 // non-pretty DWARF register names in assembly text.
49 void AMDGPUInstPrinter::printInst(const MCInst
*MI
, uint64_t Address
,
50 StringRef Annot
, const MCSubtargetInfo
&STI
,
53 printInstruction(MI
, Address
, STI
, OS
);
54 printAnnotation(OS
, Annot
);
57 void AMDGPUInstPrinter::printU4ImmOperand(const MCInst
*MI
, unsigned OpNo
,
58 const MCSubtargetInfo
&STI
,
60 O
<< formatHex(MI
->getOperand(OpNo
).getImm() & 0xf);
63 void AMDGPUInstPrinter::printU8ImmOperand(const MCInst
*MI
, unsigned OpNo
,
65 O
<< formatHex(MI
->getOperand(OpNo
).getImm() & 0xff);
68 void AMDGPUInstPrinter::printU16ImmOperand(const MCInst
*MI
, unsigned OpNo
,
69 const MCSubtargetInfo
&STI
,
71 // It's possible to end up with a 32-bit literal used with a 16-bit operand
72 // with ignored high bits. Print as 32-bit anyway in that case.
73 int64_t Imm
= MI
->getOperand(OpNo
).getImm();
74 if (isInt
<16>(Imm
) || isUInt
<16>(Imm
))
75 O
<< formatHex(static_cast<uint64_t>(Imm
& 0xffff));
77 printU32ImmOperand(MI
, OpNo
, STI
, O
);
80 void AMDGPUInstPrinter::printU4ImmDecOperand(const MCInst
*MI
, unsigned OpNo
,
82 O
<< formatDec(MI
->getOperand(OpNo
).getImm() & 0xf);
85 void AMDGPUInstPrinter::printU8ImmDecOperand(const MCInst
*MI
, unsigned OpNo
,
87 O
<< formatDec(MI
->getOperand(OpNo
).getImm() & 0xff);
90 void AMDGPUInstPrinter::printU16ImmDecOperand(const MCInst
*MI
, unsigned OpNo
,
92 O
<< formatDec(MI
->getOperand(OpNo
).getImm() & 0xffff);
95 void AMDGPUInstPrinter::printU32ImmOperand(const MCInst
*MI
, unsigned OpNo
,
96 const MCSubtargetInfo
&STI
,
98 O
<< formatHex(MI
->getOperand(OpNo
).getImm() & 0xffffffff);
101 void AMDGPUInstPrinter::printNamedBit(const MCInst
*MI
, unsigned OpNo
,
102 raw_ostream
&O
, StringRef BitName
) {
103 if (MI
->getOperand(OpNo
).getImm()) {
108 void AMDGPUInstPrinter::printOffen(const MCInst
*MI
, unsigned OpNo
,
110 printNamedBit(MI
, OpNo
, O
, "offen");
113 void AMDGPUInstPrinter::printIdxen(const MCInst
*MI
, unsigned OpNo
,
115 printNamedBit(MI
, OpNo
, O
, "idxen");
118 void AMDGPUInstPrinter::printAddr64(const MCInst
*MI
, unsigned OpNo
,
120 printNamedBit(MI
, OpNo
, O
, "addr64");
123 void AMDGPUInstPrinter::printMBUFOffset(const MCInst
*MI
, unsigned OpNo
,
125 if (MI
->getOperand(OpNo
).getImm()) {
127 printU16ImmDecOperand(MI
, OpNo
, O
);
131 void AMDGPUInstPrinter::printOffset(const MCInst
*MI
, unsigned OpNo
,
132 const MCSubtargetInfo
&STI
,
134 uint16_t Imm
= MI
->getOperand(OpNo
).getImm();
137 printU16ImmDecOperand(MI
, OpNo
, O
);
141 void AMDGPUInstPrinter::printFlatOffset(const MCInst
*MI
, unsigned OpNo
,
142 const MCSubtargetInfo
&STI
,
144 uint16_t Imm
= MI
->getOperand(OpNo
).getImm();
148 const MCInstrDesc
&Desc
= MII
.get(MI
->getOpcode());
149 bool IsFlatSeg
= !(Desc
.TSFlags
&
150 (SIInstrFlags::FlatGlobal
| SIInstrFlags::FlatScratch
));
152 if (IsFlatSeg
) { // Unsigned offset
153 printU16ImmDecOperand(MI
, OpNo
, O
);
154 } else { // Signed offset
155 if (AMDGPU::isGFX10Plus(STI
)) {
156 O
<< formatDec(SignExtend32
<12>(MI
->getOperand(OpNo
).getImm()));
158 O
<< formatDec(SignExtend32
<13>(MI
->getOperand(OpNo
).getImm()));
164 void AMDGPUInstPrinter::printOffset0(const MCInst
*MI
, unsigned OpNo
,
165 const MCSubtargetInfo
&STI
,
167 if (MI
->getOperand(OpNo
).getImm()) {
169 printU8ImmDecOperand(MI
, OpNo
, O
);
173 void AMDGPUInstPrinter::printOffset1(const MCInst
*MI
, unsigned OpNo
,
174 const MCSubtargetInfo
&STI
,
176 if (MI
->getOperand(OpNo
).getImm()) {
178 printU8ImmDecOperand(MI
, OpNo
, O
);
182 void AMDGPUInstPrinter::printSMRDOffset8(const MCInst
*MI
, unsigned OpNo
,
183 const MCSubtargetInfo
&STI
,
185 printU32ImmOperand(MI
, OpNo
, STI
, O
);
188 void AMDGPUInstPrinter::printSMEMOffset(const MCInst
*MI
, unsigned OpNo
,
189 const MCSubtargetInfo
&STI
,
191 O
<< formatHex(MI
->getOperand(OpNo
).getImm());
194 void AMDGPUInstPrinter::printSMRDLiteralOffset(const MCInst
*MI
, unsigned OpNo
,
195 const MCSubtargetInfo
&STI
,
197 printU32ImmOperand(MI
, OpNo
, STI
, O
);
200 void AMDGPUInstPrinter::printGDS(const MCInst
*MI
, unsigned OpNo
,
201 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
202 printNamedBit(MI
, OpNo
, O
, "gds");
205 void AMDGPUInstPrinter::printCPol(const MCInst
*MI
, unsigned OpNo
,
206 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
207 auto Imm
= MI
->getOperand(OpNo
).getImm();
212 if ((Imm
& CPol::DLC
) && AMDGPU::isGFX10Plus(STI
))
214 if ((Imm
& CPol::SCC
) && AMDGPU::isGFX90A(STI
))
216 if (Imm
& ~CPol::ALL
)
217 O
<< " /* unexpected cache policy bit */";
220 void AMDGPUInstPrinter::printSWZ(const MCInst
*MI
, unsigned OpNo
,
221 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
224 void AMDGPUInstPrinter::printTFE(const MCInst
*MI
, unsigned OpNo
,
225 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
226 printNamedBit(MI
, OpNo
, O
, "tfe");
229 void AMDGPUInstPrinter::printDMask(const MCInst
*MI
, unsigned OpNo
,
230 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
231 if (MI
->getOperand(OpNo
).getImm()) {
233 printU16ImmOperand(MI
, OpNo
, STI
, O
);
237 void AMDGPUInstPrinter::printDim(const MCInst
*MI
, unsigned OpNo
,
238 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
239 unsigned Dim
= MI
->getOperand(OpNo
).getImm();
240 O
<< " dim:SQ_RSRC_IMG_";
242 const AMDGPU::MIMGDimInfo
*DimInfo
= AMDGPU::getMIMGDimInfoByEncoding(Dim
);
244 O
<< DimInfo
->AsmSuffix
;
249 void AMDGPUInstPrinter::printUNorm(const MCInst
*MI
, unsigned OpNo
,
250 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
251 printNamedBit(MI
, OpNo
, O
, "unorm");
254 void AMDGPUInstPrinter::printDA(const MCInst
*MI
, unsigned OpNo
,
255 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
256 printNamedBit(MI
, OpNo
, O
, "da");
259 void AMDGPUInstPrinter::printR128A16(const MCInst
*MI
, unsigned OpNo
,
260 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
261 if (STI
.hasFeature(AMDGPU::FeatureR128A16
))
262 printNamedBit(MI
, OpNo
, O
, "a16");
264 printNamedBit(MI
, OpNo
, O
, "r128");
267 void AMDGPUInstPrinter::printGFX10A16(const MCInst
*MI
, unsigned OpNo
,
268 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
269 printNamedBit(MI
, OpNo
, O
, "a16");
272 void AMDGPUInstPrinter::printLWE(const MCInst
*MI
, unsigned OpNo
,
273 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
274 printNamedBit(MI
, OpNo
, O
, "lwe");
277 void AMDGPUInstPrinter::printD16(const MCInst
*MI
, unsigned OpNo
,
278 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
279 printNamedBit(MI
, OpNo
, O
, "d16");
282 void AMDGPUInstPrinter::printExpCompr(const MCInst
*MI
, unsigned OpNo
,
283 const MCSubtargetInfo
&STI
,
285 printNamedBit(MI
, OpNo
, O
, "compr");
288 void AMDGPUInstPrinter::printExpVM(const MCInst
*MI
, unsigned OpNo
,
289 const MCSubtargetInfo
&STI
,
291 printNamedBit(MI
, OpNo
, O
, "vm");
294 void AMDGPUInstPrinter::printFORMAT(const MCInst
*MI
, unsigned OpNo
,
295 const MCSubtargetInfo
&STI
,
299 void AMDGPUInstPrinter::printSymbolicFormat(const MCInst
*MI
,
300 const MCSubtargetInfo
&STI
,
302 using namespace llvm::AMDGPU::MTBUFFormat
;
305 AMDGPU::getNamedOperandIdx(MI
->getOpcode(), AMDGPU::OpName::format
);
308 unsigned Val
= MI
->getOperand(OpNo
).getImm();
309 if (AMDGPU::isGFX10Plus(STI
)) {
310 if (Val
== UFMT_DEFAULT
)
312 if (isValidUnifiedFormat(Val
)) {
313 O
<< " format:[" << getUnifiedFormatName(Val
) << ']';
315 O
<< " format:" << Val
;
318 if (Val
== DFMT_NFMT_DEFAULT
)
320 if (isValidDfmtNfmt(Val
, STI
)) {
323 decodeDfmtNfmt(Val
, Dfmt
, Nfmt
);
325 if (Dfmt
!= DFMT_DEFAULT
) {
326 O
<< getDfmtName(Dfmt
);
327 if (Nfmt
!= NFMT_DEFAULT
) {
331 if (Nfmt
!= NFMT_DEFAULT
) {
332 O
<< getNfmtName(Nfmt
, STI
);
336 O
<< " format:" << Val
;
341 void AMDGPUInstPrinter::printRegOperand(unsigned RegNo
, raw_ostream
&O
,
342 const MCRegisterInfo
&MRI
) {
347 case AMDGPU::PRIVATE_RSRC_REG
:
348 llvm_unreachable("pseudo-register should not ever be emitted");
350 llvm_unreachable("pseudo scc should not ever be emitted");
356 StringRef
RegName(getRegisterName(RegNo
));
357 if (!Keep16BitSuffixes
)
358 if (!RegName
.consume_back(".l"))
359 RegName
.consume_back(".h");
364 void AMDGPUInstPrinter::printVOPDst(const MCInst
*MI
, unsigned OpNo
,
365 const MCSubtargetInfo
&STI
,
367 auto Opcode
= MI
->getOpcode();
368 auto Flags
= MII
.get(Opcode
).TSFlags
;
371 if (Flags
& SIInstrFlags::VOP3
) {
372 if (!getVOP3IsSingle(Opcode
))
374 } else if (Flags
& SIInstrFlags::DPP
) {
376 } else if (Flags
& SIInstrFlags::SDWA
) {
378 } else if (((Flags
& SIInstrFlags::VOP1
) && !getVOP1IsSingle(Opcode
)) ||
379 ((Flags
& SIInstrFlags::VOP2
) && !getVOP2IsSingle(Opcode
))) {
385 printOperand(MI
, OpNo
, STI
, O
);
387 // Print default vcc/vcc_lo operand.
391 case AMDGPU::V_ADD_CO_CI_U32_e32_gfx10
:
392 case AMDGPU::V_SUB_CO_CI_U32_e32_gfx10
:
393 case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10
:
394 case AMDGPU::V_ADD_CO_CI_U32_sdwa_gfx10
:
395 case AMDGPU::V_SUB_CO_CI_U32_sdwa_gfx10
:
396 case AMDGPU::V_SUBREV_CO_CI_U32_sdwa_gfx10
:
397 case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx10
:
398 case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx10
:
399 case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx10
:
400 case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx10
:
401 case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx10
:
402 case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx10
:
403 printDefaultVccOperand(1, STI
, O
);
408 void AMDGPUInstPrinter::printVINTRPDst(const MCInst
*MI
, unsigned OpNo
,
409 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
410 if (AMDGPU::isSI(STI
) || AMDGPU::isCI(STI
))
415 printOperand(MI
, OpNo
, STI
, O
);
418 void AMDGPUInstPrinter::printImmediateInt16(uint32_t Imm
,
419 const MCSubtargetInfo
&STI
,
421 int16_t SImm
= static_cast<int16_t>(Imm
);
422 if (isInlinableIntLiteral(SImm
)) {
425 uint64_t Imm16
= static_cast<uint16_t>(Imm
);
426 O
<< formatHex(Imm16
);
430 void AMDGPUInstPrinter::printImmediate16(uint32_t Imm
,
431 const MCSubtargetInfo
&STI
,
433 int16_t SImm
= static_cast<int16_t>(Imm
);
434 if (isInlinableIntLiteral(SImm
)) {
441 else if (Imm
== 0xBC00)
443 else if (Imm
== 0x3800)
445 else if (Imm
== 0xB800)
447 else if (Imm
== 0x4000)
449 else if (Imm
== 0xC000)
451 else if (Imm
== 0x4400)
453 else if (Imm
== 0xC400)
455 else if (Imm
== 0x3118 &&
456 STI
.getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm
]) {
459 uint64_t Imm16
= static_cast<uint16_t>(Imm
);
460 O
<< formatHex(Imm16
);
464 void AMDGPUInstPrinter::printImmediateV216(uint32_t Imm
,
465 const MCSubtargetInfo
&STI
,
467 uint16_t Lo16
= static_cast<uint16_t>(Imm
);
468 printImmediate16(Lo16
, STI
, O
);
471 void AMDGPUInstPrinter::printImmediate32(uint32_t Imm
,
472 const MCSubtargetInfo
&STI
,
474 int32_t SImm
= static_cast<int32_t>(Imm
);
475 if (SImm
>= -16 && SImm
<= 64) {
480 if (Imm
== FloatToBits(0.0f
))
482 else if (Imm
== FloatToBits(1.0f
))
484 else if (Imm
== FloatToBits(-1.0f
))
486 else if (Imm
== FloatToBits(0.5f
))
488 else if (Imm
== FloatToBits(-0.5f
))
490 else if (Imm
== FloatToBits(2.0f
))
492 else if (Imm
== FloatToBits(-2.0f
))
494 else if (Imm
== FloatToBits(4.0f
))
496 else if (Imm
== FloatToBits(-4.0f
))
498 else if (Imm
== 0x3e22f983 &&
499 STI
.getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm
])
502 O
<< formatHex(static_cast<uint64_t>(Imm
));
505 void AMDGPUInstPrinter::printImmediate64(uint64_t Imm
,
506 const MCSubtargetInfo
&STI
,
508 int64_t SImm
= static_cast<int64_t>(Imm
);
509 if (SImm
>= -16 && SImm
<= 64) {
514 if (Imm
== DoubleToBits(0.0))
516 else if (Imm
== DoubleToBits(1.0))
518 else if (Imm
== DoubleToBits(-1.0))
520 else if (Imm
== DoubleToBits(0.5))
522 else if (Imm
== DoubleToBits(-0.5))
524 else if (Imm
== DoubleToBits(2.0))
526 else if (Imm
== DoubleToBits(-2.0))
528 else if (Imm
== DoubleToBits(4.0))
530 else if (Imm
== DoubleToBits(-4.0))
532 else if (Imm
== 0x3fc45f306dc9c882 &&
533 STI
.getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm
])
534 O
<< "0.15915494309189532";
536 assert(isUInt
<32>(Imm
) || Imm
== 0x3fc45f306dc9c882);
538 // In rare situations, we will have a 32-bit literal in a 64-bit
539 // operand. This is technically allowed for the encoding of s_mov_b64.
540 O
<< formatHex(static_cast<uint64_t>(Imm
));
544 void AMDGPUInstPrinter::printBLGP(const MCInst
*MI
, unsigned OpNo
,
545 const MCSubtargetInfo
&STI
,
547 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
551 O
<< " blgp:" << Imm
;
554 void AMDGPUInstPrinter::printCBSZ(const MCInst
*MI
, unsigned OpNo
,
555 const MCSubtargetInfo
&STI
,
557 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
561 O
<< " cbsz:" << Imm
;
564 void AMDGPUInstPrinter::printABID(const MCInst
*MI
, unsigned OpNo
,
565 const MCSubtargetInfo
&STI
,
567 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
571 O
<< " abid:" << Imm
;
574 void AMDGPUInstPrinter::printDefaultVccOperand(unsigned OpNo
,
575 const MCSubtargetInfo
&STI
,
579 printRegOperand(STI
.getFeatureBits()[AMDGPU::FeatureWavefrontSize64
] ?
580 AMDGPU::VCC
: AMDGPU::VCC_LO
, O
, MRI
);
585 void AMDGPUInstPrinter::printOperand(const MCInst
*MI
, unsigned OpNo
,
586 const MCSubtargetInfo
&STI
,
588 // Print default vcc/vcc_lo operand of VOPC.
589 const MCInstrDesc
&Desc
= MII
.get(MI
->getOpcode());
590 if (OpNo
== 0 && (Desc
.TSFlags
& SIInstrFlags::VOPC
) &&
591 (Desc
.hasImplicitDefOfPhysReg(AMDGPU::VCC
) ||
592 Desc
.hasImplicitDefOfPhysReg(AMDGPU::VCC_LO
)))
593 printDefaultVccOperand(OpNo
, STI
, O
);
595 if (OpNo
>= MI
->getNumOperands()) {
596 O
<< "/*Missing OP" << OpNo
<< "*/";
600 const MCOperand
&Op
= MI
->getOperand(OpNo
);
602 printRegOperand(Op
.getReg(), O
, MRI
);
603 } else if (Op
.isImm()) {
604 const uint8_t OpTy
= Desc
.OpInfo
[OpNo
].OperandType
;
606 case AMDGPU::OPERAND_REG_IMM_INT32
:
607 case AMDGPU::OPERAND_REG_IMM_FP32
:
608 case AMDGPU::OPERAND_REG_INLINE_C_INT32
:
609 case AMDGPU::OPERAND_REG_INLINE_C_FP32
:
610 case AMDGPU::OPERAND_REG_INLINE_AC_INT32
:
611 case AMDGPU::OPERAND_REG_INLINE_AC_FP32
:
612 case AMDGPU::OPERAND_REG_IMM_V2INT32
:
613 case AMDGPU::OPERAND_REG_IMM_V2FP32
:
614 case AMDGPU::OPERAND_REG_INLINE_C_V2INT32
:
615 case AMDGPU::OPERAND_REG_INLINE_C_V2FP32
:
616 case MCOI::OPERAND_IMMEDIATE
:
617 printImmediate32(Op
.getImm(), STI
, O
);
619 case AMDGPU::OPERAND_REG_IMM_INT64
:
620 case AMDGPU::OPERAND_REG_IMM_FP64
:
621 case AMDGPU::OPERAND_REG_INLINE_C_INT64
:
622 case AMDGPU::OPERAND_REG_INLINE_C_FP64
:
623 case AMDGPU::OPERAND_REG_INLINE_AC_FP64
:
624 printImmediate64(Op
.getImm(), STI
, O
);
626 case AMDGPU::OPERAND_REG_INLINE_C_INT16
:
627 case AMDGPU::OPERAND_REG_INLINE_AC_INT16
:
628 case AMDGPU::OPERAND_REG_IMM_INT16
:
629 printImmediateInt16(Op
.getImm(), STI
, O
);
631 case AMDGPU::OPERAND_REG_INLINE_C_FP16
:
632 case AMDGPU::OPERAND_REG_INLINE_AC_FP16
:
633 case AMDGPU::OPERAND_REG_IMM_FP16
:
634 printImmediate16(Op
.getImm(), STI
, O
);
636 case AMDGPU::OPERAND_REG_IMM_V2INT16
:
637 case AMDGPU::OPERAND_REG_IMM_V2FP16
:
638 if (!isUInt
<16>(Op
.getImm()) &&
639 STI
.getFeatureBits()[AMDGPU::FeatureVOP3Literal
]) {
640 printImmediate32(Op
.getImm(), STI
, O
);
644 // Deal with 16-bit FP inline immediates not working.
645 if (OpTy
== AMDGPU::OPERAND_REG_IMM_V2FP16
) {
646 printImmediate16(static_cast<uint16_t>(Op
.getImm()), STI
, O
);
650 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16
:
651 case AMDGPU::OPERAND_REG_INLINE_AC_V2INT16
:
652 printImmediateInt16(static_cast<uint16_t>(Op
.getImm()), STI
, O
);
654 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16
:
655 case AMDGPU::OPERAND_REG_INLINE_AC_V2FP16
:
656 printImmediateV216(Op
.getImm(), STI
, O
);
658 case MCOI::OPERAND_UNKNOWN
:
659 case MCOI::OPERAND_PCREL
:
660 O
<< formatDec(Op
.getImm());
662 case MCOI::OPERAND_REGISTER
:
663 // FIXME: This should be removed and handled somewhere else. Seems to come
664 // from a disassembler bug.
665 O
<< "/*invalid immediate*/";
668 // We hit this for the immediate instruction bits that don't yet have a
670 llvm_unreachable("unexpected immediate operand type");
672 } else if (Op
.isDFPImm()) {
673 double Value
= bit_cast
<double>(Op
.getDFPImm());
674 // We special case 0.0 because otherwise it will be printed as an integer.
678 const MCInstrDesc
&Desc
= MII
.get(MI
->getOpcode());
679 int RCID
= Desc
.OpInfo
[OpNo
].RegClass
;
680 unsigned RCBits
= AMDGPU::getRegBitWidth(MRI
.getRegClass(RCID
));
682 printImmediate32(FloatToBits(Value
), STI
, O
);
683 else if (RCBits
== 64)
684 printImmediate64(DoubleToBits(Value
), STI
, O
);
686 llvm_unreachable("Invalid register class size");
688 } else if (Op
.isExpr()) {
689 const MCExpr
*Exp
= Op
.getExpr();
695 // Print default vcc/vcc_lo operand of v_cndmask_b32_e32.
696 switch (MI
->getOpcode()) {
699 case AMDGPU::V_CNDMASK_B32_e32_gfx10
:
700 case AMDGPU::V_ADD_CO_CI_U32_e32_gfx10
:
701 case AMDGPU::V_SUB_CO_CI_U32_e32_gfx10
:
702 case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10
:
703 case AMDGPU::V_CNDMASK_B32_dpp_gfx10
:
704 case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx10
:
705 case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx10
:
706 case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx10
:
707 case AMDGPU::V_CNDMASK_B32_dpp8_gfx10
:
708 case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx10
:
709 case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx10
:
710 case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx10
:
712 case AMDGPU::V_CNDMASK_B32_e32_gfx6_gfx7
:
713 case AMDGPU::V_CNDMASK_B32_e32_vi
:
714 if ((int)OpNo
== AMDGPU::getNamedOperandIdx(MI
->getOpcode(),
715 AMDGPU::OpName::src1
))
716 printDefaultVccOperand(OpNo
, STI
, O
);
720 if (Desc
.TSFlags
& SIInstrFlags::MTBUF
) {
722 AMDGPU::getNamedOperandIdx(MI
->getOpcode(), AMDGPU::OpName::soffset
);
723 assert(SOffsetIdx
!= -1);
724 if ((int)OpNo
== SOffsetIdx
)
725 printSymbolicFormat(MI
, STI
, O
);
729 void AMDGPUInstPrinter::printOperandAndFPInputMods(const MCInst
*MI
,
731 const MCSubtargetInfo
&STI
,
733 unsigned InputModifiers
= MI
->getOperand(OpNo
).getImm();
735 // Use 'neg(...)' instead of '-' to avoid ambiguity.
736 // This is important for integer literals because
737 // -1 is not the same value as neg(1).
738 bool NegMnemo
= false;
740 if (InputModifiers
& SISrcMods::NEG
) {
741 if (OpNo
+ 1 < MI
->getNumOperands() &&
742 (InputModifiers
& SISrcMods::ABS
) == 0) {
743 const MCOperand
&Op
= MI
->getOperand(OpNo
+ 1);
744 NegMnemo
= Op
.isImm() || Op
.isDFPImm();
753 if (InputModifiers
& SISrcMods::ABS
)
755 printOperand(MI
, OpNo
+ 1, STI
, O
);
756 if (InputModifiers
& SISrcMods::ABS
)
764 void AMDGPUInstPrinter::printOperandAndIntInputMods(const MCInst
*MI
,
766 const MCSubtargetInfo
&STI
,
768 unsigned InputModifiers
= MI
->getOperand(OpNo
).getImm();
769 if (InputModifiers
& SISrcMods::SEXT
)
771 printOperand(MI
, OpNo
+ 1, STI
, O
);
772 if (InputModifiers
& SISrcMods::SEXT
)
775 // Print default vcc/vcc_lo operand of VOP2b.
776 switch (MI
->getOpcode()) {
779 case AMDGPU::V_CNDMASK_B32_sdwa_gfx10
:
780 case AMDGPU::V_ADD_CO_CI_U32_sdwa_gfx10
:
781 case AMDGPU::V_SUB_CO_CI_U32_sdwa_gfx10
:
782 case AMDGPU::V_SUBREV_CO_CI_U32_sdwa_gfx10
:
783 if ((int)OpNo
+ 1 == AMDGPU::getNamedOperandIdx(MI
->getOpcode(),
784 AMDGPU::OpName::src1
))
785 printDefaultVccOperand(OpNo
, STI
, O
);
790 void AMDGPUInstPrinter::printDPP8(const MCInst
*MI
, unsigned OpNo
,
791 const MCSubtargetInfo
&STI
,
793 if (!AMDGPU::isGFX10Plus(STI
))
794 llvm_unreachable("dpp8 is not supported on ASICs earlier than GFX10");
796 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
797 O
<< "dpp8:[" << formatDec(Imm
& 0x7);
798 for (size_t i
= 1; i
< 8; ++i
) {
799 O
<< ',' << formatDec((Imm
>> (3 * i
)) & 0x7);
804 void AMDGPUInstPrinter::printDPPCtrl(const MCInst
*MI
, unsigned OpNo
,
805 const MCSubtargetInfo
&STI
,
807 using namespace AMDGPU::DPP
;
809 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
810 const MCInstrDesc
&Desc
= MII
.get(MI
->getOpcode());
811 int Src0Idx
= AMDGPU::getNamedOperandIdx(MI
->getOpcode(),
812 AMDGPU::OpName::src0
);
815 Desc
.OpInfo
[Src0Idx
].RegClass
== AMDGPU::VReg_64RegClassID
&&
816 !AMDGPU::isLegal64BitDPPControl(Imm
)) {
817 O
<< " /* 64 bit dpp only supports row_newbcast */";
819 } else if (Imm
<= DppCtrl::QUAD_PERM_LAST
) {
821 O
<< formatDec(Imm
& 0x3) << ',';
822 O
<< formatDec((Imm
& 0xc) >> 2) << ',';
823 O
<< formatDec((Imm
& 0x30) >> 4) << ',';
824 O
<< formatDec((Imm
& 0xc0) >> 6) << ']';
825 } else if ((Imm
>= DppCtrl::ROW_SHL_FIRST
) &&
826 (Imm
<= DppCtrl::ROW_SHL_LAST
)) {
828 printU4ImmDecOperand(MI
, OpNo
, O
);
829 } else if ((Imm
>= DppCtrl::ROW_SHR_FIRST
) &&
830 (Imm
<= DppCtrl::ROW_SHR_LAST
)) {
832 printU4ImmDecOperand(MI
, OpNo
, O
);
833 } else if ((Imm
>= DppCtrl::ROW_ROR_FIRST
) &&
834 (Imm
<= DppCtrl::ROW_ROR_LAST
)) {
836 printU4ImmDecOperand(MI
, OpNo
, O
);
837 } else if (Imm
== DppCtrl::WAVE_SHL1
) {
838 if (AMDGPU::isGFX10Plus(STI
)) {
839 O
<< "/* wave_shl is not supported starting from GFX10 */";
843 } else if (Imm
== DppCtrl::WAVE_ROL1
) {
844 if (AMDGPU::isGFX10Plus(STI
)) {
845 O
<< "/* wave_rol is not supported starting from GFX10 */";
849 } else if (Imm
== DppCtrl::WAVE_SHR1
) {
850 if (AMDGPU::isGFX10Plus(STI
)) {
851 O
<< "/* wave_shr is not supported starting from GFX10 */";
855 } else if (Imm
== DppCtrl::WAVE_ROR1
) {
856 if (AMDGPU::isGFX10Plus(STI
)) {
857 O
<< "/* wave_ror is not supported starting from GFX10 */";
861 } else if (Imm
== DppCtrl::ROW_MIRROR
) {
863 } else if (Imm
== DppCtrl::ROW_HALF_MIRROR
) {
864 O
<< "row_half_mirror";
865 } else if (Imm
== DppCtrl::BCAST15
) {
866 if (AMDGPU::isGFX10Plus(STI
)) {
867 O
<< "/* row_bcast is not supported starting from GFX10 */";
871 } else if (Imm
== DppCtrl::BCAST31
) {
872 if (AMDGPU::isGFX10Plus(STI
)) {
873 O
<< "/* row_bcast is not supported starting from GFX10 */";
877 } else if ((Imm
>= DppCtrl::ROW_SHARE_FIRST
) &&
878 (Imm
<= DppCtrl::ROW_SHARE_LAST
)) {
879 if (AMDGPU::isGFX90A(STI
)) {
880 O
<< "row_newbcast:";
881 } else if (AMDGPU::isGFX10Plus(STI
)) {
884 O
<< " /* row_newbcast/row_share is not supported on ASICs earlier "
885 "than GFX90A/GFX10 */";
888 printU4ImmDecOperand(MI
, OpNo
, O
);
889 } else if ((Imm
>= DppCtrl::ROW_XMASK_FIRST
) &&
890 (Imm
<= DppCtrl::ROW_XMASK_LAST
)) {
891 if (!AMDGPU::isGFX10Plus(STI
)) {
892 O
<< "/* row_xmask is not supported on ASICs earlier than GFX10 */";
896 printU4ImmDecOperand(MI
, OpNo
, O
);
898 O
<< "/* Invalid dpp_ctrl value */";
902 void AMDGPUInstPrinter::printRowMask(const MCInst
*MI
, unsigned OpNo
,
903 const MCSubtargetInfo
&STI
,
906 printU4ImmOperand(MI
, OpNo
, STI
, O
);
909 void AMDGPUInstPrinter::printBankMask(const MCInst
*MI
, unsigned OpNo
,
910 const MCSubtargetInfo
&STI
,
913 printU4ImmOperand(MI
, OpNo
, STI
, O
);
916 void AMDGPUInstPrinter::printBoundCtrl(const MCInst
*MI
, unsigned OpNo
,
917 const MCSubtargetInfo
&STI
,
919 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
921 O
<< " bound_ctrl:1";
925 void AMDGPUInstPrinter::printFI(const MCInst
*MI
, unsigned OpNo
,
926 const MCSubtargetInfo
&STI
,
928 using namespace llvm::AMDGPU::DPP
;
929 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
930 if (Imm
== DPP_FI_1
|| Imm
== DPP8_FI_1
) {
935 void AMDGPUInstPrinter::printSDWASel(const MCInst
*MI
, unsigned OpNo
,
937 using namespace llvm::AMDGPU::SDWA
;
939 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
941 case SdwaSel::BYTE_0
: O
<< "BYTE_0"; break;
942 case SdwaSel::BYTE_1
: O
<< "BYTE_1"; break;
943 case SdwaSel::BYTE_2
: O
<< "BYTE_2"; break;
944 case SdwaSel::BYTE_3
: O
<< "BYTE_3"; break;
945 case SdwaSel::WORD_0
: O
<< "WORD_0"; break;
946 case SdwaSel::WORD_1
: O
<< "WORD_1"; break;
947 case SdwaSel::DWORD
: O
<< "DWORD"; break;
948 default: llvm_unreachable("Invalid SDWA data select operand");
952 void AMDGPUInstPrinter::printSDWADstSel(const MCInst
*MI
, unsigned OpNo
,
953 const MCSubtargetInfo
&STI
,
956 printSDWASel(MI
, OpNo
, O
);
959 void AMDGPUInstPrinter::printSDWASrc0Sel(const MCInst
*MI
, unsigned OpNo
,
960 const MCSubtargetInfo
&STI
,
963 printSDWASel(MI
, OpNo
, O
);
966 void AMDGPUInstPrinter::printSDWASrc1Sel(const MCInst
*MI
, unsigned OpNo
,
967 const MCSubtargetInfo
&STI
,
970 printSDWASel(MI
, OpNo
, O
);
973 void AMDGPUInstPrinter::printSDWADstUnused(const MCInst
*MI
, unsigned OpNo
,
974 const MCSubtargetInfo
&STI
,
976 using namespace llvm::AMDGPU::SDWA
;
979 unsigned Imm
= MI
->getOperand(OpNo
).getImm();
981 case DstUnused::UNUSED_PAD
: O
<< "UNUSED_PAD"; break;
982 case DstUnused::UNUSED_SEXT
: O
<< "UNUSED_SEXT"; break;
983 case DstUnused::UNUSED_PRESERVE
: O
<< "UNUSED_PRESERVE"; break;
984 default: llvm_unreachable("Invalid SDWA dest_unused operand");
988 void AMDGPUInstPrinter::printExpSrcN(const MCInst
*MI
, unsigned OpNo
,
989 const MCSubtargetInfo
&STI
, raw_ostream
&O
,
991 unsigned Opc
= MI
->getOpcode();
992 int EnIdx
= AMDGPU::getNamedOperandIdx(Opc
, AMDGPU::OpName::en
);
993 unsigned En
= MI
->getOperand(EnIdx
).getImm();
995 int ComprIdx
= AMDGPU::getNamedOperandIdx(Opc
, AMDGPU::OpName::compr
);
997 // If compr is set, print as src0, src0, src1, src1
998 if (MI
->getOperand(ComprIdx
).getImm())
999 OpNo
= OpNo
- N
+ N
/ 2;
1002 printRegOperand(MI
->getOperand(OpNo
).getReg(), O
, MRI
);
1007 void AMDGPUInstPrinter::printExpSrc0(const MCInst
*MI
, unsigned OpNo
,
1008 const MCSubtargetInfo
&STI
,
1010 printExpSrcN(MI
, OpNo
, STI
, O
, 0);
1013 void AMDGPUInstPrinter::printExpSrc1(const MCInst
*MI
, unsigned OpNo
,
1014 const MCSubtargetInfo
&STI
,
1016 printExpSrcN(MI
, OpNo
, STI
, O
, 1);
1019 void AMDGPUInstPrinter::printExpSrc2(const MCInst
*MI
, unsigned OpNo
,
1020 const MCSubtargetInfo
&STI
,
1022 printExpSrcN(MI
, OpNo
, STI
, O
, 2);
1025 void AMDGPUInstPrinter::printExpSrc3(const MCInst
*MI
, unsigned OpNo
,
1026 const MCSubtargetInfo
&STI
,
1028 printExpSrcN(MI
, OpNo
, STI
, O
, 3);
1031 void AMDGPUInstPrinter::printExpTgt(const MCInst
*MI
, unsigned OpNo
,
1032 const MCSubtargetInfo
&STI
,
1034 using namespace llvm::AMDGPU::Exp
;
1036 // This is really a 6 bit field.
1037 unsigned Id
= MI
->getOperand(OpNo
).getImm() & ((1 << 6) - 1);
1041 if (getTgtName(Id
, TgtName
, Index
) && isSupportedTgtId(Id
, STI
)) {
1042 O
<< ' ' << TgtName
;
1046 O
<< " invalid_target_" << Id
;
1050 static bool allOpsDefaultValue(const int* Ops
, int NumOps
, int Mod
,
1051 bool IsPacked
, bool HasDstSel
) {
1052 int DefaultValue
= IsPacked
&& (Mod
== SISrcMods::OP_SEL_1
);
1054 for (int I
= 0; I
< NumOps
; ++I
) {
1055 if (!!(Ops
[I
] & Mod
) != DefaultValue
)
1059 if (HasDstSel
&& (Ops
[0] & SISrcMods::DST_OP_SEL
) != 0)
1065 void AMDGPUInstPrinter::printPackedModifier(const MCInst
*MI
,
1069 unsigned Opc
= MI
->getOpcode();
1073 for (int OpName
: { AMDGPU::OpName::src0_modifiers
,
1074 AMDGPU::OpName::src1_modifiers
,
1075 AMDGPU::OpName::src2_modifiers
}) {
1076 int Idx
= AMDGPU::getNamedOperandIdx(Opc
, OpName
);
1080 Ops
[NumOps
++] = MI
->getOperand(Idx
).getImm();
1083 const bool HasDstSel
=
1085 Mod
== SISrcMods::OP_SEL_0
&&
1086 MII
.get(MI
->getOpcode()).TSFlags
& SIInstrFlags::VOP3_OPSEL
;
1088 const bool IsPacked
=
1089 MII
.get(MI
->getOpcode()).TSFlags
& SIInstrFlags::IsPacked
;
1091 if (allOpsDefaultValue(Ops
, NumOps
, Mod
, IsPacked
, HasDstSel
))
1095 for (int I
= 0; I
< NumOps
; ++I
) {
1099 O
<< !!(Ops
[I
] & Mod
);
1103 O
<< ',' << !!(Ops
[0] & SISrcMods::DST_OP_SEL
);
1109 void AMDGPUInstPrinter::printOpSel(const MCInst
*MI
, unsigned,
1110 const MCSubtargetInfo
&STI
,
1112 unsigned Opc
= MI
->getOpcode();
1113 if (Opc
== AMDGPU::V_PERMLANE16_B32_gfx10
||
1114 Opc
== AMDGPU::V_PERMLANEX16_B32_gfx10
) {
1115 auto FIN
= AMDGPU::getNamedOperandIdx(Opc
, AMDGPU::OpName::src0_modifiers
);
1116 auto BCN
= AMDGPU::getNamedOperandIdx(Opc
, AMDGPU::OpName::src1_modifiers
);
1117 unsigned FI
= !!(MI
->getOperand(FIN
).getImm() & SISrcMods::OP_SEL_0
);
1118 unsigned BC
= !!(MI
->getOperand(BCN
).getImm() & SISrcMods::OP_SEL_0
);
1120 O
<< " op_sel:[" << FI
<< ',' << BC
<< ']';
1124 printPackedModifier(MI
, " op_sel:[", SISrcMods::OP_SEL_0
, O
);
1127 void AMDGPUInstPrinter::printOpSelHi(const MCInst
*MI
, unsigned OpNo
,
1128 const MCSubtargetInfo
&STI
,
1130 printPackedModifier(MI
, " op_sel_hi:[", SISrcMods::OP_SEL_1
, O
);
1133 void AMDGPUInstPrinter::printNegLo(const MCInst
*MI
, unsigned OpNo
,
1134 const MCSubtargetInfo
&STI
,
1136 printPackedModifier(MI
, " neg_lo:[", SISrcMods::NEG
, O
);
1139 void AMDGPUInstPrinter::printNegHi(const MCInst
*MI
, unsigned OpNo
,
1140 const MCSubtargetInfo
&STI
,
1142 printPackedModifier(MI
, " neg_hi:[", SISrcMods::NEG_HI
, O
);
1145 void AMDGPUInstPrinter::printInterpSlot(const MCInst
*MI
, unsigned OpNum
,
1146 const MCSubtargetInfo
&STI
,
1148 unsigned Imm
= MI
->getOperand(OpNum
).getImm();
1160 O
<< "invalid_param_" << Imm
;
1164 void AMDGPUInstPrinter::printInterpAttr(const MCInst
*MI
, unsigned OpNum
,
1165 const MCSubtargetInfo
&STI
,
1167 unsigned Attr
= MI
->getOperand(OpNum
).getImm();
1168 O
<< "attr" << Attr
;
1171 void AMDGPUInstPrinter::printInterpAttrChan(const MCInst
*MI
, unsigned OpNum
,
1172 const MCSubtargetInfo
&STI
,
1174 unsigned Chan
= MI
->getOperand(OpNum
).getImm();
1175 O
<< '.' << "xyzw"[Chan
& 0x3];
1178 void AMDGPUInstPrinter::printVGPRIndexMode(const MCInst
*MI
, unsigned OpNo
,
1179 const MCSubtargetInfo
&STI
,
1181 using namespace llvm::AMDGPU::VGPRIndexMode
;
1182 unsigned Val
= MI
->getOperand(OpNo
).getImm();
1184 if ((Val
& ~ENABLE_MASK
) != 0) {
1185 O
<< formatHex(static_cast<uint64_t>(Val
));
1188 bool NeedComma
= false;
1189 for (unsigned ModeId
= ID_MIN
; ModeId
<= ID_MAX
; ++ModeId
) {
1190 if (Val
& (1 << ModeId
)) {
1193 O
<< IdSymbolic
[ModeId
];
1201 void AMDGPUInstPrinter::printMemOperand(const MCInst
*MI
, unsigned OpNo
,
1202 const MCSubtargetInfo
&STI
,
1204 printOperand(MI
, OpNo
, STI
, O
);
1206 printOperand(MI
, OpNo
+ 1, STI
, O
);
1209 void AMDGPUInstPrinter::printIfSet(const MCInst
*MI
, unsigned OpNo
,
1210 raw_ostream
&O
, StringRef Asm
,
1211 StringRef Default
) {
1212 const MCOperand
&Op
= MI
->getOperand(OpNo
);
1214 if (Op
.getImm() == 1) {
1221 void AMDGPUInstPrinter::printIfSet(const MCInst
*MI
, unsigned OpNo
,
1222 raw_ostream
&O
, char Asm
) {
1223 const MCOperand
&Op
= MI
->getOperand(OpNo
);
1225 if (Op
.getImm() == 1)
1229 void AMDGPUInstPrinter::printHigh(const MCInst
*MI
, unsigned OpNo
,
1230 const MCSubtargetInfo
&STI
,
1232 printNamedBit(MI
, OpNo
, O
, "high");
1235 void AMDGPUInstPrinter::printClampSI(const MCInst
*MI
, unsigned OpNo
,
1236 const MCSubtargetInfo
&STI
,
1238 printNamedBit(MI
, OpNo
, O
, "clamp");
1241 void AMDGPUInstPrinter::printOModSI(const MCInst
*MI
, unsigned OpNo
,
1242 const MCSubtargetInfo
&STI
,
1244 int Imm
= MI
->getOperand(OpNo
).getImm();
1245 if (Imm
== SIOutMods::MUL2
)
1247 else if (Imm
== SIOutMods::MUL4
)
1249 else if (Imm
== SIOutMods::DIV2
)
1253 void AMDGPUInstPrinter::printSendMsg(const MCInst
*MI
, unsigned OpNo
,
1254 const MCSubtargetInfo
&STI
,
1256 using namespace llvm::AMDGPU::SendMsg
;
1258 const unsigned Imm16
= MI
->getOperand(OpNo
).getImm();
1263 decodeMsg(Imm16
, MsgId
, OpId
, StreamId
);
1265 if (isValidMsgId(MsgId
, STI
) &&
1266 isValidMsgOp(MsgId
, OpId
, STI
) &&
1267 isValidMsgStream(MsgId
, OpId
, StreamId
, STI
)) {
1268 O
<< "sendmsg(" << getMsgName(MsgId
);
1269 if (msgRequiresOp(MsgId
)) {
1270 O
<< ", " << getMsgOpName(MsgId
, OpId
);
1271 if (msgSupportsStream(MsgId
, OpId
)) {
1272 O
<< ", " << StreamId
;
1276 } else if (encodeMsg(MsgId
, OpId
, StreamId
) == Imm16
) {
1277 O
<< "sendmsg(" << MsgId
<< ", " << OpId
<< ", " << StreamId
<< ')';
1279 O
<< Imm16
; // Unknown imm16 code.
1283 static void printSwizzleBitmask(const uint16_t AndMask
,
1284 const uint16_t OrMask
,
1285 const uint16_t XorMask
,
1287 using namespace llvm::AMDGPU::Swizzle
;
1289 uint16_t Probe0
= ((0 & AndMask
) | OrMask
) ^ XorMask
;
1290 uint16_t Probe1
= ((BITMASK_MASK
& AndMask
) | OrMask
) ^ XorMask
;
1294 for (unsigned Mask
= 1 << (BITMASK_WIDTH
- 1); Mask
> 0; Mask
>>= 1) {
1295 uint16_t p0
= Probe0
& Mask
;
1296 uint16_t p1
= Probe1
& Mask
;
1316 void AMDGPUInstPrinter::printSwizzle(const MCInst
*MI
, unsigned OpNo
,
1317 const MCSubtargetInfo
&STI
,
1319 using namespace llvm::AMDGPU::Swizzle
;
1321 uint16_t Imm
= MI
->getOperand(OpNo
).getImm();
1328 if ((Imm
& QUAD_PERM_ENC_MASK
) == QUAD_PERM_ENC
) {
1330 O
<< "swizzle(" << IdSymbolic
[ID_QUAD_PERM
];
1331 for (unsigned I
= 0; I
< LANE_NUM
; ++I
) {
1333 O
<< formatDec(Imm
& LANE_MASK
);
1338 } else if ((Imm
& BITMASK_PERM_ENC_MASK
) == BITMASK_PERM_ENC
) {
1340 uint16_t AndMask
= (Imm
>> BITMASK_AND_SHIFT
) & BITMASK_MASK
;
1341 uint16_t OrMask
= (Imm
>> BITMASK_OR_SHIFT
) & BITMASK_MASK
;
1342 uint16_t XorMask
= (Imm
>> BITMASK_XOR_SHIFT
) & BITMASK_MASK
;
1344 if (AndMask
== BITMASK_MAX
&&
1346 countPopulation(XorMask
) == 1) {
1348 O
<< "swizzle(" << IdSymbolic
[ID_SWAP
];
1350 O
<< formatDec(XorMask
);
1353 } else if (AndMask
== BITMASK_MAX
&&
1354 OrMask
== 0 && XorMask
> 0 &&
1355 isPowerOf2_64(XorMask
+ 1)) {
1357 O
<< "swizzle(" << IdSymbolic
[ID_REVERSE
];
1359 O
<< formatDec(XorMask
+ 1);
1364 uint16_t GroupSize
= BITMASK_MAX
- AndMask
+ 1;
1365 if (GroupSize
> 1 &&
1366 isPowerOf2_64(GroupSize
) &&
1367 OrMask
< GroupSize
&&
1370 O
<< "swizzle(" << IdSymbolic
[ID_BROADCAST
];
1372 O
<< formatDec(GroupSize
);
1374 O
<< formatDec(OrMask
);
1378 O
<< "swizzle(" << IdSymbolic
[ID_BITMASK_PERM
];
1380 printSwizzleBitmask(AndMask
, OrMask
, XorMask
, O
);
1385 printU16ImmDecOperand(MI
, OpNo
, O
);
1389 void AMDGPUInstPrinter::printWaitFlag(const MCInst
*MI
, unsigned OpNo
,
1390 const MCSubtargetInfo
&STI
,
1392 AMDGPU::IsaVersion ISA
= AMDGPU::getIsaVersion(STI
.getCPU());
1394 unsigned SImm16
= MI
->getOperand(OpNo
).getImm();
1395 unsigned Vmcnt
, Expcnt
, Lgkmcnt
;
1396 decodeWaitcnt(ISA
, SImm16
, Vmcnt
, Expcnt
, Lgkmcnt
);
1398 bool NeedSpace
= false;
1400 if (Vmcnt
!= getVmcntBitMask(ISA
)) {
1401 O
<< "vmcnt(" << Vmcnt
<< ')';
1405 if (Expcnt
!= getExpcntBitMask(ISA
)) {
1408 O
<< "expcnt(" << Expcnt
<< ')';
1412 if (Lgkmcnt
!= getLgkmcntBitMask(ISA
)) {
1415 O
<< "lgkmcnt(" << Lgkmcnt
<< ')';
1419 void AMDGPUInstPrinter::printHwreg(const MCInst
*MI
, unsigned OpNo
,
1420 const MCSubtargetInfo
&STI
, raw_ostream
&O
) {
1425 using namespace llvm::AMDGPU::Hwreg
;
1426 unsigned Val
= MI
->getOperand(OpNo
).getImm();
1427 decodeHwreg(Val
, Id
, Offset
, Width
);
1428 StringRef HwRegName
= getHwreg(Id
, STI
);
1431 if (!HwRegName
.empty()) {
1436 if (Width
!= WIDTH_DEFAULT_
|| Offset
!= OFFSET_DEFAULT_
) {
1437 O
<< ", " << Offset
<< ", " << Width
;
1442 void AMDGPUInstPrinter::printEndpgm(const MCInst
*MI
, unsigned OpNo
,
1443 const MCSubtargetInfo
&STI
,
1445 uint16_t Imm
= MI
->getOperand(OpNo
).getImm();
1450 O
<< ' ' << formatDec(Imm
);
1453 #include "AMDGPUGenAsmWriter.inc"
1455 void R600InstPrinter::printInst(const MCInst
*MI
, uint64_t Address
,
1456 StringRef Annot
, const MCSubtargetInfo
&STI
,
1459 printInstruction(MI
, Address
, O
);
1460 printAnnotation(O
, Annot
);
1463 void R600InstPrinter::printAbs(const MCInst
*MI
, unsigned OpNo
,
1465 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, '|');
1468 void R600InstPrinter::printBankSwizzle(const MCInst
*MI
, unsigned OpNo
,
1470 int BankSwizzle
= MI
->getOperand(OpNo
).getImm();
1471 switch (BankSwizzle
) {
1473 O
<< "BS:VEC_021/SCL_122";
1476 O
<< "BS:VEC_120/SCL_212";
1479 O
<< "BS:VEC_102/SCL_221";
1492 void R600InstPrinter::printClamp(const MCInst
*MI
, unsigned OpNo
,
1494 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, "_SAT");
1497 void R600InstPrinter::printCT(const MCInst
*MI
, unsigned OpNo
,
1499 unsigned CT
= MI
->getOperand(OpNo
).getImm();
1512 void R600InstPrinter::printKCache(const MCInst
*MI
, unsigned OpNo
,
1514 int KCacheMode
= MI
->getOperand(OpNo
).getImm();
1515 if (KCacheMode
> 0) {
1516 int KCacheBank
= MI
->getOperand(OpNo
- 2).getImm();
1517 O
<< "CB" << KCacheBank
<< ':';
1518 int KCacheAddr
= MI
->getOperand(OpNo
+ 2).getImm();
1519 int LineSize
= (KCacheMode
== 1) ? 16 : 32;
1520 O
<< KCacheAddr
* 16 << '-' << KCacheAddr
* 16 + LineSize
;
1524 void R600InstPrinter::printLast(const MCInst
*MI
, unsigned OpNo
,
1526 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, "*", " ");
1529 void R600InstPrinter::printLiteral(const MCInst
*MI
, unsigned OpNo
,
1531 const MCOperand
&Op
= MI
->getOperand(OpNo
);
1532 assert(Op
.isImm() || Op
.isExpr());
1534 int64_t Imm
= Op
.getImm();
1535 O
<< Imm
<< '(' << BitsToFloat(Imm
) << ')';
1538 Op
.getExpr()->print(O
<< '@', &MAI
);
1542 void R600InstPrinter::printNeg(const MCInst
*MI
, unsigned OpNo
,
1544 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, '-');
1547 void R600InstPrinter::printOMOD(const MCInst
*MI
, unsigned OpNo
,
1549 switch (MI
->getOperand(OpNo
).getImm()) {
1563 void R600InstPrinter::printMemOperand(const MCInst
*MI
, unsigned OpNo
,
1565 printOperand(MI
, OpNo
, O
);
1567 printOperand(MI
, OpNo
+ 1, O
);
1570 void R600InstPrinter::printOperand(const MCInst
*MI
, unsigned OpNo
,
1572 if (OpNo
>= MI
->getNumOperands()) {
1573 O
<< "/*Missing OP" << OpNo
<< "*/";
1577 const MCOperand
&Op
= MI
->getOperand(OpNo
);
1579 switch (Op
.getReg()) {
1580 // This is the default predicate state, so we don't need to print it.
1581 case R600::PRED_SEL_OFF
:
1585 O
<< getRegisterName(Op
.getReg());
1588 } else if (Op
.isImm()) {
1590 } else if (Op
.isDFPImm()) {
1591 // We special case 0.0 because otherwise it will be printed as an integer.
1592 if (Op
.getDFPImm() == 0.0)
1595 O
<< bit_cast
<double>(Op
.getDFPImm());
1597 } else if (Op
.isExpr()) {
1598 const MCExpr
*Exp
= Op
.getExpr();
1599 Exp
->print(O
, &MAI
);
1605 void R600InstPrinter::printRel(const MCInst
*MI
, unsigned OpNo
,
1607 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, '+');
1610 void R600InstPrinter::printRSel(const MCInst
*MI
, unsigned OpNo
,
1612 unsigned Sel
= MI
->getOperand(OpNo
).getImm();
1640 void R600InstPrinter::printUpdateExecMask(const MCInst
*MI
, unsigned OpNo
,
1642 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, "ExecMask,");
1645 void R600InstPrinter::printUpdatePred(const MCInst
*MI
, unsigned OpNo
,
1647 AMDGPUInstPrinter::printIfSet(MI
, OpNo
, O
, "Pred,");
1650 void R600InstPrinter::printWrite(const MCInst
*MI
, unsigned OpNo
,
1652 const MCOperand
&Op
= MI
->getOperand(OpNo
);
1653 if (Op
.getImm() == 0) {
1658 #include "R600GenAsmWriter.inc"