blob: d2847a91c68b290c61600b06857252326584559b [file] [log] [blame]
Sean Callanan04cc3072009-12-19 02:59:52 +00001//===- X86RecognizableInstr.cpp - Disassembler instruction spec --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is part of the X86 Disassembler Emitter.
11// It contains the implementation of a single recognizable instruction.
12// Documentation for the disassembler emitter in general can be found in
13// X86DisasemblerEmitter.h.
14//
15//===----------------------------------------------------------------------===//
16
17#include "X86DisassemblerShared.h"
18#include "X86RecognizableInstr.h"
19#include "X86ModRMFilters.h"
20
21#include "llvm/Support/ErrorHandling.h"
22
23#include <string>
24
25using namespace llvm;
26
Sean Callanandde9c122010-02-12 23:39:46 +000027#define MRM_MAPPING \
28 MAP(C1, 33) \
Chris Lattner140caa72010-02-13 00:41:14 +000029 MAP(C2, 34) \
30 MAP(C3, 35) \
31 MAP(C4, 36) \
32 MAP(C8, 37) \
33 MAP(C9, 38) \
34 MAP(E8, 39) \
35 MAP(F0, 40) \
Duncan Sands41b4a6b2010-07-12 08:16:59 +000036 MAP(F8, 41) \
Rafael Espindolae3906212011-02-22 00:35:18 +000037 MAP(F9, 42) \
38 MAP(D0, 45) \
Craig Toppered7aa462012-02-18 08:19:49 +000039 MAP(D1, 46) \
Craig Topper66a35972012-02-19 01:39:49 +000040 MAP(D4, 47) \
41 MAP(D8, 48) \
42 MAP(D9, 49) \
43 MAP(DA, 50) \
44 MAP(DB, 51) \
45 MAP(DC, 52) \
46 MAP(DD, 53) \
47 MAP(DE, 54) \
48 MAP(DF, 55)
Sean Callanandde9c122010-02-12 23:39:46 +000049
Sean Callanan04cc3072009-12-19 02:59:52 +000050// A clone of X86 since we can't depend on something that is generated.
51namespace X86Local {
52 enum {
53 Pseudo = 0,
54 RawFrm = 1,
55 AddRegFrm = 2,
56 MRMDestReg = 3,
57 MRMDestMem = 4,
58 MRMSrcReg = 5,
59 MRMSrcMem = 6,
Craig Topperac172e22012-07-30 04:48:12 +000060 MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19,
Sean Callanan04cc3072009-12-19 02:59:52 +000061 MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23,
62 MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27,
63 MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31,
Sean Callanandde9c122010-02-12 23:39:46 +000064 MRMInitReg = 32,
Richard Trieu9208abd2012-07-18 23:04:22 +000065 RawFrmImm8 = 43,
66 RawFrmImm16 = 44,
Sean Callanandde9c122010-02-12 23:39:46 +000067#define MAP(from, to) MRM_##from = to,
68 MRM_MAPPING
69#undef MAP
70 lastMRM
Sean Callanan04cc3072009-12-19 02:59:52 +000071 };
Craig Topperac172e22012-07-30 04:48:12 +000072
Sean Callanan04cc3072009-12-19 02:59:52 +000073 enum {
74 TB = 1,
75 REP = 2,
76 D8 = 3, D9 = 4, DA = 5, DB = 6,
77 DC = 7, DD = 8, DE = 9, DF = 10,
78 XD = 11, XS = 12,
Chris Lattnerf7477e52010-02-12 02:06:33 +000079 T8 = 13, P_TA = 14,
Craig Topper980d5982011-10-23 07:34:00 +000080 A6 = 15, A7 = 16, T8XD = 17, T8XS = 18, TAXD = 19
Sean Callanan04cc3072009-12-19 02:59:52 +000081 };
82}
Sean Callanandde9c122010-02-12 23:39:46 +000083
84// If rows are added to the opcode extension tables, then corresponding entries
Craig Topperac172e22012-07-30 04:48:12 +000085// must be added here.
Sean Callanandde9c122010-02-12 23:39:46 +000086//
87// If the row corresponds to a single byte (i.e., 8f), then add an entry for
88// that byte to ONE_BYTE_EXTENSION_TABLES.
89//
Craig Topperac172e22012-07-30 04:48:12 +000090// If the row corresponds to two bytes where the first is 0f, add an entry for
Sean Callanandde9c122010-02-12 23:39:46 +000091// the second byte to TWO_BYTE_EXTENSION_TABLES.
92//
93// If the row corresponds to some other set of bytes, you will need to modify
94// the code in RecognizableInstr::emitDecodePath() as well, and add new prefixes
Craig Topperac172e22012-07-30 04:48:12 +000095// to the X86 TD files, except in two cases: if the first two bytes of such a
Sean Callanandde9c122010-02-12 23:39:46 +000096// new combination are 0f 38 or 0f 3a, you just have to add maps called
97// THREE_BYTE_38_EXTENSION_TABLES and THREE_BYTE_3A_EXTENSION_TABLES and add a
98// switch(Opcode) just below the case X86Local::T8: or case X86Local::TA: line
99// in RecognizableInstr::emitDecodePath().
100
Sean Callanan04cc3072009-12-19 02:59:52 +0000101#define ONE_BYTE_EXTENSION_TABLES \
102 EXTENSION_TABLE(80) \
103 EXTENSION_TABLE(81) \
104 EXTENSION_TABLE(82) \
105 EXTENSION_TABLE(83) \
106 EXTENSION_TABLE(8f) \
107 EXTENSION_TABLE(c0) \
108 EXTENSION_TABLE(c1) \
109 EXTENSION_TABLE(c6) \
110 EXTENSION_TABLE(c7) \
111 EXTENSION_TABLE(d0) \
112 EXTENSION_TABLE(d1) \
113 EXTENSION_TABLE(d2) \
114 EXTENSION_TABLE(d3) \
115 EXTENSION_TABLE(f6) \
116 EXTENSION_TABLE(f7) \
117 EXTENSION_TABLE(fe) \
118 EXTENSION_TABLE(ff)
Craig Topperac172e22012-07-30 04:48:12 +0000119
Sean Callanan04cc3072009-12-19 02:59:52 +0000120#define TWO_BYTE_EXTENSION_TABLES \
121 EXTENSION_TABLE(00) \
122 EXTENSION_TABLE(01) \
123 EXTENSION_TABLE(18) \
124 EXTENSION_TABLE(71) \
125 EXTENSION_TABLE(72) \
126 EXTENSION_TABLE(73) \
127 EXTENSION_TABLE(ae) \
Sean Callanan04cc3072009-12-19 02:59:52 +0000128 EXTENSION_TABLE(ba) \
129 EXTENSION_TABLE(c7)
Sean Callanan04cc3072009-12-19 02:59:52 +0000130
Craig Topper27ad1252011-10-15 20:46:47 +0000131#define THREE_BYTE_38_EXTENSION_TABLES \
132 EXTENSION_TABLE(F3)
133
Sean Callanan04cc3072009-12-19 02:59:52 +0000134using namespace X86Disassembler;
135
136/// needsModRMForDecode - Indicates whether a particular instruction requires a
Craig Topperac172e22012-07-30 04:48:12 +0000137/// ModR/M byte for the instruction to be properly decoded. For example, a
Sean Callanan04cc3072009-12-19 02:59:52 +0000138/// MRMDestReg instruction needs the Mod field in the ModR/M byte to be set to
139/// 0b11.
140///
141/// @param form - The form of the instruction.
142/// @return - true if the form implies that a ModR/M byte is required, false
143/// otherwise.
144static bool needsModRMForDecode(uint8_t form) {
145 if (form == X86Local::MRMDestReg ||
146 form == X86Local::MRMDestMem ||
147 form == X86Local::MRMSrcReg ||
148 form == X86Local::MRMSrcMem ||
149 (form >= X86Local::MRM0r && form <= X86Local::MRM7r) ||
150 (form >= X86Local::MRM0m && form <= X86Local::MRM7m))
151 return true;
152 else
153 return false;
154}
155
156/// isRegFormat - Indicates whether a particular form requires the Mod field of
157/// the ModR/M byte to be 0b11.
158///
159/// @param form - The form of the instruction.
160/// @return - true if the form implies that Mod must be 0b11, false
161/// otherwise.
162static bool isRegFormat(uint8_t form) {
163 if (form == X86Local::MRMDestReg ||
164 form == X86Local::MRMSrcReg ||
165 (form >= X86Local::MRM0r && form <= X86Local::MRM7r))
166 return true;
167 else
168 return false;
169}
170
171/// byteFromBitsInit - Extracts a value at most 8 bits in width from a BitsInit.
172/// Useful for switch statements and the like.
173///
174/// @param init - A reference to the BitsInit to be decoded.
175/// @return - The field, with the first bit in the BitsInit as the lowest
176/// order bit.
David Greeneaf8ee2c2011-07-29 22:43:06 +0000177static uint8_t byteFromBitsInit(BitsInit &init) {
Sean Callanan04cc3072009-12-19 02:59:52 +0000178 int width = init.getNumBits();
179
180 assert(width <= 8 && "Field is too large for uint8_t!");
181
182 int index;
183 uint8_t mask = 0x01;
184
185 uint8_t ret = 0;
186
187 for (index = 0; index < width; index++) {
David Greeneaf8ee2c2011-07-29 22:43:06 +0000188 if (static_cast<BitInit*>(init.getBit(index))->getValue())
Sean Callanan04cc3072009-12-19 02:59:52 +0000189 ret |= mask;
190
191 mask <<= 1;
192 }
193
194 return ret;
195}
196
197/// byteFromRec - Extract a value at most 8 bits in with from a Record given the
198/// name of the field.
199///
200/// @param rec - The record from which to extract the value.
201/// @param name - The name of the field in the record.
202/// @return - The field, as translated by byteFromBitsInit().
203static uint8_t byteFromRec(const Record* rec, const std::string &name) {
David Greeneaf8ee2c2011-07-29 22:43:06 +0000204 BitsInit* bits = rec->getValueAsBitsInit(name);
Sean Callanan04cc3072009-12-19 02:59:52 +0000205 return byteFromBitsInit(*bits);
206}
207
208RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
209 const CodeGenInstruction &insn,
210 InstrUID uid) {
211 UID = uid;
212
213 Rec = insn.TheDef;
214 Name = Rec->getName();
215 Spec = &tables.specForUID(UID);
Craig Topperac172e22012-07-30 04:48:12 +0000216
Sean Callanan04cc3072009-12-19 02:59:52 +0000217 if (!Rec->isSubClassOf("X86Inst")) {
218 ShouldBeEmitted = false;
219 return;
220 }
Craig Topperac172e22012-07-30 04:48:12 +0000221
Sean Callanan04cc3072009-12-19 02:59:52 +0000222 Prefix = byteFromRec(Rec, "Prefix");
223 Opcode = byteFromRec(Rec, "Opcode");
224 Form = byteFromRec(Rec, "FormBits");
225 SegOvr = byteFromRec(Rec, "SegOvrBits");
Craig Topperac172e22012-07-30 04:48:12 +0000226
Sean Callanan04cc3072009-12-19 02:59:52 +0000227 HasOpSizePrefix = Rec->getValueAsBit("hasOpSizePrefix");
Craig Topper6491c802012-02-27 01:54:29 +0000228 HasAdSizePrefix = Rec->getValueAsBit("hasAdSizePrefix");
Sean Callanan04cc3072009-12-19 02:59:52 +0000229 HasREX_WPrefix = Rec->getValueAsBit("hasREX_WPrefix");
Sean Callananc3fd5232011-03-15 01:23:15 +0000230 HasVEXPrefix = Rec->getValueAsBit("hasVEXPrefix");
Bruno Cardoso Lopesc2f87b72010-06-08 22:51:23 +0000231 HasVEX_4VPrefix = Rec->getValueAsBit("hasVEX_4VPrefix");
Craig Topperaea148c2011-10-16 07:55:05 +0000232 HasVEX_4VOp3Prefix = Rec->getValueAsBit("hasVEX_4VOp3Prefix");
Sean Callananc3fd5232011-03-15 01:23:15 +0000233 HasVEX_WPrefix = Rec->getValueAsBit("hasVEX_WPrefix");
Craig Topper03a0bed2011-12-30 05:20:36 +0000234 HasMemOp4Prefix = Rec->getValueAsBit("hasMemOp4Prefix");
Craig Topperf18c8962011-10-04 06:30:42 +0000235 IgnoresVEX_L = Rec->getValueAsBit("ignoresVEX_L");
Sean Callanan04cc3072009-12-19 02:59:52 +0000236 HasLockPrefix = Rec->getValueAsBit("hasLockPrefix");
237 IsCodeGenOnly = Rec->getValueAsBit("isCodeGenOnly");
Craig Topperac172e22012-07-30 04:48:12 +0000238
Sean Callanan04cc3072009-12-19 02:59:52 +0000239 Name = Rec->getName();
240 AsmString = Rec->getValueAsString("AsmString");
Craig Topperac172e22012-07-30 04:48:12 +0000241
Chris Lattnerd8adec72010-11-01 04:03:32 +0000242 Operands = &insn.Operands.OperandList;
Craig Topperac172e22012-07-30 04:48:12 +0000243
Kevin Enderby54e09b42011-09-02 18:03:03 +0000244 IsSSE = (HasOpSizePrefix && (Name.find("16") == Name.npos)) ||
245 (Name.find("CRC32") != Name.npos);
Sean Callananc3fd5232011-03-15 01:23:15 +0000246 HasFROperands = hasFROperands();
247 HasVEX_LPrefix = has256BitOperands() || Rec->getValueAsBit("hasVEX_L");
Craig Topper25ea4e52011-10-16 03:51:13 +0000248
Eli Friedman03180362011-07-16 02:41:28 +0000249 // Check for 64-bit inst which does not require REX
Craig Topper526adab2011-09-23 06:57:25 +0000250 Is32Bit = false;
Eli Friedman03180362011-07-16 02:41:28 +0000251 Is64Bit = false;
252 // FIXME: Is there some better way to check for In64BitMode?
253 std::vector<Record*> Predicates = Rec->getValueAsListOfDefs("Predicates");
254 for (unsigned i = 0, e = Predicates.size(); i != e; ++i) {
Craig Topper526adab2011-09-23 06:57:25 +0000255 if (Predicates[i]->getName().find("32Bit") != Name.npos) {
256 Is32Bit = true;
257 break;
258 }
Eli Friedman03180362011-07-16 02:41:28 +0000259 if (Predicates[i]->getName().find("64Bit") != Name.npos) {
260 Is64Bit = true;
261 break;
262 }
263 }
264 // FIXME: These instructions aren't marked as 64-bit in any way
Craig Topperac172e22012-07-30 04:48:12 +0000265 Is64Bit |= Rec->getName() == "JMP64pcrel32" ||
266 Rec->getName() == "MASKMOVDQU64" ||
267 Rec->getName() == "POPFS64" ||
268 Rec->getName() == "POPGS64" ||
269 Rec->getName() == "PUSHFS64" ||
Eli Friedman03180362011-07-16 02:41:28 +0000270 Rec->getName() == "PUSHGS64" ||
271 Rec->getName() == "REX64_PREFIX" ||
Craig Topperac172e22012-07-30 04:48:12 +0000272 Rec->getName().find("MOV64") != Name.npos ||
Eli Friedman03180362011-07-16 02:41:28 +0000273 Rec->getName().find("PUSH64") != Name.npos ||
274 Rec->getName().find("POP64") != Name.npos;
275
Sean Callanan04cc3072009-12-19 02:59:52 +0000276 ShouldBeEmitted = true;
277}
Craig Topperac172e22012-07-30 04:48:12 +0000278
Sean Callanan04cc3072009-12-19 02:59:52 +0000279void RecognizableInstr::processInstr(DisassemblerTables &tables,
Craig Topperf7755df2012-07-12 06:52:41 +0000280 const CodeGenInstruction &insn,
281 InstrUID uid)
Sean Callanan04cc3072009-12-19 02:59:52 +0000282{
Daniel Dunbar5661c0c2010-05-20 20:20:32 +0000283 // Ignore "asm parser only" instructions.
284 if (insn.TheDef->getValueAsBit("isAsmParserOnly"))
285 return;
Craig Topperac172e22012-07-30 04:48:12 +0000286
Sean Callanan04cc3072009-12-19 02:59:52 +0000287 RecognizableInstr recogInstr(tables, insn, uid);
Craig Topperac172e22012-07-30 04:48:12 +0000288
Sean Callanan04cc3072009-12-19 02:59:52 +0000289 recogInstr.emitInstructionSpecifier(tables);
Craig Topperac172e22012-07-30 04:48:12 +0000290
Sean Callanan04cc3072009-12-19 02:59:52 +0000291 if (recogInstr.shouldBeEmitted())
292 recogInstr.emitDecodePath(tables);
293}
294
295InstructionContext RecognizableInstr::insnContext() const {
296 InstructionContext insnContext;
297
Craig Topperaea148c2011-10-16 07:55:05 +0000298 if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix|| HasVEXPrefix) {
Craig Topperf01f1b52011-11-06 23:04:08 +0000299 if (HasVEX_LPrefix && HasVEX_WPrefix) {
300 if (HasOpSizePrefix)
301 insnContext = IC_VEX_L_W_OPSIZE;
302 else
303 llvm_unreachable("Don't support VEX.L and VEX.W together");
304 } else if (HasOpSizePrefix && HasVEX_LPrefix)
Sean Callananc3fd5232011-03-15 01:23:15 +0000305 insnContext = IC_VEX_L_OPSIZE;
306 else if (HasOpSizePrefix && HasVEX_WPrefix)
307 insnContext = IC_VEX_W_OPSIZE;
308 else if (HasOpSizePrefix)
309 insnContext = IC_VEX_OPSIZE;
Craig Topper96fa5972011-10-16 16:50:08 +0000310 else if (HasVEX_LPrefix &&
311 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
Sean Callananc3fd5232011-03-15 01:23:15 +0000312 insnContext = IC_VEX_L_XS;
Craig Topper980d5982011-10-23 07:34:00 +0000313 else if (HasVEX_LPrefix && (Prefix == X86Local::XD ||
314 Prefix == X86Local::T8XD ||
315 Prefix == X86Local::TAXD))
Sean Callananc3fd5232011-03-15 01:23:15 +0000316 insnContext = IC_VEX_L_XD;
Craig Topper96fa5972011-10-16 16:50:08 +0000317 else if (HasVEX_WPrefix &&
318 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
Sean Callananc3fd5232011-03-15 01:23:15 +0000319 insnContext = IC_VEX_W_XS;
Craig Topper980d5982011-10-23 07:34:00 +0000320 else if (HasVEX_WPrefix && (Prefix == X86Local::XD ||
321 Prefix == X86Local::T8XD ||
322 Prefix == X86Local::TAXD))
Sean Callananc3fd5232011-03-15 01:23:15 +0000323 insnContext = IC_VEX_W_XD;
324 else if (HasVEX_WPrefix)
325 insnContext = IC_VEX_W;
326 else if (HasVEX_LPrefix)
327 insnContext = IC_VEX_L;
Craig Topper980d5982011-10-23 07:34:00 +0000328 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
329 Prefix == X86Local::TAXD)
Sean Callananc3fd5232011-03-15 01:23:15 +0000330 insnContext = IC_VEX_XD;
Craig Topper96fa5972011-10-16 16:50:08 +0000331 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
Sean Callananc3fd5232011-03-15 01:23:15 +0000332 insnContext = IC_VEX_XS;
333 else
334 insnContext = IC_VEX;
Eli Friedman03180362011-07-16 02:41:28 +0000335 } else if (Is64Bit || HasREX_WPrefix) {
Sean Callanan04cc3072009-12-19 02:59:52 +0000336 if (HasREX_WPrefix && HasOpSizePrefix)
337 insnContext = IC_64BIT_REXW_OPSIZE;
Craig Topper980d5982011-10-23 07:34:00 +0000338 else if (HasOpSizePrefix && (Prefix == X86Local::XD ||
339 Prefix == X86Local::T8XD ||
340 Prefix == X86Local::TAXD))
Craig Topper88cb33e2011-10-01 19:54:56 +0000341 insnContext = IC_64BIT_XD_OPSIZE;
Craig Topper96fa5972011-10-16 16:50:08 +0000342 else if (HasOpSizePrefix &&
343 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
Craig Toppera6978522011-10-11 04:34:23 +0000344 insnContext = IC_64BIT_XS_OPSIZE;
Sean Callanan04cc3072009-12-19 02:59:52 +0000345 else if (HasOpSizePrefix)
346 insnContext = IC_64BIT_OPSIZE;
Craig Topper6491c802012-02-27 01:54:29 +0000347 else if (HasAdSizePrefix)
348 insnContext = IC_64BIT_ADSIZE;
Craig Topper96fa5972011-10-16 16:50:08 +0000349 else if (HasREX_WPrefix &&
350 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
Sean Callanan04cc3072009-12-19 02:59:52 +0000351 insnContext = IC_64BIT_REXW_XS;
Craig Topper980d5982011-10-23 07:34:00 +0000352 else if (HasREX_WPrefix && (Prefix == X86Local::XD ||
353 Prefix == X86Local::T8XD ||
354 Prefix == X86Local::TAXD))
Sean Callanan04cc3072009-12-19 02:59:52 +0000355 insnContext = IC_64BIT_REXW_XD;
Craig Topper980d5982011-10-23 07:34:00 +0000356 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
357 Prefix == X86Local::TAXD)
Sean Callanan04cc3072009-12-19 02:59:52 +0000358 insnContext = IC_64BIT_XD;
Craig Topper96fa5972011-10-16 16:50:08 +0000359 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
Sean Callanan04cc3072009-12-19 02:59:52 +0000360 insnContext = IC_64BIT_XS;
361 else if (HasREX_WPrefix)
362 insnContext = IC_64BIT_REXW;
363 else
364 insnContext = IC_64BIT;
365 } else {
Craig Topper980d5982011-10-23 07:34:00 +0000366 if (HasOpSizePrefix && (Prefix == X86Local::XD ||
367 Prefix == X86Local::T8XD ||
368 Prefix == X86Local::TAXD))
Craig Topper88cb33e2011-10-01 19:54:56 +0000369 insnContext = IC_XD_OPSIZE;
Craig Topper96fa5972011-10-16 16:50:08 +0000370 else if (HasOpSizePrefix &&
371 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
Craig Toppera6978522011-10-11 04:34:23 +0000372 insnContext = IC_XS_OPSIZE;
Kevin Enderby54e09b42011-09-02 18:03:03 +0000373 else if (HasOpSizePrefix)
Sean Callanan04cc3072009-12-19 02:59:52 +0000374 insnContext = IC_OPSIZE;
Craig Topper6491c802012-02-27 01:54:29 +0000375 else if (HasAdSizePrefix)
376 insnContext = IC_ADSIZE;
Craig Topper980d5982011-10-23 07:34:00 +0000377 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
378 Prefix == X86Local::TAXD)
Sean Callanan04cc3072009-12-19 02:59:52 +0000379 insnContext = IC_XD;
Craig Topper96fa5972011-10-16 16:50:08 +0000380 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS ||
381 Prefix == X86Local::REP)
Sean Callanan04cc3072009-12-19 02:59:52 +0000382 insnContext = IC_XS;
383 else
384 insnContext = IC;
385 }
386
387 return insnContext;
388}
Craig Topperac172e22012-07-30 04:48:12 +0000389
Sean Callanan04cc3072009-12-19 02:59:52 +0000390RecognizableInstr::filter_ret RecognizableInstr::filter() const {
Sean Callananc3fd5232011-03-15 01:23:15 +0000391 ///////////////////
392 // FILTER_STRONG
393 //
Craig Topperac172e22012-07-30 04:48:12 +0000394
Sean Callanan04cc3072009-12-19 02:59:52 +0000395 // Filter out intrinsics
Craig Topperac172e22012-07-30 04:48:12 +0000396
Craig Topper6f4ad802012-07-30 05:39:34 +0000397 assert(Rec->isSubClassOf("X86Inst") && "Can only filter X86 instructions");
Craig Topperac172e22012-07-30 04:48:12 +0000398
Sean Callanan04cc3072009-12-19 02:59:52 +0000399 if (Form == X86Local::Pseudo ||
Craig Toppera88e3562011-09-11 21:41:45 +0000400 (IsCodeGenOnly && Name.find("_REV") == Name.npos))
Sean Callanan04cc3072009-12-19 02:59:52 +0000401 return FILTER_STRONG;
Craig Topperac172e22012-07-30 04:48:12 +0000402
Sean Callanan69c02262010-02-24 02:56:25 +0000403 if (Form == X86Local::MRMInitReg)
404 return FILTER_STRONG;
Craig Topperac172e22012-07-30 04:48:12 +0000405
406
Kevin Enderby014e1cd2012-03-09 17:52:49 +0000407 // Filter out artificial instructions but leave in the LOCK_PREFIX so it is
408 // printed as a separate "instruction".
Craig Topperac172e22012-07-30 04:48:12 +0000409
Craig Topper75ffc5f2011-11-19 05:48:20 +0000410 if (Name.find("_Int") != Name.npos ||
Sean Callananc3fd5232011-03-15 01:23:15 +0000411 Name.find("Int_") != Name.npos ||
Craig Topperc7690ac2012-07-26 07:48:28 +0000412 Name.find("_NOREX") != Name.npos)
Sean Callananc3fd5232011-03-15 01:23:15 +0000413 return FILTER_STRONG;
414
415 // Filter out instructions with segment override prefixes.
416 // They're too messy to handle now and we'll special case them if needed.
Craig Topperac172e22012-07-30 04:48:12 +0000417
Sean Callananc3fd5232011-03-15 01:23:15 +0000418 if (SegOvr)
419 return FILTER_STRONG;
Craig Topperac172e22012-07-30 04:48:12 +0000420
Sean Callananc3fd5232011-03-15 01:23:15 +0000421 // Filter out instructions that can't be printed.
Craig Topperac172e22012-07-30 04:48:12 +0000422
Sean Callananc3fd5232011-03-15 01:23:15 +0000423 if (AsmString.size() == 0)
424 return FILTER_STRONG;
Craig Topperac172e22012-07-30 04:48:12 +0000425
Sean Callananc3fd5232011-03-15 01:23:15 +0000426 // Filter out instructions with subreg operands.
Craig Topperac172e22012-07-30 04:48:12 +0000427
Sean Callananc3fd5232011-03-15 01:23:15 +0000428 if (AsmString.find("subreg") != AsmString.npos)
429 return FILTER_STRONG;
430
431 /////////////////
432 // FILTER_WEAK
433 //
434
Craig Topperac172e22012-07-30 04:48:12 +0000435
Sean Callanan04cc3072009-12-19 02:59:52 +0000436 // Filter out instructions with a LOCK prefix;
437 // prefer forms that do not have the prefix
438 if (HasLockPrefix)
439 return FILTER_WEAK;
Sean Callanan04cc3072009-12-19 02:59:52 +0000440
Sean Callananc3fd5232011-03-15 01:23:15 +0000441 // Filter out alternate forms of AVX instructions
442 if (Name.find("_alt") != Name.npos ||
443 Name.find("XrYr") != Name.npos ||
Craig Topper88cb33e2011-10-01 19:54:56 +0000444 (Name.find("r64r") != Name.npos && Name.find("r64r64") == Name.npos) ||
Sean Callananc3fd5232011-03-15 01:23:15 +0000445 Name.find("_64mr") != Name.npos ||
446 Name.find("Xrr") != Name.npos ||
447 Name.find("rr64") != Name.npos)
448 return FILTER_WEAK;
Sean Callanan04cc3072009-12-19 02:59:52 +0000449
450 // Special cases.
Dale Johannesen605acfe2010-09-07 18:10:56 +0000451
Sean Callanan04cc3072009-12-19 02:59:52 +0000452 if (Name.find("PCMPISTRI") != Name.npos && Name != "PCMPISTRI")
453 return FILTER_WEAK;
454 if (Name.find("PCMPESTRI") != Name.npos && Name != "PCMPESTRI")
455 return FILTER_WEAK;
456
457 if (Name.find("MOV") != Name.npos && Name.find("r0") != Name.npos)
458 return FILTER_WEAK;
459 if (Name.find("MOVZ") != Name.npos && Name.find("MOVZX") == Name.npos)
460 return FILTER_WEAK;
461 if (Name.find("Fs") != Name.npos)
462 return FILTER_WEAK;
Craig Topper75ffc5f2011-11-19 05:48:20 +0000463 if (Name == "PUSH64i16" ||
Sean Callanan04cc3072009-12-19 02:59:52 +0000464 Name == "MOVPQI2QImr" ||
Sean Callananc3fd5232011-03-15 01:23:15 +0000465 Name == "VMOVPQI2QImr" ||
Sean Callanan04cc3072009-12-19 02:59:52 +0000466 Name == "MMX_MOVD64rrv164" ||
Sean Callanan04cc3072009-12-19 02:59:52 +0000467 Name == "MOV64ri64i32" ||
Craig Topper75ffc5f2011-11-19 05:48:20 +0000468 Name == "VMASKMOVDQU64" ||
469 Name == "VEXTRACTPSrr64" ||
470 Name == "VMOVQd64rr" ||
471 Name == "VMOVQs64rr")
Sean Callanan04cc3072009-12-19 02:59:52 +0000472 return FILTER_WEAK;
473
Sean Callanan04cc3072009-12-19 02:59:52 +0000474 if (HasFROperands && Name.find("MOV") != Name.npos &&
Craig Topperac172e22012-07-30 04:48:12 +0000475 ((Name.find("2") != Name.npos && Name.find("32") == Name.npos) ||
Sean Callanan04cc3072009-12-19 02:59:52 +0000476 (Name.find("to") != Name.npos)))
Craig Topperb58dc172012-07-30 05:10:05 +0000477 return FILTER_STRONG;
Sean Callanan04cc3072009-12-19 02:59:52 +0000478
479 return FILTER_NORMAL;
480}
Sean Callananc3fd5232011-03-15 01:23:15 +0000481
482bool RecognizableInstr::hasFROperands() const {
483 const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
484 unsigned numOperands = OperandList.size();
485
486 for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
487 const std::string &recName = OperandList[operandIndex].Rec->getName();
Craig Topperac172e22012-07-30 04:48:12 +0000488
Sean Callananc3fd5232011-03-15 01:23:15 +0000489 if (recName.find("FR") != recName.npos)
490 return true;
491 }
492 return false;
493}
494
495bool RecognizableInstr::has256BitOperands() const {
496 const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
497 unsigned numOperands = OperandList.size();
Craig Topperac172e22012-07-30 04:48:12 +0000498
Sean Callananc3fd5232011-03-15 01:23:15 +0000499 for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
500 const std::string &recName = OperandList[operandIndex].Rec->getName();
Craig Topperac172e22012-07-30 04:48:12 +0000501
Craig Topper60a58ac2012-07-30 04:53:00 +0000502 if (!recName.compare("VR256")) {
Sean Callananc3fd5232011-03-15 01:23:15 +0000503 return true;
504 }
505 }
506 return false;
507}
Craig Topperac172e22012-07-30 04:48:12 +0000508
Craig Topperf7755df2012-07-12 06:52:41 +0000509void RecognizableInstr::handleOperand(bool optional, unsigned &operandIndex,
510 unsigned &physicalOperandIndex,
511 unsigned &numPhysicalOperands,
512 const unsigned *operandMapping,
513 OperandEncoding (*encodingFromString)
514 (const std::string&,
515 bool hasOpSizePrefix)) {
Sean Callanan04cc3072009-12-19 02:59:52 +0000516 if (optional) {
517 if (physicalOperandIndex >= numPhysicalOperands)
518 return;
519 } else {
520 assert(physicalOperandIndex < numPhysicalOperands);
521 }
Craig Topperac172e22012-07-30 04:48:12 +0000522
Sean Callanan04cc3072009-12-19 02:59:52 +0000523 while (operandMapping[operandIndex] != operandIndex) {
524 Spec->operands[operandIndex].encoding = ENCODING_DUP;
525 Spec->operands[operandIndex].type =
526 (OperandType)(TYPE_DUP0 + operandMapping[operandIndex]);
527 ++operandIndex;
528 }
Craig Topperac172e22012-07-30 04:48:12 +0000529
Sean Callanan04cc3072009-12-19 02:59:52 +0000530 const std::string &typeName = (*Operands)[operandIndex].Rec->getName();
Sean Callananc3fd5232011-03-15 01:23:15 +0000531
Sean Callanan04cc3072009-12-19 02:59:52 +0000532 Spec->operands[operandIndex].encoding = encodingFromString(typeName,
533 HasOpSizePrefix);
Craig Topperac172e22012-07-30 04:48:12 +0000534 Spec->operands[operandIndex].type = typeFromString(typeName,
Sean Callananc3fd5232011-03-15 01:23:15 +0000535 IsSSE,
536 HasREX_WPrefix,
537 HasOpSizePrefix);
Craig Topperac172e22012-07-30 04:48:12 +0000538
Sean Callanan04cc3072009-12-19 02:59:52 +0000539 ++operandIndex;
540 ++physicalOperandIndex;
541}
542
543void RecognizableInstr::emitInstructionSpecifier(DisassemblerTables &tables) {
544 Spec->name = Name;
Craig Topperac172e22012-07-30 04:48:12 +0000545
Craig Topper6f4ad802012-07-30 05:39:34 +0000546 if (!ShouldBeEmitted)
Sean Callanan04cc3072009-12-19 02:59:52 +0000547 return;
Craig Topperac172e22012-07-30 04:48:12 +0000548
Sean Callanan04cc3072009-12-19 02:59:52 +0000549 switch (filter()) {
550 case FILTER_WEAK:
551 Spec->filtered = true;
552 break;
553 case FILTER_STRONG:
554 ShouldBeEmitted = false;
555 return;
556 case FILTER_NORMAL:
557 break;
558 }
Craig Topperac172e22012-07-30 04:48:12 +0000559
Sean Callanan04cc3072009-12-19 02:59:52 +0000560 Spec->insnContext = insnContext();
Craig Topperac172e22012-07-30 04:48:12 +0000561
Chris Lattnerd8adec72010-11-01 04:03:32 +0000562 const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
Craig Topperac172e22012-07-30 04:48:12 +0000563
Sean Callanan04cc3072009-12-19 02:59:52 +0000564 unsigned numOperands = OperandList.size();
565 unsigned numPhysicalOperands = 0;
Craig Topperac172e22012-07-30 04:48:12 +0000566
Sean Callanan04cc3072009-12-19 02:59:52 +0000567 // operandMapping maps from operands in OperandList to their originals.
568 // If operandMapping[i] != i, then the entry is a duplicate.
569 unsigned operandMapping[X86_MAX_OPERANDS];
Craig Topper2ba766a2011-12-30 06:23:39 +0000570 assert(numOperands <= X86_MAX_OPERANDS && "X86_MAX_OPERANDS is not large enough");
Craig Topperac172e22012-07-30 04:48:12 +0000571
Craig Topperf7755df2012-07-12 06:52:41 +0000572 for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
Sean Callanan04cc3072009-12-19 02:59:52 +0000573 if (OperandList[operandIndex].Constraints.size()) {
Chris Lattnerd8adec72010-11-01 04:03:32 +0000574 const CGIOperandList::ConstraintInfo &Constraint =
Chris Lattnera9dfb1b2010-02-10 01:45:28 +0000575 OperandList[operandIndex].Constraints[0];
576 if (Constraint.isTied()) {
Craig Topperf7755df2012-07-12 06:52:41 +0000577 operandMapping[operandIndex] = operandIndex;
578 operandMapping[Constraint.getTiedOperand()] = operandIndex;
Sean Callanan04cc3072009-12-19 02:59:52 +0000579 } else {
580 ++numPhysicalOperands;
581 operandMapping[operandIndex] = operandIndex;
582 }
583 } else {
584 ++numPhysicalOperands;
585 operandMapping[operandIndex] = operandIndex;
586 }
Sean Callanan04cc3072009-12-19 02:59:52 +0000587 }
Craig Topperac172e22012-07-30 04:48:12 +0000588
Sean Callanan04cc3072009-12-19 02:59:52 +0000589#define HANDLE_OPERAND(class) \
590 handleOperand(false, \
591 operandIndex, \
592 physicalOperandIndex, \
593 numPhysicalOperands, \
594 operandMapping, \
595 class##EncodingFromString);
Craig Topperac172e22012-07-30 04:48:12 +0000596
Sean Callanan04cc3072009-12-19 02:59:52 +0000597#define HANDLE_OPTIONAL(class) \
598 handleOperand(true, \
599 operandIndex, \
600 physicalOperandIndex, \
601 numPhysicalOperands, \
602 operandMapping, \
603 class##EncodingFromString);
Craig Topperac172e22012-07-30 04:48:12 +0000604
Sean Callanan04cc3072009-12-19 02:59:52 +0000605 // operandIndex should always be < numOperands
Craig Topperf7755df2012-07-12 06:52:41 +0000606 unsigned operandIndex = 0;
Sean Callanan04cc3072009-12-19 02:59:52 +0000607 // physicalOperandIndex should always be < numPhysicalOperands
608 unsigned physicalOperandIndex = 0;
Craig Topperac172e22012-07-30 04:48:12 +0000609
Sean Callanan04cc3072009-12-19 02:59:52 +0000610 switch (Form) {
611 case X86Local::RawFrm:
612 // Operand 1 (optional) is an address or immediate.
613 // Operand 2 (optional) is an immediate.
Craig Topperac172e22012-07-30 04:48:12 +0000614 assert(numPhysicalOperands <= 2 &&
Sean Callanan04cc3072009-12-19 02:59:52 +0000615 "Unexpected number of operands for RawFrm");
616 HANDLE_OPTIONAL(relocation)
617 HANDLE_OPTIONAL(immediate)
618 break;
619 case X86Local::AddRegFrm:
620 // Operand 1 is added to the opcode.
621 // Operand 2 (optional) is an address.
622 assert(numPhysicalOperands >= 1 && numPhysicalOperands <= 2 &&
623 "Unexpected number of operands for AddRegFrm");
624 HANDLE_OPERAND(opcodeModifier)
625 HANDLE_OPTIONAL(relocation)
626 break;
627 case X86Local::MRMDestReg:
628 // Operand 1 is a register operand in the R/M field.
629 // Operand 2 is a register operand in the Reg/Opcode field.
Craig Topper4f2fba12011-08-30 07:09:35 +0000630 // - In AVX, there is a register operand in the VEX.vvvv field here -
Sean Callanan04cc3072009-12-19 02:59:52 +0000631 // Operand 3 (optional) is an immediate.
Craig Topper4f2fba12011-08-30 07:09:35 +0000632 if (HasVEX_4VPrefix)
633 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
634 "Unexpected number of operands for MRMDestRegFrm with VEX_4V");
635 else
636 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
637 "Unexpected number of operands for MRMDestRegFrm");
Craig Topperac172e22012-07-30 04:48:12 +0000638
Sean Callanan04cc3072009-12-19 02:59:52 +0000639 HANDLE_OPERAND(rmRegister)
Craig Topper4f2fba12011-08-30 07:09:35 +0000640
641 if (HasVEX_4VPrefix)
642 // FIXME: In AVX, the register below becomes the one encoded
643 // in ModRMVEX and the one above the one in the VEX.VVVV field
644 HANDLE_OPERAND(vvvvRegister)
Craig Topperac172e22012-07-30 04:48:12 +0000645
Sean Callanan04cc3072009-12-19 02:59:52 +0000646 HANDLE_OPERAND(roRegister)
647 HANDLE_OPTIONAL(immediate)
648 break;
649 case X86Local::MRMDestMem:
650 // Operand 1 is a memory operand (possibly SIB-extended)
651 // Operand 2 is a register operand in the Reg/Opcode field.
Craig Topper4f2fba12011-08-30 07:09:35 +0000652 // - In AVX, there is a register operand in the VEX.vvvv field here -
Sean Callanan04cc3072009-12-19 02:59:52 +0000653 // Operand 3 (optional) is an immediate.
Craig Topper4f2fba12011-08-30 07:09:35 +0000654 if (HasVEX_4VPrefix)
655 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
656 "Unexpected number of operands for MRMDestMemFrm with VEX_4V");
657 else
658 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
659 "Unexpected number of operands for MRMDestMemFrm");
Sean Callanan04cc3072009-12-19 02:59:52 +0000660 HANDLE_OPERAND(memory)
Craig Topper4f2fba12011-08-30 07:09:35 +0000661
662 if (HasVEX_4VPrefix)
663 // FIXME: In AVX, the register below becomes the one encoded
664 // in ModRMVEX and the one above the one in the VEX.VVVV field
665 HANDLE_OPERAND(vvvvRegister)
Craig Topperac172e22012-07-30 04:48:12 +0000666
Sean Callanan04cc3072009-12-19 02:59:52 +0000667 HANDLE_OPERAND(roRegister)
668 HANDLE_OPTIONAL(immediate)
669 break;
670 case X86Local::MRMSrcReg:
671 // Operand 1 is a register operand in the Reg/Opcode field.
672 // Operand 2 is a register operand in the R/M field.
Sean Callananc3fd5232011-03-15 01:23:15 +0000673 // - In AVX, there is a register operand in the VEX.vvvv field here -
Sean Callanan04cc3072009-12-19 02:59:52 +0000674 // Operand 3 (optional) is an immediate.
Benjamin Krameref479ea2012-05-29 19:05:25 +0000675 // Operand 4 (optional) is an immediate.
Bruno Cardoso Lopesc2f87b72010-06-08 22:51:23 +0000676
Craig Topperaea148c2011-10-16 07:55:05 +0000677 if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
Craig Topper2ba766a2011-12-30 06:23:39 +0000678 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
Craig Topperac172e22012-07-30 04:48:12 +0000679 "Unexpected number of operands for MRMSrcRegFrm with VEX_4V");
Sean Callananc3fd5232011-03-15 01:23:15 +0000680 else
Benjamin Krameref479ea2012-05-29 19:05:25 +0000681 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 4 &&
Sean Callananc3fd5232011-03-15 01:23:15 +0000682 "Unexpected number of operands for MRMSrcRegFrm");
Craig Topperac172e22012-07-30 04:48:12 +0000683
Sean Callananc3fd5232011-03-15 01:23:15 +0000684 HANDLE_OPERAND(roRegister)
Craig Topper25ea4e52011-10-16 03:51:13 +0000685
Craig Topperaea148c2011-10-16 07:55:05 +0000686 if (HasVEX_4VPrefix)
Bruno Cardoso Lopesfd5458d2010-06-11 23:50:47 +0000687 // FIXME: In AVX, the register below becomes the one encoded
688 // in ModRMVEX and the one above the one in the VEX.VVVV field
Sean Callananc3fd5232011-03-15 01:23:15 +0000689 HANDLE_OPERAND(vvvvRegister)
Craig Topper25ea4e52011-10-16 03:51:13 +0000690
Craig Topper03a0bed2011-12-30 05:20:36 +0000691 if (HasMemOp4Prefix)
692 HANDLE_OPERAND(immediate)
693
Sean Callananc3fd5232011-03-15 01:23:15 +0000694 HANDLE_OPERAND(rmRegister)
Craig Topper25ea4e52011-10-16 03:51:13 +0000695
Craig Topperaea148c2011-10-16 07:55:05 +0000696 if (HasVEX_4VOp3Prefix)
Craig Topper25ea4e52011-10-16 03:51:13 +0000697 HANDLE_OPERAND(vvvvRegister)
698
Craig Topper2ba766a2011-12-30 06:23:39 +0000699 if (!HasMemOp4Prefix)
700 HANDLE_OPTIONAL(immediate)
701 HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
Benjamin Krameref479ea2012-05-29 19:05:25 +0000702 HANDLE_OPTIONAL(immediate)
Sean Callanan04cc3072009-12-19 02:59:52 +0000703 break;
704 case X86Local::MRMSrcMem:
705 // Operand 1 is a register operand in the Reg/Opcode field.
706 // Operand 2 is a memory operand (possibly SIB-extended)
Sean Callananc3fd5232011-03-15 01:23:15 +0000707 // - In AVX, there is a register operand in the VEX.vvvv field here -
Sean Callanan04cc3072009-12-19 02:59:52 +0000708 // Operand 3 (optional) is an immediate.
Craig Topperaea148c2011-10-16 07:55:05 +0000709
710 if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
Craig Topper2ba766a2011-12-30 06:23:39 +0000711 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
Craig Topperac172e22012-07-30 04:48:12 +0000712 "Unexpected number of operands for MRMSrcMemFrm with VEX_4V");
Sean Callananc3fd5232011-03-15 01:23:15 +0000713 else
714 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
715 "Unexpected number of operands for MRMSrcMemFrm");
Craig Topperac172e22012-07-30 04:48:12 +0000716
Sean Callanan04cc3072009-12-19 02:59:52 +0000717 HANDLE_OPERAND(roRegister)
Bruno Cardoso Lopesfd5458d2010-06-11 23:50:47 +0000718
Craig Topperaea148c2011-10-16 07:55:05 +0000719 if (HasVEX_4VPrefix)
Bruno Cardoso Lopesfd5458d2010-06-11 23:50:47 +0000720 // FIXME: In AVX, the register below becomes the one encoded
721 // in ModRMVEX and the one above the one in the VEX.VVVV field
Sean Callananc3fd5232011-03-15 01:23:15 +0000722 HANDLE_OPERAND(vvvvRegister)
Bruno Cardoso Lopesfd5458d2010-06-11 23:50:47 +0000723
Craig Topper03a0bed2011-12-30 05:20:36 +0000724 if (HasMemOp4Prefix)
725 HANDLE_OPERAND(immediate)
726
Sean Callanan04cc3072009-12-19 02:59:52 +0000727 HANDLE_OPERAND(memory)
Craig Topper25ea4e52011-10-16 03:51:13 +0000728
Craig Topperaea148c2011-10-16 07:55:05 +0000729 if (HasVEX_4VOp3Prefix)
Craig Topper25ea4e52011-10-16 03:51:13 +0000730 HANDLE_OPERAND(vvvvRegister)
731
Craig Topper2ba766a2011-12-30 06:23:39 +0000732 if (!HasMemOp4Prefix)
733 HANDLE_OPTIONAL(immediate)
734 HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
Sean Callanan04cc3072009-12-19 02:59:52 +0000735 break;
736 case X86Local::MRM0r:
737 case X86Local::MRM1r:
738 case X86Local::MRM2r:
739 case X86Local::MRM3r:
740 case X86Local::MRM4r:
741 case X86Local::MRM5r:
742 case X86Local::MRM6r:
743 case X86Local::MRM7r:
744 // Operand 1 is a register operand in the R/M field.
745 // Operand 2 (optional) is an immediate or relocation.
Benjamin Krameref479ea2012-05-29 19:05:25 +0000746 // Operand 3 (optional) is an immediate.
Sean Callananc3fd5232011-03-15 01:23:15 +0000747 if (HasVEX_4VPrefix)
748 assert(numPhysicalOperands <= 3 &&
Craig Topper27ad1252011-10-15 20:46:47 +0000749 "Unexpected number of operands for MRMnRFrm with VEX_4V");
Sean Callananc3fd5232011-03-15 01:23:15 +0000750 else
Benjamin Krameref479ea2012-05-29 19:05:25 +0000751 assert(numPhysicalOperands <= 3 &&
Sean Callananc3fd5232011-03-15 01:23:15 +0000752 "Unexpected number of operands for MRMnRFrm");
753 if (HasVEX_4VPrefix)
Craig Topper27ad1252011-10-15 20:46:47 +0000754 HANDLE_OPERAND(vvvvRegister)
Sean Callanan04cc3072009-12-19 02:59:52 +0000755 HANDLE_OPTIONAL(rmRegister)
756 HANDLE_OPTIONAL(relocation)
Benjamin Krameref479ea2012-05-29 19:05:25 +0000757 HANDLE_OPTIONAL(immediate)
Sean Callanan04cc3072009-12-19 02:59:52 +0000758 break;
759 case X86Local::MRM0m:
760 case X86Local::MRM1m:
761 case X86Local::MRM2m:
762 case X86Local::MRM3m:
763 case X86Local::MRM4m:
764 case X86Local::MRM5m:
765 case X86Local::MRM6m:
766 case X86Local::MRM7m:
767 // Operand 1 is a memory operand (possibly SIB-extended)
768 // Operand 2 (optional) is an immediate or relocation.
Craig Topper27ad1252011-10-15 20:46:47 +0000769 if (HasVEX_4VPrefix)
770 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
771 "Unexpected number of operands for MRMnMFrm");
772 else
773 assert(numPhysicalOperands >= 1 && numPhysicalOperands <= 2 &&
774 "Unexpected number of operands for MRMnMFrm");
775 if (HasVEX_4VPrefix)
776 HANDLE_OPERAND(vvvvRegister)
Sean Callanan04cc3072009-12-19 02:59:52 +0000777 HANDLE_OPERAND(memory)
778 HANDLE_OPTIONAL(relocation)
779 break;
Sean Callanan8d302b22010-10-04 22:45:51 +0000780 case X86Local::RawFrmImm8:
781 // operand 1 is a 16-bit immediate
782 // operand 2 is an 8-bit immediate
783 assert(numPhysicalOperands == 2 &&
784 "Unexpected number of operands for X86Local::RawFrmImm8");
785 HANDLE_OPERAND(immediate)
786 HANDLE_OPERAND(immediate)
787 break;
788 case X86Local::RawFrmImm16:
789 // operand 1 is a 16-bit immediate
790 // operand 2 is a 16-bit immediate
791 HANDLE_OPERAND(immediate)
792 HANDLE_OPERAND(immediate)
793 break;
Sean Callanan04cc3072009-12-19 02:59:52 +0000794 case X86Local::MRMInitReg:
795 // Ignored.
796 break;
797 }
Craig Topperac172e22012-07-30 04:48:12 +0000798
Sean Callanan04cc3072009-12-19 02:59:52 +0000799 #undef HANDLE_OPERAND
800 #undef HANDLE_OPTIONAL
801}
802
803void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
804 // Special cases where the LLVM tables are not complete
805
Sean Callanandde9c122010-02-12 23:39:46 +0000806#define MAP(from, to) \
807 case X86Local::MRM_##from: \
808 filter = new ExactFilter(0x##from); \
809 break;
Sean Callanan04cc3072009-12-19 02:59:52 +0000810
811 OpcodeType opcodeType = (OpcodeType)-1;
Craig Topperac172e22012-07-30 04:48:12 +0000812
813 ModRMFilter* filter = NULL;
Sean Callanan04cc3072009-12-19 02:59:52 +0000814 uint8_t opcodeToSet = 0;
815
816 switch (Prefix) {
817 // Extended two-byte opcodes can start with f2 0f, f3 0f, or 0f
818 case X86Local::XD:
819 case X86Local::XS:
820 case X86Local::TB:
821 opcodeType = TWOBYTE;
822
823 switch (Opcode) {
Sean Callanan44232af2010-02-13 01:48:34 +0000824 default:
825 if (needsModRMForDecode(Form))
826 filter = new ModFilter(isRegFormat(Form));
827 else
828 filter = new DumbFilter();
829 break;
Sean Callanan04cc3072009-12-19 02:59:52 +0000830#define EXTENSION_TABLE(n) case 0x##n:
831 TWO_BYTE_EXTENSION_TABLES
832#undef EXTENSION_TABLE
833 switch (Form) {
834 default:
835 llvm_unreachable("Unhandled two-byte extended opcode");
836 case X86Local::MRM0r:
837 case X86Local::MRM1r:
838 case X86Local::MRM2r:
839 case X86Local::MRM3r:
840 case X86Local::MRM4r:
841 case X86Local::MRM5r:
842 case X86Local::MRM6r:
843 case X86Local::MRM7r:
844 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
845 break;
846 case X86Local::MRM0m:
847 case X86Local::MRM1m:
848 case X86Local::MRM2m:
849 case X86Local::MRM3m:
850 case X86Local::MRM4m:
851 case X86Local::MRM5m:
852 case X86Local::MRM6m:
853 case X86Local::MRM7m:
854 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
855 break;
Sean Callanandde9c122010-02-12 23:39:46 +0000856 MRM_MAPPING
Sean Callanan04cc3072009-12-19 02:59:52 +0000857 } // switch (Form)
858 break;
Sean Callanan44232af2010-02-13 01:48:34 +0000859 } // switch (Opcode)
Sean Callanan04cc3072009-12-19 02:59:52 +0000860 opcodeToSet = Opcode;
861 break;
862 case X86Local::T8:
Craig Topper96fa5972011-10-16 16:50:08 +0000863 case X86Local::T8XD:
864 case X86Local::T8XS:
Sean Callanan04cc3072009-12-19 02:59:52 +0000865 opcodeType = THREEBYTE_38;
Craig Topper27ad1252011-10-15 20:46:47 +0000866 switch (Opcode) {
867 default:
868 if (needsModRMForDecode(Form))
869 filter = new ModFilter(isRegFormat(Form));
870 else
871 filter = new DumbFilter();
872 break;
873#define EXTENSION_TABLE(n) case 0x##n:
874 THREE_BYTE_38_EXTENSION_TABLES
875#undef EXTENSION_TABLE
876 switch (Form) {
877 default:
878 llvm_unreachable("Unhandled two-byte extended opcode");
879 case X86Local::MRM0r:
880 case X86Local::MRM1r:
881 case X86Local::MRM2r:
882 case X86Local::MRM3r:
883 case X86Local::MRM4r:
884 case X86Local::MRM5r:
885 case X86Local::MRM6r:
886 case X86Local::MRM7r:
887 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
888 break;
889 case X86Local::MRM0m:
890 case X86Local::MRM1m:
891 case X86Local::MRM2m:
892 case X86Local::MRM3m:
893 case X86Local::MRM4m:
894 case X86Local::MRM5m:
895 case X86Local::MRM6m:
896 case X86Local::MRM7m:
897 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
898 break;
899 MRM_MAPPING
900 } // switch (Form)
901 break;
902 } // switch (Opcode)
Sean Callanan04cc3072009-12-19 02:59:52 +0000903 opcodeToSet = Opcode;
904 break;
Chris Lattnerf7477e52010-02-12 02:06:33 +0000905 case X86Local::P_TA:
Craig Topper980d5982011-10-23 07:34:00 +0000906 case X86Local::TAXD:
Sean Callanan04cc3072009-12-19 02:59:52 +0000907 opcodeType = THREEBYTE_3A;
908 if (needsModRMForDecode(Form))
909 filter = new ModFilter(isRegFormat(Form));
910 else
911 filter = new DumbFilter();
912 opcodeToSet = Opcode;
913 break;
Joerg Sonnenbergerfc4789d2011-04-04 16:58:13 +0000914 case X86Local::A6:
915 opcodeType = THREEBYTE_A6;
916 if (needsModRMForDecode(Form))
917 filter = new ModFilter(isRegFormat(Form));
918 else
919 filter = new DumbFilter();
920 opcodeToSet = Opcode;
921 break;
922 case X86Local::A7:
923 opcodeType = THREEBYTE_A7;
924 if (needsModRMForDecode(Form))
925 filter = new ModFilter(isRegFormat(Form));
926 else
927 filter = new DumbFilter();
928 opcodeToSet = Opcode;
929 break;
Sean Callanan04cc3072009-12-19 02:59:52 +0000930 case X86Local::D8:
931 case X86Local::D9:
932 case X86Local::DA:
933 case X86Local::DB:
934 case X86Local::DC:
935 case X86Local::DD:
936 case X86Local::DE:
937 case X86Local::DF:
938 assert(Opcode >= 0xc0 && "Unexpected opcode for an escape opcode");
939 opcodeType = ONEBYTE;
940 if (Form == X86Local::AddRegFrm) {
941 Spec->modifierType = MODIFIER_MODRM;
942 Spec->modifierBase = Opcode;
943 filter = new AddRegEscapeFilter(Opcode);
944 } else {
945 filter = new EscapeFilter(true, Opcode);
946 }
947 opcodeToSet = 0xd8 + (Prefix - X86Local::D8);
948 break;
Craig Toppera948cb92011-09-11 20:23:20 +0000949 case X86Local::REP:
Sean Callanan04cc3072009-12-19 02:59:52 +0000950 default:
951 opcodeType = ONEBYTE;
952 switch (Opcode) {
953#define EXTENSION_TABLE(n) case 0x##n:
954 ONE_BYTE_EXTENSION_TABLES
955#undef EXTENSION_TABLE
956 switch (Form) {
957 default:
958 llvm_unreachable("Fell through the cracks of a single-byte "
959 "extended opcode");
960 case X86Local::MRM0r:
961 case X86Local::MRM1r:
962 case X86Local::MRM2r:
963 case X86Local::MRM3r:
964 case X86Local::MRM4r:
965 case X86Local::MRM5r:
966 case X86Local::MRM6r:
967 case X86Local::MRM7r:
968 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
969 break;
970 case X86Local::MRM0m:
971 case X86Local::MRM1m:
972 case X86Local::MRM2m:
973 case X86Local::MRM3m:
974 case X86Local::MRM4m:
975 case X86Local::MRM5m:
976 case X86Local::MRM6m:
977 case X86Local::MRM7m:
978 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
979 break;
Sean Callanandde9c122010-02-12 23:39:46 +0000980 MRM_MAPPING
Sean Callanan04cc3072009-12-19 02:59:52 +0000981 } // switch (Form)
982 break;
983 case 0xd8:
984 case 0xd9:
985 case 0xda:
986 case 0xdb:
987 case 0xdc:
988 case 0xdd:
989 case 0xde:
990 case 0xdf:
991 filter = new EscapeFilter(false, Form - X86Local::MRM0m);
992 break;
993 default:
994 if (needsModRMForDecode(Form))
995 filter = new ModFilter(isRegFormat(Form));
996 else
997 filter = new DumbFilter();
998 break;
999 } // switch (Opcode)
1000 opcodeToSet = Opcode;
1001 } // switch (Prefix)
1002
1003 assert(opcodeType != (OpcodeType)-1 &&
1004 "Opcode type not set");
1005 assert(filter && "Filter not set");
1006
1007 if (Form == X86Local::AddRegFrm) {
1008 if(Spec->modifierType != MODIFIER_MODRM) {
1009 assert(opcodeToSet < 0xf9 &&
1010 "Not enough room for all ADDREG_FRM operands");
Craig Topperac172e22012-07-30 04:48:12 +00001011
Sean Callanan04cc3072009-12-19 02:59:52 +00001012 uint8_t currentOpcode;
1013
1014 for (currentOpcode = opcodeToSet;
1015 currentOpcode < opcodeToSet + 8;
1016 ++currentOpcode)
Craig Topperac172e22012-07-30 04:48:12 +00001017 tables.setTableFields(opcodeType,
1018 insnContext(),
1019 currentOpcode,
1020 *filter,
Craig Topperf18c8962011-10-04 06:30:42 +00001021 UID, Is32Bit, IgnoresVEX_L);
Craig Topperac172e22012-07-30 04:48:12 +00001022
Sean Callanan04cc3072009-12-19 02:59:52 +00001023 Spec->modifierType = MODIFIER_OPCODE;
1024 Spec->modifierBase = opcodeToSet;
1025 } else {
1026 // modifierBase was set where MODIFIER_MODRM was set
Craig Topperac172e22012-07-30 04:48:12 +00001027 tables.setTableFields(opcodeType,
1028 insnContext(),
1029 opcodeToSet,
1030 *filter,
Craig Topperf18c8962011-10-04 06:30:42 +00001031 UID, Is32Bit, IgnoresVEX_L);
Sean Callanan04cc3072009-12-19 02:59:52 +00001032 }
1033 } else {
1034 tables.setTableFields(opcodeType,
1035 insnContext(),
1036 opcodeToSet,
1037 *filter,
Craig Topperf18c8962011-10-04 06:30:42 +00001038 UID, Is32Bit, IgnoresVEX_L);
Craig Topperac172e22012-07-30 04:48:12 +00001039
Sean Callanan04cc3072009-12-19 02:59:52 +00001040 Spec->modifierType = MODIFIER_NONE;
1041 Spec->modifierBase = opcodeToSet;
1042 }
Craig Topperac172e22012-07-30 04:48:12 +00001043
Sean Callanan04cc3072009-12-19 02:59:52 +00001044 delete filter;
Craig Topperac172e22012-07-30 04:48:12 +00001045
Sean Callanandde9c122010-02-12 23:39:46 +00001046#undef MAP
Sean Callanan04cc3072009-12-19 02:59:52 +00001047}
1048
1049#define TYPE(str, type) if (s == str) return type;
1050OperandType RecognizableInstr::typeFromString(const std::string &s,
1051 bool isSSE,
1052 bool hasREX_WPrefix,
1053 bool hasOpSizePrefix) {
1054 if (isSSE) {
Craig Topperac172e22012-07-30 04:48:12 +00001055 // For SSE instructions, we ignore the OpSize prefix and force operand
Sean Callanan04cc3072009-12-19 02:59:52 +00001056 // sizes.
1057 TYPE("GR16", TYPE_R16)
1058 TYPE("GR32", TYPE_R32)
1059 TYPE("GR64", TYPE_R64)
1060 }
1061 if(hasREX_WPrefix) {
1062 // For instructions with a REX_W prefix, a declared 32-bit register encoding
1063 // is special.
1064 TYPE("GR32", TYPE_R32)
1065 }
1066 if(!hasOpSizePrefix) {
1067 // For instructions without an OpSize prefix, a declared 16-bit register or
1068 // immediate encoding is special.
1069 TYPE("GR16", TYPE_R16)
1070 TYPE("i16imm", TYPE_IMM16)
1071 }
1072 TYPE("i16mem", TYPE_Mv)
1073 TYPE("i16imm", TYPE_IMMv)
1074 TYPE("i16i8imm", TYPE_IMMv)
1075 TYPE("GR16", TYPE_Rv)
1076 TYPE("i32mem", TYPE_Mv)
1077 TYPE("i32imm", TYPE_IMMv)
1078 TYPE("i32i8imm", TYPE_IMM32)
Kevin Enderby5ef6c452011-07-27 23:01:50 +00001079 TYPE("u32u8imm", TYPE_IMM32)
Sean Callanan04cc3072009-12-19 02:59:52 +00001080 TYPE("GR32", TYPE_Rv)
1081 TYPE("i64mem", TYPE_Mv)
1082 TYPE("i64i32imm", TYPE_IMM64)
1083 TYPE("i64i8imm", TYPE_IMM64)
1084 TYPE("GR64", TYPE_R64)
1085 TYPE("i8mem", TYPE_M8)
1086 TYPE("i8imm", TYPE_IMM8)
1087 TYPE("GR8", TYPE_R8)
1088 TYPE("VR128", TYPE_XMM128)
1089 TYPE("f128mem", TYPE_M128)
Chris Lattnerf60062f2010-09-29 02:57:56 +00001090 TYPE("f256mem", TYPE_M256)
Sean Callanan04cc3072009-12-19 02:59:52 +00001091 TYPE("FR64", TYPE_XMM64)
1092 TYPE("f64mem", TYPE_M64FP)
Chris Lattnerf60062f2010-09-29 02:57:56 +00001093 TYPE("sdmem", TYPE_M64FP)
Sean Callanan04cc3072009-12-19 02:59:52 +00001094 TYPE("FR32", TYPE_XMM32)
1095 TYPE("f32mem", TYPE_M32FP)
Chris Lattnerf60062f2010-09-29 02:57:56 +00001096 TYPE("ssmem", TYPE_M32FP)
Sean Callanan04cc3072009-12-19 02:59:52 +00001097 TYPE("RST", TYPE_ST)
1098 TYPE("i128mem", TYPE_M128)
Sean Callananc3fd5232011-03-15 01:23:15 +00001099 TYPE("i256mem", TYPE_M256)
Sean Callanan04cc3072009-12-19 02:59:52 +00001100 TYPE("i64i32imm_pcrel", TYPE_REL64)
Chris Lattnerac588122010-07-07 22:27:31 +00001101 TYPE("i16imm_pcrel", TYPE_REL16)
Sean Callanan04cc3072009-12-19 02:59:52 +00001102 TYPE("i32imm_pcrel", TYPE_REL32)
Sean Callanan1efe6612010-04-07 21:42:19 +00001103 TYPE("SSECC", TYPE_IMM3)
Craig Topper7629d632012-04-03 05:20:24 +00001104 TYPE("AVXCC", TYPE_IMM5)
Sean Callanan04cc3072009-12-19 02:59:52 +00001105 TYPE("brtarget", TYPE_RELv)
Owen Anderson578074b2010-12-13 19:31:11 +00001106 TYPE("uncondbrtarget", TYPE_RELv)
Sean Callanan04cc3072009-12-19 02:59:52 +00001107 TYPE("brtarget8", TYPE_REL8)
1108 TYPE("f80mem", TYPE_M80FP)
Sean Callanan36eab802009-12-22 21:12:55 +00001109 TYPE("lea32mem", TYPE_LEA)
1110 TYPE("lea64_32mem", TYPE_LEA)
1111 TYPE("lea64mem", TYPE_LEA)
Sean Callanan04cc3072009-12-19 02:59:52 +00001112 TYPE("VR64", TYPE_MM64)
1113 TYPE("i64imm", TYPE_IMMv)
1114 TYPE("opaque32mem", TYPE_M1616)
1115 TYPE("opaque48mem", TYPE_M1632)
1116 TYPE("opaque80mem", TYPE_M1664)
1117 TYPE("opaque512mem", TYPE_M512)
1118 TYPE("SEGMENT_REG", TYPE_SEGMENTREG)
1119 TYPE("DEBUG_REG", TYPE_DEBUGREG)
Sean Callanane7e1cf92010-05-06 20:59:00 +00001120 TYPE("CONTROL_REG", TYPE_CONTROLREG)
Sean Callanan04cc3072009-12-19 02:59:52 +00001121 TYPE("offset8", TYPE_MOFFS8)
1122 TYPE("offset16", TYPE_MOFFS16)
1123 TYPE("offset32", TYPE_MOFFS32)
1124 TYPE("offset64", TYPE_MOFFS64)
Sean Callananc3fd5232011-03-15 01:23:15 +00001125 TYPE("VR256", TYPE_XMM256)
Craig Topper23eb4682011-10-06 06:44:41 +00001126 TYPE("GR16_NOAX", TYPE_Rv)
1127 TYPE("GR32_NOAX", TYPE_Rv)
1128 TYPE("GR64_NOAX", TYPE_R64)
Craig Topper01deb5f2012-07-18 04:11:12 +00001129 TYPE("vx32mem", TYPE_M32)
1130 TYPE("vy32mem", TYPE_M32)
1131 TYPE("vx64mem", TYPE_M64)
1132 TYPE("vy64mem", TYPE_M64)
Sean Callanan04cc3072009-12-19 02:59:52 +00001133 errs() << "Unhandled type string " << s << "\n";
1134 llvm_unreachable("Unhandled type string");
1135}
1136#undef TYPE
1137
1138#define ENCODING(str, encoding) if (s == str) return encoding;
1139OperandEncoding RecognizableInstr::immediateEncodingFromString
1140 (const std::string &s,
1141 bool hasOpSizePrefix) {
1142 if(!hasOpSizePrefix) {
1143 // For instructions without an OpSize prefix, a declared 16-bit register or
1144 // immediate encoding is special.
1145 ENCODING("i16imm", ENCODING_IW)
1146 }
1147 ENCODING("i32i8imm", ENCODING_IB)
Kevin Enderby5ef6c452011-07-27 23:01:50 +00001148 ENCODING("u32u8imm", ENCODING_IB)
Sean Callanan04cc3072009-12-19 02:59:52 +00001149 ENCODING("SSECC", ENCODING_IB)
Craig Topper7629d632012-04-03 05:20:24 +00001150 ENCODING("AVXCC", ENCODING_IB)
Sean Callanan04cc3072009-12-19 02:59:52 +00001151 ENCODING("i16imm", ENCODING_Iv)
1152 ENCODING("i16i8imm", ENCODING_IB)
1153 ENCODING("i32imm", ENCODING_Iv)
1154 ENCODING("i64i32imm", ENCODING_ID)
1155 ENCODING("i64i8imm", ENCODING_IB)
1156 ENCODING("i8imm", ENCODING_IB)
Sean Callananc3fd5232011-03-15 01:23:15 +00001157 // This is not a typo. Instructions like BLENDVPD put
1158 // register IDs in 8-bit immediates nowadays.
1159 ENCODING("VR256", ENCODING_IB)
1160 ENCODING("VR128", ENCODING_IB)
Sean Callanan04cc3072009-12-19 02:59:52 +00001161 errs() << "Unhandled immediate encoding " << s << "\n";
1162 llvm_unreachable("Unhandled immediate encoding");
1163}
1164
1165OperandEncoding RecognizableInstr::rmRegisterEncodingFromString
1166 (const std::string &s,
1167 bool hasOpSizePrefix) {
1168 ENCODING("GR16", ENCODING_RM)
1169 ENCODING("GR32", ENCODING_RM)
1170 ENCODING("GR64", ENCODING_RM)
1171 ENCODING("GR8", ENCODING_RM)
1172 ENCODING("VR128", ENCODING_RM)
1173 ENCODING("FR64", ENCODING_RM)
1174 ENCODING("FR32", ENCODING_RM)
1175 ENCODING("VR64", ENCODING_RM)
Sean Callananc3fd5232011-03-15 01:23:15 +00001176 ENCODING("VR256", ENCODING_RM)
Sean Callanan04cc3072009-12-19 02:59:52 +00001177 errs() << "Unhandled R/M register encoding " << s << "\n";
1178 llvm_unreachable("Unhandled R/M register encoding");
1179}
1180
1181OperandEncoding RecognizableInstr::roRegisterEncodingFromString
1182 (const std::string &s,
1183 bool hasOpSizePrefix) {
1184 ENCODING("GR16", ENCODING_REG)
1185 ENCODING("GR32", ENCODING_REG)
1186 ENCODING("GR64", ENCODING_REG)
1187 ENCODING("GR8", ENCODING_REG)
1188 ENCODING("VR128", ENCODING_REG)
1189 ENCODING("FR64", ENCODING_REG)
1190 ENCODING("FR32", ENCODING_REG)
1191 ENCODING("VR64", ENCODING_REG)
1192 ENCODING("SEGMENT_REG", ENCODING_REG)
1193 ENCODING("DEBUG_REG", ENCODING_REG)
Sean Callanane7e1cf92010-05-06 20:59:00 +00001194 ENCODING("CONTROL_REG", ENCODING_REG)
Sean Callananc3fd5232011-03-15 01:23:15 +00001195 ENCODING("VR256", ENCODING_REG)
Sean Callanan04cc3072009-12-19 02:59:52 +00001196 errs() << "Unhandled reg/opcode register encoding " << s << "\n";
1197 llvm_unreachable("Unhandled reg/opcode register encoding");
1198}
1199
Sean Callananc3fd5232011-03-15 01:23:15 +00001200OperandEncoding RecognizableInstr::vvvvRegisterEncodingFromString
1201 (const std::string &s,
1202 bool hasOpSizePrefix) {
Craig Topper965de2c2011-10-14 07:06:56 +00001203 ENCODING("GR32", ENCODING_VVVV)
1204 ENCODING("GR64", ENCODING_VVVV)
Sean Callananc3fd5232011-03-15 01:23:15 +00001205 ENCODING("FR32", ENCODING_VVVV)
1206 ENCODING("FR64", ENCODING_VVVV)
1207 ENCODING("VR128", ENCODING_VVVV)
1208 ENCODING("VR256", ENCODING_VVVV)
1209 errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
1210 llvm_unreachable("Unhandled VEX.vvvv register encoding");
1211}
1212
Sean Callanan04cc3072009-12-19 02:59:52 +00001213OperandEncoding RecognizableInstr::memoryEncodingFromString
1214 (const std::string &s,
1215 bool hasOpSizePrefix) {
1216 ENCODING("i16mem", ENCODING_RM)
1217 ENCODING("i32mem", ENCODING_RM)
1218 ENCODING("i64mem", ENCODING_RM)
1219 ENCODING("i8mem", ENCODING_RM)
Chris Lattnerf60062f2010-09-29 02:57:56 +00001220 ENCODING("ssmem", ENCODING_RM)
1221 ENCODING("sdmem", ENCODING_RM)
Sean Callanan04cc3072009-12-19 02:59:52 +00001222 ENCODING("f128mem", ENCODING_RM)
Chris Lattnerf60062f2010-09-29 02:57:56 +00001223 ENCODING("f256mem", ENCODING_RM)
Sean Callanan04cc3072009-12-19 02:59:52 +00001224 ENCODING("f64mem", ENCODING_RM)
1225 ENCODING("f32mem", ENCODING_RM)
1226 ENCODING("i128mem", ENCODING_RM)
Sean Callananc3fd5232011-03-15 01:23:15 +00001227 ENCODING("i256mem", ENCODING_RM)
Sean Callanan04cc3072009-12-19 02:59:52 +00001228 ENCODING("f80mem", ENCODING_RM)
1229 ENCODING("lea32mem", ENCODING_RM)
1230 ENCODING("lea64_32mem", ENCODING_RM)
1231 ENCODING("lea64mem", ENCODING_RM)
1232 ENCODING("opaque32mem", ENCODING_RM)
1233 ENCODING("opaque48mem", ENCODING_RM)
1234 ENCODING("opaque80mem", ENCODING_RM)
1235 ENCODING("opaque512mem", ENCODING_RM)
Craig Topper01deb5f2012-07-18 04:11:12 +00001236 ENCODING("vx32mem", ENCODING_RM)
1237 ENCODING("vy32mem", ENCODING_RM)
1238 ENCODING("vx64mem", ENCODING_RM)
1239 ENCODING("vy64mem", ENCODING_RM)
Sean Callanan04cc3072009-12-19 02:59:52 +00001240 errs() << "Unhandled memory encoding " << s << "\n";
1241 llvm_unreachable("Unhandled memory encoding");
1242}
1243
1244OperandEncoding RecognizableInstr::relocationEncodingFromString
1245 (const std::string &s,
1246 bool hasOpSizePrefix) {
1247 if(!hasOpSizePrefix) {
1248 // For instructions without an OpSize prefix, a declared 16-bit register or
1249 // immediate encoding is special.
1250 ENCODING("i16imm", ENCODING_IW)
1251 }
1252 ENCODING("i16imm", ENCODING_Iv)
1253 ENCODING("i16i8imm", ENCODING_IB)
1254 ENCODING("i32imm", ENCODING_Iv)
1255 ENCODING("i32i8imm", ENCODING_IB)
1256 ENCODING("i64i32imm", ENCODING_ID)
1257 ENCODING("i64i8imm", ENCODING_IB)
1258 ENCODING("i8imm", ENCODING_IB)
1259 ENCODING("i64i32imm_pcrel", ENCODING_ID)
Chris Lattnerac588122010-07-07 22:27:31 +00001260 ENCODING("i16imm_pcrel", ENCODING_IW)
Sean Callanan04cc3072009-12-19 02:59:52 +00001261 ENCODING("i32imm_pcrel", ENCODING_ID)
1262 ENCODING("brtarget", ENCODING_Iv)
1263 ENCODING("brtarget8", ENCODING_IB)
1264 ENCODING("i64imm", ENCODING_IO)
1265 ENCODING("offset8", ENCODING_Ia)
1266 ENCODING("offset16", ENCODING_Ia)
1267 ENCODING("offset32", ENCODING_Ia)
1268 ENCODING("offset64", ENCODING_Ia)
1269 errs() << "Unhandled relocation encoding " << s << "\n";
1270 llvm_unreachable("Unhandled relocation encoding");
1271}
1272
1273OperandEncoding RecognizableInstr::opcodeModifierEncodingFromString
1274 (const std::string &s,
1275 bool hasOpSizePrefix) {
1276 ENCODING("RST", ENCODING_I)
1277 ENCODING("GR32", ENCODING_Rv)
1278 ENCODING("GR64", ENCODING_RO)
1279 ENCODING("GR16", ENCODING_Rv)
1280 ENCODING("GR8", ENCODING_RB)
Craig Topper23eb4682011-10-06 06:44:41 +00001281 ENCODING("GR16_NOAX", ENCODING_Rv)
1282 ENCODING("GR32_NOAX", ENCODING_Rv)
1283 ENCODING("GR64_NOAX", ENCODING_RO)
Sean Callanan04cc3072009-12-19 02:59:52 +00001284 errs() << "Unhandled opcode modifier encoding " << s << "\n";
1285 llvm_unreachable("Unhandled opcode modifier encoding");
1286}
Daniel Dunbarf008ea52009-12-19 04:16:48 +00001287#undef ENCODING