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 
25ac106addSNikolay 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"
30ac106addSNikolay 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 
42ac106addSNikolay Haustov inline static MCDisassembler::DecodeStatus
43ac106addSNikolay Haustov addOperand(MCInst &Inst, const MCOperand& Opnd) {
44ac106addSNikolay Haustov   Inst.addOperand(Opnd);
45ac106addSNikolay Haustov   return Opnd.isValid() ?
46ac106addSNikolay Haustov     MCDisassembler::Success :
47ac106addSNikolay Haustov     MCDisassembler::SoftFail;
48e1818af8STom Stellard }
49e1818af8STom Stellard 
50ac106addSNikolay Haustov #define DECODE_OPERAND2(RegClass, DecName) \
51ac106addSNikolay Haustov static DecodeStatus Decode##RegClass##RegisterClass(MCInst &Inst, \
52ac106addSNikolay Haustov                                                     unsigned Imm, \
53ac106addSNikolay Haustov                                                     uint64_t /*Addr*/, \
54ac106addSNikolay Haustov                                                     const void *Decoder) { \
55ac106addSNikolay Haustov   auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder); \
56ac106addSNikolay Haustov   return addOperand(Inst, DAsm->decodeOperand_##DecName(Imm)); \
57e1818af8STom Stellard }
58e1818af8STom Stellard 
59ac106addSNikolay Haustov #define DECODE_OPERAND(RegClass) DECODE_OPERAND2(RegClass, RegClass)
60e1818af8STom Stellard 
61ac106addSNikolay Haustov DECODE_OPERAND(VGPR_32)
62ac106addSNikolay Haustov DECODE_OPERAND(VS_32)
63ac106addSNikolay Haustov DECODE_OPERAND(VS_64)
64e1818af8STom Stellard 
65ac106addSNikolay Haustov DECODE_OPERAND(VReg_64)
66ac106addSNikolay Haustov DECODE_OPERAND(VReg_96)
67ac106addSNikolay Haustov DECODE_OPERAND(VReg_128)
68e1818af8STom Stellard 
69ac106addSNikolay Haustov DECODE_OPERAND(SReg_32)
70*38e496b1SArtem Tamazov DECODE_OPERAND(SReg_32_XM0)
71ac106addSNikolay Haustov DECODE_OPERAND(SReg_64)
72ac106addSNikolay Haustov DECODE_OPERAND(SReg_128)
73ac106addSNikolay Haustov DECODE_OPERAND(SReg_256)
74a4db224dSValery Pykhtin 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 
861048fb18SSam Kolton template <typename T> static inline T eatBytes(ArrayRef<uint8_t>& Bytes) {
871048fb18SSam Kolton   assert(Bytes.size() >= sizeof(T));
881048fb18SSam Kolton   const auto Res = support::endian::read<T, support::endianness::little>(Bytes.data());
891048fb18SSam Kolton   Bytes = Bytes.slice(sizeof(T));
90ac106addSNikolay Haustov   return Res;
91ac106addSNikolay Haustov }
92ac106addSNikolay Haustov 
93ac106addSNikolay Haustov DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t* Table,
94ac106addSNikolay Haustov                                                MCInst &MI,
95ac106addSNikolay Haustov                                                uint64_t Inst,
96ac106addSNikolay Haustov                                                uint64_t Address) const {
97ac106addSNikolay Haustov   assert(MI.getOpcode() == 0);
98ac106addSNikolay Haustov   assert(MI.getNumOperands() == 0);
99ac106addSNikolay Haustov   MCInst TmpInst;
100ac106addSNikolay Haustov   const auto SavedBytes = Bytes;
101ac106addSNikolay Haustov   if (decodeInstruction(Table, TmpInst, Inst, Address, this, STI)) {
102ac106addSNikolay Haustov     MI = TmpInst;
103ac106addSNikolay Haustov     return MCDisassembler::Success;
104ac106addSNikolay Haustov   }
105ac106addSNikolay Haustov   Bytes = SavedBytes;
106ac106addSNikolay Haustov   return MCDisassembler::Fail;
107ac106addSNikolay Haustov }
108ac106addSNikolay Haustov 
109e1818af8STom Stellard DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
110ac106addSNikolay 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 
119ac106addSNikolay Haustov   const unsigned MaxInstBytesNum = (std::min)((size_t)8, Bytes_.size());
120ac106addSNikolay Haustov   Bytes = Bytes_.slice(0, MaxInstBytesNum);
121161a158eSNikolay Haustov 
122ac106addSNikolay Haustov   DecodeStatus Res = MCDisassembler::Fail;
123ac106addSNikolay Haustov   do {
124824e804bSValery Pykhtin     // ToDo: better to switch encoding length using some bit predicate
125ac106addSNikolay Haustov     // but it is unknown yet, so try all we can
1261048fb18SSam Kolton 
1271048fb18SSam Kolton     // Try to decode DPP first to solve conflict with VOP1 and VOP2 encodings
1281048fb18SSam Kolton     if (Bytes.size() >= 8) {
1291048fb18SSam Kolton       const uint64_t QW = eatBytes<uint64_t>(Bytes);
1301048fb18SSam Kolton       Res = tryDecodeInst(DecoderTableDPP64, MI, QW, Address);
1311048fb18SSam Kolton       if (Res) break;
1321048fb18SSam Kolton     }
1331048fb18SSam Kolton 
1341048fb18SSam Kolton     // Reinitialize Bytes as DPP64 could have eaten too much
1351048fb18SSam Kolton     Bytes = Bytes_.slice(0, MaxInstBytesNum);
1361048fb18SSam Kolton 
1371048fb18SSam Kolton     // Try decode 32-bit instruction
138ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
1391048fb18SSam Kolton     const uint32_t DW = eatBytes<uint32_t>(Bytes);
140ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI32, MI, DW, Address);
141ac106addSNikolay Haustov     if (Res) break;
142e1818af8STom Stellard 
143ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU32, MI, DW, Address);
144ac106addSNikolay Haustov     if (Res) break;
145ac106addSNikolay Haustov 
146ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
1471048fb18SSam Kolton     const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
148ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI64, MI, QW, Address);
149ac106addSNikolay Haustov     if (Res) break;
150ac106addSNikolay Haustov 
151ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address);
152ac106addSNikolay Haustov   } while (false);
153ac106addSNikolay Haustov 
154ac106addSNikolay Haustov   Size = Res ? (MaxInstBytesNum - Bytes.size()) : 0;
155ac106addSNikolay Haustov   return Res;
156161a158eSNikolay Haustov }
157e1818af8STom Stellard 
158ac106addSNikolay Haustov const char* AMDGPUDisassembler::getRegClassName(unsigned RegClassID) const {
159ac106addSNikolay Haustov   return getContext().getRegisterInfo()->
160ac106addSNikolay Haustov     getRegClassName(&AMDGPUMCRegisterClasses[RegClassID]);
161e1818af8STom Stellard }
162e1818af8STom Stellard 
163ac106addSNikolay Haustov inline
164ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::errOperand(unsigned V,
165ac106addSNikolay Haustov                                          const Twine& ErrMsg) const {
166ac106addSNikolay Haustov   *CommentStream << "Error: " + ErrMsg;
167ac106addSNikolay Haustov 
168ac106addSNikolay Haustov   // ToDo: add support for error operands to MCInst.h
169ac106addSNikolay Haustov   // return MCOperand::createError(V);
170ac106addSNikolay Haustov   return MCOperand();
171ac106addSNikolay Haustov }
172ac106addSNikolay Haustov 
173ac106addSNikolay Haustov inline
174ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned int RegId) const {
175ac106addSNikolay Haustov   return MCOperand::createReg(RegId);
176ac106addSNikolay Haustov }
177ac106addSNikolay Haustov 
178ac106addSNikolay Haustov inline
179ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned RegClassID,
180ac106addSNikolay Haustov                                                unsigned Val) const {
181ac106addSNikolay Haustov   const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
182ac106addSNikolay Haustov   if (Val >= RegCl.getNumRegs())
183ac106addSNikolay Haustov     return errOperand(Val, Twine(getRegClassName(RegClassID)) +
184ac106addSNikolay Haustov                            ": unknown register " + Twine(Val));
185ac106addSNikolay Haustov   return createRegOperand(RegCl.getRegister(Val));
186ac106addSNikolay Haustov }
187ac106addSNikolay Haustov 
188ac106addSNikolay Haustov inline
189ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createSRegOperand(unsigned SRegClassID,
190ac106addSNikolay Haustov                                                 unsigned Val) const {
191ac106addSNikolay Haustov   // ToDo: SI/CI have 104 SGPRs, VI - 102
192ac106addSNikolay Haustov   // Valery: here we accepting as much as we can, let assembler sort it out
193ac106addSNikolay Haustov   int shift = 0;
194ac106addSNikolay Haustov   switch (SRegClassID) {
195ac106addSNikolay Haustov   case AMDGPU::SGPR_32RegClassID:
196ac106addSNikolay Haustov   case AMDGPU::SReg_32RegClassID: break;
197ac106addSNikolay Haustov   case AMDGPU::SGPR_64RegClassID:
198ac106addSNikolay Haustov   case AMDGPU::SReg_64RegClassID:  shift = 1; break;
199ac106addSNikolay Haustov   case AMDGPU::SReg_128RegClassID:
200ac106addSNikolay Haustov   // ToDo: unclear if s[100:104] is available on VI. Can we use VCC as SGPR in
201ac106addSNikolay Haustov   // this bundle?
202ac106addSNikolay Haustov   case AMDGPU::SReg_256RegClassID:
203ac106addSNikolay Haustov   // ToDo: unclear if s[96:104] is available on VI. Can we use VCC as SGPR in
204ac106addSNikolay Haustov   // this bundle?
205ac106addSNikolay Haustov   case AMDGPU::SReg_512RegClassID: shift = 2; break;
206ac106addSNikolay Haustov   // ToDo: unclear if s[88:104] is available on VI. Can we use VCC as SGPR in
207ac106addSNikolay Haustov   // this bundle?
208ac106addSNikolay Haustov   default: assert(false); break;
209ac106addSNikolay Haustov   }
210ac106addSNikolay Haustov   if (Val % (1 << shift))
211ac106addSNikolay Haustov     *CommentStream << "Warning: " << getRegClassName(SRegClassID)
212ac106addSNikolay Haustov                    << ": scalar reg isn't aligned " << Val;
213ac106addSNikolay Haustov   return createRegOperand(SRegClassID, Val >> shift);
214ac106addSNikolay Haustov }
215ac106addSNikolay Haustov 
216ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_32(unsigned Val) const {
217ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
218ac106addSNikolay Haustov }
219ac106addSNikolay Haustov 
220ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_64(unsigned Val) const {
221ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
222ac106addSNikolay Haustov }
223ac106addSNikolay Haustov 
224ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VGPR_32(unsigned Val) const {
225ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VGPR_32RegClassID, Val);
226ac106addSNikolay Haustov }
227ac106addSNikolay Haustov 
228ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_64(unsigned Val) const {
229ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_64RegClassID, Val);
230ac106addSNikolay Haustov }
231ac106addSNikolay Haustov 
232ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_96(unsigned Val) const {
233ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_96RegClassID, Val);
234ac106addSNikolay Haustov }
235ac106addSNikolay Haustov 
236ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_128(unsigned Val) const {
237ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_128RegClassID, Val);
238ac106addSNikolay Haustov }
239ac106addSNikolay Haustov 
240ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_32(unsigned Val) const {
241ac106addSNikolay Haustov   // table-gen generated disassembler doesn't care about operand types
242ac106addSNikolay Haustov   // leaving only registry class so SSrc_32 operand turns into SReg_32
243ac106addSNikolay Haustov   // and therefore we accept immediates and literals here as well
244ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
245ac106addSNikolay Haustov }
246ac106addSNikolay Haustov 
247*38e496b1SArtem Tamazov MCOperand AMDGPUDisassembler::decodeOperand_SReg_32_XM0(unsigned Val) const {
248*38e496b1SArtem Tamazov   // SReg_32_XM0 is SReg_32 without M0
249*38e496b1SArtem Tamazov   return decodeOperand_SReg_32(Val);
250*38e496b1SArtem Tamazov }
251*38e496b1SArtem Tamazov 
252ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_64(unsigned Val) const {
253ac106addSNikolay Haustov   // see decodeOperand_SReg_32 comment
254ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
255ac106addSNikolay Haustov }
256ac106addSNikolay Haustov 
257ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_128(unsigned Val) const {
258ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_128RegClassID, Val);
259ac106addSNikolay Haustov }
260ac106addSNikolay Haustov 
261ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_256(unsigned Val) const {
262ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_256RegClassID, Val);
263ac106addSNikolay Haustov }
264ac106addSNikolay Haustov 
265ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_512(unsigned Val) const {
266ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_512RegClassID, Val);
267ac106addSNikolay Haustov }
268ac106addSNikolay Haustov 
269ac106addSNikolay Haustov 
270ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
271ac106addSNikolay Haustov   // For now all literal constants are supposed to be unsigned integer
272ac106addSNikolay Haustov   // ToDo: deal with signed/unsigned 64-bit integer constants
273ac106addSNikolay Haustov   // ToDo: deal with float/double constants
274ac106addSNikolay Haustov   if (Bytes.size() < 4)
275ac106addSNikolay Haustov     return errOperand(0, "cannot read literal, inst bytes left " +
276ac106addSNikolay Haustov                          Twine(Bytes.size()));
2771048fb18SSam Kolton   return MCOperand::createImm(eatBytes<uint32_t>(Bytes));
278ac106addSNikolay Haustov }
279ac106addSNikolay Haustov 
280ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeIntImmed(unsigned Imm) {
281ac106addSNikolay Haustov   assert(Imm >= 128 && Imm <= 208);
282ac106addSNikolay Haustov   return MCOperand::createImm((Imm <= 192) ? (Imm - 128) : (192 - Imm));
283ac106addSNikolay Haustov }
284ac106addSNikolay Haustov 
285ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeFPImmed(bool Is32, unsigned Imm) {
286ac106addSNikolay Haustov   assert(Imm >= 240 && Imm <= 248);
287e1818af8STom Stellard   // ToDo: case 248: 1/(2*PI) - is allowed only on VI
288e1818af8STom Stellard   // ToDo: AMDGPUInstPrinter does not support 1/(2*PI). It consider 1/(2*PI) as
289e1818af8STom Stellard   // literal constant.
290ac106addSNikolay Haustov   float V = 0.0f;
291e1818af8STom Stellard   switch (Imm) {
292ac106addSNikolay Haustov   case 240: V =  0.5f; break;
293ac106addSNikolay Haustov   case 241: V = -0.5f; break;
294ac106addSNikolay Haustov   case 242: V =  1.0f; break;
295ac106addSNikolay Haustov   case 243: V = -1.0f; break;
296ac106addSNikolay Haustov   case 244: V =  2.0f; break;
297ac106addSNikolay Haustov   case 245: V = -2.0f; break;
298ac106addSNikolay Haustov   case 246: V =  4.0f; break;
299ac106addSNikolay Haustov   case 247: V = -4.0f; break;
300ac106addSNikolay Haustov   case 248: return MCOperand::createImm(Is32 ?         // 1/(2*PI)
301ac106addSNikolay Haustov                                           0x3e22f983 :
302ac106addSNikolay Haustov                                           0x3fc45f306dc9c882);
303ac106addSNikolay Haustov   default: break;
304e1818af8STom Stellard   }
305ac106addSNikolay Haustov   return MCOperand::createImm(Is32? FloatToBits(V) : DoubleToBits(V));
306e1818af8STom Stellard }
307e1818af8STom Stellard 
308ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSrcOp(bool Is32, unsigned Val) const {
309e1818af8STom Stellard   using namespace AMDGPU;
310ac106addSNikolay Haustov   assert(Val < 512); // enum9
311ac106addSNikolay Haustov 
312ac106addSNikolay Haustov   if (Val >= 256)
313ac106addSNikolay Haustov     return createRegOperand(Is32 ? VGPR_32RegClassID : VReg_64RegClassID,
314ac106addSNikolay Haustov                             Val - 256);
315ac106addSNikolay Haustov   if (Val <= 101)
316ac106addSNikolay Haustov     return createSRegOperand(Is32 ? SGPR_32RegClassID : SGPR_64RegClassID,
317ac106addSNikolay Haustov                              Val);
318ac106addSNikolay Haustov 
319ac106addSNikolay Haustov   if (Val >= 128 && Val <= 208)
320ac106addSNikolay Haustov     return decodeIntImmed(Val);
321ac106addSNikolay Haustov 
322ac106addSNikolay Haustov   if (Val >= 240 && Val <= 248)
323ac106addSNikolay Haustov     return decodeFPImmed(Is32, Val);
324ac106addSNikolay Haustov 
325ac106addSNikolay Haustov   if (Val == 255)
326ac106addSNikolay Haustov     return decodeLiteralConstant();
327ac106addSNikolay Haustov 
328ac106addSNikolay Haustov   return Is32 ? decodeSpecialReg32(Val) : decodeSpecialReg64(Val);
329ac106addSNikolay Haustov }
330ac106addSNikolay Haustov 
331ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg32(unsigned Val) const {
332ac106addSNikolay Haustov   using namespace AMDGPU;
333e1818af8STom Stellard   switch (Val) {
334ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR_LO, STI));
335ac106addSNikolay Haustov   case 103: return createRegOperand(getMCReg(FLAT_SCR_HI, STI));
336e1818af8STom Stellard     // ToDo: no support for xnack_mask_lo/_hi register
337e1818af8STom Stellard   case 104:
338ac106addSNikolay Haustov   case 105: break;
339ac106addSNikolay Haustov   case 106: return createRegOperand(VCC_LO);
340ac106addSNikolay Haustov   case 107: return createRegOperand(VCC_HI);
341e1818af8STom Stellard     // ToDo: no support for tba_lo/_hi register
342e1818af8STom Stellard   case 108:
343ac106addSNikolay Haustov   case 109: break;
344e1818af8STom Stellard     // ToDo: no support for tma_lo/_hi register
345e1818af8STom Stellard   case 110:
346ac106addSNikolay Haustov   case 111: break;
347e1818af8STom Stellard     // ToDo: no support for ttmp[0:11] register
348e1818af8STom Stellard   case 112:
349e1818af8STom Stellard   case 113:
350e1818af8STom Stellard   case 114:
351e1818af8STom Stellard   case 115:
352e1818af8STom Stellard   case 116:
353e1818af8STom Stellard   case 117:
354e1818af8STom Stellard   case 118:
355e1818af8STom Stellard   case 119:
356e1818af8STom Stellard   case 120:
357e1818af8STom Stellard   case 121:
358e1818af8STom Stellard   case 122:
359ac106addSNikolay Haustov   case 123: break;
360ac106addSNikolay Haustov   case 124: return createRegOperand(M0);
361ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC_LO);
362ac106addSNikolay Haustov   case 127: return createRegOperand(EXEC_HI);
363e1818af8STom Stellard     // ToDo: no support for vccz register
364ac106addSNikolay Haustov   case 251: break;
365e1818af8STom Stellard     // ToDo: no support for execz register
366ac106addSNikolay Haustov   case 252: break;
367ac106addSNikolay Haustov   case 253: return createRegOperand(SCC);
368ac106addSNikolay Haustov   default: break;
369e1818af8STom Stellard   }
370ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
371e1818af8STom Stellard }
372e1818af8STom Stellard 
373ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg64(unsigned Val) const {
374161a158eSNikolay Haustov   using namespace AMDGPU;
375161a158eSNikolay Haustov   switch (Val) {
376ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR, STI));
377ac106addSNikolay Haustov   case 106: return createRegOperand(VCC);
378ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC);
379ac106addSNikolay Haustov   default: break;
380161a158eSNikolay Haustov   }
381ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
382161a158eSNikolay Haustov }
383161a158eSNikolay Haustov 
384e1818af8STom Stellard static MCDisassembler *createAMDGPUDisassembler(const Target &T,
385e1818af8STom Stellard                                                 const MCSubtargetInfo &STI,
386e1818af8STom Stellard                                                 MCContext &Ctx) {
387e1818af8STom Stellard   return new AMDGPUDisassembler(STI, Ctx);
388e1818af8STom Stellard }
389e1818af8STom Stellard 
390e1818af8STom Stellard extern "C" void LLVMInitializeAMDGPUDisassembler() {
391e1818af8STom Stellard   TargetRegistry::RegisterMCDisassembler(TheGCNTarget, createAMDGPUDisassembler);
392e1818af8STom Stellard }
393