18c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===-- X86BaseInfo.h - Top level definitions for X86 -------- --*- C++ -*-===// 28c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 38c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// The LLVM Compiler Infrastructure 48c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 58c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// This file is distributed under the University of Illinois Open Source 68c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// License. See LICENSE.TXT for details. 78c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 88c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===----------------------------------------------------------------------===// 98c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// This file contains small standalone helper functions and enum definitions for 118c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// the X86 target useful for the compiler back-end and the MC libraries. 128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// As such, it deliberately does not include references to LLVM core 138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// code gen types, passes, etc.. 148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===----------------------------------------------------------------------===// 168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H 1837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86BASEINFO_H 198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#include "X86MCTargetDesc.h" 2136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCInstrDesc.h" 228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#include "llvm/Support/DataTypes.h" 236d1263acb9704b38a8d90fd6ce94f49193cd4ddeCraig Topper#include "llvm/Support/ErrorHandling.h" 248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace llvm { 268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace X86 { 288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Enums for memory operand decoding. Each memory operand is represented with 298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // a 5 operand sequence in the form: 308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // [BaseReg, ScaleAmt, IndexReg, Disp, Segment] 318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // These enums help decode this. 328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng enum { 338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrBaseReg = 0, 348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrScaleAmt = 1, 358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrIndexReg = 2, 368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrDisp = 3, 378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddrSegmentReg - The operand # of the segment in the memory operand. 398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrSegmentReg = 4, 408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddrNumOperands - Total number of operands in a memory reference. 428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrNumOperands = 5 438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} // end namespace X86; 458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// X86II - This namespace holds all of the target specific flags that 478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// instruction info tracks. 488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// 498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace X86II { 508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Target Operand Flag enum. 518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng enum TOF { 528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // X86 Specific MachineOperand flags. 548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_NO_FLAG, 568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a 588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// relocation of: 598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL + [. - PICBASELABEL] 608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOT_ABSOLUTE_ADDRESS, 618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the 638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// immediate should get the value of the symbol minus the PIC base label: 648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL - PICBASELABEL 658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_PIC_BASE_OFFSET, 668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOT - On a symbol operand this indicates that the immediate is the 688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the GOT entry for the symbol name from the base of the GOT. 698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOT 728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOT, 738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTOFF - On a symbol operand this indicates that the immediate is 758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// the offset to the location of the symbol name from the base of the GOT. 768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTOFF 798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTOFF, 808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is 828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the GOT entry for the symbol name from the current code 838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// location. 848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTPCREL 878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTPCREL, 888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_PLT - On a symbol operand this indicates that the immediate is 908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the PLT entry of symbol name from the current code location. 918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @PLT 948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_PLT, 958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLSGD - On a symbol operand this indicates that the immediate is 97d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the offset of the GOT entry with the TLS index structure that contains 98d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the module number and variable offset for the symbol. Used in the 99d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// general dynamic TLS access model. 1008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @TLSGD 1038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TLSGD, 1048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 105f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// MO_TLSLD - On a symbol operand this indicates that the immediate is 106f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// the offset of the GOT entry with the TLS index for the module that 1077c1ac767691b2cb5d3367e667e51714f34eb675bHans Wennborg /// contains the symbol. When this index is passed to a call to 108f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// __tls_get_addr, the function will return the base address of the TLS 109d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// block for the symbol. Used in the x86-64 local dynamic TLS access model. 110f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// 111f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// See 'ELF Handling for Thread-Local Storage' for more details. 112f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// SYMBOL_LABEL @TLSLD 113f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg MO_TLSLD, 114f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg 115f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// MO_TLSLDM - On a symbol operand this indicates that the immediate is 116f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// the offset of the GOT entry with the TLS index for the module that 1177c1ac767691b2cb5d3367e667e51714f34eb675bHans Wennborg /// contains the symbol. When this index is passed to a call to 118f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// ___tls_get_addr, the function will return the base address of the TLS 119d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// block for the symbol. Used in the IA32 local dynamic TLS access model. 120f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// 121f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// See 'ELF Handling for Thread-Local Storage' for more details. 122f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// SYMBOL_LABEL @TLSLDM 123f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg MO_TLSLDM, 124f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg 1258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is 126d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the offset of the GOT entry with the thread-pointer offset for the 127d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// symbol. Used in the x86-64 initial exec TLS access model. 1288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTTPOFF 1318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTTPOFF, 1328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is 134d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the absolute address of the GOT entry with the negative thread-pointer 135d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// offset for the symbol. Used in the non-PIC IA32 initial exec TLS access 136d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// model. 1378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @INDNTPOFF 1408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_INDNTPOFF, 1418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TPOFF - On a symbol operand this indicates that the immediate is 143d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the thread-pointer offset for the symbol. Used in the x86-64 local 144d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// exec TLS access model. 1458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @TPOFF 1488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TPOFF, 1498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 150f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// MO_DTPOFF - On a symbol operand this indicates that the immediate is 151d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the offset of the GOT entry with the TLS offset of the symbol. Used 152d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// in the local dynamic TLS access model. 153f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// 154f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// See 'ELF Handling for Thread-Local Storage' for more details. 155f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg /// SYMBOL_LABEL @DTPOFF 156f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg MO_DTPOFF, 157f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg 1588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_NTPOFF - On a symbol operand this indicates that the immediate is 159d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the negative thread-pointer offset for the symbol. Used in the IA32 160d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// local exec TLS access model. 1618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @NTPOFF 1648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_NTPOFF, 1658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 166228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg /// MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is 167d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the offset of the GOT entry with the negative thread-pointer offset for 168d01d693c0b337cfcbf524a3a38c8123a6c5fe54eHans Wennborg /// the symbol. Used in the PIC IA32 initial exec TLS access model. 169228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg /// 170228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg /// See 'ELF Handling for Thread-Local Storage' for more details. 171228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg /// SYMBOL_LABEL @GOTNTPOFF 172228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg MO_GOTNTPOFF, 173228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg 1748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the 1758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "__imp_FOO" symbol. This is used for 1768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// dllimport linkage on windows. 1778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DLLIMPORT, 1788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_STUB - On a symbol operand "FOO", this indicates that the 1808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "FOO$stub" symbol. This is used for calls 1818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// and jumps to external functions on Tiger and earlier. 1828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_STUB, 1838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the 1858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a 1868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 1878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_NONLAZY, 1888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates 1908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is 1918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 1928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_NONLAZY_PIC_BASE, 1938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this 1958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE", 1968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// which is a PIC-base-relative reference to a hidden dyld lazy pointer 1978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// stub. 1988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE, 1998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLVP - On a symbol operand this indicates that the immediate is 2018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 2028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// This is the TLS offset for the Darwin TLS mechanism. 2048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TLVP, 2058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate 2078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// is some TLS offset from the picbase. 2088c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// This is the 32-bit TLS offset for Darwin TLS in PIC mode. 210d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov MO_TLVP_PIC_BASE, 211d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov 212d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov /// MO_SECREL - On a symbol operand this indicates that the immediate is 213d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov /// the offset from beginning of section. 214d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov /// 215d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov /// This is the TLS offset for the COFF/Windows TLS mechanism. 216cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar MO_SECREL 2178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 2188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 21937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines enum : uint64_t { 2208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 2218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Instruction encodings. These are the standard/most common forms for X86 2228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // instructions. 2238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 2248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // PseudoFrm - This represents an instruction that is a pseudo instruction 2268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // or one that has not been implemented yet. It is illegal to code generate 2278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // it, but tolerated for intermediate implementation stages. 2288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Pseudo = 0, 2298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Raw - This form is for instructions that don't have any operands, so 2318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// they are just a fixed opcode value, like 'leave'. 2328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng RawFrm = 1, 2338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddRegFrm - This form is used for instructions like 'push r32' that have 2358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// their one register operand added to their opcode. 2368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddRegFrm = 2, 2378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMDestReg - This form is used for instructions that use the Mod/RM byte 2398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a destination, which in this case is a register. 2408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMDestReg = 3, 2428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMDestMem - This form is used for instructions that use the Mod/RM byte 2448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a destination, which in this case is memory. 2458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMDestMem = 4, 2478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte 2498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a source, which in this case is a register. 2508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMSrcReg = 5, 2528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte 2548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a source, which in this case is memory. 2558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMSrcMem = 6, 2578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 25836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RawFrmMemOffs - This form is for instructions that store an absolute 25936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// memory offset as an immediate with a possible segment override. 26036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmMemOffs = 7, 26136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 26236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RawFrmSrc - This form is for instructions that use the source index 26336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// register SI/ESI/RSI with a possible segment override. 26436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmSrc = 8, 26536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 26636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RawFrmDst - This form is for instructions that use the destination index 26736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// register DI/EDI/ESI. 26836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmDst = 9, 26936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 270cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar /// RawFrmSrc - This form is for instructions that use the source index 27136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// register SI/ESI/ERI with a possible segment override, and also the 27236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// destination index register DI/ESI/RDI. 27336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmDstSrc = 10, 27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 27536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RawFrmImm8 - This is used for the ENTER instruction, which has two 27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// immediates, the first of which is a 16-bit immediate (specified by 27736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// the imm encoding) and the second is a 8-bit fixed value. 27836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmImm8 = 11, 27936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 28036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// RawFrmImm16 - This is used for CALL FAR instructions, which have two 28136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// immediates, the first of which is a 16 or 32-bit immediate (specified by 28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// the imm encoding) and the second is a 16-bit fixed value. In the AMD 28336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// manual, this operand is described as pntr16:32 and pntr16:16 28436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines RawFrmImm16 = 12, 28536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 28636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// MRMX[rm] - The forms are used to represent instructions that use a 28736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Mod/RM byte, and don't use the middle field for anything. 28836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MRMXr = 14, MRMXm = 15, 28936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 2908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRM[0-7][rm] - These forms are used to represent instructions that use 2918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// a Mod/RM byte, and use the middle field to hold extended opcode 2928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// information. In the intel manual these are represented as /0, /1, ... 2938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // First, instructions that operate on a register r/m operand... 2968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19, // Format /0 /1 /2 /3 2978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23, // Format /4 /5 /6 /7 2988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Next, instructions that operate on a memory r/m operand... 3008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27, // Format /0 /1 /2 /3 3018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31, // Format /4 /5 /6 /7 3028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3039e3d0b335111b2df73984a6cfd9ef1cd5d323872Craig Topper //// MRM_XX - A mod/rm byte of exactly 0xXX. 30436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MRM_C0 = 32, MRM_C1 = 33, MRM_C2 = 34, MRM_C3 = 35, 305ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_C4 = 36, MRM_C5 = 37, MRM_C6 = 38, MRM_C7 = 39, 306ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_C8 = 40, MRM_C9 = 41, MRM_CA = 42, MRM_CB = 43, 307ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_CC = 44, MRM_CD = 45, MRM_CE = 46, MRM_CF = 47, 308ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_D0 = 48, MRM_D1 = 49, MRM_D2 = 50, MRM_D3 = 51, 309ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_D4 = 52, MRM_D5 = 53, MRM_D6 = 54, MRM_D7 = 55, 310ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_D8 = 56, MRM_D9 = 57, MRM_DA = 58, MRM_DB = 59, 311ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_DC = 60, MRM_DD = 61, MRM_DE = 62, MRM_DF = 63, 312ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_E0 = 64, MRM_E1 = 65, MRM_E2 = 66, MRM_E3 = 67, 313ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_E4 = 68, MRM_E5 = 69, MRM_E6 = 70, MRM_E7 = 71, 314ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_E8 = 72, MRM_E9 = 73, MRM_EA = 74, MRM_EB = 75, 315ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_EC = 76, MRM_ED = 77, MRM_EE = 78, MRM_EF = 79, 316ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_F0 = 80, MRM_F1 = 81, MRM_F2 = 82, MRM_F3 = 83, 317ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_F4 = 84, MRM_F5 = 85, MRM_F6 = 86, MRM_F7 = 87, 318ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_F8 = 88, MRM_F9 = 89, MRM_FA = 90, MRM_FB = 91, 319ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines MRM_FC = 92, MRM_FD = 93, MRM_FE = 94, MRM_FF = 95, 32036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 32136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines FormMask = 127, 3228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Actual flags... 3258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 32636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // OpSize - OpSizeFixed implies instruction never needs a 0x66 prefix. 32736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // OpSize16 means this is a 16-bit instruction and needs 0x66 prefix in 32836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // 32-bit mode. OpSize32 means this is a 32-bit instruction needs a 0x66 32936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // prefix in 16-bit mode. 33036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpSizeShift = 7, 33136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpSizeMask = 0x3 << OpSizeShift, 33236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 333ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines OpSizeFixed = 0 << OpSizeShift, 334ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines OpSize16 = 1 << OpSizeShift, 335ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines OpSize32 = 2 << OpSizeShift, 3368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 337ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // AsSize - AdSizeX implies this instruction determines its need of 0x67 338ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // prefix from a normal ModRM memory operand. The other types indicate that 339ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // an operand is encoded with a specific width and a prefix is needed if 340ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // it differs from the current mode. 34136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines AdSizeShift = OpSizeShift + 2, 342ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AdSizeMask = 0x3 << AdSizeShift, 343ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 344ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AdSizeX = 1 << AdSizeShift, 345ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AdSize16 = 1 << AdSizeShift, 346ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AdSize32 = 2 << AdSizeShift, 347ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines AdSize64 = 3 << AdSizeShift, 3488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 35036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // OpPrefix - There are several prefix bytes that are used as opcode 35136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // extensions. These are 0x66, 0xF3, and 0xF2. If this field is 0 there is 35236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // no prefix. 3538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 354ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines OpPrefixShift = AdSizeShift + 2, 35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpPrefixMask = 0x7 << OpPrefixShift, 3568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 35736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // PS, PD - Prefix code for packed single and double precision vector 35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // floating point operations performed in the SSE registers. 35936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines PS = 1 << OpPrefixShift, PD = 2 << OpPrefixShift, 3608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // XS, XD - These prefix codes are for single and double precision scalar 3628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // floating point operations performed in the SSE registers. 36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines XS = 3 << OpPrefixShift, XD = 4 << OpPrefixShift, 3648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines //===------------------------------------------------------------------===// 36636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // OpMap - This field determines which opcode map this instruction 36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // belongs to. i.e. one-byte, two-byte, 0x0f 0x38, 0x0f 0x3a, etc. 36836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // 36936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpMapShift = OpPrefixShift + 3, 37036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpMapMask = 0x7 << OpMapShift, 3718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 37236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // OB - OneByte - Set if this instruction has a one byte opcode. 37336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OB = 0 << OpMapShift, 374ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper 37536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // TB - TwoByte - Set if this instruction has a two byte opcode, which 37636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // starts with a 0x0F byte before the real opcode. 37736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines TB = 1 << OpMapShift, 3788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 37936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // T8, TA - Prefix after the 0x0F prefix. 38036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines T8 = 2 << OpMapShift, TA = 3 << OpMapShift, 38175485d6746f8b5b23c17cf6d2364e7e1e0705992Craig Topper 382ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin // XOP8 - Prefix to include use of imm byte. 38336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines XOP8 = 4 << OpMapShift, 384ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 385ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin // XOP9 - Prefix to exclude use of imm byte. 38636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines XOP9 = 5 << OpMapShift, 387ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 388685707c28e2c7117f025fb4e95e6ca64ed179bb0Yunzhong Gao // XOPA - Prefix to encode 0xA in VEX.MMMM of XOP instructions. 38936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines XOPA = 6 << OpMapShift, 390685707c28e2c7117f025fb4e95e6ca64ed179bb0Yunzhong Gao 3918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // REX_W - REX prefixes are instruction prefixes used in 64-bit mode. 3938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // They are used to specify GPRs and SSE registers, 64-bit operand size, 3948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // etc. We only cares about REX.W and REX.R bits and only the former is 3958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // statically determined. 3968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 39736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines REXShift = OpMapShift + 3, 3988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng REX_W = 1 << REXShift, 3998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 4018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // This three-bit field describes the size of an immediate operand. Zero is 4028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // unused so that we can tell if we forgot to set a value. 4038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ImmShift = REXShift + 1, 40436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ImmMask = 15 << ImmShift, 4058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm8 = 1 << ImmShift, 4068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm8PCRel = 2 << ImmShift, 4078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm16 = 3 << ImmShift, 4088c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm16PCRel = 4 << ImmShift, 4098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm32 = 5 << ImmShift, 4108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm32PCRel = 6 << ImmShift, 41136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Imm32S = 7 << ImmShift, 41236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Imm64 = 8 << ImmShift, 4138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 4158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // FP Instruction Classification... Zero is non-fp instruction. 4168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // FPTypeMask - Mask for all of the FP types... 41836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines FPTypeShift = ImmShift + 4, 4198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng FPTypeMask = 7 << FPTypeShift, 4208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // NotFP - The default, set for instructions that do not use FP registers. 4228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng NotFP = 0 << FPTypeShift, 4238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0 4258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ZeroArgFP = 1 << FPTypeShift, 4268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst 4288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OneArgFP = 2 << FPTypeShift, 4298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a 4318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // result back to ST(0). For example, fcos, fsqrt, etc. 4328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 4338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OneArgFPRW = 3 << FPTypeShift, 4348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an 4368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // explicit argument, storing the result to either ST(0) or the implicit 4378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // argument. For example: fadd, fsub, fmul, etc... 4388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng TwoArgFP = 4 << FPTypeShift, 4398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an 4418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // explicit argument, but have no destination. Example: fucom, fucomi, ... 4428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng CompareFP = 5 << FPTypeShift, 4438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // CondMovFP - "2 operand" floating point conditional move instructions. 4458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng CondMovFP = 6 << FPTypeShift, 4468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // SpecialFP - Special instruction forms. Dispatch by opcode explicitly. 4488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng SpecialFP = 7 << FPTypeShift, 4498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Lock prefix 4518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng LOCKShift = FPTypeShift + 3, 4528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng LOCK = 1 << LOCKShift, 4538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 45436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // REP prefix 45536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines REPShift = LOCKShift + 1, 45636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines REP = 1 << REPShift, 45736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 45836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Execution domain for SSE instructions. 45936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // 0 means normal, non-SSE instruction. 46036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines SSEDomainShift = REPShift + 1, 46136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 46236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Encoding 46336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EncodingShift = SSEDomainShift + 2, 46436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines EncodingMask = 0x3 << EncodingShift, 46536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 46636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // VEX - encoding using 0xC4/0xC5 46737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX = 1 << EncodingShift, 46836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 46936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// XOP - Opcode prefix used by XOP instructions. 47037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines XOP = 2 << EncodingShift, 4718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 47236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // VEX_EVEX - Specifies that this instruction use EVEX form which provides 47336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // syntax support up to 32 512-bit register operands and up to 7 16-bit 47436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // mask operands as well as source operand data swizzling/memory operand 47536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // conversion, eviction hint, and rounding mode. 47637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX = 3 << EncodingShift, 4778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 47836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // Opcode 47936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines OpcodeShift = EncodingShift + 2, 4808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_W - Has a opcode specific functionality, but is used in the same 4828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// way as REX_W is for regular SSE instructions. 48337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_WShift = OpcodeShift + 8, 48437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_W = 1ULL << VEX_WShift, 4858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_4V - Used to specify an additional AVX/SSE register. Several 2 4878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// address instructions in SSE are represented as 3 address ones in AVX 4888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// and the additional register is encoded in VEX_VVVV prefix. 48937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_4VShift = VEX_WShift + 1, 49037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_4V = 1ULL << VEX_4VShift, 4918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 492b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper /// VEX_4VOp3 - Similar to VEX_4V, but used on instructions that encode 493b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper /// operand 3 with VEX.vvvv. 49437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_4VOp3Shift = VEX_4VShift + 1, 49537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_4VOp3 = 1ULL << VEX_4VOp3Shift, 496b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper 4978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_I8IMM - Specifies that the last register used in a AVX instruction, 4988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// must be encoded in the i8 immediate field. This usually happens in 4998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// instructions with 4 operands. 50037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_I8IMMShift = VEX_4VOp3Shift + 1, 50137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_I8IMM = 1ULL << VEX_I8IMMShift, 5028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_L - Stands for a bit in the VEX opcode prefix meaning the current 5048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// instruction uses 256-bit wide registers. This is usually auto detected 5058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// if a VR256 register is used, but some AVX instructions also have this 5068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// field marked when using a f256 memory references. 50737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_LShift = VEX_I8IMMShift + 1, 50837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_L = 1ULL << VEX_LShift, 5098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5106744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper // VEX_LIG - Specifies that this instruction ignores the L-bit in the VEX 5116744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper // prefix. Usually used for scalar instructions. Needed by disassembler. 51237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_LIGShift = VEX_LShift + 1, 51337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines VEX_LIG = 1ULL << VEX_LIGShift, 5146744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper 515c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // TODO: we should combine VEX_L and VEX_LIG together to form a 2-bit field 516c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // with following encoding: 517c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // - 00 V128 518c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // - 01 V256 519c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // - 10 V512 520c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // - 11 LIG (but, in insn encoding, leave VEX.L and EVEX.L in zeros. 521c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // this will save 1 tsflag bit 522c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 523c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // EVEX_K - Set if this instruction requires masking 52437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_KShift = VEX_LIGShift + 1, 52537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_K = 1ULL << EVEX_KShift, 526c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 527c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // EVEX_Z - Set if this instruction has EVEX.Z field set. 52837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_ZShift = EVEX_KShift + 1, 52937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_Z = 1ULL << EVEX_ZShift, 530c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 531c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // EVEX_L2 - Set if this instruction has EVEX.L' field set. 53237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_L2Shift = EVEX_ZShift + 1, 53337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_L2 = 1ULL << EVEX_L2Shift, 534c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 535c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // EVEX_B - Set if this instruction has EVEX.B field set. 53637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_BShift = EVEX_L2Shift + 1, 53737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_B = 1ULL << EVEX_BShift, 538c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 53937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // The scaling factor for the AVX512's 8-bit compressed displacement. 54037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines CD8_Scale_Shift = EVEX_BShift + 1, 54137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines CD8_Scale_Mask = 127ULL << CD8_Scale_Shift, 542c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 5438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Has3DNow0F0FOpcode - This flag indicates that the instruction uses the 5448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// wacky 0x0F 0x0F prefix for 3DNow! instructions. The manual documents 5458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// this as having a 0x0F prefix with a 0x0F opcode, and each instruction 5468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// storing a classifier in the imm8 field. To simplify our implementation, 5478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// we handle this by storeing the classifier in the opcode field and using 5488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// this flag to indicate that the encoder should do the wacky 3DNow! thing. 54937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines Has3DNow0F0FOpcodeShift = CD8_Scale_Shift + 7, 55037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines Has3DNow0F0FOpcode = 1ULL << Has3DNow0F0FOpcodeShift, 5511b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes 5525d1a38cbfac62f75ee22cc0c9195616ea5fe5553Craig Topper /// MemOp4 - Used to indicate swapping of operand 3 and 4 to be encoded in 5535d1a38cbfac62f75ee22cc0c9195616ea5fe5553Craig Topper /// ModRM or I8IMM. This is used for FMA4 and XOP instructions. 55437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines MemOp4Shift = Has3DNow0F0FOpcodeShift + 1, 55537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines MemOp4 = 1ULL << MemOp4Shift, 556ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 55736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// Explicitly specified rounding control 55837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_RCShift = MemOp4Shift + 1, 55937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines EVEX_RC = 1ULL << EVEX_RCShift 5608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 5618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // getBaseOpcodeFor - This function returns the "base" X86 opcode for the 5638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // specified machine instruction. 5648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 565305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) { 5668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return TSFlags >> X86II::OpcodeShift; 5678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 569305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline bool hasImm(uint64_t TSFlags) { 5708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return (TSFlags & X86II::ImmMask) != 0; 5718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field 5748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// of the specified instruction. 575305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline unsigned getSizeOfImm(uint64_t TSFlags) { 5768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::ImmMask) { 5776d1263acb9704b38a8d90fd6ce94f49193cd4ddeCraig Topper default: llvm_unreachable("Unknown immediate size"); 5788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8: 5798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8PCRel: return 1; 5808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16: 5818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16PCRel: return 2; 5828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32: 58336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm32S: 5848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32PCRel: return 4; 5858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm64: return 8; 5868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// isImmPCRel - Return true if the immediate of the specified instruction's 5908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// TSFlags indicates that it is pc relative. 591305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline unsigned isImmPCRel(uint64_t TSFlags) { 5928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::ImmMask) { 5936d1263acb9704b38a8d90fd6ce94f49193cd4ddeCraig Topper default: llvm_unreachable("Unknown immediate size"); 5948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8PCRel: 5958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16PCRel: 5968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32PCRel: 5978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return true; 5988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8: 5998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16: 6008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32: 60136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm32S: 60236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm64: 60336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return false; 60436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 60536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 60636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 60736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// isImmSigned - Return true if the immediate of the specified instruction's 60836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines /// TSFlags indicates that it is signed. 60936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines inline unsigned isImmSigned(uint64_t TSFlags) { 61036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines switch (TSFlags & X86II::ImmMask) { 61136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines default: llvm_unreachable("Unknown immediate signedness"); 61236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm32S: 61336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return true; 61436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm8: 61536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm8PCRel: 61636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm16: 61736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm16PCRel: 61836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm32: 61936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::Imm32PCRel: 6208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm64: 6218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return false; 6228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 6238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 6248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 62515b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd /// getOperandBias - compute any additional adjustment needed to 62615b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd /// the offset to the start of the memory operand 62715b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd /// in this instruction. 62815b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd /// If this is a two-address instruction,skip one of the register operands. 62915b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd /// FIXME: This should be handled during MCInst lowering. 63015b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd inline int getOperandBias(const MCInstrDesc& Desc) 63115b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd { 63215b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd unsigned NumOps = Desc.getNumOperands(); 63315b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd unsigned CurOp = 0; 63415b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd if (NumOps > 1 && Desc.getOperandConstraint(1, MCOI::TIED_TO) == 0) 63515b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd ++CurOp; 636c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky else if (NumOps > 3 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 && 637c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky Desc.getOperandConstraint(3, MCOI::TIED_TO) == 1) 638c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // Special case for AVX-512 GATHER with 2 TIED_TO operands 639c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // Skip the first 2 operands: dst, mask_wb 640c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky CurOp += 2; 641c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky else if (NumOps > 3 && Desc.getOperandConstraint(2, MCOI::TIED_TO) == 0 && 642c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky Desc.getOperandConstraint(NumOps - 1, MCOI::TIED_TO) == 1) 64315b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd // Special case for GATHER with 2 TIED_TO operands 64415b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd // Skip the first 2 operands: dst, mask_wb 64515b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd CurOp += 2; 646c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky else if (NumOps > 2 && Desc.getOperandConstraint(NumOps - 2, MCOI::TIED_TO) == 0) 647c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky // SCATTER 648c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky ++CurOp; 64915b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd return CurOp; 65015b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd } 65115b64d0e28efc625bd740b19ad4138f48d5b98b0Preston Gurd 6528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// getMemoryOperandNo - The function returns the MCInst operand # for the 6538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// first field of the memory operand. If the instruction doesn't have a 6548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// memory operand, this returns -1. 6558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 6568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Note that this ignores tied operands. If there is a tied register which 6578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// is duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only 6588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// counted as one operand. 6598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 660305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline int getMemoryOperandNo(uint64_t TSFlags, unsigned Opcode) { 66137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool HasVEX_4V = TSFlags & X86II::VEX_4V; 66237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool HasMemOp4 = TSFlags & X86II::MemOp4; 66337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool HasEVEX_K = TSFlags & X86II::EVEX_K; 66437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 6658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::FormMask) { 6666d1263acb9704b38a8d90fd6ce94f49193cd4ddeCraig Topper default: llvm_unreachable("Unknown FormMask value in getMemoryOperandNo!"); 6678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Pseudo: 6688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrm: 6698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::AddRegFrm: 6708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMDestReg: 6718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMSrcReg: 6728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrmImm8: 6738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrmImm16: 67436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::RawFrmMemOffs: 67536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::RawFrmSrc: 67636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::RawFrmDst: 67736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::RawFrmDstSrc: 6788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 6798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMDestMem: 6808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return 0; 681ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines case X86II::MRMSrcMem: 682ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // Start from 1, skip any registers encoded in VEX_VVVV or I8IMM, or a 683ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // mask register. 684ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return 1 + HasVEX_4V + HasMemOp4 + HasEVEX_K; 68536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::MRMXr: 6868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM0r: case X86II::MRM1r: 6878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM2r: case X86II::MRM3r: 6888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM4r: case X86II::MRM5r: 6898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM6r: case X86II::MRM7r: 6908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 69136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::MRMXm: 6928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM0m: case X86II::MRM1m: 6938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM2m: case X86II::MRM3m: 6948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM4m: case X86II::MRM5m: 695ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines case X86II::MRM6m: case X86II::MRM7m: 696ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines // Start from 0, skip registers encoded in VEX_VVVV or a mask register. 697ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines return 0 + HasVEX_4V + HasEVEX_K; 69836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::MRM_C0: case X86II::MRM_C1: case X86II::MRM_C2: 69936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::MRM_C3: case X86II::MRM_C4: case X86II::MRM_C8: 70036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case X86II::MRM_C9: case X86II::MRM_CA: case X86II::MRM_CB: 70137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_CF: case X86II::MRM_D0: case X86II::MRM_D1: 70237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_D4: case X86II::MRM_D5: case X86II::MRM_D6: 70337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_D7: case X86II::MRM_D8: case X86II::MRM_D9: 70437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_DA: case X86II::MRM_DB: case X86II::MRM_DC: 70537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_DD: case X86II::MRM_DE: case X86II::MRM_DF: 70637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_E0: case X86II::MRM_E1: case X86II::MRM_E2: 70737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_E3: case X86II::MRM_E4: case X86II::MRM_E5: 70837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_E8: case X86II::MRM_E9: case X86II::MRM_EA: 70937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_EB: case X86II::MRM_EC: case X86II::MRM_ED: 71037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_EE: case X86II::MRM_F0: case X86II::MRM_F1: 71137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_F2: case X86II::MRM_F3: case X86II::MRM_F4: 71237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_F5: case X86II::MRM_F6: case X86II::MRM_F7: 71337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_F8: case X86II::MRM_F9: case X86II::MRM_FA: 71437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_FB: case X86II::MRM_FC: case X86II::MRM_FD: 71537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case X86II::MRM_FE: case X86II::MRM_FF: 7168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 7178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 7188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 7198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 7208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// isX86_64ExtendedReg - Is the MachineOperand a x86-64 extended (r8 or 7218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// higher) register? e.g. r8, xmm8, xmm13, etc. 722305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline bool isX86_64ExtendedReg(unsigned RegNo) { 723c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky if ((RegNo > X86::XMM7 && RegNo <= X86::XMM15) || 724c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::XMM23 && RegNo <= X86::XMM31) || 725c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::YMM7 && RegNo <= X86::YMM15) || 726c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::YMM23 && RegNo <= X86::YMM31) || 727c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::ZMM7 && RegNo <= X86::ZMM15) || 728c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::ZMM23 && RegNo <= X86::ZMM31)) 729c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky return true; 730c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 7318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (RegNo) { 7328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng default: break; 7338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8: case X86::R9: case X86::R10: case X86::R11: 7348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12: case X86::R13: case X86::R14: case X86::R15: 7358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8D: case X86::R9D: case X86::R10D: case X86::R11D: 7368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12D: case X86::R13D: case X86::R14D: case X86::R15D: 7378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8W: case X86::R9W: case X86::R10W: case X86::R11W: 7388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12W: case X86::R13W: case X86::R14W: case X86::R15W: 7398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8B: case X86::R9B: case X86::R10B: case X86::R11B: 7408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12B: case X86::R13B: case X86::R14B: case X86::R15B: 7418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::CR8: case X86::CR9: case X86::CR10: case X86::CR11: 7428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::CR12: case X86::CR13: case X86::CR14: case X86::CR15: 7438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return true; 7448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 7458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return false; 7468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 747c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 748c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky /// is32ExtendedReg - Is the MemoryOperand a 32 extended (zmm16 or higher) 749c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky /// registers? e.g. zmm21, etc. 750c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky static inline bool is32ExtendedReg(unsigned RegNo) { 751c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky return ((RegNo > X86::XMM15 && RegNo <= X86::XMM31) || 752c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::YMM15 && RegNo <= X86::YMM31) || 753c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky (RegNo > X86::ZMM15 && RegNo <= X86::ZMM31)); 754c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky } 755c18f4efc5dd24adcc653806455fc7ae8508e9c66Elena Demikhovsky 756ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines 757305b515c2787f47adecbe120e4b4bef55c5e5525Chandler Carruth inline bool isX86_64NonExtLowByteReg(unsigned reg) { 7588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return (reg == X86::SPL || reg == X86::BPL || 7598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng reg == X86::SIL || reg == X86::DIL); 7608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 7618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} 7628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 7638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} // end namespace llvm; 7648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 7658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#endif 766