//===- X86InstrFormats.td - X86 Instruction Formats --------*- tablegen -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // X86 Instruction Format Definitions. // // Format specifies the encoding used by the instruction. This is part of the // ad-hoc solution used to emit machine instruction encodings by our machine // code emitter. class Format val> { bits<6> Value = val; } def Pseudo : Format<0>; def RawFrm : Format<1>; def AddRegFrm : Format<2>; def MRMDestReg : Format<3>; def MRMDestMem : Format<4>; def MRMSrcReg : Format<5>; def MRMSrcMem : Format<6>; def MRM0r : Format<16>; def MRM1r : Format<17>; def MRM2r : Format<18>; def MRM3r : Format<19>; def MRM4r : Format<20>; def MRM5r : Format<21>; def MRM6r : Format<22>; def MRM7r : Format<23>; def MRM0m : Format<24>; def MRM1m : Format<25>; def MRM2m : Format<26>; def MRM3m : Format<27>; def MRM4m : Format<28>; def MRM5m : Format<29>; def MRM6m : Format<30>; def MRM7m : Format<31>; def MRMInitReg : Format<32>; def MRM_C1 : Format<33>; def MRM_C2 : Format<34>; def MRM_C3 : Format<35>; def MRM_C4 : Format<36>; def MRM_C8 : Format<37>; def MRM_C9 : Format<38>; def MRM_E8 : Format<39>; def MRM_F0 : Format<40>; def MRM_F8 : Format<41>; def MRM_F9 : Format<42>; // ImmType - This specifies the immediate type used by an instruction. This is // part of the ad-hoc solution used to emit machine instruction encodings by our // machine code emitter. class ImmType val> { bits<3> Value = val; } def NoImm : ImmType<0>; def Imm8 : ImmType<1>; def Imm8PCRel : ImmType<2>; def Imm16 : ImmType<3>; def Imm32 : ImmType<4>; def Imm32PCRel : ImmType<5>; def Imm64 : ImmType<6>; // FPFormat - This specifies what form this FP instruction has. This is used by // the Floating-Point stackifier pass. class FPFormat val> { bits<3> Value = val; } def NotFP : FPFormat<0>; def ZeroArgFP : FPFormat<1>; def OneArgFP : FPFormat<2>; def OneArgFPRW : FPFormat<3>; def TwoArgFP : FPFormat<4>; def CompareFP : FPFormat<5>; def CondMovFP : FPFormat<6>; def SpecialFP : FPFormat<7>; // Class specifying the SSE execution domain, used by the SSEDomainFix pass. // Keep in sync with tables in X86InstrInfo.cpp. class Domain val> { bits<2> Value = val; } def GenericDomain : Domain<0>; def SSEPackedSingle : Domain<1>; def SSEPackedDouble : Domain<2>; def SSEPackedInt : Domain<3>; // Prefix byte classes which are used to indicate to the ad-hoc machine code // emitter that various prefix bytes are required. class OpSize { bit hasOpSizePrefix = 1; } class AdSize { bit hasAdSizePrefix = 1; } class REX_W { bit hasREX_WPrefix = 1; } class LOCK { bit hasLockPrefix = 1; } class SegFS { bits<2> SegOvrBits = 1; } class SegGS { bits<2> SegOvrBits = 2; } class TB { bits<4> Prefix = 1; } class REP { bits<4> Prefix = 2; } class D8 { bits<4> Prefix = 3; } class D9 { bits<4> Prefix = 4; } class DA { bits<4> Prefix = 5; } class DB { bits<4> Prefix = 6; } class DC { bits<4> Prefix = 7; } class DD { bits<4> Prefix = 8; } class DE { bits<4> Prefix = 9; } class DF { bits<4> Prefix = 10; } class XD { bits<4> Prefix = 11; } class XS { bits<4> Prefix = 12; } class T8 { bits<4> Prefix = 13; } class TA { bits<4> Prefix = 14; } class TF { bits<4> Prefix = 15; } class VEX { bit hasVEXPrefix = 1; } class VEX_4V : VEX { bit hasVEX_4VPrefix = 1; } class X86Inst opcod, Format f, ImmType i, dag outs, dag ins, string AsmStr, Domain d = GenericDomain> : Instruction { let Namespace = "X86"; bits<8> Opcode = opcod; Format Form = f; bits<6> FormBits = Form.Value; ImmType ImmT = i; dag OutOperandList = outs; dag InOperandList = ins; string AsmString = AsmStr; // // Attributes specific to X86 instructions... // bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix? bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix? bits<4> Prefix = 0; // Which prefix byte does this inst have? bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix? FPFormat FPForm = NotFP; // What flavor of FP instruction is this? bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix? bits<2> SegOvrBits = 0; // Segment override prefix. Domain ExeDomain = d; bit hasVEXPrefix = 0; // Does this inst requires a VEX prefix? bit hasVEX_4VPrefix = 0; // Does this inst requires the VEX.VVVV field? // TSFlags layout should be kept in sync with X86InstrInfo.h. let TSFlags{5-0} = FormBits; let TSFlags{6} = hasOpSizePrefix; let TSFlags{7} = hasAdSizePrefix; let TSFlags{11-8} = Prefix; let TSFlags{12} = hasREX_WPrefix; let TSFlags{15-13} = ImmT.Value; let TSFlags{18-16} = FPForm.Value; let TSFlags{19} = hasLockPrefix; let TSFlags{21-20} = SegOvrBits; let TSFlags{23-22} = ExeDomain.Value; let TSFlags{31-24} = Opcode; let TSFlags{32} = hasVEXPrefix; let TSFlags{33} = hasVEX_4VPrefix; } class I o, Format f, dag outs, dag ins, string asm, list pattern, Domain d = GenericDomain> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Ii8 o, Format f, dag outs, dag ins, string asm, list pattern, Domain d = GenericDomain> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Ii8PCRel o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Ii16 o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Ii32 o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Ii32PCRel o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } // FPStack Instruction Templates: // FPI - Floating Point Instruction template. class FPI o, Format F, dag outs, dag ins, string asm> : I {} // FpI_ - Floating Point Psuedo Instruction template. Not Predicated. class FpI_ pattern> : X86Inst<0, Pseudo, NoImm, outs, ins, ""> { let FPForm = fp; let Pattern = pattern; } // Templates for instructions that use a 16- or 32-bit segmented address as // their only operand: lcall (FAR CALL) and ljmp (FAR JMP) // // Iseg16 - 16-bit segment selector, 16-bit offset // Iseg32 - 16-bit segment selector, 32-bit offset class Iseg16 o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } class Iseg32 o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst { let Pattern = pattern; let CodeSize = 3; } // SI - SSE 1 & 2 scalar instructions class SI o, Format F, dag outs, dag ins, string asm, list pattern> : I { let Predicates = !if(hasVEXPrefix /* VEX_4V */, !if(!eq(Prefix, 11 /* XD */), [HasAVX, HasSSE2], [HasAVX, HasSSE1]), !if(!eq(Prefix, 12 /* XS */), [HasSSE1], [HasSSE2])); // AVX instructions have a 'v' prefix in the mnemonic let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm); } // PI - SSE 1 & 2 packed instructions class PI o, Format F, dag outs, dag ins, string asm, list pattern, Domain d> : I { let Predicates = !if(hasVEXPrefix /* VEX_4V */, !if(hasOpSizePrefix /* OpSize */, [HasAVX, HasSSE2], [HasAVX, HasSSE1]), !if(hasOpSizePrefix /* OpSize */, [HasSSE2], [HasSSE1])); // AVX instructions have a 'v' prefix in the mnemonic let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm); } // PIi8 - SSE 1 & 2 packed instructions with immediate class PIi8 o, Format F, dag outs, dag ins, string asm, list pattern, Domain d> : Ii8 { let Predicates = !if(hasVEX_4VPrefix /* VEX_4V */, !if(hasOpSizePrefix /* OpSize */, [HasAVX, HasSSE2], [HasAVX, HasSSE1]), !if(hasOpSizePrefix /* OpSize */, [HasSSE2], [HasSSE1])); // AVX instructions have a 'v' prefix in the mnemonic let AsmString = !if(hasVEX_4VPrefix, !strconcat("v", asm), asm); } // SSE1 Instruction Templates: // // SSI - SSE1 instructions with XS prefix. // PSI - SSE1 instructions with TB prefix. // PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix. // VSSI - SSE1 instructions with XS prefix in AVX form. // VPSI - SSE1 instructions with TB prefix in AVX form. class SSI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XS, Requires<[HasSSE1]>; class SSIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, XS, Requires<[HasSSE1]>; class PSI o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, Requires<[HasSSE1]>; class PSIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TB, Requires<[HasSSE1]>; class VSSI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XS, VEX_4V, Requires<[HasAVX, HasSSE1]>; class VPSI o, Format F, dag outs, dag ins, string asm, list pattern> : I, VEX_4V, Requires<[HasAVX, HasSSE1]>; // SSE2 Instruction Templates: // // SDI - SSE2 instructions with XD prefix. // SDIi8 - SSE2 instructions with ImmT == Imm8 and XD prefix. // SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix. // PDI - SSE2 instructions with TB and OpSize prefixes. // PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes. // VSDI - SSE2 instructions with XD prefix in AVX form. // VPDI - SSE2 instructions with TB and OpSize prefixes in AVX form. class SDI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XD, Requires<[HasSSE2]>; class SDIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, XD, Requires<[HasSSE2]>; class SSDIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, XS, Requires<[HasSSE2]>; class PDI o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, OpSize, Requires<[HasSSE2]>; class PDIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TB, OpSize, Requires<[HasSSE2]>; class VSDI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XD, VEX_4V, Requires<[HasAVX, HasSSE2]>; class VPDI o, Format F, dag outs, dag ins, string asm, list pattern> : I, VEX_4V, OpSize, Requires<[HasAVX, HasSSE2]>; // SSE3 Instruction Templates: // // S3I - SSE3 instructions with TB and OpSize prefixes. // S3SI - SSE3 instructions with XS prefix. // S3DI - SSE3 instructions with XD prefix. class S3SI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XS, Requires<[HasSSE3]>; class S3DI o, Format F, dag outs, dag ins, string asm, list pattern> : I, XD, Requires<[HasSSE3]>; class S3I o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, OpSize, Requires<[HasSSE3]>; // SSSE3 Instruction Templates: // // SS38I - SSSE3 instructions with T8 prefix. // SS3AI - SSSE3 instructions with TA prefix. // // Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version // uses the MMX registers. We put those instructions here because they better // fit into the SSSE3 instruction category rather than the MMX category. class SS38I o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, T8, Requires<[HasSSSE3]>; class SS3AI o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TA, Requires<[HasSSSE3]>; // SSE4.1 Instruction Templates: // // SS48I - SSE 4.1 instructions with T8 prefix. // SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8. // class SS48I o, Format F, dag outs, dag ins, string asm, list pattern> : I, T8, Requires<[HasSSE41]>; class SS4AIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TA, Requires<[HasSSE41]>; // SSE4.2 Instruction Templates: // // SS428I - SSE 4.2 instructions with T8 prefix. class SS428I o, Format F, dag outs, dag ins, string asm, list pattern> : I, T8, Requires<[HasSSE42]>; // SS42FI - SSE 4.2 instructions with TF prefix. class SS42FI o, Format F, dag outs, dag ins, string asm, list pattern> : I, TF, Requires<[HasSSE42]>; // SS42AI = SSE 4.2 instructions with TA prefix class SS42AI o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TA, Requires<[HasSSE42]>; // AES Instruction Templates: // // AES8I // These use the same encoding as the SSE4.2 T8 and TA encodings. class AES8I o, Format F, dag outs, dag ins, string asm, listpattern> : I, T8, Requires<[HasAES]>; class AESAI o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TA, Requires<[HasAES]>; // X86-64 Instruction templates... // class RI o, Format F, dag outs, dag ins, string asm, list pattern> : I, REX_W; class RIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, REX_W; class RIi32 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii32, REX_W; class RIi64 o, Format f, dag outs, dag ins, string asm, list pattern> : X86Inst, REX_W { let Pattern = pattern; let CodeSize = 3; } class RSSI o, Format F, dag outs, dag ins, string asm, list pattern> : SSI, REX_W; class RSDI o, Format F, dag outs, dag ins, string asm, list pattern> : SDI, REX_W; class RPDI o, Format F, dag outs, dag ins, string asm, list pattern> : PDI, REX_W; // MMX Instruction templates // // MMXI - MMX instructions with TB prefix. // MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode. // MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes. // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix. // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix. // MMXID - MMX instructions with XD prefix. // MMXIS - MMX instructions with XS prefix. class MMXI o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, Requires<[HasMMX]>; class MMXI64 o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, Requires<[HasMMX,In64BitMode]>; class MMXRI o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, REX_W, Requires<[HasMMX]>; class MMX2I o, Format F, dag outs, dag ins, string asm, list pattern> : I, TB, OpSize, Requires<[HasMMX]>; class MMXIi8 o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, TB, Requires<[HasMMX]>; class MMXID o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, XD, Requires<[HasMMX]>; class MMXIS o, Format F, dag outs, dag ins, string asm, list pattern> : Ii8, XS, Requires<[HasMMX]>;