1 //===- X86RecognizableInstr.cpp - Disassembler instruction spec --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #include "X86RecognizableInstr.h"
18 #include "X86DisassemblerShared.h"
19 #include "X86ModRMFilters.h"
20 #include "llvm/Support/ErrorHandling.h"
52 // A clone of X86 since we can't depend on something that is generated.
62 MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19,
63 MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23,
64 MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27,
65 MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31,
69 #define MAP(from, to) MRM_##from = to,
78 D8 = 3, D9 = 4, DA = 5, DB = 6,
79 DC = 7, DD = 8, DE = 9, DF = 10,
82 A6 = 15, A7 = 16, T8XD = 17, T8XS = 18, TAXD = 19,
83 XOP8 = 20, XOP9 = 21, XOPA = 22
87 // If rows are added to the opcode extension tables, then corresponding entries
88 // must be added here.
90 // If the row corresponds to a single byte (i.e., 8f), then add an entry for
91 // that byte to ONE_BYTE_EXTENSION_TABLES.
93 // If the row corresponds to two bytes where the first is 0f, add an entry for
94 // the second byte to TWO_BYTE_EXTENSION_TABLES.
96 // If the row corresponds to some other set of bytes, you will need to modify
97 // the code in RecognizableInstr::emitDecodePath() as well, and add new prefixes
98 // to the X86 TD files, except in two cases: if the first two bytes of such a
99 // new combination are 0f 38 or 0f 3a, you just have to add maps called
100 // THREE_BYTE_38_EXTENSION_TABLES and THREE_BYTE_3A_EXTENSION_TABLES and add a
101 // switch(Opcode) just below the case X86Local::T8: or case X86Local::TA: line
102 // in RecognizableInstr::emitDecodePath().
104 #define ONE_BYTE_EXTENSION_TABLES \
105 EXTENSION_TABLE(80) \
106 EXTENSION_TABLE(81) \
107 EXTENSION_TABLE(82) \
108 EXTENSION_TABLE(83) \
109 EXTENSION_TABLE(8f) \
110 EXTENSION_TABLE(c0) \
111 EXTENSION_TABLE(c1) \
112 EXTENSION_TABLE(c6) \
113 EXTENSION_TABLE(c7) \
114 EXTENSION_TABLE(d0) \
115 EXTENSION_TABLE(d1) \
116 EXTENSION_TABLE(d2) \
117 EXTENSION_TABLE(d3) \
118 EXTENSION_TABLE(f6) \
119 EXTENSION_TABLE(f7) \
120 EXTENSION_TABLE(fe) \
123 #define TWO_BYTE_EXTENSION_TABLES \
124 EXTENSION_TABLE(00) \
125 EXTENSION_TABLE(01) \
126 EXTENSION_TABLE(0d) \
127 EXTENSION_TABLE(18) \
128 EXTENSION_TABLE(71) \
129 EXTENSION_TABLE(72) \
130 EXTENSION_TABLE(73) \
131 EXTENSION_TABLE(ae) \
132 EXTENSION_TABLE(ba) \
135 #define THREE_BYTE_38_EXTENSION_TABLES \
138 #define XOP9_MAP_EXTENSION_TABLES \
139 EXTENSION_TABLE(01) \
142 using namespace X86Disassembler;
144 /// needsModRMForDecode - Indicates whether a particular instruction requires a
145 /// ModR/M byte for the instruction to be properly decoded. For example, a
146 /// MRMDestReg instruction needs the Mod field in the ModR/M byte to be set to
149 /// @param form - The form of the instruction.
150 /// @return - true if the form implies that a ModR/M byte is required, false
152 static bool needsModRMForDecode(uint8_t form) {
153 if (form == X86Local::MRMDestReg ||
154 form == X86Local::MRMDestMem ||
155 form == X86Local::MRMSrcReg ||
156 form == X86Local::MRMSrcMem ||
157 (form >= X86Local::MRM0r && form <= X86Local::MRM7r) ||
158 (form >= X86Local::MRM0m && form <= X86Local::MRM7m))
164 /// isRegFormat - Indicates whether a particular form requires the Mod field of
165 /// the ModR/M byte to be 0b11.
167 /// @param form - The form of the instruction.
168 /// @return - true if the form implies that Mod must be 0b11, false
170 static bool isRegFormat(uint8_t form) {
171 if (form == X86Local::MRMDestReg ||
172 form == X86Local::MRMSrcReg ||
173 (form >= X86Local::MRM0r && form <= X86Local::MRM7r))
179 /// byteFromBitsInit - Extracts a value at most 8 bits in width from a BitsInit.
180 /// Useful for switch statements and the like.
182 /// @param init - A reference to the BitsInit to be decoded.
183 /// @return - The field, with the first bit in the BitsInit as the lowest
185 static uint8_t byteFromBitsInit(BitsInit &init) {
186 int width = init.getNumBits();
188 assert(width <= 8 && "Field is too large for uint8_t!");
195 for (index = 0; index < width; index++) {
196 if (static_cast<BitInit*>(init.getBit(index))->getValue())
205 /// byteFromRec - Extract a value at most 8 bits in with from a Record given the
206 /// name of the field.
208 /// @param rec - The record from which to extract the value.
209 /// @param name - The name of the field in the record.
210 /// @return - The field, as translated by byteFromBitsInit().
211 static uint8_t byteFromRec(const Record* rec, const std::string &name) {
212 BitsInit* bits = rec->getValueAsBitsInit(name);
213 return byteFromBitsInit(*bits);
216 RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
217 const CodeGenInstruction &insn,
222 Name = Rec->getName();
223 Spec = &tables.specForUID(UID);
225 if (!Rec->isSubClassOf("X86Inst")) {
226 ShouldBeEmitted = false;
230 Prefix = byteFromRec(Rec, "Prefix");
231 Opcode = byteFromRec(Rec, "Opcode");
232 Form = byteFromRec(Rec, "FormBits");
233 SegOvr = byteFromRec(Rec, "SegOvrBits");
235 HasOpSizePrefix = Rec->getValueAsBit("hasOpSizePrefix");
236 HasAdSizePrefix = Rec->getValueAsBit("hasAdSizePrefix");
237 HasREX_WPrefix = Rec->getValueAsBit("hasREX_WPrefix");
238 HasVEXPrefix = Rec->getValueAsBit("hasVEXPrefix");
239 HasVEX_4VPrefix = Rec->getValueAsBit("hasVEX_4VPrefix");
240 HasVEX_4VOp3Prefix = Rec->getValueAsBit("hasVEX_4VOp3Prefix");
241 HasVEX_WPrefix = Rec->getValueAsBit("hasVEX_WPrefix");
242 HasMemOp4Prefix = Rec->getValueAsBit("hasMemOp4Prefix");
243 IgnoresVEX_L = Rec->getValueAsBit("ignoresVEX_L");
244 HasEVEXPrefix = Rec->getValueAsBit("hasEVEXPrefix");
245 HasEVEX_L2Prefix = Rec->getValueAsBit("hasEVEX_L2");
246 HasEVEX_K = Rec->getValueAsBit("hasEVEX_K");
247 HasEVEX_KZ = Rec->getValueAsBit("hasEVEX_Z");
248 HasEVEX_B = Rec->getValueAsBit("hasEVEX_B");
249 HasLockPrefix = Rec->getValueAsBit("hasLockPrefix");
250 IsCodeGenOnly = Rec->getValueAsBit("isCodeGenOnly");
252 Name = Rec->getName();
253 AsmString = Rec->getValueAsString("AsmString");
255 Operands = &insn.Operands.OperandList;
257 IsSSE = (HasOpSizePrefix && (Name.find("16") == Name.npos)) ||
258 (Name.find("CRC32") != Name.npos);
259 HasFROperands = hasFROperands();
260 HasVEX_LPrefix = Rec->getValueAsBit("hasVEX_L");
262 // Check for 64-bit inst which does not require REX
265 // FIXME: Is there some better way to check for In64BitMode?
266 std::vector<Record*> Predicates = Rec->getValueAsListOfDefs("Predicates");
267 for (unsigned i = 0, e = Predicates.size(); i != e; ++i) {
268 if (Predicates[i]->getName().find("Not64Bit") != Name.npos ||
269 Predicates[i]->getName().find("In32Bit") != Name.npos) {
273 if (Predicates[i]->getName().find("In64Bit") != Name.npos) {
278 // FIXME: These instructions aren't marked as 64-bit in any way
279 Is64Bit |= Rec->getName() == "JMP64pcrel32" ||
280 Rec->getName() == "MASKMOVDQU64" ||
281 Rec->getName() == "POPFS64" ||
282 Rec->getName() == "POPGS64" ||
283 Rec->getName() == "PUSHFS64" ||
284 Rec->getName() == "PUSHGS64" ||
285 Rec->getName() == "REX64_PREFIX" ||
286 Rec->getName().find("MOV64") != Name.npos ||
287 Rec->getName().find("PUSH64") != Name.npos ||
288 Rec->getName().find("POP64") != Name.npos;
290 ShouldBeEmitted = true;
293 void RecognizableInstr::processInstr(DisassemblerTables &tables,
294 const CodeGenInstruction &insn,
297 // Ignore "asm parser only" instructions.
298 if (insn.TheDef->getValueAsBit("isAsmParserOnly"))
301 RecognizableInstr recogInstr(tables, insn, uid);
303 recogInstr.emitInstructionSpecifier(tables);
305 if (recogInstr.shouldBeEmitted())
306 recogInstr.emitDecodePath(tables);
309 #define EVEX_KB(n) (HasEVEX_KZ && HasEVEX_B ? n##_KZ_B : \
310 (HasEVEX_K && HasEVEX_B ? n##_K_B : \
311 (HasEVEX_KZ ? n##_KZ : \
312 (HasEVEX_K? n##_K : (HasEVEX_B ? n##_B : n)))))
314 InstructionContext RecognizableInstr::insnContext() const {
315 InstructionContext insnContext;
318 if (HasVEX_LPrefix && HasEVEX_L2Prefix) {
319 errs() << "Don't support VEX.L if EVEX_L2 is enabled: " << Name << "\n";
320 llvm_unreachable("Don't support VEX.L if EVEX_L2 is enabled");
323 if (HasVEX_LPrefix && HasVEX_WPrefix) {
325 insnContext = EVEX_KB(IC_EVEX_L_W_OPSIZE);
326 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
327 insnContext = EVEX_KB(IC_EVEX_L_W_XS);
328 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
329 Prefix == X86Local::TAXD)
330 insnContext = EVEX_KB(IC_EVEX_L_W_XD);
332 insnContext = EVEX_KB(IC_EVEX_L_W);
333 } else if (HasVEX_LPrefix) {
336 insnContext = EVEX_KB(IC_EVEX_L_OPSIZE);
337 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
338 insnContext = EVEX_KB(IC_EVEX_L_XS);
339 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
340 Prefix == X86Local::TAXD)
341 insnContext = EVEX_KB(IC_EVEX_L_XD);
343 insnContext = EVEX_KB(IC_EVEX_L);
345 else if (HasEVEX_L2Prefix && HasVEX_WPrefix) {
348 insnContext = EVEX_KB(IC_EVEX_L2_W_OPSIZE);
349 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
350 insnContext = EVEX_KB(IC_EVEX_L2_W_XS);
351 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
352 Prefix == X86Local::TAXD)
353 insnContext = EVEX_KB(IC_EVEX_L2_W_XD);
355 insnContext = EVEX_KB(IC_EVEX_L2_W);
356 } else if (HasEVEX_L2Prefix) {
359 insnContext = EVEX_KB(IC_EVEX_L2_OPSIZE);
360 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
361 Prefix == X86Local::TAXD)
362 insnContext = EVEX_KB(IC_EVEX_L2_XD);
363 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
364 insnContext = EVEX_KB(IC_EVEX_L2_XS);
366 insnContext = EVEX_KB(IC_EVEX_L2);
368 else if (HasVEX_WPrefix) {
371 insnContext = EVEX_KB(IC_EVEX_W_OPSIZE);
372 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
373 insnContext = EVEX_KB(IC_EVEX_W_XS);
374 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
375 Prefix == X86Local::TAXD)
376 insnContext = EVEX_KB(IC_EVEX_W_XD);
378 insnContext = EVEX_KB(IC_EVEX_W);
381 else if (HasOpSizePrefix)
382 insnContext = EVEX_KB(IC_EVEX_OPSIZE);
383 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
384 Prefix == X86Local::TAXD)
385 insnContext = EVEX_KB(IC_EVEX_XD);
386 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
387 insnContext = EVEX_KB(IC_EVEX_XS);
389 insnContext = EVEX_KB(IC_EVEX);
391 } else if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix|| HasVEXPrefix) {
392 if (HasVEX_LPrefix && HasVEX_WPrefix) {
394 insnContext = IC_VEX_L_W_OPSIZE;
395 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
396 insnContext = IC_VEX_L_W_XS;
397 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
398 Prefix == X86Local::TAXD)
399 insnContext = IC_VEX_L_W_XD;
401 insnContext = IC_VEX_L_W;
402 } else if (HasOpSizePrefix && HasVEX_LPrefix)
403 insnContext = IC_VEX_L_OPSIZE;
404 else if (HasOpSizePrefix && HasVEX_WPrefix)
405 insnContext = IC_VEX_W_OPSIZE;
406 else if (HasOpSizePrefix)
407 insnContext = IC_VEX_OPSIZE;
408 else if (HasVEX_LPrefix &&
409 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
410 insnContext = IC_VEX_L_XS;
411 else if (HasVEX_LPrefix && (Prefix == X86Local::XD ||
412 Prefix == X86Local::T8XD ||
413 Prefix == X86Local::TAXD))
414 insnContext = IC_VEX_L_XD;
415 else if (HasVEX_WPrefix &&
416 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
417 insnContext = IC_VEX_W_XS;
418 else if (HasVEX_WPrefix && (Prefix == X86Local::XD ||
419 Prefix == X86Local::T8XD ||
420 Prefix == X86Local::TAXD))
421 insnContext = IC_VEX_W_XD;
422 else if (HasVEX_WPrefix)
423 insnContext = IC_VEX_W;
424 else if (HasVEX_LPrefix)
425 insnContext = IC_VEX_L;
426 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
427 Prefix == X86Local::TAXD)
428 insnContext = IC_VEX_XD;
429 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
430 insnContext = IC_VEX_XS;
432 insnContext = IC_VEX;
433 } else if (Is64Bit || HasREX_WPrefix) {
434 if (HasREX_WPrefix && HasOpSizePrefix)
435 insnContext = IC_64BIT_REXW_OPSIZE;
436 else if (HasOpSizePrefix && (Prefix == X86Local::XD ||
437 Prefix == X86Local::T8XD ||
438 Prefix == X86Local::TAXD))
439 insnContext = IC_64BIT_XD_OPSIZE;
440 else if (HasOpSizePrefix &&
441 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
442 insnContext = IC_64BIT_XS_OPSIZE;
443 else if (HasOpSizePrefix)
444 insnContext = IC_64BIT_OPSIZE;
445 else if (HasAdSizePrefix)
446 insnContext = IC_64BIT_ADSIZE;
447 else if (HasREX_WPrefix &&
448 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
449 insnContext = IC_64BIT_REXW_XS;
450 else if (HasREX_WPrefix && (Prefix == X86Local::XD ||
451 Prefix == X86Local::T8XD ||
452 Prefix == X86Local::TAXD))
453 insnContext = IC_64BIT_REXW_XD;
454 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
455 Prefix == X86Local::TAXD)
456 insnContext = IC_64BIT_XD;
457 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
458 insnContext = IC_64BIT_XS;
459 else if (HasREX_WPrefix)
460 insnContext = IC_64BIT_REXW;
462 insnContext = IC_64BIT;
464 if (HasOpSizePrefix && (Prefix == X86Local::XD ||
465 Prefix == X86Local::T8XD ||
466 Prefix == X86Local::TAXD))
467 insnContext = IC_XD_OPSIZE;
468 else if (HasOpSizePrefix &&
469 (Prefix == X86Local::XS || Prefix == X86Local::T8XS))
470 insnContext = IC_XS_OPSIZE;
471 else if (HasOpSizePrefix)
472 insnContext = IC_OPSIZE;
473 else if (HasAdSizePrefix)
474 insnContext = IC_ADSIZE;
475 else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
476 Prefix == X86Local::TAXD)
478 else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS ||
479 Prefix == X86Local::REP)
488 RecognizableInstr::filter_ret RecognizableInstr::filter() const {
493 // Filter out intrinsics
495 assert(Rec->isSubClassOf("X86Inst") && "Can only filter X86 instructions");
497 if (Form == X86Local::Pseudo ||
498 (IsCodeGenOnly && Name.find("_REV") == Name.npos &&
499 Name.find("INC32") == Name.npos && Name.find("DEC32") == Name.npos))
500 return FILTER_STRONG;
503 // Filter out artificial instructions but leave in the LOCK_PREFIX so it is
504 // printed as a separate "instruction".
506 if (Name.find("_Int") != Name.npos ||
507 Name.find("Int_") != Name.npos)
508 return FILTER_STRONG;
510 // Filter out instructions with segment override prefixes.
511 // They're too messy to handle now and we'll special case them if needed.
514 return FILTER_STRONG;
522 // Filter out instructions with a LOCK prefix;
523 // prefer forms that do not have the prefix
527 // Filter out alternate forms of AVX instructions
528 if (Name.find("_alt") != Name.npos ||
529 (Name.find("r64r") != Name.npos && Name.find("r64r64") == Name.npos && Name.find("r64r8") == Name.npos) ||
530 Name.find("_64mr") != Name.npos ||
531 Name.find("rr64") != Name.npos)
536 if (Name == "PUSH64i16" ||
537 Name == "MOVPQI2QImr" ||
538 Name == "VMOVPQI2QImr" ||
539 Name == "VMASKMOVDQU64")
542 // XACQUIRE and XRELEASE reuse REPNE and REP respectively.
543 // For now, just prefer the REP versions.
544 if (Name == "XACQUIRE_PREFIX" ||
545 Name == "XRELEASE_PREFIX")
548 return FILTER_NORMAL;
551 bool RecognizableInstr::hasFROperands() const {
552 const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
553 unsigned numOperands = OperandList.size();
555 for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
556 const std::string &recName = OperandList[operandIndex].Rec->getName();
558 if (recName.find("FR") != recName.npos)
564 void RecognizableInstr::handleOperand(bool optional, unsigned &operandIndex,
565 unsigned &physicalOperandIndex,
566 unsigned &numPhysicalOperands,
567 const unsigned *operandMapping,
568 OperandEncoding (*encodingFromString)
570 bool hasOpSizePrefix)) {
572 if (physicalOperandIndex >= numPhysicalOperands)
575 assert(physicalOperandIndex < numPhysicalOperands);
578 while (operandMapping[operandIndex] != operandIndex) {
579 Spec->operands[operandIndex].encoding = ENCODING_DUP;
580 Spec->operands[operandIndex].type =
581 (OperandType)(TYPE_DUP0 + operandMapping[operandIndex]);
585 const std::string &typeName = (*Operands)[operandIndex].Rec->getName();
587 Spec->operands[operandIndex].encoding = encodingFromString(typeName,
589 Spec->operands[operandIndex].type = typeFromString(typeName,
595 ++physicalOperandIndex;
598 void RecognizableInstr::emitInstructionSpecifier(DisassemblerTables &tables) {
601 if (!ShouldBeEmitted)
606 Spec->filtered = true;
609 ShouldBeEmitted = false;
615 Spec->insnContext = insnContext();
617 const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
619 unsigned numOperands = OperandList.size();
620 unsigned numPhysicalOperands = 0;
622 // operandMapping maps from operands in OperandList to their originals.
623 // If operandMapping[i] != i, then the entry is a duplicate.
624 unsigned operandMapping[X86_MAX_OPERANDS];
625 assert(numOperands <= X86_MAX_OPERANDS && "X86_MAX_OPERANDS is not large enough");
627 for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
628 if (OperandList[operandIndex].Constraints.size()) {
629 const CGIOperandList::ConstraintInfo &Constraint =
630 OperandList[operandIndex].Constraints[0];
631 if (Constraint.isTied()) {
632 operandMapping[operandIndex] = operandIndex;
633 operandMapping[Constraint.getTiedOperand()] = operandIndex;
635 ++numPhysicalOperands;
636 operandMapping[operandIndex] = operandIndex;
639 ++numPhysicalOperands;
640 operandMapping[operandIndex] = operandIndex;
644 #define HANDLE_OPERAND(class) \
645 handleOperand(false, \
647 physicalOperandIndex, \
648 numPhysicalOperands, \
650 class##EncodingFromString);
652 #define HANDLE_OPTIONAL(class) \
653 handleOperand(true, \
655 physicalOperandIndex, \
656 numPhysicalOperands, \
658 class##EncodingFromString);
660 // operandIndex should always be < numOperands
661 unsigned operandIndex = 0;
662 // physicalOperandIndex should always be < numPhysicalOperands
663 unsigned physicalOperandIndex = 0;
666 case X86Local::RawFrm:
667 // Operand 1 (optional) is an address or immediate.
668 // Operand 2 (optional) is an immediate.
669 assert(numPhysicalOperands <= 2 &&
670 "Unexpected number of operands for RawFrm");
671 HANDLE_OPTIONAL(relocation)
672 HANDLE_OPTIONAL(immediate)
674 case X86Local::AddRegFrm:
675 // Operand 1 is added to the opcode.
676 // Operand 2 (optional) is an address.
677 assert(numPhysicalOperands >= 1 && numPhysicalOperands <= 2 &&
678 "Unexpected number of operands for AddRegFrm");
679 HANDLE_OPERAND(opcodeModifier)
680 HANDLE_OPTIONAL(relocation)
682 case X86Local::MRMDestReg:
683 // Operand 1 is a register operand in the R/M field.
684 // Operand 2 is a register operand in the Reg/Opcode field.
685 // - In AVX, there is a register operand in the VEX.vvvv field here -
686 // Operand 3 (optional) is an immediate.
688 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
689 "Unexpected number of operands for MRMDestRegFrm with VEX_4V");
691 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
692 "Unexpected number of operands for MRMDestRegFrm");
694 HANDLE_OPERAND(rmRegister)
697 // FIXME: In AVX, the register below becomes the one encoded
698 // in ModRMVEX and the one above the one in the VEX.VVVV field
699 HANDLE_OPERAND(vvvvRegister)
701 HANDLE_OPERAND(roRegister)
702 HANDLE_OPTIONAL(immediate)
704 case X86Local::MRMDestMem:
705 // Operand 1 is a memory operand (possibly SIB-extended)
706 // Operand 2 is a register operand in the Reg/Opcode field.
707 // - In AVX, there is a register operand in the VEX.vvvv field here -
708 // Operand 3 (optional) is an immediate.
710 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
711 "Unexpected number of operands for MRMDestMemFrm with VEX_4V");
713 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
714 "Unexpected number of operands for MRMDestMemFrm");
715 HANDLE_OPERAND(memory)
718 HANDLE_OPERAND(writemaskRegister)
721 // FIXME: In AVX, the register below becomes the one encoded
722 // in ModRMVEX and the one above the one in the VEX.VVVV field
723 HANDLE_OPERAND(vvvvRegister)
725 HANDLE_OPERAND(roRegister)
726 HANDLE_OPTIONAL(immediate)
728 case X86Local::MRMSrcReg:
729 // Operand 1 is a register operand in the Reg/Opcode field.
730 // Operand 2 is a register operand in the R/M field.
731 // - In AVX, there is a register operand in the VEX.vvvv field here -
732 // Operand 3 (optional) is an immediate.
733 // Operand 4 (optional) is an immediate.
735 if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
736 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
737 "Unexpected number of operands for MRMSrcRegFrm with VEX_4V");
739 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 4 &&
740 "Unexpected number of operands for MRMSrcRegFrm");
742 HANDLE_OPERAND(roRegister)
745 HANDLE_OPERAND(writemaskRegister)
748 // FIXME: In AVX, the register below becomes the one encoded
749 // in ModRMVEX and the one above the one in the VEX.VVVV field
750 HANDLE_OPERAND(vvvvRegister)
753 HANDLE_OPERAND(immediate)
755 HANDLE_OPERAND(rmRegister)
757 if (HasVEX_4VOp3Prefix)
758 HANDLE_OPERAND(vvvvRegister)
760 if (!HasMemOp4Prefix)
761 HANDLE_OPTIONAL(immediate)
762 HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
763 HANDLE_OPTIONAL(immediate)
765 case X86Local::MRMSrcMem:
766 // Operand 1 is a register operand in the Reg/Opcode field.
767 // Operand 2 is a memory operand (possibly SIB-extended)
768 // - In AVX, there is a register operand in the VEX.vvvv field here -
769 // Operand 3 (optional) is an immediate.
771 if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
772 assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
773 "Unexpected number of operands for MRMSrcMemFrm with VEX_4V");
775 assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
776 "Unexpected number of operands for MRMSrcMemFrm");
778 HANDLE_OPERAND(roRegister)
781 HANDLE_OPERAND(writemaskRegister)
784 // FIXME: In AVX, the register below becomes the one encoded
785 // in ModRMVEX and the one above the one in the VEX.VVVV field
786 HANDLE_OPERAND(vvvvRegister)
789 HANDLE_OPERAND(immediate)
791 HANDLE_OPERAND(memory)
793 if (HasVEX_4VOp3Prefix)
794 HANDLE_OPERAND(vvvvRegister)
796 if (!HasMemOp4Prefix)
797 HANDLE_OPTIONAL(immediate)
798 HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
800 case X86Local::MRM0r:
801 case X86Local::MRM1r:
802 case X86Local::MRM2r:
803 case X86Local::MRM3r:
804 case X86Local::MRM4r:
805 case X86Local::MRM5r:
806 case X86Local::MRM6r:
807 case X86Local::MRM7r:
809 // Operand 1 is a register operand in the R/M field.
810 // Operand 2 (optional) is an immediate or relocation.
811 // Operand 3 (optional) is an immediate.
812 unsigned kOp = (HasEVEX_K) ? 1:0;
813 unsigned Op4v = (HasVEX_4VPrefix) ? 1:0;
814 if (numPhysicalOperands > 3 + kOp + Op4v)
815 llvm_unreachable("Unexpected number of operands for MRMnr");
818 HANDLE_OPERAND(vvvvRegister)
821 HANDLE_OPERAND(writemaskRegister)
822 HANDLE_OPTIONAL(rmRegister)
823 HANDLE_OPTIONAL(relocation)
824 HANDLE_OPTIONAL(immediate)
826 case X86Local::MRM0m:
827 case X86Local::MRM1m:
828 case X86Local::MRM2m:
829 case X86Local::MRM3m:
830 case X86Local::MRM4m:
831 case X86Local::MRM5m:
832 case X86Local::MRM6m:
833 case X86Local::MRM7m:
835 // Operand 1 is a memory operand (possibly SIB-extended)
836 // Operand 2 (optional) is an immediate or relocation.
837 unsigned kOp = (HasEVEX_K) ? 1:0;
838 unsigned Op4v = (HasVEX_4VPrefix) ? 1:0;
839 if (numPhysicalOperands < 1 + kOp + Op4v ||
840 numPhysicalOperands > 2 + kOp + Op4v)
841 llvm_unreachable("Unexpected number of operands for MRMnm");
844 HANDLE_OPERAND(vvvvRegister)
846 HANDLE_OPERAND(writemaskRegister)
847 HANDLE_OPERAND(memory)
848 HANDLE_OPTIONAL(relocation)
850 case X86Local::RawFrmImm8:
851 // operand 1 is a 16-bit immediate
852 // operand 2 is an 8-bit immediate
853 assert(numPhysicalOperands == 2 &&
854 "Unexpected number of operands for X86Local::RawFrmImm8");
855 HANDLE_OPERAND(immediate)
856 HANDLE_OPERAND(immediate)
858 case X86Local::RawFrmImm16:
859 // operand 1 is a 16-bit immediate
860 // operand 2 is a 16-bit immediate
861 HANDLE_OPERAND(immediate)
862 HANDLE_OPERAND(immediate)
864 case X86Local::MRM_F8:
865 if (Opcode == 0xc6) {
866 assert(numPhysicalOperands == 1 &&
867 "Unexpected number of operands for X86Local::MRM_F8");
868 HANDLE_OPERAND(immediate)
869 } else if (Opcode == 0xc7) {
870 assert(numPhysicalOperands == 1 &&
871 "Unexpected number of operands for X86Local::MRM_F8");
872 HANDLE_OPERAND(relocation)
875 case X86Local::MRMInitReg:
880 #undef HANDLE_OPERAND
881 #undef HANDLE_OPTIONAL
884 void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
885 // Special cases where the LLVM tables are not complete
887 #define MAP(from, to) \
888 case X86Local::MRM_##from: \
889 filter = new ExactFilter(0x##from); \
892 OpcodeType opcodeType = (OpcodeType)-1;
894 ModRMFilter* filter = NULL;
895 uint8_t opcodeToSet = 0;
898 default: llvm_unreachable("Invalid prefix!");
899 // Extended two-byte opcodes can start with f2 0f, f3 0f, or 0f
903 opcodeType = TWOBYTE;
907 if (needsModRMForDecode(Form))
908 filter = new ModFilter(isRegFormat(Form));
910 filter = new DumbFilter();
912 #define EXTENSION_TABLE(n) case 0x##n:
913 TWO_BYTE_EXTENSION_TABLES
914 #undef EXTENSION_TABLE
917 llvm_unreachable("Unhandled two-byte extended opcode");
918 case X86Local::MRM0r:
919 case X86Local::MRM1r:
920 case X86Local::MRM2r:
921 case X86Local::MRM3r:
922 case X86Local::MRM4r:
923 case X86Local::MRM5r:
924 case X86Local::MRM6r:
925 case X86Local::MRM7r:
926 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
928 case X86Local::MRM0m:
929 case X86Local::MRM1m:
930 case X86Local::MRM2m:
931 case X86Local::MRM3m:
932 case X86Local::MRM4m:
933 case X86Local::MRM5m:
934 case X86Local::MRM6m:
935 case X86Local::MRM7m:
936 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
942 opcodeToSet = Opcode;
947 opcodeType = THREEBYTE_38;
950 if (needsModRMForDecode(Form))
951 filter = new ModFilter(isRegFormat(Form));
953 filter = new DumbFilter();
955 #define EXTENSION_TABLE(n) case 0x##n:
956 THREE_BYTE_38_EXTENSION_TABLES
957 #undef EXTENSION_TABLE
960 llvm_unreachable("Unhandled two-byte extended opcode");
961 case X86Local::MRM0r:
962 case X86Local::MRM1r:
963 case X86Local::MRM2r:
964 case X86Local::MRM3r:
965 case X86Local::MRM4r:
966 case X86Local::MRM5r:
967 case X86Local::MRM6r:
968 case X86Local::MRM7r:
969 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
971 case X86Local::MRM0m:
972 case X86Local::MRM1m:
973 case X86Local::MRM2m:
974 case X86Local::MRM3m:
975 case X86Local::MRM4m:
976 case X86Local::MRM5m:
977 case X86Local::MRM6m:
978 case X86Local::MRM7m:
979 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
985 opcodeToSet = Opcode;
989 opcodeType = THREEBYTE_3A;
990 if (needsModRMForDecode(Form))
991 filter = new ModFilter(isRegFormat(Form));
993 filter = new DumbFilter();
994 opcodeToSet = Opcode;
997 opcodeType = THREEBYTE_A6;
998 if (needsModRMForDecode(Form))
999 filter = new ModFilter(isRegFormat(Form));
1001 filter = new DumbFilter();
1002 opcodeToSet = Opcode;
1005 opcodeType = THREEBYTE_A7;
1006 if (needsModRMForDecode(Form))
1007 filter = new ModFilter(isRegFormat(Form));
1009 filter = new DumbFilter();
1010 opcodeToSet = Opcode;
1012 case X86Local::XOP8:
1013 opcodeType = XOP8_MAP;
1014 if (needsModRMForDecode(Form))
1015 filter = new ModFilter(isRegFormat(Form));
1017 filter = new DumbFilter();
1018 opcodeToSet = Opcode;
1020 case X86Local::XOP9:
1021 opcodeType = XOP9_MAP;
1024 if (needsModRMForDecode(Form))
1025 filter = new ModFilter(isRegFormat(Form));
1027 filter = new DumbFilter();
1029 #define EXTENSION_TABLE(n) case 0x##n:
1030 XOP9_MAP_EXTENSION_TABLES
1031 #undef EXTENSION_TABLE
1034 llvm_unreachable("Unhandled XOP9 extended opcode");
1035 case X86Local::MRM0r:
1036 case X86Local::MRM1r:
1037 case X86Local::MRM2r:
1038 case X86Local::MRM3r:
1039 case X86Local::MRM4r:
1040 case X86Local::MRM5r:
1041 case X86Local::MRM6r:
1042 case X86Local::MRM7r:
1043 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
1045 case X86Local::MRM0m:
1046 case X86Local::MRM1m:
1047 case X86Local::MRM2m:
1048 case X86Local::MRM3m:
1049 case X86Local::MRM4m:
1050 case X86Local::MRM5m:
1051 case X86Local::MRM6m:
1052 case X86Local::MRM7m:
1053 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
1058 } // switch (Opcode)
1059 opcodeToSet = Opcode;
1061 case X86Local::XOPA:
1062 opcodeType = XOPA_MAP;
1063 if (needsModRMForDecode(Form))
1064 filter = new ModFilter(isRegFormat(Form));
1066 filter = new DumbFilter();
1067 opcodeToSet = Opcode;
1077 assert(Opcode >= 0xc0 && "Unexpected opcode for an escape opcode");
1078 assert(Form == X86Local::RawFrm);
1079 opcodeType = ONEBYTE;
1080 filter = new ExactFilter(Opcode);
1081 opcodeToSet = 0xd8 + (Prefix - X86Local::D8);
1085 opcodeType = ONEBYTE;
1087 #define EXTENSION_TABLE(n) case 0x##n:
1088 ONE_BYTE_EXTENSION_TABLES
1089 #undef EXTENSION_TABLE
1092 llvm_unreachable("Fell through the cracks of a single-byte "
1094 case X86Local::MRM0r:
1095 case X86Local::MRM1r:
1096 case X86Local::MRM2r:
1097 case X86Local::MRM3r:
1098 case X86Local::MRM4r:
1099 case X86Local::MRM5r:
1100 case X86Local::MRM6r:
1101 case X86Local::MRM7r:
1102 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
1104 case X86Local::MRM0m:
1105 case X86Local::MRM1m:
1106 case X86Local::MRM2m:
1107 case X86Local::MRM3m:
1108 case X86Local::MRM4m:
1109 case X86Local::MRM5m:
1110 case X86Local::MRM6m:
1111 case X86Local::MRM7m:
1112 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
1127 llvm_unreachable("Unhandled escape opcode form");
1128 case X86Local::MRM0r:
1129 case X86Local::MRM1r:
1130 case X86Local::MRM2r:
1131 case X86Local::MRM3r:
1132 case X86Local::MRM4r:
1133 case X86Local::MRM5r:
1134 case X86Local::MRM6r:
1135 case X86Local::MRM7r:
1136 filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
1138 case X86Local::MRM0m:
1139 case X86Local::MRM1m:
1140 case X86Local::MRM2m:
1141 case X86Local::MRM3m:
1142 case X86Local::MRM4m:
1143 case X86Local::MRM5m:
1144 case X86Local::MRM6m:
1145 case X86Local::MRM7m:
1146 filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
1151 if (needsModRMForDecode(Form))
1152 filter = new ModFilter(isRegFormat(Form));
1154 filter = new DumbFilter();
1156 } // switch (Opcode)
1157 opcodeToSet = Opcode;
1158 } // switch (Prefix)
1160 assert(opcodeType != (OpcodeType)-1 &&
1161 "Opcode type not set");
1162 assert(filter && "Filter not set");
1164 if (Form == X86Local::AddRegFrm) {
1165 assert(opcodeToSet < 0xf9 &&
1166 "Not enough room for all ADDREG_FRM operands");
1168 uint8_t currentOpcode;
1170 for (currentOpcode = opcodeToSet;
1171 currentOpcode < opcodeToSet + 8;
1173 tables.setTableFields(opcodeType,
1177 UID, Is32Bit, IgnoresVEX_L);
1179 Spec->modifierType = MODIFIER_OPCODE;
1180 Spec->modifierBase = opcodeToSet;
1182 tables.setTableFields(opcodeType,
1186 UID, Is32Bit, IgnoresVEX_L);
1188 Spec->modifierType = MODIFIER_NONE;
1189 Spec->modifierBase = opcodeToSet;
1197 #define TYPE(str, type) if (s == str) return type;
1198 OperandType RecognizableInstr::typeFromString(const std::string &s,
1200 bool hasREX_WPrefix,
1201 bool hasOpSizePrefix) {
1203 // For SSE instructions, we ignore the OpSize prefix and force operand
1205 TYPE("GR16", TYPE_R16)
1206 TYPE("GR32", TYPE_R32)
1207 TYPE("GR64", TYPE_R64)
1209 if(hasREX_WPrefix) {
1210 // For instructions with a REX_W prefix, a declared 32-bit register encoding
1212 TYPE("GR32", TYPE_R32)
1214 if(!hasOpSizePrefix) {
1215 // For instructions without an OpSize prefix, a declared 16-bit register or
1216 // immediate encoding is special.
1217 TYPE("GR16", TYPE_R16)
1218 TYPE("i16imm", TYPE_IMM16)
1220 TYPE("i16mem", TYPE_Mv)
1221 TYPE("i16imm", TYPE_IMMv)
1222 TYPE("i16i8imm", TYPE_IMMv)
1223 TYPE("GR16", TYPE_Rv)
1224 TYPE("i32mem", TYPE_Mv)
1225 TYPE("i32imm", TYPE_IMMv)
1226 TYPE("i32i8imm", TYPE_IMM32)
1227 TYPE("u32u8imm", TYPE_IMM32)
1228 TYPE("GR32", TYPE_Rv)
1229 TYPE("GR32orGR64", TYPE_R32)
1230 TYPE("i64mem", TYPE_Mv)
1231 TYPE("i64i32imm", TYPE_IMM64)
1232 TYPE("i64i8imm", TYPE_IMM64)
1233 TYPE("GR64", TYPE_R64)
1234 TYPE("i8mem", TYPE_M8)
1235 TYPE("i8imm", TYPE_IMM8)
1236 TYPE("GR8", TYPE_R8)
1237 TYPE("VR128", TYPE_XMM128)
1238 TYPE("VR128X", TYPE_XMM128)
1239 TYPE("f128mem", TYPE_M128)
1240 TYPE("f256mem", TYPE_M256)
1241 TYPE("f512mem", TYPE_M512)
1242 TYPE("FR64", TYPE_XMM64)
1243 TYPE("FR64X", TYPE_XMM64)
1244 TYPE("f64mem", TYPE_M64FP)
1245 TYPE("sdmem", TYPE_M64FP)
1246 TYPE("FR32", TYPE_XMM32)
1247 TYPE("FR32X", TYPE_XMM32)
1248 TYPE("f32mem", TYPE_M32FP)
1249 TYPE("ssmem", TYPE_M32FP)
1250 TYPE("RST", TYPE_ST)
1251 TYPE("i128mem", TYPE_M128)
1252 TYPE("i256mem", TYPE_M256)
1253 TYPE("i512mem", TYPE_M512)
1254 TYPE("i64i32imm_pcrel", TYPE_REL64)
1255 TYPE("i16imm_pcrel", TYPE_REL16)
1256 TYPE("i32imm_pcrel", TYPE_REL32)
1257 TYPE("SSECC", TYPE_IMM3)
1258 TYPE("AVXCC", TYPE_IMM5)
1259 TYPE("AVX512RC", TYPE_IMM32)
1260 TYPE("brtarget", TYPE_RELv)
1261 TYPE("uncondbrtarget", TYPE_RELv)
1262 TYPE("brtarget8", TYPE_REL8)
1263 TYPE("f80mem", TYPE_M80FP)
1264 TYPE("lea32mem", TYPE_LEA)
1265 TYPE("lea64_32mem", TYPE_LEA)
1266 TYPE("lea64mem", TYPE_LEA)
1267 TYPE("VR64", TYPE_MM64)
1268 TYPE("i64imm", TYPE_IMMv)
1269 TYPE("opaque32mem", TYPE_M1616)
1270 TYPE("opaque48mem", TYPE_M1632)
1271 TYPE("opaque80mem", TYPE_M1664)
1272 TYPE("opaque512mem", TYPE_M512)
1273 TYPE("SEGMENT_REG", TYPE_SEGMENTREG)
1274 TYPE("DEBUG_REG", TYPE_DEBUGREG)
1275 TYPE("CONTROL_REG", TYPE_CONTROLREG)
1276 TYPE("offset8", TYPE_MOFFS8)
1277 TYPE("offset16", TYPE_MOFFS16)
1278 TYPE("offset32", TYPE_MOFFS32)
1279 TYPE("offset64", TYPE_MOFFS64)
1280 TYPE("VR256", TYPE_XMM256)
1281 TYPE("VR256X", TYPE_XMM256)
1282 TYPE("VR512", TYPE_XMM512)
1283 TYPE("VK1", TYPE_VK1)
1284 TYPE("VK1WM", TYPE_VK1)
1285 TYPE("VK8", TYPE_VK8)
1286 TYPE("VK8WM", TYPE_VK8)
1287 TYPE("VK16", TYPE_VK16)
1288 TYPE("VK16WM", TYPE_VK16)
1289 TYPE("GR16_NOAX", TYPE_Rv)
1290 TYPE("GR32_NOAX", TYPE_Rv)
1291 TYPE("GR64_NOAX", TYPE_R64)
1292 TYPE("vx32mem", TYPE_M32)
1293 TYPE("vy32mem", TYPE_M32)
1294 TYPE("vz32mem", TYPE_M32)
1295 TYPE("vx64mem", TYPE_M64)
1296 TYPE("vy64mem", TYPE_M64)
1297 TYPE("vy64xmem", TYPE_M64)
1298 TYPE("vz64mem", TYPE_M64)
1299 errs() << "Unhandled type string " << s << "\n";
1300 llvm_unreachable("Unhandled type string");
1304 #define ENCODING(str, encoding) if (s == str) return encoding;
1305 OperandEncoding RecognizableInstr::immediateEncodingFromString
1306 (const std::string &s,
1307 bool hasOpSizePrefix) {
1308 if(!hasOpSizePrefix) {
1309 // For instructions without an OpSize prefix, a declared 16-bit register or
1310 // immediate encoding is special.
1311 ENCODING("i16imm", ENCODING_IW)
1313 ENCODING("i32i8imm", ENCODING_IB)
1314 ENCODING("u32u8imm", ENCODING_IB)
1315 ENCODING("SSECC", ENCODING_IB)
1316 ENCODING("AVXCC", ENCODING_IB)
1317 ENCODING("AVX512RC", ENCODING_IB)
1318 ENCODING("i16imm", ENCODING_Iv)
1319 ENCODING("i16i8imm", ENCODING_IB)
1320 ENCODING("i32imm", ENCODING_Iv)
1321 ENCODING("i64i32imm", ENCODING_ID)
1322 ENCODING("i64i8imm", ENCODING_IB)
1323 ENCODING("i8imm", ENCODING_IB)
1324 // This is not a typo. Instructions like BLENDVPD put
1325 // register IDs in 8-bit immediates nowadays.
1326 ENCODING("FR32", ENCODING_IB)
1327 ENCODING("FR64", ENCODING_IB)
1328 ENCODING("VR128", ENCODING_IB)
1329 ENCODING("VR256", ENCODING_IB)
1330 ENCODING("FR32X", ENCODING_IB)
1331 ENCODING("FR64X", ENCODING_IB)
1332 ENCODING("VR128X", ENCODING_IB)
1333 ENCODING("VR256X", ENCODING_IB)
1334 ENCODING("VR512", ENCODING_IB)
1335 errs() << "Unhandled immediate encoding " << s << "\n";
1336 llvm_unreachable("Unhandled immediate encoding");
1339 OperandEncoding RecognizableInstr::rmRegisterEncodingFromString
1340 (const std::string &s,
1341 bool hasOpSizePrefix) {
1342 ENCODING("RST", ENCODING_FP)
1343 ENCODING("GR16", ENCODING_RM)
1344 ENCODING("GR32", ENCODING_RM)
1345 ENCODING("GR32orGR64", ENCODING_RM)
1346 ENCODING("GR64", ENCODING_RM)
1347 ENCODING("GR8", ENCODING_RM)
1348 ENCODING("VR128", ENCODING_RM)
1349 ENCODING("VR128X", ENCODING_RM)
1350 ENCODING("FR64", ENCODING_RM)
1351 ENCODING("FR32", ENCODING_RM)
1352 ENCODING("FR64X", ENCODING_RM)
1353 ENCODING("FR32X", ENCODING_RM)
1354 ENCODING("VR64", ENCODING_RM)
1355 ENCODING("VR256", ENCODING_RM)
1356 ENCODING("VR256X", ENCODING_RM)
1357 ENCODING("VR512", ENCODING_RM)
1358 ENCODING("VK1", ENCODING_RM)
1359 ENCODING("VK8", ENCODING_RM)
1360 ENCODING("VK16", ENCODING_RM)
1361 errs() << "Unhandled R/M register encoding " << s << "\n";
1362 llvm_unreachable("Unhandled R/M register encoding");
1365 OperandEncoding RecognizableInstr::roRegisterEncodingFromString
1366 (const std::string &s,
1367 bool hasOpSizePrefix) {
1368 ENCODING("GR16", ENCODING_REG)
1369 ENCODING("GR32", ENCODING_REG)
1370 ENCODING("GR32orGR64", ENCODING_REG)
1371 ENCODING("GR64", ENCODING_REG)
1372 ENCODING("GR8", ENCODING_REG)
1373 ENCODING("VR128", ENCODING_REG)
1374 ENCODING("FR64", ENCODING_REG)
1375 ENCODING("FR32", ENCODING_REG)
1376 ENCODING("VR64", ENCODING_REG)
1377 ENCODING("SEGMENT_REG", ENCODING_REG)
1378 ENCODING("DEBUG_REG", ENCODING_REG)
1379 ENCODING("CONTROL_REG", ENCODING_REG)
1380 ENCODING("VR256", ENCODING_REG)
1381 ENCODING("VR256X", ENCODING_REG)
1382 ENCODING("VR128X", ENCODING_REG)
1383 ENCODING("FR64X", ENCODING_REG)
1384 ENCODING("FR32X", ENCODING_REG)
1385 ENCODING("VR512", ENCODING_REG)
1386 ENCODING("VK1", ENCODING_REG)
1387 ENCODING("VK8", ENCODING_REG)
1388 ENCODING("VK16", ENCODING_REG)
1389 ENCODING("VK1WM", ENCODING_REG)
1390 ENCODING("VK8WM", ENCODING_REG)
1391 ENCODING("VK16WM", ENCODING_REG)
1392 errs() << "Unhandled reg/opcode register encoding " << s << "\n";
1393 llvm_unreachable("Unhandled reg/opcode register encoding");
1396 OperandEncoding RecognizableInstr::vvvvRegisterEncodingFromString
1397 (const std::string &s,
1398 bool hasOpSizePrefix) {
1399 ENCODING("GR32", ENCODING_VVVV)
1400 ENCODING("GR64", ENCODING_VVVV)
1401 ENCODING("FR32", ENCODING_VVVV)
1402 ENCODING("FR64", ENCODING_VVVV)
1403 ENCODING("VR128", ENCODING_VVVV)
1404 ENCODING("VR256", ENCODING_VVVV)
1405 ENCODING("FR32X", ENCODING_VVVV)
1406 ENCODING("FR64X", ENCODING_VVVV)
1407 ENCODING("VR128X", ENCODING_VVVV)
1408 ENCODING("VR256X", ENCODING_VVVV)
1409 ENCODING("VR512", ENCODING_VVVV)
1410 ENCODING("VK1", ENCODING_VVVV)
1411 ENCODING("VK8", ENCODING_VVVV)
1412 ENCODING("VK16", ENCODING_VVVV)
1413 errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
1414 llvm_unreachable("Unhandled VEX.vvvv register encoding");
1417 OperandEncoding RecognizableInstr::writemaskRegisterEncodingFromString
1418 (const std::string &s,
1419 bool hasOpSizePrefix) {
1420 ENCODING("VK1WM", ENCODING_WRITEMASK)
1421 ENCODING("VK8WM", ENCODING_WRITEMASK)
1422 ENCODING("VK16WM", ENCODING_WRITEMASK)
1423 errs() << "Unhandled mask register encoding " << s << "\n";
1424 llvm_unreachable("Unhandled mask register encoding");
1427 OperandEncoding RecognizableInstr::memoryEncodingFromString
1428 (const std::string &s,
1429 bool hasOpSizePrefix) {
1430 ENCODING("i16mem", ENCODING_RM)
1431 ENCODING("i32mem", ENCODING_RM)
1432 ENCODING("i64mem", ENCODING_RM)
1433 ENCODING("i8mem", ENCODING_RM)
1434 ENCODING("ssmem", ENCODING_RM)
1435 ENCODING("sdmem", ENCODING_RM)
1436 ENCODING("f128mem", ENCODING_RM)
1437 ENCODING("f256mem", ENCODING_RM)
1438 ENCODING("f512mem", ENCODING_RM)
1439 ENCODING("f64mem", ENCODING_RM)
1440 ENCODING("f32mem", ENCODING_RM)
1441 ENCODING("i128mem", ENCODING_RM)
1442 ENCODING("i256mem", ENCODING_RM)
1443 ENCODING("i512mem", ENCODING_RM)
1444 ENCODING("f80mem", ENCODING_RM)
1445 ENCODING("lea32mem", ENCODING_RM)
1446 ENCODING("lea64_32mem", ENCODING_RM)
1447 ENCODING("lea64mem", ENCODING_RM)
1448 ENCODING("opaque32mem", ENCODING_RM)
1449 ENCODING("opaque48mem", ENCODING_RM)
1450 ENCODING("opaque80mem", ENCODING_RM)
1451 ENCODING("opaque512mem", ENCODING_RM)
1452 ENCODING("vx32mem", ENCODING_RM)
1453 ENCODING("vy32mem", ENCODING_RM)
1454 ENCODING("vz32mem", ENCODING_RM)
1455 ENCODING("vx64mem", ENCODING_RM)
1456 ENCODING("vy64mem", ENCODING_RM)
1457 ENCODING("vy64xmem", ENCODING_RM)
1458 ENCODING("vz64mem", ENCODING_RM)
1459 errs() << "Unhandled memory encoding " << s << "\n";
1460 llvm_unreachable("Unhandled memory encoding");
1463 OperandEncoding RecognizableInstr::relocationEncodingFromString
1464 (const std::string &s,
1465 bool hasOpSizePrefix) {
1466 if(!hasOpSizePrefix) {
1467 // For instructions without an OpSize prefix, a declared 16-bit register or
1468 // immediate encoding is special.
1469 ENCODING("i16imm", ENCODING_IW)
1471 ENCODING("i16imm", ENCODING_Iv)
1472 ENCODING("i16i8imm", ENCODING_IB)
1473 ENCODING("i32imm", ENCODING_Iv)
1474 ENCODING("i32i8imm", ENCODING_IB)
1475 ENCODING("i64i32imm", ENCODING_ID)
1476 ENCODING("i64i8imm", ENCODING_IB)
1477 ENCODING("i8imm", ENCODING_IB)
1478 ENCODING("i64i32imm_pcrel", ENCODING_ID)
1479 ENCODING("i16imm_pcrel", ENCODING_IW)
1480 ENCODING("i32imm_pcrel", ENCODING_ID)
1481 ENCODING("brtarget", ENCODING_Iv)
1482 ENCODING("brtarget8", ENCODING_IB)
1483 ENCODING("i64imm", ENCODING_IO)
1484 ENCODING("offset8", ENCODING_Ia)
1485 ENCODING("offset16", ENCODING_Ia)
1486 ENCODING("offset32", ENCODING_Ia)
1487 ENCODING("offset64", ENCODING_Ia)
1488 errs() << "Unhandled relocation encoding " << s << "\n";
1489 llvm_unreachable("Unhandled relocation encoding");
1492 OperandEncoding RecognizableInstr::opcodeModifierEncodingFromString
1493 (const std::string &s,
1494 bool hasOpSizePrefix) {
1495 ENCODING("GR32", ENCODING_Rv)
1496 ENCODING("GR64", ENCODING_RO)
1497 ENCODING("GR16", ENCODING_Rv)
1498 ENCODING("GR8", ENCODING_RB)
1499 ENCODING("GR16_NOAX", ENCODING_Rv)
1500 ENCODING("GR32_NOAX", ENCODING_Rv)
1501 ENCODING("GR64_NOAX", ENCODING_RO)
1502 errs() << "Unhandled opcode modifier encoding " << s << "\n";
1503 llvm_unreachable("Unhandled opcode modifier encoding");