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)
70ac106addSNikolay Haustov DECODE_OPERAND(SReg_64)
71ac106addSNikolay Haustov DECODE_OPERAND(SReg_128)
72ac106addSNikolay Haustov DECODE_OPERAND(SReg_256)
73e1818af8STom Stellard 
74e1818af8STom Stellard #define GET_SUBTARGETINFO_ENUM
75e1818af8STom Stellard #include "AMDGPUGenSubtargetInfo.inc"
76e1818af8STom Stellard #undef GET_SUBTARGETINFO_ENUM
77e1818af8STom Stellard 
78e1818af8STom Stellard #include "AMDGPUGenDisassemblerTables.inc"
79e1818af8STom Stellard 
80e1818af8STom Stellard //===----------------------------------------------------------------------===//
81e1818af8STom Stellard //
82e1818af8STom Stellard //===----------------------------------------------------------------------===//
83e1818af8STom Stellard 
84ac106addSNikolay Haustov static inline uint32_t eatB32(ArrayRef<uint8_t>& Bytes) {
85ac106addSNikolay Haustov   assert(Bytes.size() >= sizeof eatB32(Bytes));
86ac106addSNikolay Haustov   const auto Res = support::endian::read32le(Bytes.data());
87ac106addSNikolay Haustov   Bytes = Bytes.slice(sizeof Res);
88ac106addSNikolay Haustov   return Res;
89ac106addSNikolay Haustov }
90ac106addSNikolay Haustov 
91ac106addSNikolay Haustov DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t* Table,
92ac106addSNikolay Haustov                                                MCInst &MI,
93ac106addSNikolay Haustov                                                uint64_t Inst,
94ac106addSNikolay Haustov                                                uint64_t Address) const {
95ac106addSNikolay Haustov   assert(MI.getOpcode() == 0);
96ac106addSNikolay Haustov   assert(MI.getNumOperands() == 0);
97ac106addSNikolay Haustov   MCInst TmpInst;
98ac106addSNikolay Haustov   const auto SavedBytes = Bytes;
99ac106addSNikolay Haustov   if (decodeInstruction(Table, TmpInst, Inst, Address, this, STI)) {
100ac106addSNikolay Haustov     MI = TmpInst;
101ac106addSNikolay Haustov     return MCDisassembler::Success;
102ac106addSNikolay Haustov   }
103ac106addSNikolay Haustov   Bytes = SavedBytes;
104ac106addSNikolay Haustov   return MCDisassembler::Fail;
105ac106addSNikolay Haustov }
106ac106addSNikolay Haustov 
107e1818af8STom Stellard DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
108ac106addSNikolay Haustov                                                 ArrayRef<uint8_t> Bytes_,
109e1818af8STom Stellard                                                 uint64_t Address,
110e1818af8STom Stellard                                                 raw_ostream &WS,
111e1818af8STom Stellard                                                 raw_ostream &CS) const {
112e1818af8STom Stellard   CommentStream = &CS;
113e1818af8STom Stellard 
114e1818af8STom Stellard   // ToDo: AMDGPUDisassembler supports only VI ISA.
115e1818af8STom Stellard   assert(AMDGPU::isVI(STI) && "Can disassemble only VI ISA.");
116e1818af8STom Stellard 
117ac106addSNikolay Haustov   const unsigned MaxInstBytesNum = (std::min)((size_t)8, Bytes_.size());
118ac106addSNikolay Haustov   Bytes = Bytes_.slice(0, MaxInstBytesNum);
119161a158eSNikolay Haustov 
120ac106addSNikolay Haustov   DecodeStatus Res = MCDisassembler::Fail;
121ac106addSNikolay Haustov   do {
122*824e804bSValery Pykhtin     // ToDo: better to switch encoding length using some bit predicate
123ac106addSNikolay Haustov     // but it is unknown yet, so try all we can
124ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
125ac106addSNikolay Haustov     const uint32_t DW = eatB32(Bytes);
126ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI32, MI, DW, Address);
127ac106addSNikolay Haustov     if (Res) break;
128e1818af8STom Stellard 
129ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU32, MI, DW, Address);
130ac106addSNikolay Haustov     if (Res) break;
131ac106addSNikolay Haustov 
132ac106addSNikolay Haustov     if (Bytes.size() < 4) break;
133ac106addSNikolay Haustov     const uint64_t QW = ((uint64_t)eatB32(Bytes) << 32) | DW;
134ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableVI64, MI, QW, Address);
135ac106addSNikolay Haustov     if (Res) break;
136ac106addSNikolay Haustov 
137ac106addSNikolay Haustov     Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address);
138ac106addSNikolay Haustov   } while (false);
139ac106addSNikolay Haustov 
140ac106addSNikolay Haustov   Size = Res ? (MaxInstBytesNum - Bytes.size()) : 0;
141ac106addSNikolay Haustov   return Res;
142161a158eSNikolay Haustov }
143e1818af8STom Stellard 
144ac106addSNikolay Haustov const char* AMDGPUDisassembler::getRegClassName(unsigned RegClassID) const {
145ac106addSNikolay Haustov   return getContext().getRegisterInfo()->
146ac106addSNikolay Haustov     getRegClassName(&AMDGPUMCRegisterClasses[RegClassID]);
147e1818af8STom Stellard }
148e1818af8STom Stellard 
149ac106addSNikolay Haustov inline
150ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::errOperand(unsigned V,
151ac106addSNikolay Haustov                                          const Twine& ErrMsg) const {
152ac106addSNikolay Haustov   *CommentStream << "Error: " + ErrMsg;
153ac106addSNikolay Haustov 
154ac106addSNikolay Haustov   // ToDo: add support for error operands to MCInst.h
155ac106addSNikolay Haustov   // return MCOperand::createError(V);
156ac106addSNikolay Haustov   return MCOperand();
157ac106addSNikolay Haustov }
158ac106addSNikolay Haustov 
159ac106addSNikolay Haustov inline
160ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned int RegId) const {
161ac106addSNikolay Haustov   return MCOperand::createReg(RegId);
162ac106addSNikolay Haustov }
163ac106addSNikolay Haustov 
164ac106addSNikolay Haustov inline
165ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createRegOperand(unsigned RegClassID,
166ac106addSNikolay Haustov                                                unsigned Val) const {
167ac106addSNikolay Haustov   const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
168ac106addSNikolay Haustov   if (Val >= RegCl.getNumRegs())
169ac106addSNikolay Haustov     return errOperand(Val, Twine(getRegClassName(RegClassID)) +
170ac106addSNikolay Haustov                            ": unknown register " + Twine(Val));
171ac106addSNikolay Haustov   return createRegOperand(RegCl.getRegister(Val));
172ac106addSNikolay Haustov }
173ac106addSNikolay Haustov 
174ac106addSNikolay Haustov inline
175ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::createSRegOperand(unsigned SRegClassID,
176ac106addSNikolay Haustov                                                 unsigned Val) const {
177ac106addSNikolay Haustov   // ToDo: SI/CI have 104 SGPRs, VI - 102
178ac106addSNikolay Haustov   // Valery: here we accepting as much as we can, let assembler sort it out
179ac106addSNikolay Haustov   int shift = 0;
180ac106addSNikolay Haustov   switch (SRegClassID) {
181ac106addSNikolay Haustov   case AMDGPU::SGPR_32RegClassID:
182ac106addSNikolay Haustov   case AMDGPU::SReg_32RegClassID: break;
183ac106addSNikolay Haustov   case AMDGPU::SGPR_64RegClassID:
184ac106addSNikolay Haustov   case AMDGPU::SReg_64RegClassID:  shift = 1; break;
185ac106addSNikolay Haustov   case AMDGPU::SReg_128RegClassID:
186ac106addSNikolay Haustov   // ToDo: unclear if s[100:104] is available on VI. Can we use VCC as SGPR in
187ac106addSNikolay Haustov   // this bundle?
188ac106addSNikolay Haustov   case AMDGPU::SReg_256RegClassID:
189ac106addSNikolay Haustov   // ToDo: unclear if s[96:104] is available on VI. Can we use VCC as SGPR in
190ac106addSNikolay Haustov   // this bundle?
191ac106addSNikolay Haustov   case AMDGPU::SReg_512RegClassID: shift = 2; break;
192ac106addSNikolay Haustov   // ToDo: unclear if s[88:104] is available on VI. Can we use VCC as SGPR in
193ac106addSNikolay Haustov   // this bundle?
194ac106addSNikolay Haustov   default: assert(false); break;
195ac106addSNikolay Haustov   }
196ac106addSNikolay Haustov   if (Val % (1 << shift))
197ac106addSNikolay Haustov     *CommentStream << "Warning: " << getRegClassName(SRegClassID)
198ac106addSNikolay Haustov                    << ": scalar reg isn't aligned " << Val;
199ac106addSNikolay Haustov   return createRegOperand(SRegClassID, Val >> shift);
200ac106addSNikolay Haustov }
201ac106addSNikolay Haustov 
202ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_32(unsigned Val) const {
203ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
204ac106addSNikolay Haustov }
205ac106addSNikolay Haustov 
206ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VS_64(unsigned Val) const {
207ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
208ac106addSNikolay Haustov }
209ac106addSNikolay Haustov 
210ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VGPR_32(unsigned Val) const {
211ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VGPR_32RegClassID, Val);
212ac106addSNikolay Haustov }
213ac106addSNikolay Haustov 
214ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_64(unsigned Val) const {
215ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_64RegClassID, Val);
216ac106addSNikolay Haustov }
217ac106addSNikolay Haustov 
218ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_96(unsigned Val) const {
219ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_96RegClassID, Val);
220ac106addSNikolay Haustov }
221ac106addSNikolay Haustov 
222ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_VReg_128(unsigned Val) const {
223ac106addSNikolay Haustov   return createRegOperand(AMDGPU::VReg_128RegClassID, Val);
224ac106addSNikolay Haustov }
225ac106addSNikolay Haustov 
226ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SGPR_32(unsigned Val) const {
227ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SGPR_32RegClassID, Val);
228ac106addSNikolay Haustov }
229ac106addSNikolay Haustov 
230ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_32(unsigned Val) const {
231ac106addSNikolay Haustov   // table-gen generated disassembler doesn't care about operand types
232ac106addSNikolay Haustov   // leaving only registry class so SSrc_32 operand turns into SReg_32
233ac106addSNikolay Haustov   // and therefore we accept immediates and literals here as well
234ac106addSNikolay Haustov   return decodeSrcOp(OP32, Val);
235ac106addSNikolay Haustov }
236ac106addSNikolay Haustov 
237ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_64(unsigned Val) const {
238ac106addSNikolay Haustov   // see decodeOperand_SReg_32 comment
239ac106addSNikolay Haustov   return decodeSrcOp(OP64, Val);
240ac106addSNikolay Haustov }
241ac106addSNikolay Haustov 
242ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_128(unsigned Val) const {
243ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_128RegClassID, Val);
244ac106addSNikolay Haustov }
245ac106addSNikolay Haustov 
246ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_256(unsigned Val) const {
247ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_256RegClassID, Val);
248ac106addSNikolay Haustov }
249ac106addSNikolay Haustov 
250ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeOperand_SReg_512(unsigned Val) const {
251ac106addSNikolay Haustov   return createSRegOperand(AMDGPU::SReg_512RegClassID, Val);
252ac106addSNikolay Haustov }
253ac106addSNikolay Haustov 
254ac106addSNikolay Haustov 
255ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
256ac106addSNikolay Haustov   // For now all literal constants are supposed to be unsigned integer
257ac106addSNikolay Haustov   // ToDo: deal with signed/unsigned 64-bit integer constants
258ac106addSNikolay Haustov   // ToDo: deal with float/double constants
259ac106addSNikolay Haustov   if (Bytes.size() < 4)
260ac106addSNikolay Haustov     return errOperand(0, "cannot read literal, inst bytes left " +
261ac106addSNikolay Haustov                          Twine(Bytes.size()));
262ac106addSNikolay Haustov   return MCOperand::createImm(eatB32(Bytes));
263ac106addSNikolay Haustov }
264ac106addSNikolay Haustov 
265ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeIntImmed(unsigned Imm) {
266ac106addSNikolay Haustov   assert(Imm >= 128 && Imm <= 208);
267ac106addSNikolay Haustov   return MCOperand::createImm((Imm <= 192) ? (Imm - 128) : (192 - Imm));
268ac106addSNikolay Haustov }
269ac106addSNikolay Haustov 
270ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeFPImmed(bool Is32, unsigned Imm) {
271ac106addSNikolay Haustov   assert(Imm >= 240 && Imm <= 248);
272e1818af8STom Stellard   // ToDo: case 248: 1/(2*PI) - is allowed only on VI
273e1818af8STom Stellard   // ToDo: AMDGPUInstPrinter does not support 1/(2*PI). It consider 1/(2*PI) as
274e1818af8STom Stellard   // literal constant.
275ac106addSNikolay Haustov   float V = 0.0f;
276e1818af8STom Stellard   switch (Imm) {
277ac106addSNikolay Haustov   case 240: V =  0.5f; break;
278ac106addSNikolay Haustov   case 241: V = -0.5f; break;
279ac106addSNikolay Haustov   case 242: V =  1.0f; break;
280ac106addSNikolay Haustov   case 243: V = -1.0f; break;
281ac106addSNikolay Haustov   case 244: V =  2.0f; break;
282ac106addSNikolay Haustov   case 245: V = -2.0f; break;
283ac106addSNikolay Haustov   case 246: V =  4.0f; break;
284ac106addSNikolay Haustov   case 247: V = -4.0f; break;
285ac106addSNikolay Haustov   case 248: return MCOperand::createImm(Is32 ?         // 1/(2*PI)
286ac106addSNikolay Haustov                                           0x3e22f983 :
287ac106addSNikolay Haustov                                           0x3fc45f306dc9c882);
288ac106addSNikolay Haustov   default: break;
289e1818af8STom Stellard   }
290ac106addSNikolay Haustov   return MCOperand::createImm(Is32? FloatToBits(V) : DoubleToBits(V));
291e1818af8STom Stellard }
292e1818af8STom Stellard 
293ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSrcOp(bool Is32, unsigned Val) const {
294e1818af8STom Stellard   using namespace AMDGPU;
295ac106addSNikolay Haustov   assert(Val < 512); // enum9
296ac106addSNikolay Haustov 
297ac106addSNikolay Haustov   if (Val >= 256)
298ac106addSNikolay Haustov     return createRegOperand(Is32 ? VGPR_32RegClassID : VReg_64RegClassID,
299ac106addSNikolay Haustov                             Val - 256);
300ac106addSNikolay Haustov   if (Val <= 101)
301ac106addSNikolay Haustov     return createSRegOperand(Is32 ? SGPR_32RegClassID : SGPR_64RegClassID,
302ac106addSNikolay Haustov                              Val);
303ac106addSNikolay Haustov 
304ac106addSNikolay Haustov   if (Val >= 128 && Val <= 208)
305ac106addSNikolay Haustov     return decodeIntImmed(Val);
306ac106addSNikolay Haustov 
307ac106addSNikolay Haustov   if (Val >= 240 && Val <= 248)
308ac106addSNikolay Haustov     return decodeFPImmed(Is32, Val);
309ac106addSNikolay Haustov 
310ac106addSNikolay Haustov   if (Val == 255)
311ac106addSNikolay Haustov     return decodeLiteralConstant();
312ac106addSNikolay Haustov 
313ac106addSNikolay Haustov   return Is32 ? decodeSpecialReg32(Val) : decodeSpecialReg64(Val);
314ac106addSNikolay Haustov }
315ac106addSNikolay Haustov 
316ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg32(unsigned Val) const {
317ac106addSNikolay Haustov   using namespace AMDGPU;
318e1818af8STom Stellard   switch (Val) {
319ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR_LO, STI));
320ac106addSNikolay Haustov   case 103: return createRegOperand(getMCReg(FLAT_SCR_HI, STI));
321e1818af8STom Stellard     // ToDo: no support for xnack_mask_lo/_hi register
322e1818af8STom Stellard   case 104:
323ac106addSNikolay Haustov   case 105: break;
324ac106addSNikolay Haustov   case 106: return createRegOperand(VCC_LO);
325ac106addSNikolay Haustov   case 107: return createRegOperand(VCC_HI);
326e1818af8STom Stellard     // ToDo: no support for tba_lo/_hi register
327e1818af8STom Stellard   case 108:
328ac106addSNikolay Haustov   case 109: break;
329e1818af8STom Stellard     // ToDo: no support for tma_lo/_hi register
330e1818af8STom Stellard   case 110:
331ac106addSNikolay Haustov   case 111: break;
332e1818af8STom Stellard     // ToDo: no support for ttmp[0:11] register
333e1818af8STom Stellard   case 112:
334e1818af8STom Stellard   case 113:
335e1818af8STom Stellard   case 114:
336e1818af8STom Stellard   case 115:
337e1818af8STom Stellard   case 116:
338e1818af8STom Stellard   case 117:
339e1818af8STom Stellard   case 118:
340e1818af8STom Stellard   case 119:
341e1818af8STom Stellard   case 120:
342e1818af8STom Stellard   case 121:
343e1818af8STom Stellard   case 122:
344ac106addSNikolay Haustov   case 123: break;
345ac106addSNikolay Haustov   case 124: return createRegOperand(M0);
346ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC_LO);
347ac106addSNikolay Haustov   case 127: return createRegOperand(EXEC_HI);
348e1818af8STom Stellard     // ToDo: no support for vccz register
349ac106addSNikolay Haustov   case 251: break;
350e1818af8STom Stellard     // ToDo: no support for execz register
351ac106addSNikolay Haustov   case 252: break;
352ac106addSNikolay Haustov   case 253: return createRegOperand(SCC);
353ac106addSNikolay Haustov   default: break;
354e1818af8STom Stellard   }
355ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
356e1818af8STom Stellard }
357e1818af8STom Stellard 
358ac106addSNikolay Haustov MCOperand AMDGPUDisassembler::decodeSpecialReg64(unsigned Val) const {
359161a158eSNikolay Haustov   using namespace AMDGPU;
360161a158eSNikolay Haustov   switch (Val) {
361ac106addSNikolay Haustov   case 102: return createRegOperand(getMCReg(FLAT_SCR, STI));
362ac106addSNikolay Haustov   case 106: return createRegOperand(VCC);
363ac106addSNikolay Haustov   case 126: return createRegOperand(EXEC);
364ac106addSNikolay Haustov   default: break;
365161a158eSNikolay Haustov   }
366ac106addSNikolay Haustov   return errOperand(Val, "unknown operand encoding " + Twine(Val));
367161a158eSNikolay Haustov }
368161a158eSNikolay Haustov 
369e1818af8STom Stellard static MCDisassembler *createAMDGPUDisassembler(const Target &T,
370e1818af8STom Stellard                                                 const MCSubtargetInfo &STI,
371e1818af8STom Stellard                                                 MCContext &Ctx) {
372e1818af8STom Stellard   return new AMDGPUDisassembler(STI, Ctx);
373e1818af8STom Stellard }
374e1818af8STom Stellard 
375e1818af8STom Stellard extern "C" void LLVMInitializeAMDGPUDisassembler() {
376e1818af8STom Stellard   TargetRegistry::RegisterMCDisassembler(TheGCNTarget, createAMDGPUDisassembler);
377e1818af8STom Stellard }
378