1e1818af8STom Stellard //===-- AMDGPUDisassembler.cpp - Disassembler for AMDGPU ISA --------------===//
2e1818af8STom Stellard //
3e1818af8STom Stellard //                     The LLVM Compiler Infrastructure
4e1818af8STom Stellard //
5e1818af8STom Stellard // This file is distributed under the University of Illinois Open Source
6e1818af8STom Stellard // License. See LICENSE.TXT for details.
7e1818af8STom Stellard //
8e1818af8STom Stellard //===----------------------------------------------------------------------===//
9e1818af8STom Stellard //
10e1818af8STom Stellard //===----------------------------------------------------------------------===//
11e1818af8STom Stellard //
12e1818af8STom Stellard /// \file
13e1818af8STom Stellard ///
14e1818af8STom Stellard /// This file contains definition for AMDGPU ISA disassembler
15e1818af8STom Stellard //
16e1818af8STom Stellard //===----------------------------------------------------------------------===//
17e1818af8STom Stellard 
18e1818af8STom Stellard // ToDo: What to do with instruction suffixes (v_mov_b32 vs v_mov_b32_e32)?
19e1818af8STom Stellard 
20e1818af8STom Stellard #include "AMDGPUDisassembler.h"
21e1818af8STom Stellard #include "AMDGPU.h"
22e1818af8STom Stellard #include "AMDGPURegisterInfo.h"
23e1818af8STom Stellard #include "Utils/AMDGPUBaseInfo.h"
24e1818af8STom Stellard 
25*ac106addSNikolay Haustov #include "llvm/MC/MCContext.h"
26e1818af8STom Stellard #include "llvm/MC/MCFixedLenDisassembler.h"
27e1818af8STom Stellard #include "llvm/MC/MCInst.h"
28e1818af8STom Stellard #include "llvm/MC/MCInstrDesc.h"
29e1818af8STom Stellard #include "llvm/MC/MCSubtargetInfo.h"
30*ac106addSNikolay Haustov #include "llvm/Support/Endian.h"
31e1818af8STom Stellard #include "llvm/Support/Debug.h"
32e1818af8STom Stellard #include "llvm/Support/TargetRegistry.h"
33e1818af8STom Stellard 
34e1818af8STom Stellard 
35e1818af8STom Stellard using namespace llvm;
36e1818af8STom Stellard 
37e1818af8STom Stellard #define DEBUG_TYPE "amdgpu-disassembler"
38e1818af8STom Stellard 
39e1818af8STom Stellard typedef llvm::MCDisassembler::DecodeStatus DecodeStatus;
40e1818af8STom Stellard 
41e1818af8STom Stellard 
42*ac106addSNikolay Haustov inline static MCDisassembler::DecodeStatus
43*ac106addSNikolay Haustov addOperand(MCInst &Inst, const MCOperand& Opnd) {
44*ac106addSNikolay Haustov   Inst.addOperand(Opnd);
45*ac106addSNikolay Haustov   return Opnd.isValid() ?
46*ac106addSNikolay Haustov     MCDisassembler::Success :
47*ac106addSNikolay Haustov     MCDisassembler::SoftFail;
48e1818af8STom Stellard }
49e1818af8STom Stellard 
50*ac106addSNikolay Haustov #define DECODE_OPERAND2(RegClass, DecName) \
51*ac106addSNikolay Haustov static DecodeStatus Decode##RegClass##RegisterClass(MCInst &Inst, \
52*ac106addSNikolay Haustov                                                     unsigned Imm, \
53*ac106addSNikolay Haustov                                                     uint64_t /*Addr*/, \
54*ac106addSNikolay Haustov                                                     const void *Decoder) { \
55*ac106addSNikolay Haustov   auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder); \
56*ac106addSNikolay Haustov   return addOperand(Inst, DAsm->decodeOperand_##DecName(Imm)); \
57e1818af8STom Stellard }
58e1818af8STom Stellard 
59*ac106addSNikolay Haustov #define DECODE_OPERAND(RegClass) DECODE_OPERAND2(RegClass, RegClass)
60e1818af8STom Stellard 
61*ac106addSNikolay Haustov DECODE_OPERAND(VGPR_32)
62*ac106addSNikolay Haustov DECODE_OPERAND(VS_32)
63*ac106addSNikolay Haustov DECODE_OPERAND(VS_64)
64e1818af8STom Stellard 
65*ac106addSNikolay Haustov DECODE_OPERAND(VReg_64)
66*ac106addSNikolay Haustov DECODE_OPERAND(VReg_96)
67*ac106addSNikolay Haustov DECODE_OPERAND(VReg_128)
68e1818af8STom Stellard 
69*ac106addSNikolay Haustov DECODE_OPERAND(SGPR_32)
70*ac106addSNikolay Haustov DECODE_OPERAND(SReg_32)
71*ac106addSNikolay Haustov DECODE_OPERAND(SReg_64)
72*ac106addSNikolay Haustov DECODE_OPERAND(SReg_128)
73*ac106addSNikolay Haustov DECODE_OPERAND(SReg_256)
74*ac106addSNikolay Haustov DECODE_OPERAND(SReg_512)
75e1818af8STom Stellard 
76e1818af8STom Stellard #define GET_SUBTARGETINFO_ENUM
77e1818af8STom Stellard #include "AMDGPUGenSubtargetInfo.inc"
78e1818af8STom Stellard #undef GET_SUBTARGETINFO_ENUM
79e1818af8STom Stellard 
80e1818af8STom Stellard #include "AMDGPUGenDisassemblerTables.inc"
81e1818af8STom Stellard 
82e1818af8STom Stellard //===----------------------------------------------------------------------===//
83e1818af8STom Stellard //
84e1818af8STom Stellard //===----------------------------------------------------------------------===//
85e1818af8STom Stellard 
86*ac106addSNikolay Haustov static inline uint32_t eatB32(ArrayRef<uint8_t>& Bytes) {
87*ac106addSNikolay Haustov   assert(Bytes.size() >= sizeof eatB32(Bytes));
88*ac106addSNikolay Haustov   const auto Res = support::endian::read32le(Bytes.data());
89*ac106addSNikolay Haustov   Bytes = Bytes.slice(sizeof Res);
90*ac106addSNikolay Haustov   return Res;
91*ac106addSNikolay Haustov }
92*ac106addSNikolay Haustov 
93*ac106addSNikolay Haustov DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t* Table,
94*ac106addSNikolay Haustov                                                MCInst &MI,
95*ac106addSNikolay Haustov                                                uint64_t Inst,
96*ac106addSNikolay Haustov                                                uint64_t Address) const {
97*ac106addSNikolay Haustov   assert(MI.getOpcode() == 0);
98*ac106addSNikolay Haustov   assert(MI.getNumOperands() == 0);
99*ac106addSNikolay Haustov   MCInst TmpInst;
100*ac106addSNikolay Haustov   const auto SavedBytes = Bytes;
101*ac106addSNikolay Haustov   if (decodeInstruction(Table, TmpInst, Inst, Address, this, STI)) {
102*ac106addSNikolay Haustov     MI = TmpInst;
103*ac106addSNikolay Haustov     return MCDisassembler::Success;
104*ac106addSNikolay Haustov   }
105*ac106addSNikolay Haustov   Bytes = SavedBytes;
106*ac106addSNikolay Haustov   return MCDisassembler::Fail;
107*ac106addSNikolay Haustov }
108*ac106addSNikolay Haustov 
109e1818af8STom Stellard DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
110*ac106addSNikolay Haustov                                                 ArrayRef<uint8_t> Bytes_,
111e1818af8STom Stellard                                                 uint64_t Address,
112e1818af8STom Stellard                                                 raw_ostream &WS,
113e1818af8STom Stellard                                                 raw_ostream &CS) const {
114e1818af8STom Stellard   CommentStream = &CS;
115e1818af8STom Stellard 
116e1818af8STom Stellard   // ToDo: AMDGPUDisassembler supports only VI ISA.
117e1818af8STom Stellard   assert(AMDGPU::isVI(STI) && "Can disassemble only VI ISA.");
118e1818af8STom Stellard 
119*ac106addSNikolay Haustov   const unsigned MaxInstBytesNum = (std::min)((size_t)8, Bytes_.size());
120*ac106addSNikolay Haustov   Bytes = Bytes_.slice(0, MaxInstBytesNum);
121161a158eSNikolay Haustov 
122*ac106addSNikolay Haustov   DecodeStatus Res = MCDisassembler::Fail;
123*ac106addSNikolay Haustov   do {
124*ac106addSNikolay Haustov     // ToDo: better to switch enc len using some bit predicate
125*ac106addSNikolay Haustov     // but it is unknown yet, so try all we can
126*ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
127*ac106addSNikolay Haustov     const uint32_t DW = eatB32(Bytes);
128*ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI32, MI, DW, Address);
129*ac106addSNikolay Haustov     if (Res) break;
130e1818af8STom Stellard 
131*ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU32, MI, DW, Address);
132*ac106addSNikolay Haustov     if (Res) break;
133*ac106addSNikolay Haustov 
134*ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
135*ac106addSNikolay Haustov     const uint64_t QW = ((uint64_t)eatB32(Bytes) << 32) | DW;
136*ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI64, MI, QW, Address);
137*ac106addSNikolay Haustov     if (Res) break;
138*ac106addSNikolay Haustov 
139*ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address);
140*ac106addSNikolay Haustov   } while (false);
141*ac106addSNikolay Haustov 
142*ac106addSNikolay Haustov   Size = Res ? (MaxInstBytesNum - Bytes.size()) : 0;
143*ac106addSNikolay Haustov   return Res;
144161a158eSNikolay Haustov }
145e1818af8STom Stellard 
146*ac106addSNikolay Haustov const char* AMDGPUDisassembler::getRegClassName(unsigned RegClassID) const {
147*ac106addSNikolay Haustov   return getContext().getRegisterInfo()->
148*ac106addSNikolay Haustov     getRegClassName(&AMDGPUMCRegisterClasses[RegClassID]);
149e1818af8STom Stellard }
150e1818af8STom Stellard 
151*ac106addSNikolay Haustov inline
152*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::errOperand(unsigned V,
153*ac106addSNikolay Haustov                                          const Twine& ErrMsg) const {
154*ac106addSNikolay Haustov   *CommentStream << "Error: " + ErrMsg;
155*ac106addSNikolay Haustov 
156*ac106addSNikolay Haustov   // ToDo: add support for error operands to MCInst.h
157*ac106addSNikolay Haustov   // return MCOperand::createError(V);
158*ac106addSNikolay Haustov   return MCOperand();
159*ac106addSNikolay Haustov }
160*ac106addSNikolay Haustov 
161*ac106addSNikolay Haustov inline
162*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned int RegId) const {
163*ac106addSNikolay Haustov   return MCOperand::createReg(RegId);
164*ac106addSNikolay Haustov }
165*ac106addSNikolay Haustov 
166*ac106addSNikolay Haustov inline
167*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned RegClassID,
168*ac106addSNikolay Haustov                                                unsigned Val) const {
169*ac106addSNikolay Haustov   const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
170*ac106addSNikolay Haustov   if (Val >= RegCl.getNumRegs())
171*ac106addSNikolay Haustov     return errOperand(Val, Twine(getRegClassName(RegClassID)) +
172*ac106addSNikolay Haustov                            ": unknown register " + Twine(Val));
173*ac106addSNikolay Haustov   return createRegOperand(RegCl.getRegister(Val));
174*ac106addSNikolay Haustov }
175*ac106addSNikolay Haustov 
176*ac106addSNikolay Haustov inline
177*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createSRegOperand(unsigned SRegClassID,
178*ac106addSNikolay Haustov                                                 unsigned Val) const {
179*ac106addSNikolay Haustov   // ToDo: SI/CI have 104 SGPRs, VI - 102
180*ac106addSNikolay Haustov   // Valery: here we accepting as much as we can, let assembler sort it out
181*ac106addSNikolay Haustov   int shift = 0;
182*ac106addSNikolay Haustov   switch (SRegClassID) {
183*ac106addSNikolay Haustov   case AMDGPU::SGPR_32RegClassID:
184*ac106addSNikolay Haustov   case AMDGPU::SReg_32RegClassID: break;
185*ac106addSNikolay Haustov   case AMDGPU::SGPR_64RegClassID:
186*ac106addSNikolay Haustov   case AMDGPU::SReg_64RegClassID:  shift = 1; break;
187*ac106addSNikolay Haustov   case AMDGPU::SReg_128RegClassID:
188*ac106addSNikolay Haustov   // ToDo: unclear if s[100:104] is available on VI. Can we use VCC as SGPR in
189*ac106addSNikolay Haustov   // this bundle?
190*ac106addSNikolay Haustov   case AMDGPU::SReg_256RegClassID:
191*ac106addSNikolay Haustov   // ToDo: unclear if s[96:104] is available on VI. Can we use VCC as SGPR in
192*ac106addSNikolay Haustov   // this bundle?
193*ac106addSNikolay Haustov   case AMDGPU::SReg_512RegClassID: shift = 2; break;
194*ac106addSNikolay Haustov   // ToDo: unclear if s[88:104] is available on VI. Can we use VCC as SGPR in
195*ac106addSNikolay Haustov   // this bundle?
196*ac106addSNikolay Haustov   default: assert(false); break;
197*ac106addSNikolay Haustov   }
198*ac106addSNikolay Haustov   if (Val % (1 << shift))
199*ac106addSNikolay Haustov     *CommentStream << "Warning: " << getRegClassName(SRegClassID)
200*ac106addSNikolay Haustov                    << ": scalar reg isn't aligned " << Val;
201*ac106addSNikolay Haustov   return createRegOperand(SRegClassID, Val >> shift);
202*ac106addSNikolay Haustov }
203*ac106addSNikolay Haustov 
204*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_32(unsigned Val) const {
205*ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
206*ac106addSNikolay Haustov }
207*ac106addSNikolay Haustov 
208*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_64(unsigned Val) const {
209*ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
210*ac106addSNikolay Haustov }
211*ac106addSNikolay Haustov 
212*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VGPR_32(unsigned Val) const {
213*ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VGPR_32RegClassID, Val);
214*ac106addSNikolay Haustov }
215*ac106addSNikolay Haustov 
216*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_64(unsigned Val) const {
217*ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_64RegClassID, Val);
218*ac106addSNikolay Haustov }
219*ac106addSNikolay Haustov 
220*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_96(unsigned Val) const {
221*ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_96RegClassID, Val);
222*ac106addSNikolay Haustov }
223*ac106addSNikolay Haustov 
224*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_128(unsigned Val) const {
225*ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_128RegClassID, Val);
226*ac106addSNikolay Haustov }
227*ac106addSNikolay Haustov 
228*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SGPR_32(unsigned Val) const {
229*ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SGPR_32RegClassID, Val);
230*ac106addSNikolay Haustov }
231*ac106addSNikolay Haustov 
232*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_32(unsigned Val) const {
233*ac106addSNikolay Haustov   // table-gen generated disassembler doesn't care about operand types
234*ac106addSNikolay Haustov   // leaving only registry class so SSrc_32 operand turns into SReg_32
235*ac106addSNikolay Haustov   // and therefore we accept immediates and literals here as well
236*ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
237*ac106addSNikolay Haustov }
238*ac106addSNikolay Haustov 
239*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_64(unsigned Val) const {
240*ac106addSNikolay Haustov   // see decodeOperand_SReg_32 comment
241*ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
242*ac106addSNikolay Haustov }
243*ac106addSNikolay Haustov 
244*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_128(unsigned Val) const {
245*ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_128RegClassID, Val);
246*ac106addSNikolay Haustov }
247*ac106addSNikolay Haustov 
248*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_256(unsigned Val) const {
249*ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_256RegClassID, Val);
250*ac106addSNikolay Haustov }
251*ac106addSNikolay Haustov 
252*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_512(unsigned Val) const {
253*ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_512RegClassID, Val);
254*ac106addSNikolay Haustov }
255*ac106addSNikolay Haustov 
256*ac106addSNikolay Haustov 
257*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
258*ac106addSNikolay Haustov   // For now all literal constants are supposed to be unsigned integer
259*ac106addSNikolay Haustov   // ToDo: deal with signed/unsigned 64-bit integer constants
260*ac106addSNikolay Haustov   // ToDo: deal with float/double constants
261*ac106addSNikolay Haustov   if (Bytes.size() < 4)
262*ac106addSNikolay Haustov     return errOperand(0, "cannot read literal, inst bytes left " +
263*ac106addSNikolay Haustov                          Twine(Bytes.size()));
264*ac106addSNikolay Haustov   return MCOperand::createImm(eatB32(Bytes));
265*ac106addSNikolay Haustov }
266*ac106addSNikolay Haustov 
267*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeIntImmed(unsigned Imm) {
268*ac106addSNikolay Haustov   assert(Imm >= 128 && Imm <= 208);
269*ac106addSNikolay Haustov   return MCOperand::createImm((Imm <= 192) ? (Imm - 128) : (192 - Imm));
270*ac106addSNikolay Haustov }
271*ac106addSNikolay Haustov 
272*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeFPImmed(bool Is32, unsigned Imm) {
273*ac106addSNikolay Haustov   assert(Imm >= 240 && Imm <= 248);
274e1818af8STom Stellard   // ToDo: case 248: 1/(2*PI) - is allowed only on VI
275e1818af8STom Stellard   // ToDo: AMDGPUInstPrinter does not support 1/(2*PI). It consider 1/(2*PI) as
276e1818af8STom Stellard   // literal constant.
277*ac106addSNikolay Haustov   float V = 0.0f;
278e1818af8STom Stellard   switch (Imm) {
279*ac106addSNikolay Haustov   case 240: V =  0.5f; break;
280*ac106addSNikolay Haustov   case 241: V = -0.5f; break;
281*ac106addSNikolay Haustov   case 242: V =  1.0f; break;
282*ac106addSNikolay Haustov   case 243: V = -1.0f; break;
283*ac106addSNikolay Haustov   case 244: V =  2.0f; break;
284*ac106addSNikolay Haustov   case 245: V = -2.0f; break;
285*ac106addSNikolay Haustov   case 246: V =  4.0f; break;
286*ac106addSNikolay Haustov   case 247: V = -4.0f; break;
287*ac106addSNikolay Haustov   case 248: return MCOperand::createImm(Is32 ?         // 1/(2*PI)
288*ac106addSNikolay Haustov                                           0x3e22f983 :
289*ac106addSNikolay Haustov                                           0x3fc45f306dc9c882);
290*ac106addSNikolay Haustov   default: break;
291e1818af8STom Stellard   }
292*ac106addSNikolay Haustov   return MCOperand::createImm(Is32? FloatToBits(V) : DoubleToBits(V));
293e1818af8STom Stellard }
294e1818af8STom Stellard 
295*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSrcOp(bool Is32, unsigned Val) const {
296e1818af8STom Stellard   using namespace AMDGPU;
297*ac106addSNikolay Haustov   assert(Val < 512); // enum9
298*ac106addSNikolay Haustov 
299*ac106addSNikolay Haustov   if (Val >= 256)
300*ac106addSNikolay Haustov     return createRegOperand(Is32 ? VGPR_32RegClassID : VReg_64RegClassID,
301*ac106addSNikolay Haustov                             Val - 256);
302*ac106addSNikolay Haustov   if (Val <= 101)
303*ac106addSNikolay Haustov     return createSRegOperand(Is32 ? SGPR_32RegClassID : SGPR_64RegClassID,
304*ac106addSNikolay Haustov                              Val);
305*ac106addSNikolay Haustov 
306*ac106addSNikolay Haustov   if (Val >= 128 && Val <= 208)
307*ac106addSNikolay Haustov     return decodeIntImmed(Val);
308*ac106addSNikolay Haustov 
309*ac106addSNikolay Haustov   if (Val >= 240 && Val <= 248)
310*ac106addSNikolay Haustov     return decodeFPImmed(Is32, Val);
311*ac106addSNikolay Haustov 
312*ac106addSNikolay Haustov   if (Val == 255)
313*ac106addSNikolay Haustov     return decodeLiteralConstant();
314*ac106addSNikolay Haustov 
315*ac106addSNikolay Haustov   return Is32 ? decodeSpecialReg32(Val) : decodeSpecialReg64(Val);
316*ac106addSNikolay Haustov }
317*ac106addSNikolay Haustov 
318*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg32(unsigned Val) const {
319*ac106addSNikolay Haustov   using namespace AMDGPU;
320e1818af8STom Stellard   switch (Val) {
321*ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR_LO, STI));
322*ac106addSNikolay Haustov   case 103: return createRegOperand(getMCReg(FLAT_SCR_HI, STI));
323e1818af8STom Stellard     // ToDo: no support for xnack_mask_lo/_hi register
324e1818af8STom Stellard   case 104:
325*ac106addSNikolay Haustov   case 105: break;
326*ac106addSNikolay Haustov   case 106: return createRegOperand(VCC_LO);
327*ac106addSNikolay Haustov   case 107: return createRegOperand(VCC_HI);
328e1818af8STom Stellard     // ToDo: no support for tba_lo/_hi register
329e1818af8STom Stellard   case 108:
330*ac106addSNikolay Haustov   case 109: break;
331e1818af8STom Stellard     // ToDo: no support for tma_lo/_hi register
332e1818af8STom Stellard   case 110:
333*ac106addSNikolay Haustov   case 111: break;
334e1818af8STom Stellard     // ToDo: no support for ttmp[0:11] register
335e1818af8STom Stellard   case 112:
336e1818af8STom Stellard   case 113:
337e1818af8STom Stellard   case 114:
338e1818af8STom Stellard   case 115:
339e1818af8STom Stellard   case 116:
340e1818af8STom Stellard   case 117:
341e1818af8STom Stellard   case 118:
342e1818af8STom Stellard   case 119:
343e1818af8STom Stellard   case 120:
344e1818af8STom Stellard   case 121:
345e1818af8STom Stellard   case 122:
346*ac106addSNikolay Haustov   case 123: break;
347*ac106addSNikolay Haustov   case 124: return createRegOperand(M0);
348*ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC_LO);
349*ac106addSNikolay Haustov   case 127: return createRegOperand(EXEC_HI);
350e1818af8STom Stellard     // ToDo: no support for vccz register
351*ac106addSNikolay Haustov   case 251: break;
352e1818af8STom Stellard     // ToDo: no support for execz register
353*ac106addSNikolay Haustov   case 252: break;
354*ac106addSNikolay Haustov   case 253: return createRegOperand(SCC);
355*ac106addSNikolay Haustov   default: break;
356e1818af8STom Stellard   }
357*ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
358e1818af8STom Stellard }
359e1818af8STom Stellard 
360*ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg64(unsigned Val) const {
361161a158eSNikolay Haustov   using namespace AMDGPU;
362161a158eSNikolay Haustov   switch (Val) {
363*ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR, STI));
364*ac106addSNikolay Haustov   case 106: return createRegOperand(VCC);
365*ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC);
366*ac106addSNikolay Haustov   default: break;
367161a158eSNikolay Haustov   }
368*ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
369161a158eSNikolay Haustov }
370161a158eSNikolay Haustov 
371e1818af8STom Stellard static MCDisassembler *createAMDGPUDisassembler(const Target &T,
372e1818af8STom Stellard                                                 const MCSubtargetInfo &STI,
373e1818af8STom Stellard                                                 MCContext &Ctx) {
374e1818af8STom Stellard   return new AMDGPUDisassembler(STI, Ctx);
375e1818af8STom Stellard }
376e1818af8STom Stellard 
377e1818af8STom Stellard extern "C" void LLVMInitializeAMDGPUDisassembler() {
378e1818af8STom Stellard   TargetRegistry::RegisterMCDisassembler(TheGCNTarget, createAMDGPUDisassembler);
379e1818af8STom Stellard }
380