1*9880d681SAndroid Build Coastguard Worker //===-- X86BaseInfo.h - Top level definitions for X86 -------- --*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file contains small standalone helper functions and enum definitions for 11*9880d681SAndroid Build Coastguard Worker // the X86 target useful for the compiler back-end and the MC libraries. 12*9880d681SAndroid Build Coastguard Worker // As such, it deliberately does not include references to LLVM core 13*9880d681SAndroid Build Coastguard Worker // code gen types, passes, etc.. 14*9880d681SAndroid Build Coastguard Worker // 15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H 18*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker #include "X86MCTargetDesc.h" 21*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInstrDesc.h" 22*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/DataTypes.h" 23*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ErrorHandling.h" 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker namespace llvm { 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker namespace X86 { 28*9880d681SAndroid Build Coastguard Worker // Enums for memory operand decoding. Each memory operand is represented with 29*9880d681SAndroid Build Coastguard Worker // a 5 operand sequence in the form: 30*9880d681SAndroid Build Coastguard Worker // [BaseReg, ScaleAmt, IndexReg, Disp, Segment] 31*9880d681SAndroid Build Coastguard Worker // These enums help decode this. 32*9880d681SAndroid Build Coastguard Worker enum { 33*9880d681SAndroid Build Coastguard Worker AddrBaseReg = 0, 34*9880d681SAndroid Build Coastguard Worker AddrScaleAmt = 1, 35*9880d681SAndroid Build Coastguard Worker AddrIndexReg = 2, 36*9880d681SAndroid Build Coastguard Worker AddrDisp = 3, 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker /// AddrSegmentReg - The operand # of the segment in the memory operand. 39*9880d681SAndroid Build Coastguard Worker AddrSegmentReg = 4, 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker /// AddrNumOperands - Total number of operands in a memory reference. 42*9880d681SAndroid Build Coastguard Worker AddrNumOperands = 5 43*9880d681SAndroid Build Coastguard Worker }; 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker /// AVX512 static rounding constants. These need to match the values in 46*9880d681SAndroid Build Coastguard Worker /// avx512fintrin.h. 47*9880d681SAndroid Build Coastguard Worker enum STATIC_ROUNDING { 48*9880d681SAndroid Build Coastguard Worker TO_NEAREST_INT = 0, 49*9880d681SAndroid Build Coastguard Worker TO_NEG_INF = 1, 50*9880d681SAndroid Build Coastguard Worker TO_POS_INF = 2, 51*9880d681SAndroid Build Coastguard Worker TO_ZERO = 3, 52*9880d681SAndroid Build Coastguard Worker CUR_DIRECTION = 4 53*9880d681SAndroid Build Coastguard Worker }; 54*9880d681SAndroid Build Coastguard Worker } // end namespace X86; 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker /// X86II - This namespace holds all of the target specific flags that 57*9880d681SAndroid Build Coastguard Worker /// instruction info tracks. 58*9880d681SAndroid Build Coastguard Worker /// 59*9880d681SAndroid Build Coastguard Worker namespace X86II { 60*9880d681SAndroid Build Coastguard Worker /// Target Operand Flag enum. 61*9880d681SAndroid Build Coastguard Worker enum TOF { 62*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 63*9880d681SAndroid Build Coastguard Worker // X86 Specific MachineOperand flags. 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker MO_NO_FLAG, 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a 68*9880d681SAndroid Build Coastguard Worker /// relocation of: 69*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL + [. - PICBASELABEL] 70*9880d681SAndroid Build Coastguard Worker MO_GOT_ABSOLUTE_ADDRESS, 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Worker /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the 73*9880d681SAndroid Build Coastguard Worker /// immediate should get the value of the symbol minus the PIC base label: 74*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL - PICBASELABEL 75*9880d681SAndroid Build Coastguard Worker MO_PIC_BASE_OFFSET, 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker /// MO_GOT - On a symbol operand this indicates that the immediate is the 78*9880d681SAndroid Build Coastguard Worker /// offset to the GOT entry for the symbol name from the base of the GOT. 79*9880d681SAndroid Build Coastguard Worker /// 80*9880d681SAndroid Build Coastguard Worker /// See the X86-64 ELF ABI supplement for more details. 81*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @GOT 82*9880d681SAndroid Build Coastguard Worker MO_GOT, 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Worker /// MO_GOTOFF - On a symbol operand this indicates that the immediate is 85*9880d681SAndroid Build Coastguard Worker /// the offset to the location of the symbol name from the base of the GOT. 86*9880d681SAndroid Build Coastguard Worker /// 87*9880d681SAndroid Build Coastguard Worker /// See the X86-64 ELF ABI supplement for more details. 88*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @GOTOFF 89*9880d681SAndroid Build Coastguard Worker MO_GOTOFF, 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is 92*9880d681SAndroid Build Coastguard Worker /// offset to the GOT entry for the symbol name from the current code 93*9880d681SAndroid Build Coastguard Worker /// location. 94*9880d681SAndroid Build Coastguard Worker /// 95*9880d681SAndroid Build Coastguard Worker /// See the X86-64 ELF ABI supplement for more details. 96*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @GOTPCREL 97*9880d681SAndroid Build Coastguard Worker MO_GOTPCREL, 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker /// MO_PLT - On a symbol operand this indicates that the immediate is 100*9880d681SAndroid Build Coastguard Worker /// offset to the PLT entry of symbol name from the current code location. 101*9880d681SAndroid Build Coastguard Worker /// 102*9880d681SAndroid Build Coastguard Worker /// See the X86-64 ELF ABI supplement for more details. 103*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @PLT 104*9880d681SAndroid Build Coastguard Worker MO_PLT, 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker /// MO_TLSGD - On a symbol operand this indicates that the immediate is 107*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the TLS index structure that contains 108*9880d681SAndroid Build Coastguard Worker /// the module number and variable offset for the symbol. Used in the 109*9880d681SAndroid Build Coastguard Worker /// general dynamic TLS access model. 110*9880d681SAndroid Build Coastguard Worker /// 111*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 112*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @TLSGD 113*9880d681SAndroid Build Coastguard Worker MO_TLSGD, 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker /// MO_TLSLD - On a symbol operand this indicates that the immediate is 116*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the TLS index for the module that 117*9880d681SAndroid Build Coastguard Worker /// contains the symbol. When this index is passed to a call to 118*9880d681SAndroid Build Coastguard Worker /// __tls_get_addr, the function will return the base address of the TLS 119*9880d681SAndroid Build Coastguard Worker /// block for the symbol. Used in the x86-64 local dynamic TLS access model. 120*9880d681SAndroid Build Coastguard Worker /// 121*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 122*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @TLSLD 123*9880d681SAndroid Build Coastguard Worker MO_TLSLD, 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Worker /// MO_TLSLDM - On a symbol operand this indicates that the immediate is 126*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the TLS index for the module that 127*9880d681SAndroid Build Coastguard Worker /// contains the symbol. When this index is passed to a call to 128*9880d681SAndroid Build Coastguard Worker /// ___tls_get_addr, the function will return the base address of the TLS 129*9880d681SAndroid Build Coastguard Worker /// block for the symbol. Used in the IA32 local dynamic TLS access model. 130*9880d681SAndroid Build Coastguard Worker /// 131*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 132*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @TLSLDM 133*9880d681SAndroid Build Coastguard Worker MO_TLSLDM, 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is 136*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the thread-pointer offset for the 137*9880d681SAndroid Build Coastguard Worker /// symbol. Used in the x86-64 initial exec TLS access model. 138*9880d681SAndroid Build Coastguard Worker /// 139*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 140*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @GOTTPOFF 141*9880d681SAndroid Build Coastguard Worker MO_GOTTPOFF, 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard Worker /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is 144*9880d681SAndroid Build Coastguard Worker /// the absolute address of the GOT entry with the negative thread-pointer 145*9880d681SAndroid Build Coastguard Worker /// offset for the symbol. Used in the non-PIC IA32 initial exec TLS access 146*9880d681SAndroid Build Coastguard Worker /// model. 147*9880d681SAndroid Build Coastguard Worker /// 148*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 149*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @INDNTPOFF 150*9880d681SAndroid Build Coastguard Worker MO_INDNTPOFF, 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker /// MO_TPOFF - On a symbol operand this indicates that the immediate is 153*9880d681SAndroid Build Coastguard Worker /// the thread-pointer offset for the symbol. Used in the x86-64 local 154*9880d681SAndroid Build Coastguard Worker /// exec TLS access model. 155*9880d681SAndroid Build Coastguard Worker /// 156*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 157*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @TPOFF 158*9880d681SAndroid Build Coastguard Worker MO_TPOFF, 159*9880d681SAndroid Build Coastguard Worker 160*9880d681SAndroid Build Coastguard Worker /// MO_DTPOFF - On a symbol operand this indicates that the immediate is 161*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the TLS offset of the symbol. Used 162*9880d681SAndroid Build Coastguard Worker /// in the local dynamic TLS access model. 163*9880d681SAndroid Build Coastguard Worker /// 164*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 165*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @DTPOFF 166*9880d681SAndroid Build Coastguard Worker MO_DTPOFF, 167*9880d681SAndroid Build Coastguard Worker 168*9880d681SAndroid Build Coastguard Worker /// MO_NTPOFF - On a symbol operand this indicates that the immediate is 169*9880d681SAndroid Build Coastguard Worker /// the negative thread-pointer offset for the symbol. Used in the IA32 170*9880d681SAndroid Build Coastguard Worker /// local exec TLS access model. 171*9880d681SAndroid Build Coastguard Worker /// 172*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 173*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @NTPOFF 174*9880d681SAndroid Build Coastguard Worker MO_NTPOFF, 175*9880d681SAndroid Build Coastguard Worker 176*9880d681SAndroid Build Coastguard Worker /// MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is 177*9880d681SAndroid Build Coastguard Worker /// the offset of the GOT entry with the negative thread-pointer offset for 178*9880d681SAndroid Build Coastguard Worker /// the symbol. Used in the PIC IA32 initial exec TLS access model. 179*9880d681SAndroid Build Coastguard Worker /// 180*9880d681SAndroid Build Coastguard Worker /// See 'ELF Handling for Thread-Local Storage' for more details. 181*9880d681SAndroid Build Coastguard Worker /// SYMBOL_LABEL @GOTNTPOFF 182*9880d681SAndroid Build Coastguard Worker MO_GOTNTPOFF, 183*9880d681SAndroid Build Coastguard Worker 184*9880d681SAndroid Build Coastguard Worker /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the 185*9880d681SAndroid Build Coastguard Worker /// reference is actually to the "__imp_FOO" symbol. This is used for 186*9880d681SAndroid Build Coastguard Worker /// dllimport linkage on windows. 187*9880d681SAndroid Build Coastguard Worker MO_DLLIMPORT, 188*9880d681SAndroid Build Coastguard Worker 189*9880d681SAndroid Build Coastguard Worker /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the 190*9880d681SAndroid Build Coastguard Worker /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a 191*9880d681SAndroid Build Coastguard Worker /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 192*9880d681SAndroid Build Coastguard Worker MO_DARWIN_NONLAZY, 193*9880d681SAndroid Build Coastguard Worker 194*9880d681SAndroid Build Coastguard Worker /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates 195*9880d681SAndroid Build Coastguard Worker /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is 196*9880d681SAndroid Build Coastguard Worker /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 197*9880d681SAndroid Build Coastguard Worker MO_DARWIN_NONLAZY_PIC_BASE, 198*9880d681SAndroid Build Coastguard Worker 199*9880d681SAndroid Build Coastguard Worker /// MO_TLVP - On a symbol operand this indicates that the immediate is 200*9880d681SAndroid Build Coastguard Worker /// some TLS offset. 201*9880d681SAndroid Build Coastguard Worker /// 202*9880d681SAndroid Build Coastguard Worker /// This is the TLS offset for the Darwin TLS mechanism. 203*9880d681SAndroid Build Coastguard Worker MO_TLVP, 204*9880d681SAndroid Build Coastguard Worker 205*9880d681SAndroid Build Coastguard Worker /// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate 206*9880d681SAndroid Build Coastguard Worker /// is some TLS offset from the picbase. 207*9880d681SAndroid Build Coastguard Worker /// 208*9880d681SAndroid Build Coastguard Worker /// This is the 32-bit TLS offset for Darwin TLS in PIC mode. 209*9880d681SAndroid Build Coastguard Worker MO_TLVP_PIC_BASE, 210*9880d681SAndroid Build Coastguard Worker 211*9880d681SAndroid Build Coastguard Worker /// MO_SECREL - On a symbol operand this indicates that the immediate is 212*9880d681SAndroid Build Coastguard Worker /// the offset from beginning of section. 213*9880d681SAndroid Build Coastguard Worker /// 214*9880d681SAndroid Build Coastguard Worker /// This is the TLS offset for the COFF/Windows TLS mechanism. 215*9880d681SAndroid Build Coastguard Worker MO_SECREL 216*9880d681SAndroid Build Coastguard Worker }; 217*9880d681SAndroid Build Coastguard Worker 218*9880d681SAndroid Build Coastguard Worker enum : uint64_t { 219*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 220*9880d681SAndroid Build Coastguard Worker // Instruction encodings. These are the standard/most common forms for X86 221*9880d681SAndroid Build Coastguard Worker // instructions. 222*9880d681SAndroid Build Coastguard Worker // 223*9880d681SAndroid Build Coastguard Worker 224*9880d681SAndroid Build Coastguard Worker // PseudoFrm - This represents an instruction that is a pseudo instruction 225*9880d681SAndroid Build Coastguard Worker // or one that has not been implemented yet. It is illegal to code generate 226*9880d681SAndroid Build Coastguard Worker // it, but tolerated for intermediate implementation stages. 227*9880d681SAndroid Build Coastguard Worker Pseudo = 0, 228*9880d681SAndroid Build Coastguard Worker 229*9880d681SAndroid Build Coastguard Worker /// Raw - This form is for instructions that don't have any operands, so 230*9880d681SAndroid Build Coastguard Worker /// they are just a fixed opcode value, like 'leave'. 231*9880d681SAndroid Build Coastguard Worker RawFrm = 1, 232*9880d681SAndroid Build Coastguard Worker 233*9880d681SAndroid Build Coastguard Worker /// AddRegFrm - This form is used for instructions like 'push r32' that have 234*9880d681SAndroid Build Coastguard Worker /// their one register operand added to their opcode. 235*9880d681SAndroid Build Coastguard Worker AddRegFrm = 2, 236*9880d681SAndroid Build Coastguard Worker 237*9880d681SAndroid Build Coastguard Worker /// MRMDestReg - This form is used for instructions that use the Mod/RM byte 238*9880d681SAndroid Build Coastguard Worker /// to specify a destination, which in this case is a register. 239*9880d681SAndroid Build Coastguard Worker /// 240*9880d681SAndroid Build Coastguard Worker MRMDestReg = 3, 241*9880d681SAndroid Build Coastguard Worker 242*9880d681SAndroid Build Coastguard Worker /// MRMDestMem - This form is used for instructions that use the Mod/RM byte 243*9880d681SAndroid Build Coastguard Worker /// to specify a destination, which in this case is memory. 244*9880d681SAndroid Build Coastguard Worker /// 245*9880d681SAndroid Build Coastguard Worker MRMDestMem = 4, 246*9880d681SAndroid Build Coastguard Worker 247*9880d681SAndroid Build Coastguard Worker /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte 248*9880d681SAndroid Build Coastguard Worker /// to specify a source, which in this case is a register. 249*9880d681SAndroid Build Coastguard Worker /// 250*9880d681SAndroid Build Coastguard Worker MRMSrcReg = 5, 251*9880d681SAndroid Build Coastguard Worker 252*9880d681SAndroid Build Coastguard Worker /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte 253*9880d681SAndroid Build Coastguard Worker /// to specify a source, which in this case is memory. 254*9880d681SAndroid Build Coastguard Worker /// 255*9880d681SAndroid Build Coastguard Worker MRMSrcMem = 6, 256*9880d681SAndroid Build Coastguard Worker 257*9880d681SAndroid Build Coastguard Worker /// RawFrmMemOffs - This form is for instructions that store an absolute 258*9880d681SAndroid Build Coastguard Worker /// memory offset as an immediate with a possible segment override. 259*9880d681SAndroid Build Coastguard Worker RawFrmMemOffs = 7, 260*9880d681SAndroid Build Coastguard Worker 261*9880d681SAndroid Build Coastguard Worker /// RawFrmSrc - This form is for instructions that use the source index 262*9880d681SAndroid Build Coastguard Worker /// register SI/ESI/RSI with a possible segment override. 263*9880d681SAndroid Build Coastguard Worker RawFrmSrc = 8, 264*9880d681SAndroid Build Coastguard Worker 265*9880d681SAndroid Build Coastguard Worker /// RawFrmDst - This form is for instructions that use the destination index 266*9880d681SAndroid Build Coastguard Worker /// register DI/EDI/ESI. 267*9880d681SAndroid Build Coastguard Worker RawFrmDst = 9, 268*9880d681SAndroid Build Coastguard Worker 269*9880d681SAndroid Build Coastguard Worker /// RawFrmSrc - This form is for instructions that use the source index 270*9880d681SAndroid Build Coastguard Worker /// register SI/ESI/ERI with a possible segment override, and also the 271*9880d681SAndroid Build Coastguard Worker /// destination index register DI/ESI/RDI. 272*9880d681SAndroid Build Coastguard Worker RawFrmDstSrc = 10, 273*9880d681SAndroid Build Coastguard Worker 274*9880d681SAndroid Build Coastguard Worker /// RawFrmImm8 - This is used for the ENTER instruction, which has two 275*9880d681SAndroid Build Coastguard Worker /// immediates, the first of which is a 16-bit immediate (specified by 276*9880d681SAndroid Build Coastguard Worker /// the imm encoding) and the second is a 8-bit fixed value. 277*9880d681SAndroid Build Coastguard Worker RawFrmImm8 = 11, 278*9880d681SAndroid Build Coastguard Worker 279*9880d681SAndroid Build Coastguard Worker /// RawFrmImm16 - This is used for CALL FAR instructions, which have two 280*9880d681SAndroid Build Coastguard Worker /// immediates, the first of which is a 16 or 32-bit immediate (specified by 281*9880d681SAndroid Build Coastguard Worker /// the imm encoding) and the second is a 16-bit fixed value. In the AMD 282*9880d681SAndroid Build Coastguard Worker /// manual, this operand is described as pntr16:32 and pntr16:16 283*9880d681SAndroid Build Coastguard Worker RawFrmImm16 = 12, 284*9880d681SAndroid Build Coastguard Worker 285*9880d681SAndroid Build Coastguard Worker /// MRMX[rm] - The forms are used to represent instructions that use a 286*9880d681SAndroid Build Coastguard Worker /// Mod/RM byte, and don't use the middle field for anything. 287*9880d681SAndroid Build Coastguard Worker MRMXr = 14, MRMXm = 15, 288*9880d681SAndroid Build Coastguard Worker 289*9880d681SAndroid Build Coastguard Worker /// MRM[0-7][rm] - These forms are used to represent instructions that use 290*9880d681SAndroid Build Coastguard Worker /// a Mod/RM byte, and use the middle field to hold extended opcode 291*9880d681SAndroid Build Coastguard Worker /// information. In the intel manual these are represented as /0, /1, ... 292*9880d681SAndroid Build Coastguard Worker /// 293*9880d681SAndroid Build Coastguard Worker 294*9880d681SAndroid Build Coastguard Worker // First, instructions that operate on a register r/m operand... 295*9880d681SAndroid Build Coastguard Worker MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19, // Format /0 /1 /2 /3 296*9880d681SAndroid Build Coastguard Worker MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23, // Format /4 /5 /6 /7 297*9880d681SAndroid Build Coastguard Worker 298*9880d681SAndroid Build Coastguard Worker // Next, instructions that operate on a memory r/m operand... 299*9880d681SAndroid Build Coastguard Worker MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27, // Format /0 /1 /2 /3 300*9880d681SAndroid Build Coastguard Worker MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31, // Format /4 /5 /6 /7 301*9880d681SAndroid Build Coastguard Worker 302*9880d681SAndroid Build Coastguard Worker //// MRM_XX - A mod/rm byte of exactly 0xXX. 303*9880d681SAndroid Build Coastguard Worker MRM_C0 = 32, MRM_C1 = 33, MRM_C2 = 34, MRM_C3 = 35, 304*9880d681SAndroid Build Coastguard Worker MRM_C4 = 36, MRM_C5 = 37, MRM_C6 = 38, MRM_C7 = 39, 305*9880d681SAndroid Build Coastguard Worker MRM_C8 = 40, MRM_C9 = 41, MRM_CA = 42, MRM_CB = 43, 306*9880d681SAndroid Build Coastguard Worker MRM_CC = 44, MRM_CD = 45, MRM_CE = 46, MRM_CF = 47, 307*9880d681SAndroid Build Coastguard Worker MRM_D0 = 48, MRM_D1 = 49, MRM_D2 = 50, MRM_D3 = 51, 308*9880d681SAndroid Build Coastguard Worker MRM_D4 = 52, MRM_D5 = 53, MRM_D6 = 54, MRM_D7 = 55, 309*9880d681SAndroid Build Coastguard Worker MRM_D8 = 56, MRM_D9 = 57, MRM_DA = 58, MRM_DB = 59, 310*9880d681SAndroid Build Coastguard Worker MRM_DC = 60, MRM_DD = 61, MRM_DE = 62, MRM_DF = 63, 311*9880d681SAndroid Build Coastguard Worker MRM_E0 = 64, MRM_E1 = 65, MRM_E2 = 66, MRM_E3 = 67, 312*9880d681SAndroid Build Coastguard Worker MRM_E4 = 68, MRM_E5 = 69, MRM_E6 = 70, MRM_E7 = 71, 313*9880d681SAndroid Build Coastguard Worker MRM_E8 = 72, MRM_E9 = 73, MRM_EA = 74, MRM_EB = 75, 314*9880d681SAndroid Build Coastguard Worker MRM_EC = 76, MRM_ED = 77, MRM_EE = 78, MRM_EF = 79, 315*9880d681SAndroid Build Coastguard Worker MRM_F0 = 80, MRM_F1 = 81, MRM_F2 = 82, MRM_F3 = 83, 316*9880d681SAndroid Build Coastguard Worker MRM_F4 = 84, MRM_F5 = 85, MRM_F6 = 86, MRM_F7 = 87, 317*9880d681SAndroid Build Coastguard Worker MRM_F8 = 88, MRM_F9 = 89, MRM_FA = 90, MRM_FB = 91, 318*9880d681SAndroid Build Coastguard Worker MRM_FC = 92, MRM_FD = 93, MRM_FE = 94, MRM_FF = 95, 319*9880d681SAndroid Build Coastguard Worker 320*9880d681SAndroid Build Coastguard Worker FormMask = 127, 321*9880d681SAndroid Build Coastguard Worker 322*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 323*9880d681SAndroid Build Coastguard Worker // Actual flags... 324*9880d681SAndroid Build Coastguard Worker 325*9880d681SAndroid Build Coastguard Worker // OpSize - OpSizeFixed implies instruction never needs a 0x66 prefix. 326*9880d681SAndroid Build Coastguard Worker // OpSize16 means this is a 16-bit instruction and needs 0x66 prefix in 327*9880d681SAndroid Build Coastguard Worker // 32-bit mode. OpSize32 means this is a 32-bit instruction needs a 0x66 328*9880d681SAndroid Build Coastguard Worker // prefix in 16-bit mode. 329*9880d681SAndroid Build Coastguard Worker OpSizeShift = 7, 330*9880d681SAndroid Build Coastguard Worker OpSizeMask = 0x3 << OpSizeShift, 331*9880d681SAndroid Build Coastguard Worker 332*9880d681SAndroid Build Coastguard Worker OpSizeFixed = 0 << OpSizeShift, 333*9880d681SAndroid Build Coastguard Worker OpSize16 = 1 << OpSizeShift, 334*9880d681SAndroid Build Coastguard Worker OpSize32 = 2 << OpSizeShift, 335*9880d681SAndroid Build Coastguard Worker 336*9880d681SAndroid Build Coastguard Worker // AsSize - AdSizeX implies this instruction determines its need of 0x67 337*9880d681SAndroid Build Coastguard Worker // prefix from a normal ModRM memory operand. The other types indicate that 338*9880d681SAndroid Build Coastguard Worker // an operand is encoded with a specific width and a prefix is needed if 339*9880d681SAndroid Build Coastguard Worker // it differs from the current mode. 340*9880d681SAndroid Build Coastguard Worker AdSizeShift = OpSizeShift + 2, 341*9880d681SAndroid Build Coastguard Worker AdSizeMask = 0x3 << AdSizeShift, 342*9880d681SAndroid Build Coastguard Worker 343*9880d681SAndroid Build Coastguard Worker AdSizeX = 1 << AdSizeShift, 344*9880d681SAndroid Build Coastguard Worker AdSize16 = 1 << AdSizeShift, 345*9880d681SAndroid Build Coastguard Worker AdSize32 = 2 << AdSizeShift, 346*9880d681SAndroid Build Coastguard Worker AdSize64 = 3 << AdSizeShift, 347*9880d681SAndroid Build Coastguard Worker 348*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 349*9880d681SAndroid Build Coastguard Worker // OpPrefix - There are several prefix bytes that are used as opcode 350*9880d681SAndroid Build Coastguard Worker // extensions. These are 0x66, 0xF3, and 0xF2. If this field is 0 there is 351*9880d681SAndroid Build Coastguard Worker // no prefix. 352*9880d681SAndroid Build Coastguard Worker // 353*9880d681SAndroid Build Coastguard Worker OpPrefixShift = AdSizeShift + 2, 354*9880d681SAndroid Build Coastguard Worker OpPrefixMask = 0x7 << OpPrefixShift, 355*9880d681SAndroid Build Coastguard Worker 356*9880d681SAndroid Build Coastguard Worker // PS, PD - Prefix code for packed single and double precision vector 357*9880d681SAndroid Build Coastguard Worker // floating point operations performed in the SSE registers. 358*9880d681SAndroid Build Coastguard Worker PS = 1 << OpPrefixShift, PD = 2 << OpPrefixShift, 359*9880d681SAndroid Build Coastguard Worker 360*9880d681SAndroid Build Coastguard Worker // XS, XD - These prefix codes are for single and double precision scalar 361*9880d681SAndroid Build Coastguard Worker // floating point operations performed in the SSE registers. 362*9880d681SAndroid Build Coastguard Worker XS = 3 << OpPrefixShift, XD = 4 << OpPrefixShift, 363*9880d681SAndroid Build Coastguard Worker 364*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 365*9880d681SAndroid Build Coastguard Worker // OpMap - This field determines which opcode map this instruction 366*9880d681SAndroid Build Coastguard Worker // belongs to. i.e. one-byte, two-byte, 0x0f 0x38, 0x0f 0x3a, etc. 367*9880d681SAndroid Build Coastguard Worker // 368*9880d681SAndroid Build Coastguard Worker OpMapShift = OpPrefixShift + 3, 369*9880d681SAndroid Build Coastguard Worker OpMapMask = 0x7 << OpMapShift, 370*9880d681SAndroid Build Coastguard Worker 371*9880d681SAndroid Build Coastguard Worker // OB - OneByte - Set if this instruction has a one byte opcode. 372*9880d681SAndroid Build Coastguard Worker OB = 0 << OpMapShift, 373*9880d681SAndroid Build Coastguard Worker 374*9880d681SAndroid Build Coastguard Worker // TB - TwoByte - Set if this instruction has a two byte opcode, which 375*9880d681SAndroid Build Coastguard Worker // starts with a 0x0F byte before the real opcode. 376*9880d681SAndroid Build Coastguard Worker TB = 1 << OpMapShift, 377*9880d681SAndroid Build Coastguard Worker 378*9880d681SAndroid Build Coastguard Worker // T8, TA - Prefix after the 0x0F prefix. 379*9880d681SAndroid Build Coastguard Worker T8 = 2 << OpMapShift, TA = 3 << OpMapShift, 380*9880d681SAndroid Build Coastguard Worker 381*9880d681SAndroid Build Coastguard Worker // XOP8 - Prefix to include use of imm byte. 382*9880d681SAndroid Build Coastguard Worker XOP8 = 4 << OpMapShift, 383*9880d681SAndroid Build Coastguard Worker 384*9880d681SAndroid Build Coastguard Worker // XOP9 - Prefix to exclude use of imm byte. 385*9880d681SAndroid Build Coastguard Worker XOP9 = 5 << OpMapShift, 386*9880d681SAndroid Build Coastguard Worker 387*9880d681SAndroid Build Coastguard Worker // XOPA - Prefix to encode 0xA in VEX.MMMM of XOP instructions. 388*9880d681SAndroid Build Coastguard Worker XOPA = 6 << OpMapShift, 389*9880d681SAndroid Build Coastguard Worker 390*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 391*9880d681SAndroid Build Coastguard Worker // REX_W - REX prefixes are instruction prefixes used in 64-bit mode. 392*9880d681SAndroid Build Coastguard Worker // They are used to specify GPRs and SSE registers, 64-bit operand size, 393*9880d681SAndroid Build Coastguard Worker // etc. We only cares about REX.W and REX.R bits and only the former is 394*9880d681SAndroid Build Coastguard Worker // statically determined. 395*9880d681SAndroid Build Coastguard Worker // 396*9880d681SAndroid Build Coastguard Worker REXShift = OpMapShift + 3, 397*9880d681SAndroid Build Coastguard Worker REX_W = 1 << REXShift, 398*9880d681SAndroid Build Coastguard Worker 399*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 400*9880d681SAndroid Build Coastguard Worker // This three-bit field describes the size of an immediate operand. Zero is 401*9880d681SAndroid Build Coastguard Worker // unused so that we can tell if we forgot to set a value. 402*9880d681SAndroid Build Coastguard Worker ImmShift = REXShift + 1, 403*9880d681SAndroid Build Coastguard Worker ImmMask = 15 << ImmShift, 404*9880d681SAndroid Build Coastguard Worker Imm8 = 1 << ImmShift, 405*9880d681SAndroid Build Coastguard Worker Imm8PCRel = 2 << ImmShift, 406*9880d681SAndroid Build Coastguard Worker Imm16 = 3 << ImmShift, 407*9880d681SAndroid Build Coastguard Worker Imm16PCRel = 4 << ImmShift, 408*9880d681SAndroid Build Coastguard Worker Imm32 = 5 << ImmShift, 409*9880d681SAndroid Build Coastguard Worker Imm32PCRel = 6 << ImmShift, 410*9880d681SAndroid Build Coastguard Worker Imm32S = 7 << ImmShift, 411*9880d681SAndroid Build Coastguard Worker Imm64 = 8 << ImmShift, 412*9880d681SAndroid Build Coastguard Worker 413*9880d681SAndroid Build Coastguard Worker //===------------------------------------------------------------------===// 414*9880d681SAndroid Build Coastguard Worker // FP Instruction Classification... Zero is non-fp instruction. 415*9880d681SAndroid Build Coastguard Worker 416*9880d681SAndroid Build Coastguard Worker // FPTypeMask - Mask for all of the FP types... 417*9880d681SAndroid Build Coastguard Worker FPTypeShift = ImmShift + 4, 418*9880d681SAndroid Build Coastguard Worker FPTypeMask = 7 << FPTypeShift, 419*9880d681SAndroid Build Coastguard Worker 420*9880d681SAndroid Build Coastguard Worker // NotFP - The default, set for instructions that do not use FP registers. 421*9880d681SAndroid Build Coastguard Worker NotFP = 0 << FPTypeShift, 422*9880d681SAndroid Build Coastguard Worker 423*9880d681SAndroid Build Coastguard Worker // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0 424*9880d681SAndroid Build Coastguard Worker ZeroArgFP = 1 << FPTypeShift, 425*9880d681SAndroid Build Coastguard Worker 426*9880d681SAndroid Build Coastguard Worker // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst 427*9880d681SAndroid Build Coastguard Worker OneArgFP = 2 << FPTypeShift, 428*9880d681SAndroid Build Coastguard Worker 429*9880d681SAndroid Build Coastguard Worker // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a 430*9880d681SAndroid Build Coastguard Worker // result back to ST(0). For example, fcos, fsqrt, etc. 431*9880d681SAndroid Build Coastguard Worker // 432*9880d681SAndroid Build Coastguard Worker OneArgFPRW = 3 << FPTypeShift, 433*9880d681SAndroid Build Coastguard Worker 434*9880d681SAndroid Build Coastguard Worker // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an 435*9880d681SAndroid Build Coastguard Worker // explicit argument, storing the result to either ST(0) or the implicit 436*9880d681SAndroid Build Coastguard Worker // argument. For example: fadd, fsub, fmul, etc... 437*9880d681SAndroid Build Coastguard Worker TwoArgFP = 4 << FPTypeShift, 438*9880d681SAndroid Build Coastguard Worker 439*9880d681SAndroid Build Coastguard Worker // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an 440*9880d681SAndroid Build Coastguard Worker // explicit argument, but have no destination. Example: fucom, fucomi, ... 441*9880d681SAndroid Build Coastguard Worker CompareFP = 5 << FPTypeShift, 442*9880d681SAndroid Build Coastguard Worker 443*9880d681SAndroid Build Coastguard Worker // CondMovFP - "2 operand" floating point conditional move instructions. 444*9880d681SAndroid Build Coastguard Worker CondMovFP = 6 << FPTypeShift, 445*9880d681SAndroid Build Coastguard Worker 446*9880d681SAndroid Build Coastguard Worker // SpecialFP - Special instruction forms. Dispatch by opcode explicitly. 447*9880d681SAndroid Build Coastguard Worker SpecialFP = 7 << FPTypeShift, 448*9880d681SAndroid Build Coastguard Worker 449*9880d681SAndroid Build Coastguard Worker // Lock prefix 450*9880d681SAndroid Build Coastguard Worker LOCKShift = FPTypeShift + 3, 451*9880d681SAndroid Build Coastguard Worker LOCK = 1 << LOCKShift, 452*9880d681SAndroid Build Coastguard Worker 453*9880d681SAndroid Build Coastguard Worker // REP prefix 454*9880d681SAndroid Build Coastguard Worker REPShift = LOCKShift + 1, 455*9880d681SAndroid Build Coastguard Worker REP = 1 << REPShift, 456*9880d681SAndroid Build Coastguard Worker 457*9880d681SAndroid Build Coastguard Worker // Execution domain for SSE instructions. 458*9880d681SAndroid Build Coastguard Worker // 0 means normal, non-SSE instruction. 459*9880d681SAndroid Build Coastguard Worker SSEDomainShift = REPShift + 1, 460*9880d681SAndroid Build Coastguard Worker 461*9880d681SAndroid Build Coastguard Worker // Encoding 462*9880d681SAndroid Build Coastguard Worker EncodingShift = SSEDomainShift + 2, 463*9880d681SAndroid Build Coastguard Worker EncodingMask = 0x3 << EncodingShift, 464*9880d681SAndroid Build Coastguard Worker 465*9880d681SAndroid Build Coastguard Worker // VEX - encoding using 0xC4/0xC5 466*9880d681SAndroid Build Coastguard Worker VEX = 1 << EncodingShift, 467*9880d681SAndroid Build Coastguard Worker 468*9880d681SAndroid Build Coastguard Worker /// XOP - Opcode prefix used by XOP instructions. 469*9880d681SAndroid Build Coastguard Worker XOP = 2 << EncodingShift, 470*9880d681SAndroid Build Coastguard Worker 471*9880d681SAndroid Build Coastguard Worker // VEX_EVEX - Specifies that this instruction use EVEX form which provides 472*9880d681SAndroid Build Coastguard Worker // syntax support up to 32 512-bit register operands and up to 7 16-bit 473*9880d681SAndroid Build Coastguard Worker // mask operands as well as source operand data swizzling/memory operand 474*9880d681SAndroid Build Coastguard Worker // conversion, eviction hint, and rounding mode. 475*9880d681SAndroid Build Coastguard Worker EVEX = 3 << EncodingShift, 476*9880d681SAndroid Build Coastguard Worker 477*9880d681SAndroid Build Coastguard Worker // Opcode 478*9880d681SAndroid Build Coastguard Worker OpcodeShift = EncodingShift + 2, 479*9880d681SAndroid Build Coastguard Worker 480*9880d681SAndroid Build Coastguard Worker /// VEX_W - Has a opcode specific functionality, but is used in the same 481*9880d681SAndroid Build Coastguard Worker /// way as REX_W is for regular SSE instructions. 482*9880d681SAndroid Build Coastguard Worker VEX_WShift = OpcodeShift + 8, 483*9880d681SAndroid Build Coastguard Worker VEX_W = 1ULL << VEX_WShift, 484*9880d681SAndroid Build Coastguard Worker 485*9880d681SAndroid Build Coastguard Worker /// VEX_4V - Used to specify an additional AVX/SSE register. Several 2 486*9880d681SAndroid Build Coastguard Worker /// address instructions in SSE are represented as 3 address ones in AVX 487*9880d681SAndroid Build Coastguard Worker /// and the additional register is encoded in VEX_VVVV prefix. 488*9880d681SAndroid Build Coastguard Worker VEX_4VShift = VEX_WShift + 1, 489*9880d681SAndroid Build Coastguard Worker VEX_4V = 1ULL << VEX_4VShift, 490*9880d681SAndroid Build Coastguard Worker 491*9880d681SAndroid Build Coastguard Worker /// VEX_4VOp3 - Similar to VEX_4V, but used on instructions that encode 492*9880d681SAndroid Build Coastguard Worker /// operand 3 with VEX.vvvv. 493*9880d681SAndroid Build Coastguard Worker VEX_4VOp3Shift = VEX_4VShift + 1, 494*9880d681SAndroid Build Coastguard Worker VEX_4VOp3 = 1ULL << VEX_4VOp3Shift, 495*9880d681SAndroid Build Coastguard Worker 496*9880d681SAndroid Build Coastguard Worker /// VEX_I8IMM - Specifies that the last register used in a AVX instruction, 497*9880d681SAndroid Build Coastguard Worker /// must be encoded in the i8 immediate field. This usually happens in 498*9880d681SAndroid Build Coastguard Worker /// instructions with 4 operands. 499*9880d681SAndroid Build Coastguard Worker VEX_I8IMMShift = VEX_4VOp3Shift + 1, 500*9880d681SAndroid Build Coastguard Worker VEX_I8IMM = 1ULL << VEX_I8IMMShift, 501*9880d681SAndroid Build Coastguard Worker 502*9880d681SAndroid Build Coastguard Worker /// VEX_L - Stands for a bit in the VEX opcode prefix meaning the current 503*9880d681SAndroid Build Coastguard Worker /// instruction uses 256-bit wide registers. This is usually auto detected 504*9880d681SAndroid Build Coastguard Worker /// if a VR256 register is used, but some AVX instructions also have this 505*9880d681SAndroid Build Coastguard Worker /// field marked when using a f256 memory references. 506*9880d681SAndroid Build Coastguard Worker VEX_LShift = VEX_I8IMMShift + 1, 507*9880d681SAndroid Build Coastguard Worker VEX_L = 1ULL << VEX_LShift, 508*9880d681SAndroid Build Coastguard Worker 509*9880d681SAndroid Build Coastguard Worker // VEX_LIG - Specifies that this instruction ignores the L-bit in the VEX 510*9880d681SAndroid Build Coastguard Worker // prefix. Usually used for scalar instructions. Needed by disassembler. 511*9880d681SAndroid Build Coastguard Worker VEX_LIGShift = VEX_LShift + 1, 512*9880d681SAndroid Build Coastguard Worker VEX_LIG = 1ULL << VEX_LIGShift, 513*9880d681SAndroid Build Coastguard Worker 514*9880d681SAndroid Build Coastguard Worker // TODO: we should combine VEX_L and VEX_LIG together to form a 2-bit field 515*9880d681SAndroid Build Coastguard Worker // with following encoding: 516*9880d681SAndroid Build Coastguard Worker // - 00 V128 517*9880d681SAndroid Build Coastguard Worker // - 01 V256 518*9880d681SAndroid Build Coastguard Worker // - 10 V512 519*9880d681SAndroid Build Coastguard Worker // - 11 LIG (but, in insn encoding, leave VEX.L and EVEX.L in zeros. 520*9880d681SAndroid Build Coastguard Worker // this will save 1 tsflag bit 521*9880d681SAndroid Build Coastguard Worker 522*9880d681SAndroid Build Coastguard Worker // EVEX_K - Set if this instruction requires masking 523*9880d681SAndroid Build Coastguard Worker EVEX_KShift = VEX_LIGShift + 1, 524*9880d681SAndroid Build Coastguard Worker EVEX_K = 1ULL << EVEX_KShift, 525*9880d681SAndroid Build Coastguard Worker 526*9880d681SAndroid Build Coastguard Worker // EVEX_Z - Set if this instruction has EVEX.Z field set. 527*9880d681SAndroid Build Coastguard Worker EVEX_ZShift = EVEX_KShift + 1, 528*9880d681SAndroid Build Coastguard Worker EVEX_Z = 1ULL << EVEX_ZShift, 529*9880d681SAndroid Build Coastguard Worker 530*9880d681SAndroid Build Coastguard Worker // EVEX_L2 - Set if this instruction has EVEX.L' field set. 531*9880d681SAndroid Build Coastguard Worker EVEX_L2Shift = EVEX_ZShift + 1, 532*9880d681SAndroid Build Coastguard Worker EVEX_L2 = 1ULL << EVEX_L2Shift, 533*9880d681SAndroid Build Coastguard Worker 534*9880d681SAndroid Build Coastguard Worker // EVEX_B - Set if this instruction has EVEX.B field set. 535*9880d681SAndroid Build Coastguard Worker EVEX_BShift = EVEX_L2Shift + 1, 536*9880d681SAndroid Build Coastguard Worker EVEX_B = 1ULL << EVEX_BShift, 537*9880d681SAndroid Build Coastguard Worker 538*9880d681SAndroid Build Coastguard Worker // The scaling factor for the AVX512's 8-bit compressed displacement. 539*9880d681SAndroid Build Coastguard Worker CD8_Scale_Shift = EVEX_BShift + 1, 540*9880d681SAndroid Build Coastguard Worker CD8_Scale_Mask = 127ULL << CD8_Scale_Shift, 541*9880d681SAndroid Build Coastguard Worker 542*9880d681SAndroid Build Coastguard Worker /// Has3DNow0F0FOpcode - This flag indicates that the instruction uses the 543*9880d681SAndroid Build Coastguard Worker /// wacky 0x0F 0x0F prefix for 3DNow! instructions. The manual documents 544*9880d681SAndroid Build Coastguard Worker /// this as having a 0x0F prefix with a 0x0F opcode, and each instruction 545*9880d681SAndroid Build Coastguard Worker /// storing a classifier in the imm8 field. To simplify our implementation, 546*9880d681SAndroid Build Coastguard Worker /// we handle this by storeing the classifier in the opcode field and using 547*9880d681SAndroid Build Coastguard Worker /// this flag to indicate that the encoder should do the wacky 3DNow! thing. 548*9880d681SAndroid Build Coastguard Worker Has3DNow0F0FOpcodeShift = CD8_Scale_Shift + 7, 549*9880d681SAndroid Build Coastguard Worker Has3DNow0F0FOpcode = 1ULL << Has3DNow0F0FOpcodeShift, 550*9880d681SAndroid Build Coastguard Worker 551*9880d681SAndroid Build Coastguard Worker /// MemOp4 - Used to indicate swapping of operand 3 and 4 to be encoded in 552*9880d681SAndroid Build Coastguard Worker /// ModRM or I8IMM. This is used for FMA4 and XOP instructions. 553*9880d681SAndroid Build Coastguard Worker MemOp4Shift = Has3DNow0F0FOpcodeShift + 1, 554*9880d681SAndroid Build Coastguard Worker MemOp4 = 1ULL << MemOp4Shift, 555*9880d681SAndroid Build Coastguard Worker 556*9880d681SAndroid Build Coastguard Worker /// Explicitly specified rounding control 557*9880d681SAndroid Build Coastguard Worker EVEX_RCShift = MemOp4Shift + 1, 558*9880d681SAndroid Build Coastguard Worker EVEX_RC = 1ULL << EVEX_RCShift 559*9880d681SAndroid Build Coastguard Worker }; 560*9880d681SAndroid Build Coastguard Worker 561*9880d681SAndroid Build Coastguard Worker // getBaseOpcodeFor - This function returns the "base" X86 opcode for the 562*9880d681SAndroid Build Coastguard Worker // specified machine instruction. 563*9880d681SAndroid Build Coastguard Worker // getBaseOpcodeFor(uint64_t TSFlags)564*9880d681SAndroid Build Coastguard Worker inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) { 565*9880d681SAndroid Build Coastguard Worker return TSFlags >> X86II::OpcodeShift; 566*9880d681SAndroid Build Coastguard Worker } 567*9880d681SAndroid Build Coastguard Worker hasImm(uint64_t TSFlags)568*9880d681SAndroid Build Coastguard Worker inline bool hasImm(uint64_t TSFlags) { 569*9880d681SAndroid Build Coastguard Worker return (TSFlags & X86II::ImmMask) != 0; 570*9880d681SAndroid Build Coastguard Worker } 571*9880d681SAndroid Build Coastguard Worker 572*9880d681SAndroid Build Coastguard Worker /// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field 573*9880d681SAndroid Build Coastguard Worker /// of the specified instruction. getSizeOfImm(uint64_t TSFlags)574*9880d681SAndroid Build Coastguard Worker inline unsigned getSizeOfImm(uint64_t TSFlags) { 575*9880d681SAndroid Build Coastguard Worker switch (TSFlags & X86II::ImmMask) { 576*9880d681SAndroid Build Coastguard Worker default: llvm_unreachable("Unknown immediate size"); 577*9880d681SAndroid Build Coastguard Worker case X86II::Imm8: 578*9880d681SAndroid Build Coastguard Worker case X86II::Imm8PCRel: return 1; 579*9880d681SAndroid Build Coastguard Worker case X86II::Imm16: 580*9880d681SAndroid Build Coastguard Worker case X86II::Imm16PCRel: return 2; 581*9880d681SAndroid Build Coastguard Worker case X86II::Imm32: 582*9880d681SAndroid Build Coastguard Worker case X86II::Imm32S: 583*9880d681SAndroid Build Coastguard Worker case X86II::Imm32PCRel: return 4; 584*9880d681SAndroid Build Coastguard Worker case X86II::Imm64: return 8; 585*9880d681SAndroid Build Coastguard Worker } 586*9880d681SAndroid Build Coastguard Worker } 587*9880d681SAndroid Build Coastguard Worker 588*9880d681SAndroid Build Coastguard Worker /// isImmPCRel - Return true if the immediate of the specified instruction's 589*9880d681SAndroid Build Coastguard Worker /// TSFlags indicates that it is pc relative. isImmPCRel(uint64_t TSFlags)590*9880d681SAndroid Build Coastguard Worker inline unsigned isImmPCRel(uint64_t TSFlags) { 591*9880d681SAndroid Build Coastguard Worker switch (TSFlags & X86II::ImmMask) { 592*9880d681SAndroid Build Coastguard Worker default: llvm_unreachable("Unknown immediate size"); 593*9880d681SAndroid Build Coastguard Worker case X86II::Imm8PCRel: 594*9880d681SAndroid Build Coastguard Worker case X86II::Imm16PCRel: 595*9880d681SAndroid Build Coastguard Worker case X86II::Imm32PCRel: 596*9880d681SAndroid Build Coastguard Worker return true; 597*9880d681SAndroid Build Coastguard Worker case X86II::Imm8: 598*9880d681SAndroid Build Coastguard Worker case X86II::Imm16: 599*9880d681SAndroid Build Coastguard Worker case X86II::Imm32: 600*9880d681SAndroid Build Coastguard Worker case X86II::Imm32S: 601*9880d681SAndroid Build Coastguard Worker case X86II::Imm64: 602*9880d681SAndroid Build Coastguard Worker return false; 603*9880d681SAndroid Build Coastguard Worker } 604*9880d681SAndroid Build Coastguard Worker } 605*9880d681SAndroid Build Coastguard Worker 606*9880d681SAndroid Build Coastguard Worker /// isImmSigned - Return true if the immediate of the specified instruction's 607*9880d681SAndroid Build Coastguard Worker /// TSFlags indicates that it is signed. isImmSigned(uint64_t TSFlags)608*9880d681SAndroid Build Coastguard Worker inline unsigned isImmSigned(uint64_t TSFlags) { 609*9880d681SAndroid Build Coastguard Worker switch (TSFlags & X86II::ImmMask) { 610*9880d681SAndroid Build Coastguard Worker default: llvm_unreachable("Unknown immediate signedness"); 611*9880d681SAndroid Build Coastguard Worker case X86II::Imm32S: 612*9880d681SAndroid Build Coastguard Worker return true; 613*9880d681SAndroid Build Coastguard Worker case X86II::Imm8: 614*9880d681SAndroid Build Coastguard Worker case X86II::Imm8PCRel: 615*9880d681SAndroid Build Coastguard Worker case X86II::Imm16: 616*9880d681SAndroid Build Coastguard Worker case X86II::Imm16PCRel: 617*9880d681SAndroid Build Coastguard Worker case X86II::Imm32: 618*9880d681SAndroid Build Coastguard Worker case X86II::Imm32PCRel: 619*9880d681SAndroid Build Coastguard Worker case X86II::Imm64: 620*9880d681SAndroid Build Coastguard Worker return false; 621*9880d681SAndroid Build Coastguard Worker } 622*9880d681SAndroid Build Coastguard Worker } 623*9880d681SAndroid Build Coastguard Worker 624*9880d681SAndroid Build Coastguard Worker /// getOperandBias - compute any additional adjustment needed to 625*9880d681SAndroid Build Coastguard Worker /// the offset to the start of the memory operand 626*9880d681SAndroid Build Coastguard Worker /// in this instruction. 627*9880d681SAndroid Build Coastguard Worker /// If this is a two-address instruction,skip one of the register operands. 628*9880d681SAndroid Build Coastguard Worker /// FIXME: This should be handled during MCInst lowering. getOperandBias(const MCInstrDesc & Desc)629*9880d681SAndroid Build Coastguard Worker inline int getOperandBias(const MCInstrDesc& Desc) 630*9880d681SAndroid Build Coastguard Worker { 631*9880d681SAndroid Build Coastguard Worker unsigned NumOps = Desc.getNumOperands(); 632*9880d681SAndroid Build Coastguard Worker unsigned CurOp = 0; 633*9880d681SAndroid Build Coastguard Worker if (NumOps > 1 && Desc.getOperandConstraint(1, MCOI::TIED_TO) == 0) 634*9880d681SAndroid Build Coastguard Worker ++CurOp; 635*9880d681SAndroid Build Coastguard Worker else if (NumOps > 3 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 && 636*9880d681SAndroid Build Coastguard Worker Desc.getOperandConstraint(3, MCOI::TIED_TO) == 1) 637*9880d681SAndroid Build Coastguard Worker // Special case for AVX-512 GATHER with 2 TIED_TO operands 638*9880d681SAndroid Build Coastguard Worker // Skip the first 2 operands: dst, mask_wb 639*9880d681SAndroid Build Coastguard Worker CurOp += 2; 640*9880d681SAndroid Build Coastguard Worker else if (NumOps > 3 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 && 641*9880d681SAndroid Build Coastguard Worker Desc.getOperandConstraint(NumOps - 1, MCOI::TIED_TO) == 1) 642*9880d681SAndroid Build Coastguard Worker // Special case for GATHER with 2 TIED_TO operands 643*9880d681SAndroid Build Coastguard Worker // Skip the first 2 operands: dst, mask_wb 644*9880d681SAndroid Build Coastguard Worker CurOp += 2; 645*9880d681SAndroid Build Coastguard Worker else if (NumOps > 2 && Desc.getOperandConstraint(NumOps - 2, MCOI::TIED_TO) == 0) 646*9880d681SAndroid Build Coastguard Worker // SCATTER 647*9880d681SAndroid Build Coastguard Worker ++CurOp; 648*9880d681SAndroid Build Coastguard Worker return CurOp; 649*9880d681SAndroid Build Coastguard Worker } 650*9880d681SAndroid Build Coastguard Worker 651*9880d681SAndroid Build Coastguard Worker /// getMemoryOperandNo - The function returns the MCInst operand # for the 652*9880d681SAndroid Build Coastguard Worker /// first field of the memory operand. If the instruction doesn't have a 653*9880d681SAndroid Build Coastguard Worker /// memory operand, this returns -1. 654*9880d681SAndroid Build Coastguard Worker /// 655*9880d681SAndroid Build Coastguard Worker /// Note that this ignores tied operands. If there is a tied register which 656*9880d681SAndroid Build Coastguard Worker /// is duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only 657*9880d681SAndroid Build Coastguard Worker /// counted as one operand. 658*9880d681SAndroid Build Coastguard Worker /// getMemoryOperandNo(uint64_t TSFlags)659*9880d681SAndroid Build Coastguard Worker inline int getMemoryOperandNo(uint64_t TSFlags) { 660*9880d681SAndroid Build Coastguard Worker bool HasVEX_4V = TSFlags & X86II::VEX_4V; 661*9880d681SAndroid Build Coastguard Worker bool HasMemOp4 = TSFlags & X86II::MemOp4; 662*9880d681SAndroid Build Coastguard Worker bool HasEVEX_K = TSFlags & X86II::EVEX_K; 663*9880d681SAndroid Build Coastguard Worker 664*9880d681SAndroid Build Coastguard Worker switch (TSFlags & X86II::FormMask) { 665*9880d681SAndroid Build Coastguard Worker default: llvm_unreachable("Unknown FormMask value in getMemoryOperandNo!"); 666*9880d681SAndroid Build Coastguard Worker case X86II::Pseudo: 667*9880d681SAndroid Build Coastguard Worker case X86II::RawFrm: 668*9880d681SAndroid Build Coastguard Worker case X86II::AddRegFrm: 669*9880d681SAndroid Build Coastguard Worker case X86II::MRMDestReg: 670*9880d681SAndroid Build Coastguard Worker case X86II::MRMSrcReg: 671*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmImm8: 672*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmImm16: 673*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmMemOffs: 674*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmSrc: 675*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmDst: 676*9880d681SAndroid Build Coastguard Worker case X86II::RawFrmDstSrc: 677*9880d681SAndroid Build Coastguard Worker return -1; 678*9880d681SAndroid Build Coastguard Worker case X86II::MRMDestMem: 679*9880d681SAndroid Build Coastguard Worker return 0; 680*9880d681SAndroid Build Coastguard Worker case X86II::MRMSrcMem: 681*9880d681SAndroid Build Coastguard Worker // Start from 1, skip any registers encoded in VEX_VVVV or I8IMM, or a 682*9880d681SAndroid Build Coastguard Worker // mask register. 683*9880d681SAndroid Build Coastguard Worker return 1 + HasVEX_4V + HasMemOp4 + HasEVEX_K; 684*9880d681SAndroid Build Coastguard Worker case X86II::MRMXr: 685*9880d681SAndroid Build Coastguard Worker case X86II::MRM0r: case X86II::MRM1r: 686*9880d681SAndroid Build Coastguard Worker case X86II::MRM2r: case X86II::MRM3r: 687*9880d681SAndroid Build Coastguard Worker case X86II::MRM4r: case X86II::MRM5r: 688*9880d681SAndroid Build Coastguard Worker case X86II::MRM6r: case X86II::MRM7r: 689*9880d681SAndroid Build Coastguard Worker return -1; 690*9880d681SAndroid Build Coastguard Worker case X86II::MRMXm: 691*9880d681SAndroid Build Coastguard Worker case X86II::MRM0m: case X86II::MRM1m: 692*9880d681SAndroid Build Coastguard Worker case X86II::MRM2m: case X86II::MRM3m: 693*9880d681SAndroid Build Coastguard Worker case X86II::MRM4m: case X86II::MRM5m: 694*9880d681SAndroid Build Coastguard Worker case X86II::MRM6m: case X86II::MRM7m: 695*9880d681SAndroid Build Coastguard Worker // Start from 0, skip registers encoded in VEX_VVVV or a mask register. 696*9880d681SAndroid Build Coastguard Worker return 0 + HasVEX_4V + HasEVEX_K; 697*9880d681SAndroid Build Coastguard Worker case X86II::MRM_C0: case X86II::MRM_C1: case X86II::MRM_C2: 698*9880d681SAndroid Build Coastguard Worker case X86II::MRM_C3: case X86II::MRM_C4: case X86II::MRM_C5: 699*9880d681SAndroid Build Coastguard Worker case X86II::MRM_C6: case X86II::MRM_C7: case X86II::MRM_C8: 700*9880d681SAndroid Build Coastguard Worker case X86II::MRM_C9: case X86II::MRM_CA: case X86II::MRM_CB: 701*9880d681SAndroid Build Coastguard Worker case X86II::MRM_CC: case X86II::MRM_CD: case X86II::MRM_CE: 702*9880d681SAndroid Build Coastguard Worker case X86II::MRM_CF: case X86II::MRM_D0: case X86II::MRM_D1: 703*9880d681SAndroid Build Coastguard Worker case X86II::MRM_D2: case X86II::MRM_D3: case X86II::MRM_D4: 704*9880d681SAndroid Build Coastguard Worker case X86II::MRM_D5: case X86II::MRM_D6: case X86II::MRM_D7: 705*9880d681SAndroid Build Coastguard Worker case X86II::MRM_D8: case X86II::MRM_D9: case X86II::MRM_DA: 706*9880d681SAndroid Build Coastguard Worker case X86II::MRM_DB: case X86II::MRM_DC: case X86II::MRM_DD: 707*9880d681SAndroid Build Coastguard Worker case X86II::MRM_DE: case X86II::MRM_DF: case X86II::MRM_E0: 708*9880d681SAndroid Build Coastguard Worker case X86II::MRM_E1: case X86II::MRM_E2: case X86II::MRM_E3: 709*9880d681SAndroid Build Coastguard Worker case X86II::MRM_E4: case X86II::MRM_E5: case X86II::MRM_E6: 710*9880d681SAndroid Build Coastguard Worker case X86II::MRM_E7: case X86II::MRM_E8: case X86II::MRM_E9: 711*9880d681SAndroid Build Coastguard Worker case X86II::MRM_EA: case X86II::MRM_EB: case X86II::MRM_EC: 712*9880d681SAndroid Build Coastguard Worker case X86II::MRM_ED: case X86II::MRM_EE: case X86II::MRM_EF: 713*9880d681SAndroid Build Coastguard Worker case X86II::MRM_F0: case X86II::MRM_F1: case X86II::MRM_F2: 714*9880d681SAndroid Build Coastguard Worker case X86II::MRM_F3: case X86II::MRM_F4: case X86II::MRM_F5: 715*9880d681SAndroid Build Coastguard Worker case X86II::MRM_F6: case X86II::MRM_F7: case X86II::MRM_F8: 716*9880d681SAndroid Build Coastguard Worker case X86II::MRM_F9: case X86II::MRM_FA: case X86II::MRM_FB: 717*9880d681SAndroid Build Coastguard Worker case X86II::MRM_FC: case X86II::MRM_FD: case X86II::MRM_FE: 718*9880d681SAndroid Build Coastguard Worker case X86II::MRM_FF: 719*9880d681SAndroid Build Coastguard Worker return -1; 720*9880d681SAndroid Build Coastguard Worker } 721*9880d681SAndroid Build Coastguard Worker } 722*9880d681SAndroid Build Coastguard Worker 723*9880d681SAndroid Build Coastguard Worker /// isX86_64ExtendedReg - Is the MachineOperand a x86-64 extended (r8 or 724*9880d681SAndroid Build Coastguard Worker /// higher) register? e.g. r8, xmm8, xmm13, etc. isX86_64ExtendedReg(unsigned RegNo)725*9880d681SAndroid Build Coastguard Worker inline bool isX86_64ExtendedReg(unsigned RegNo) { 726*9880d681SAndroid Build Coastguard Worker if ((RegNo >= X86::XMM8 && RegNo <= X86::XMM15) || 727*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::XMM24 && RegNo <= X86::XMM31) || 728*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::YMM8 && RegNo <= X86::YMM15) || 729*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::YMM24 && RegNo <= X86::YMM31) || 730*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::ZMM8 && RegNo <= X86::ZMM15) || 731*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::ZMM24 && RegNo <= X86::ZMM31)) 732*9880d681SAndroid Build Coastguard Worker return true; 733*9880d681SAndroid Build Coastguard Worker 734*9880d681SAndroid Build Coastguard Worker switch (RegNo) { 735*9880d681SAndroid Build Coastguard Worker default: break; 736*9880d681SAndroid Build Coastguard Worker case X86::R8: case X86::R9: case X86::R10: case X86::R11: 737*9880d681SAndroid Build Coastguard Worker case X86::R12: case X86::R13: case X86::R14: case X86::R15: 738*9880d681SAndroid Build Coastguard Worker case X86::R8D: case X86::R9D: case X86::R10D: case X86::R11D: 739*9880d681SAndroid Build Coastguard Worker case X86::R12D: case X86::R13D: case X86::R14D: case X86::R15D: 740*9880d681SAndroid Build Coastguard Worker case X86::R8W: case X86::R9W: case X86::R10W: case X86::R11W: 741*9880d681SAndroid Build Coastguard Worker case X86::R12W: case X86::R13W: case X86::R14W: case X86::R15W: 742*9880d681SAndroid Build Coastguard Worker case X86::R8B: case X86::R9B: case X86::R10B: case X86::R11B: 743*9880d681SAndroid Build Coastguard Worker case X86::R12B: case X86::R13B: case X86::R14B: case X86::R15B: 744*9880d681SAndroid Build Coastguard Worker case X86::CR8: case X86::CR9: case X86::CR10: case X86::CR11: 745*9880d681SAndroid Build Coastguard Worker case X86::CR12: case X86::CR13: case X86::CR14: case X86::CR15: 746*9880d681SAndroid Build Coastguard Worker return true; 747*9880d681SAndroid Build Coastguard Worker } 748*9880d681SAndroid Build Coastguard Worker return false; 749*9880d681SAndroid Build Coastguard Worker } 750*9880d681SAndroid Build Coastguard Worker 751*9880d681SAndroid Build Coastguard Worker /// is32ExtendedReg - Is the MemoryOperand a 32 extended (zmm16 or higher) 752*9880d681SAndroid Build Coastguard Worker /// registers? e.g. zmm21, etc. is32ExtendedReg(unsigned RegNo)753*9880d681SAndroid Build Coastguard Worker static inline bool is32ExtendedReg(unsigned RegNo) { 754*9880d681SAndroid Build Coastguard Worker return ((RegNo >= X86::XMM16 && RegNo <= X86::XMM31) || 755*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::YMM16 && RegNo <= X86::YMM31) || 756*9880d681SAndroid Build Coastguard Worker (RegNo >= X86::ZMM16 && RegNo <= X86::ZMM31)); 757*9880d681SAndroid Build Coastguard Worker } 758*9880d681SAndroid Build Coastguard Worker 759*9880d681SAndroid Build Coastguard Worker isX86_64NonExtLowByteReg(unsigned reg)760*9880d681SAndroid Build Coastguard Worker inline bool isX86_64NonExtLowByteReg(unsigned reg) { 761*9880d681SAndroid Build Coastguard Worker return (reg == X86::SPL || reg == X86::BPL || 762*9880d681SAndroid Build Coastguard Worker reg == X86::SIL || reg == X86::DIL); 763*9880d681SAndroid Build Coastguard Worker } 764*9880d681SAndroid Build Coastguard Worker } 765*9880d681SAndroid Build Coastguard Worker 766*9880d681SAndroid Build Coastguard Worker } // end namespace llvm; 767*9880d681SAndroid Build Coastguard Worker 768*9880d681SAndroid Build Coastguard Worker #endif 769