857399168bcf2a7231f01232fdcd4b86b9771165
[oota-llvm.git] / lib / Target / X86 / X86InstrFormats.td
1 //===-- X86InstrFormats.td - X86 Instruction Formats -------*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 // X86 Instruction Format Definitions.
12 //
13
14 // Format specifies the encoding used by the instruction.  This is part of the
15 // ad-hoc solution used to emit machine instruction encodings by our machine
16 // code emitter.
17 class Format<bits<6> val> {
18   bits<6> Value = val;
19 }
20
21 def Pseudo     : Format<0>; def RawFrm     : Format<1>;
22 def AddRegFrm  : Format<2>; def MRMDestReg : Format<3>;
23 def MRMDestMem : Format<4>; def MRMSrcReg  : Format<5>;
24 def MRMSrcMem  : Format<6>;
25 def MRM0r  : Format<16>; def MRM1r  : Format<17>; def MRM2r  : Format<18>;
26 def MRM3r  : Format<19>; def MRM4r  : Format<20>; def MRM5r  : Format<21>;
27 def MRM6r  : Format<22>; def MRM7r  : Format<23>;
28 def MRM0m  : Format<24>; def MRM1m  : Format<25>; def MRM2m  : Format<26>;
29 def MRM3m  : Format<27>; def MRM4m  : Format<28>; def MRM5m  : Format<29>;
30 def MRM6m  : Format<30>; def MRM7m  : Format<31>;
31 def MRM_C1 : Format<33>;
32 def MRM_C2 : Format<34>;
33 def MRM_C3 : Format<35>;
34 def MRM_C4 : Format<36>;
35 def MRM_C8 : Format<37>;
36 def MRM_C9 : Format<38>;
37 def MRM_CA : Format<39>;
38 def MRM_CB : Format<40>;
39 def MRM_E8 : Format<41>;
40 def MRM_F0 : Format<42>;
41 def RawFrmImm8 : Format<43>;
42 def RawFrmImm16 : Format<44>;
43 def MRM_F8 : Format<45>;
44 def MRM_F9 : Format<46>;
45 def MRM_D0 : Format<47>;
46 def MRM_D1 : Format<48>;
47 def MRM_D4 : Format<49>;
48 def MRM_D5 : Format<50>;
49 def MRM_D6 : Format<51>;
50 def MRM_D8 : Format<52>;
51 def MRM_D9 : Format<53>;
52 def MRM_DA : Format<54>;
53 def MRM_DB : Format<55>;
54 def MRM_DC : Format<56>;
55 def MRM_DD : Format<57>;
56 def MRM_DE : Format<58>;
57 def MRM_DF : Format<59>;
58
59 // ImmType - This specifies the immediate type used by an instruction. This is
60 // part of the ad-hoc solution used to emit machine instruction encodings by our
61 // machine code emitter.
62 class ImmType<bits<3> val> {
63   bits<3> Value = val;
64 }
65 def NoImm      : ImmType<0>;
66 def Imm8       : ImmType<1>;
67 def Imm8PCRel  : ImmType<2>;
68 def Imm16      : ImmType<3>;
69 def Imm16PCRel : ImmType<4>;
70 def Imm32      : ImmType<5>;
71 def Imm32PCRel : ImmType<6>;
72 def Imm64      : ImmType<7>;
73
74 // FPFormat - This specifies what form this FP instruction has.  This is used by
75 // the Floating-Point stackifier pass.
76 class FPFormat<bits<3> val> {
77   bits<3> Value = val;
78 }
79 def NotFP      : FPFormat<0>;
80 def ZeroArgFP  : FPFormat<1>;
81 def OneArgFP   : FPFormat<2>;
82 def OneArgFPRW : FPFormat<3>;
83 def TwoArgFP   : FPFormat<4>;
84 def CompareFP  : FPFormat<5>;
85 def CondMovFP  : FPFormat<6>;
86 def SpecialFP  : FPFormat<7>;
87
88 // Class specifying the SSE execution domain, used by the SSEDomainFix pass.
89 // Keep in sync with tables in X86InstrInfo.cpp.
90 class Domain<bits<2> val> {
91   bits<2> Value = val;
92 }
93 def GenericDomain   : Domain<0>;
94 def SSEPackedSingle : Domain<1>;
95 def SSEPackedDouble : Domain<2>;
96 def SSEPackedInt    : Domain<3>;
97
98 // Class specifying the vector form of the decompressed
99 // displacement of 8-bit.
100 class CD8VForm<bits<3> val> {
101   bits<3> Value = val;
102 }
103 def CD8VF  : CD8VForm<0>;  // v := VL
104 def CD8VH  : CD8VForm<1>;  // v := VL/2
105 def CD8VQ  : CD8VForm<2>;  // v := VL/4
106 def CD8VO  : CD8VForm<3>;  // v := VL/8
107 def CD8VT1 : CD8VForm<4>;  // v := 1
108 def CD8VT2 : CD8VForm<5>;  // v := 2
109 def CD8VT4 : CD8VForm<6>;  // v := 4
110 def CD8VT8 : CD8VForm<7>;  // v := 8
111
112 // Prefix byte classes which are used to indicate to the ad-hoc machine code
113 // emitter that various prefix bytes are required.
114 class OpSize { bit hasOpSizePrefix = 1; }
115 class AdSize { bit hasAdSizePrefix = 1; }
116 class REX_W  { bit hasREX_WPrefix = 1; }
117 class LOCK   { bit hasLockPrefix = 1; }
118 class SegFS  { bits<2> SegOvrBits = 1; }
119 class SegGS  { bits<2> SegOvrBits = 2; }
120 class TB     { bits<5> Prefix = 1; }
121 class REP    { bits<5> Prefix = 2; }
122 class D8     { bits<5> Prefix = 3; }
123 class D9     { bits<5> Prefix = 4; }
124 class DA     { bits<5> Prefix = 5; }
125 class DB     { bits<5> Prefix = 6; }
126 class DC     { bits<5> Prefix = 7; }
127 class DD     { bits<5> Prefix = 8; }
128 class DE     { bits<5> Prefix = 9; }
129 class DF     { bits<5> Prefix = 10; }
130 class XD     { bits<5> Prefix = 11; }
131 class XS     { bits<5> Prefix = 12; }
132 class T8     { bits<5> Prefix = 13; }
133 class TA     { bits<5> Prefix = 14; }
134 class A6     { bits<5> Prefix = 15; }
135 class A7     { bits<5> Prefix = 16; }
136 class T8XD   { bits<5> Prefix = 17; }
137 class T8XS   { bits<5> Prefix = 18; }
138 class TAXD   { bits<5> Prefix = 19; }
139 class XOP8   { bits<5> Prefix = 20; }
140 class XOP9   { bits<5> Prefix = 21; }
141 class XOPA   { bits<5> Prefix = 22; }
142 class VEX    { bit hasVEXPrefix = 1; }
143 class VEX_W  { bit hasVEX_WPrefix = 1; }
144 class VEX_4V : VEX { bit hasVEX_4VPrefix = 1; }
145 class VEX_4VOp3 : VEX { bit hasVEX_4VOp3Prefix = 1; }
146 class VEX_I8IMM { bit hasVEX_i8ImmReg = 1; }
147 class VEX_L  { bit hasVEX_L = 1; }
148 class VEX_LIG { bit ignoresVEX_L = 1; }
149 class EVEX : VEX { bit hasEVEXPrefix = 1; }
150 class EVEX_4V : VEX_4V { bit hasEVEXPrefix = 1; }
151 class EVEX_K { bit hasEVEX_K = 1; }
152 class EVEX_KZ : EVEX_K { bit hasEVEX_Z = 1; }
153 class EVEX_B { bit hasEVEX_B = 1; }
154 class EVEX_V512 { bit hasEVEX_L2 = 1; bit hasVEX_L = 0; }
155 class EVEX_CD8<int esize, CD8VForm form> {
156   bits<2> EVEX_CD8E = !if(!eq(esize, 8),  0b00,
157                       !if(!eq(esize, 16), 0b01,
158                       !if(!eq(esize, 32), 0b10,
159                       !if(!eq(esize, 64), 0b11, ?))));
160   bits<3> EVEX_CD8V = form.Value;
161 }
162 class Has3DNow0F0FOpcode  { bit has3DNow0F0FOpcode = 1; }
163 class MemOp4 { bit hasMemOp4Prefix = 1; }
164 class XOP { bit hasXOP_Prefix = 1; }
165 class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
166               string AsmStr,
167               InstrItinClass itin,
168               Domain d = GenericDomain>
169   : Instruction {
170   let Namespace = "X86";
171
172   bits<8> Opcode = opcod;
173   Format Form = f;
174   bits<6> FormBits = Form.Value;
175   ImmType ImmT = i;
176
177   dag OutOperandList = outs;
178   dag InOperandList = ins;
179   string AsmString = AsmStr;
180
181   // If this is a pseudo instruction, mark it isCodeGenOnly.
182   let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
183
184   let Itinerary = itin;
185
186   //
187   // Attributes specific to X86 instructions...
188   //
189   bit ForceDisassemble = 0; // Force instruction to disassemble even though it's
190                             // isCodeGenonly. Needed to hide an ambiguous
191                             // AsmString from the parser, but still disassemble.
192
193   bit hasOpSizePrefix = 0;  // Does this inst have a 0x66 prefix?
194   bit hasAdSizePrefix = 0;  // Does this inst have a 0x67 prefix?
195
196   bits<5> Prefix = 0;       // Which prefix byte does this inst have?
197   bit hasREX_WPrefix  = 0;  // Does this inst require the REX.W prefix?
198   FPFormat FPForm = NotFP;  // What flavor of FP instruction is this?
199   bit hasLockPrefix = 0;    // Does this inst have a 0xF0 prefix?
200   bits<2> SegOvrBits = 0;   // Segment override prefix.
201   Domain ExeDomain = d;
202   bit hasVEXPrefix = 0;     // Does this inst require a VEX prefix?
203   bit hasVEX_WPrefix = 0;   // Does this inst set the VEX_W field?
204   bit hasVEX_4VPrefix = 0;  // Does this inst require the VEX.VVVV field?
205   bit hasVEX_4VOp3Prefix = 0;  // Does this inst require the VEX.VVVV field to
206                                // encode the third operand?
207   bit hasVEX_i8ImmReg = 0;  // Does this inst require the last source register
208                             // to be encoded in a immediate field?
209   bit hasVEX_L = 0;         // Does this inst use large (256-bit) registers?
210   bit ignoresVEX_L = 0;     // Does this instruction ignore the L-bit
211   bit hasEVEXPrefix = 0;    // Does this inst require EVEX form?
212   bit hasEVEX_K = 0;        // Does this inst require masking?
213   bit hasEVEX_Z = 0;        // Does this inst set the EVEX_Z field?
214   bit hasEVEX_L2 = 0;       // Does this inst set the EVEX_L2 field?
215   bit hasEVEX_B = 0;        // Does this inst set the EVEX_B field?
216   bits<2> EVEX_CD8E = 0;    // Compressed disp8 form - element-size.
217   bits<3> EVEX_CD8V = 0;    // Compressed disp8 form - vector-width.
218   bit has3DNow0F0FOpcode =0;// Wacky 3dNow! encoding?
219   bit hasMemOp4Prefix = 0;  // Same bit as VEX_W, but used for swapping operands
220   bit hasXOP_Prefix = 0;    // Does this inst require an XOP prefix?
221
222   // TSFlags layout should be kept in sync with X86InstrInfo.h.
223   let TSFlags{5-0}   = FormBits;
224   let TSFlags{6}     = hasOpSizePrefix;
225   let TSFlags{7}     = hasAdSizePrefix;
226   let TSFlags{12-8}  = Prefix;
227   let TSFlags{13}    = hasREX_WPrefix;
228   let TSFlags{16-14} = ImmT.Value;
229   let TSFlags{19-17} = FPForm.Value;
230   let TSFlags{20}    = hasLockPrefix;
231   let TSFlags{22-21} = SegOvrBits;
232   let TSFlags{24-23} = ExeDomain.Value;
233   let TSFlags{32-25} = Opcode;
234   let TSFlags{33}    = hasVEXPrefix;
235   let TSFlags{34}    = hasVEX_WPrefix;
236   let TSFlags{35}    = hasVEX_4VPrefix;
237   let TSFlags{36}    = hasVEX_4VOp3Prefix;
238   let TSFlags{37}    = hasVEX_i8ImmReg;
239   let TSFlags{38}    = hasVEX_L;
240   let TSFlags{39}    = ignoresVEX_L;
241   let TSFlags{40}    = hasEVEXPrefix;
242   let TSFlags{41}    = hasEVEX_K;
243   let TSFlags{42}    = hasEVEX_Z;
244   let TSFlags{43}    = hasEVEX_L2;
245   let TSFlags{44}    = hasEVEX_B;
246   let TSFlags{46-45} = EVEX_CD8E;
247   let TSFlags{49-47} = EVEX_CD8V;
248   let TSFlags{50}    = has3DNow0F0FOpcode;
249   let TSFlags{51}    = hasMemOp4Prefix;
250   let TSFlags{52}    = hasXOP_Prefix;
251 }
252
253 class PseudoI<dag oops, dag iops, list<dag> pattern>
254   : X86Inst<0, Pseudo, NoImm, oops, iops, "", NoItinerary> {
255   let Pattern = pattern;
256 }
257
258 class I<bits<8> o, Format f, dag outs, dag ins, string asm,
259         list<dag> pattern, InstrItinClass itin = NoItinerary,
260         Domain d = GenericDomain>
261   : X86Inst<o, f, NoImm, outs, ins, asm, itin, d> {
262   let Pattern = pattern;
263   let CodeSize = 3;
264 }
265 class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm, 
266            list<dag> pattern, InstrItinClass itin = NoItinerary,
267            Domain d = GenericDomain>
268   : X86Inst<o, f, Imm8, outs, ins, asm, itin, d> {
269   let Pattern = pattern;
270   let CodeSize = 3;
271 }
272 class Ii8PCRel<bits<8> o, Format f, dag outs, dag ins, string asm, 
273                list<dag> pattern, InstrItinClass itin = NoItinerary>
274   : X86Inst<o, f, Imm8PCRel, outs, ins, asm, itin> {
275   let Pattern = pattern;
276   let CodeSize = 3;
277 }
278 class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm, 
279            list<dag> pattern, InstrItinClass itin = NoItinerary>
280   : X86Inst<o, f, Imm16, outs, ins, asm, itin> {
281   let Pattern = pattern;
282   let CodeSize = 3;
283 }
284 class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm, 
285            list<dag> pattern, InstrItinClass itin = NoItinerary>
286   : X86Inst<o, f, Imm32, outs, ins, asm, itin> {
287   let Pattern = pattern;
288   let CodeSize = 3;
289 }
290
291 class Ii16PCRel<bits<8> o, Format f, dag outs, dag ins, string asm, 
292            list<dag> pattern, InstrItinClass itin = NoItinerary>
293            : X86Inst<o, f, Imm16PCRel, outs, ins, asm, itin> {
294   let Pattern = pattern;
295   let CodeSize = 3;
296 }
297
298 class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm, 
299            list<dag> pattern, InstrItinClass itin = NoItinerary>
300   : X86Inst<o, f, Imm32PCRel, outs, ins, asm, itin> {
301   let Pattern = pattern;
302   let CodeSize = 3;
303 }
304
305 // FPStack Instruction Templates:
306 // FPI - Floating Point Instruction template.
307 class FPI<bits<8> o, Format F, dag outs, dag ins, string asm,
308           InstrItinClass itin = NoItinerary>
309   : I<o, F, outs, ins, asm, [], itin> {}
310
311 // FpI_ - Floating Point Pseudo Instruction template. Not Predicated.
312 class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern,
313            InstrItinClass itin = NoItinerary>
314   : X86Inst<0, Pseudo, NoImm, outs, ins, "", itin> {
315   let FPForm = fp;
316   let Pattern = pattern;
317 }
318
319 // Templates for instructions that use a 16- or 32-bit segmented address as
320 //  their only operand: lcall (FAR CALL) and ljmp (FAR JMP)
321 //
322 //   Iseg16 - 16-bit segment selector, 16-bit offset
323 //   Iseg32 - 16-bit segment selector, 32-bit offset
324
325 class Iseg16 <bits<8> o, Format f, dag outs, dag ins, string asm, 
326               list<dag> pattern, InstrItinClass itin = NoItinerary>
327       : X86Inst<o, f, Imm16, outs, ins, asm, itin> {
328   let Pattern = pattern;
329   let CodeSize = 3;
330 }
331
332 class Iseg32 <bits<8> o, Format f, dag outs, dag ins, string asm, 
333               list<dag> pattern, InstrItinClass itin = NoItinerary>
334       : X86Inst<o, f, Imm32, outs, ins, asm, itin> {
335   let Pattern = pattern;
336   let CodeSize = 3;
337 }
338
339 def __xs : XS;
340 def __xd : XD;
341
342 // SI - SSE 1 & 2 scalar instructions
343 class SI<bits<8> o, Format F, dag outs, dag ins, string asm,
344          list<dag> pattern, InstrItinClass itin = NoItinerary>
345       : I<o, F, outs, ins, asm, pattern, itin> {
346   let Predicates = !if(hasEVEXPrefix /* EVEX */, [HasAVX512],
347                    !if(hasVEXPrefix /* VEX */, [UseAVX],
348                    !if(!eq(Prefix, __xs.Prefix), [UseSSE1],
349                    !if(!eq(Prefix, __xd.Prefix), [UseSSE2],
350                    !if(hasOpSizePrefix, [UseSSE2], [UseSSE1])))));
351
352   // AVX instructions have a 'v' prefix in the mnemonic
353   let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
354 }
355
356 // SIi8 - SSE 1 & 2 scalar instructions
357 class SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
358            list<dag> pattern, InstrItinClass itin = NoItinerary>
359       : Ii8<o, F, outs, ins, asm, pattern, itin> {
360   let Predicates = !if(hasEVEXPrefix /* EVEX */, [HasAVX512],
361                    !if(hasVEXPrefix /* VEX */, [UseAVX],
362                    !if(!eq(Prefix, __xs.Prefix), [UseSSE1], [UseSSE2])));
363
364   // AVX instructions have a 'v' prefix in the mnemonic
365   let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
366 }
367
368 // PI - SSE 1 & 2 packed instructions
369 class PI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern,
370          InstrItinClass itin, Domain d>
371       : I<o, F, outs, ins, asm, pattern, itin, d> {
372   let Predicates = !if(hasEVEXPrefix /* EVEX */, [HasAVX512],
373                    !if(hasVEXPrefix /* VEX */, [HasAVX],
374                    !if(hasOpSizePrefix /* OpSize */, [UseSSE2], [UseSSE1])));
375
376   // AVX instructions have a 'v' prefix in the mnemonic
377   let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
378 }
379
380 // MMXPI - SSE 1 & 2 packed instructions with MMX operands
381 class MMXPI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern,
382             InstrItinClass itin, Domain d>
383       : I<o, F, outs, ins, asm, pattern, itin, d> {
384   let Predicates = !if(hasOpSizePrefix /* OpSize */, [HasSSE2], [HasSSE1]);
385 }
386
387 // PIi8 - SSE 1 & 2 packed instructions with immediate
388 class PIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
389            list<dag> pattern, InstrItinClass itin, Domain d>
390       : Ii8<o, F, outs, ins, asm, pattern, itin, d> {
391   let Predicates = !if(hasEVEXPrefix /* EVEX */, [HasAVX512],
392                    !if(hasVEXPrefix /* VEX */, [HasAVX],
393                    !if(hasOpSizePrefix /* OpSize */, [UseSSE2], [UseSSE1])));
394
395   // AVX instructions have a 'v' prefix in the mnemonic
396   let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
397 }
398
399 // SSE1 Instruction Templates:
400 // 
401 //   SSI   - SSE1 instructions with XS prefix.
402 //   PSI   - SSE1 instructions with TB prefix.
403 //   PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
404 //   VSSI  - SSE1 instructions with XS prefix in AVX form.
405 //   VPSI  - SSE1 instructions with TB prefix in AVX form, packed single.
406
407 class SSI<bits<8> o, Format F, dag outs, dag ins, string asm,
408           list<dag> pattern, InstrItinClass itin = NoItinerary>
409       : I<o, F, outs, ins, asm, pattern, itin>, XS, Requires<[UseSSE1]>;
410 class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
411             list<dag> pattern, InstrItinClass itin = NoItinerary>
412       : Ii8<o, F, outs, ins, asm, pattern, itin>, XS, Requires<[UseSSE1]>;
413 class PSI<bits<8> o, Format F, dag outs, dag ins, string asm,
414           list<dag> pattern, InstrItinClass itin = NoItinerary>
415       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedSingle>, TB,
416         Requires<[UseSSE1]>;
417 class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
418             list<dag> pattern, InstrItinClass itin = NoItinerary>
419       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedSingle>, TB,
420         Requires<[UseSSE1]>;
421 class VSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
422            list<dag> pattern, InstrItinClass itin = NoItinerary>
423       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin>, XS,
424         Requires<[HasAVX]>;
425 class VPSI<bits<8> o, Format F, dag outs, dag ins, string asm,
426            list<dag> pattern, InstrItinClass itin = NoItinerary>
427       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin, SSEPackedSingle>, TB,
428         Requires<[HasAVX]>;
429
430 // SSE2 Instruction Templates:
431 // 
432 //   SDI    - SSE2 instructions with XD prefix.
433 //   SDIi8  - SSE2 instructions with ImmT == Imm8 and XD prefix.
434 //   S2SI   - SSE2 instructions with XS prefix.
435 //   SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
436 //   PDI    - SSE2 instructions with TB and OpSize prefixes, packed double domain.
437 //   PDIi8  - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
438 //   VSDI   - SSE2 scalar instructions with XD prefix in AVX form.
439 //   VPDI   - SSE2 vector instructions with TB and OpSize prefixes in AVX form,
440 //                 packed double domain.
441 //   VS2I   - SSE2 scalar instructions with TB and OpSize prefixes in AVX form.
442 //   S2I    - SSE2 scalar instructions with TB and OpSize prefixes.
443 //   MMXSDIi8  - SSE2 instructions with ImmT == Imm8 and XD prefix as well as
444 //               MMX operands.
445 //   MMXSSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix as well as
446 //               MMX operands.
447
448 class SDI<bits<8> o, Format F, dag outs, dag ins, string asm,
449           list<dag> pattern, InstrItinClass itin = NoItinerary>
450       : I<o, F, outs, ins, asm, pattern, itin>, XD, Requires<[UseSSE2]>;
451 class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
452             list<dag> pattern, InstrItinClass itin = NoItinerary>
453       : Ii8<o, F, outs, ins, asm, pattern, itin>, XD, Requires<[UseSSE2]>;
454 class S2SI<bits<8> o, Format F, dag outs, dag ins, string asm,
455            list<dag> pattern, InstrItinClass itin = NoItinerary>
456       : I<o, F, outs, ins, asm, pattern, itin>, XS, Requires<[UseSSE2]>;
457 class S2SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
458              list<dag> pattern, InstrItinClass itin = NoItinerary>
459       : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[UseSSE2]>;
460 class PDI<bits<8> o, Format F, dag outs, dag ins, string asm,
461           list<dag> pattern, InstrItinClass itin = NoItinerary>
462       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>, TB, OpSize,
463         Requires<[UseSSE2]>;
464 class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
465             list<dag> pattern, InstrItinClass itin = NoItinerary>
466       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>, TB, OpSize,
467         Requires<[UseSSE2]>;
468 class VSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
469            list<dag> pattern, InstrItinClass itin = NoItinerary>
470       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin>, XD,
471         Requires<[UseAVX]>;
472 class VS2SI<bits<8> o, Format F, dag outs, dag ins, string asm,
473             list<dag> pattern, InstrItinClass itin = NoItinerary>
474       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin>, XS,
475         Requires<[HasAVX]>;
476 class VPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
477            list<dag> pattern, InstrItinClass itin = NoItinerary>
478       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin, SSEPackedDouble>, TB,
479         OpSize, Requires<[HasAVX]>;
480 class VS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
481            list<dag> pattern, InstrItinClass itin = NoItinerary>
482       : I<o, F, outs, ins, !strconcat("v", asm), pattern, itin>, TB,
483         OpSize, Requires<[UseAVX]>;
484 class S2I<bits<8> o, Format F, dag outs, dag ins, string asm,
485            list<dag> pattern, InstrItinClass itin = NoItinerary>
486       : I<o, F, outs, ins, asm, pattern, itin>, TB,
487         OpSize, Requires<[UseSSE2]>;
488 class MMXSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
489                list<dag> pattern, InstrItinClass itin = NoItinerary>
490       : Ii8<o, F, outs, ins, asm, pattern, itin>, XD, Requires<[HasSSE2]>;
491 class MMXS2SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
492                 list<dag> pattern, InstrItinClass itin = NoItinerary>
493       : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE2]>;
494
495 // SSE3 Instruction Templates:
496 // 
497 //   S3I   - SSE3 instructions with TB and OpSize prefixes.
498 //   S3SI  - SSE3 instructions with XS prefix.
499 //   S3DI  - SSE3 instructions with XD prefix.
500
501 class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, 
502            list<dag> pattern, InstrItinClass itin = NoItinerary>
503       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedSingle>, XS,
504         Requires<[UseSSE3]>;
505 class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, 
506            list<dag> pattern, InstrItinClass itin = NoItinerary>
507       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>, XD,
508         Requires<[UseSSE3]>;
509 class S3I<bits<8> o, Format F, dag outs, dag ins, string asm,
510           list<dag> pattern, InstrItinClass itin = NoItinerary>
511       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>, TB, OpSize,
512         Requires<[UseSSE3]>;
513
514
515 // SSSE3 Instruction Templates:
516 // 
517 //   SS38I - SSSE3 instructions with T8 prefix.
518 //   SS3AI - SSSE3 instructions with TA prefix.
519 //   MMXSS38I - SSSE3 instructions with T8 prefix and MMX operands.
520 //   MMXSS3AI - SSSE3 instructions with TA prefix and MMX operands.
521 //
522 // Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
523 // uses the MMX registers. The 64-bit versions are grouped with the MMX
524 // classes. They need to be enabled even if AVX is enabled.
525
526 class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
527             list<dag> pattern, InstrItinClass itin = NoItinerary>
528       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8,
529         Requires<[UseSSSE3]>;
530 class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
531             list<dag> pattern, InstrItinClass itin = NoItinerary>
532       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
533         Requires<[UseSSSE3]>;
534 class MMXSS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
535                list<dag> pattern, InstrItinClass itin = NoItinerary>
536       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8,
537         Requires<[HasSSSE3]>;
538 class MMXSS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
539                list<dag> pattern, InstrItinClass itin = NoItinerary>
540       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
541         Requires<[HasSSSE3]>;
542
543 // SSE4.1 Instruction Templates:
544 // 
545 //   SS48I - SSE 4.1 instructions with T8 prefix.
546 //   SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
547 //
548 class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
549             list<dag> pattern, InstrItinClass itin = NoItinerary>
550       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8,
551         Requires<[UseSSE41]>;
552 class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
553             list<dag> pattern, InstrItinClass itin = NoItinerary>
554       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
555         Requires<[UseSSE41]>;
556
557 // SSE4.2 Instruction Templates:
558 // 
559 //   SS428I - SSE 4.2 instructions with T8 prefix.
560 class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
561              list<dag> pattern, InstrItinClass itin = NoItinerary>
562       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8,
563         Requires<[UseSSE42]>;
564
565 //   SS42FI - SSE 4.2 instructions with T8XD prefix.
566 // NOTE: 'HasSSE42' is used as SS42FI is only used for CRC32 insns.
567 class SS42FI<bits<8> o, Format F, dag outs, dag ins, string asm,
568              list<dag> pattern, InstrItinClass itin = NoItinerary>
569       : I<o, F, outs, ins, asm, pattern, itin>, T8XD, Requires<[HasSSE42]>;
570
571 //   SS42AI = SSE 4.2 instructions with TA prefix
572 class SS42AI<bits<8> o, Format F, dag outs, dag ins, string asm,
573              list<dag> pattern, InstrItinClass itin = NoItinerary>
574       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
575         Requires<[UseSSE42]>;
576
577 // AVX Instruction Templates:
578 //   Instructions introduced in AVX (no SSE equivalent forms)
579 //
580 //   AVX8I - AVX instructions with T8 and OpSize prefix.
581 //   AVXAIi8 - AVX instructions with TA, OpSize prefix and ImmT = Imm8.
582 class AVX8I<bits<8> o, Format F, dag outs, dag ins, string asm,
583             list<dag> pattern, InstrItinClass itin = NoItinerary>
584       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8, OpSize,
585         Requires<[HasAVX]>;
586 class AVXAIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
587               list<dag> pattern, InstrItinClass itin = NoItinerary>
588       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA, OpSize,
589         Requires<[HasAVX]>;
590
591 // AVX2 Instruction Templates:
592 //   Instructions introduced in AVX2 (no SSE equivalent forms)
593 //
594 //   AVX28I - AVX2 instructions with T8 and OpSize prefix.
595 //   AVX2AIi8 - AVX2 instructions with TA, OpSize prefix and ImmT = Imm8.
596 class AVX28I<bits<8> o, Format F, dag outs, dag ins, string asm,
597             list<dag> pattern, InstrItinClass itin = NoItinerary>
598       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8, OpSize,
599         Requires<[HasAVX2]>;
600 class AVX2AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
601               list<dag> pattern, InstrItinClass itin = NoItinerary>
602       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA, OpSize,
603         Requires<[HasAVX2]>;
604
605
606 // AVX-512 Instruction Templates:
607 //   Instructions introduced in AVX-512 (no SSE equivalent forms)
608 //
609 //   AVX5128I - AVX-512 instructions with T8 and OpSize prefix.
610 //   AVX512AIi8 - AVX-512 instructions with TA, OpSize prefix and ImmT = Imm8.
611 //   AVX512PDI  - AVX-512 instructions with TB, OpSize, double packed.
612 //   AVX512PSI  - AVX-512 instructions with TB, single packed.
613 //   AVX512XS8I - AVX-512 instructions with T8 and XS prefixes.
614 //   AVX512XSI  - AVX-512 instructions with XS prefix, generic domain.
615 //   AVX512BI   - AVX-512 instructions with TB, OpSize, int packed domain.
616 //   AVX512SI   - AVX-512 scalar instructions with TB and OpSize prefixes.
617
618 class AVX5128I<bits<8> o, Format F, dag outs, dag ins, string asm,
619             list<dag> pattern, InstrItinClass itin = NoItinerary>
620       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8, OpSize,
621         Requires<[HasAVX512]>;
622 class AVX512XS8I<bits<8> o, Format F, dag outs, dag ins, string asm,
623             list<dag> pattern, InstrItinClass itin = NoItinerary>
624       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8XS,
625         Requires<[HasAVX512]>;
626 class AVX512XSI<bits<8> o, Format F, dag outs, dag ins, string asm,
627             list<dag> pattern, InstrItinClass itin = NoItinerary>
628       : I<o, F, outs, ins, asm, pattern, itin>, XS,
629         Requires<[HasAVX512]>;
630 class AVX512XDI<bits<8> o, Format F, dag outs, dag ins, string asm,
631             list<dag> pattern, InstrItinClass itin = NoItinerary>
632       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, XD,
633         Requires<[HasAVX512]>;
634 class AVX512BI<bits<8> o, Format F, dag outs, dag ins, string asm,
635             list<dag> pattern, InstrItinClass itin = NoItinerary>
636       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TB, OpSize,
637         Requires<[HasAVX512]>;
638 class AVX512BIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
639               list<dag> pattern, InstrItinClass itin = NoItinerary>
640       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TB, OpSize,
641         Requires<[HasAVX512]>;
642 class AVX512SI<bits<8> o, Format F, dag outs, dag ins, string asm,
643             list<dag> pattern, InstrItinClass itin = NoItinerary>
644       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TB, OpSize,
645         Requires<[HasAVX512]>;
646 class AVX512AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
647               list<dag> pattern, InstrItinClass itin = NoItinerary>
648       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA, OpSize,
649         Requires<[HasAVX512]>;
650 class AVX512Ii8<bits<8> o, Format F, dag outs, dag ins, string asm,
651               list<dag> pattern, InstrItinClass itin = NoItinerary>
652       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TB,
653       Requires<[HasAVX512]>;
654 class AVX512PDI<bits<8> o, Format F, dag outs, dag ins, string asm,
655            list<dag> pattern, InstrItinClass itin = NoItinerary>
656       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>, TB,
657         OpSize, Requires<[HasAVX512]>;
658 class AVX512PSI<bits<8> o, Format F, dag outs, dag ins, string asm,
659            list<dag> pattern, InstrItinClass itin = NoItinerary>
660       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedSingle>, TB,
661         Requires<[HasAVX512]>;
662 class AVX512PIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
663               list<dag> pattern, Domain d, InstrItinClass itin = NoItinerary>
664       : Ii8<o, F, outs, ins, asm, pattern, itin, d>, TB, Requires<[HasAVX512]>;
665 class AVX512PI<bits<8> o, Format F, dag outs, dag ins, string asm,
666               list<dag> pattern, Domain d, InstrItinClass itin = NoItinerary>
667       : I<o, F, outs, ins, asm, pattern, itin, d>, TB, Requires<[HasAVX512]>;
668 class AVX512FMA3<bits<8> o, Format F, dag outs, dag ins, string asm,
669            list<dag>pattern, InstrItinClass itin = NoItinerary>
670       : I<o, F, outs, ins, asm, pattern, itin>, T8,
671         OpSize, EVEX_4V, Requires<[HasAVX512]>;
672
673 // AES Instruction Templates:
674 //
675 // AES8I
676 // These use the same encoding as the SSE4.2 T8 and TA encodings.
677 class AES8I<bits<8> o, Format F, dag outs, dag ins, string asm,
678             list<dag>pattern, InstrItinClass itin = IIC_AES>
679       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, T8,
680         Requires<[HasAES]>;
681
682 class AESAI<bits<8> o, Format F, dag outs, dag ins, string asm,
683             list<dag> pattern, InstrItinClass itin = NoItinerary>
684       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
685         Requires<[HasAES]>;
686
687 // PCLMUL Instruction Templates
688 class PCLMULIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
689                list<dag>pattern, InstrItinClass itin = NoItinerary>
690       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
691         OpSize, Requires<[HasPCLMUL]>;
692
693 class AVXPCLMULIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
694                   list<dag>pattern, InstrItinClass itin = NoItinerary>
695       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
696         OpSize, VEX_4V, Requires<[HasAVX, HasPCLMUL]>;
697
698 // FMA3 Instruction Templates
699 class FMA3<bits<8> o, Format F, dag outs, dag ins, string asm,
700            list<dag>pattern, InstrItinClass itin = NoItinerary>
701       : I<o, F, outs, ins, asm, pattern, itin>, T8,
702         OpSize, VEX_4V, FMASC, Requires<[HasFMA]>;
703
704 // FMA4 Instruction Templates
705 class FMA4<bits<8> o, Format F, dag outs, dag ins, string asm,
706            list<dag>pattern, InstrItinClass itin = NoItinerary>
707       : Ii8<o, F, outs, ins, asm, pattern, itin>, TA,
708         OpSize, VEX_4V, VEX_I8IMM, FMASC, Requires<[HasFMA4]>;
709
710 // XOP 2, 3 and 4 Operand Instruction Template
711 class IXOP<bits<8> o, Format F, dag outs, dag ins, string asm,
712            list<dag> pattern, InstrItinClass itin = NoItinerary>
713       : I<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>,
714          XOP, XOP9, Requires<[HasXOP]>;
715
716 // XOP 2, 3 and 4 Operand Instruction Templates with imm byte
717 class IXOPi8<bits<8> o, Format F, dag outs, dag ins, string asm,
718            list<dag> pattern, InstrItinClass itin = NoItinerary>
719       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedDouble>,
720          XOP, XOP8, Requires<[HasXOP]>;
721
722 //  XOP 5 operand instruction (VEX encoding!)
723 class IXOP5<bits<8> o, Format F, dag outs, dag ins, string asm,
724            list<dag>pattern, InstrItinClass itin = NoItinerary>
725       : Ii8<o, F, outs, ins, asm, pattern, itin, SSEPackedInt>, TA,
726         OpSize, VEX_4V, VEX_I8IMM, Requires<[HasXOP]>;
727
728 // X86-64 Instruction templates...
729 //
730
731 class RI<bits<8> o, Format F, dag outs, dag ins, string asm,
732          list<dag> pattern, InstrItinClass itin = NoItinerary>
733       : I<o, F, outs, ins, asm, pattern, itin>, REX_W;
734 class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
735             list<dag> pattern, InstrItinClass itin = NoItinerary>
736       : Ii8<o, F, outs, ins, asm, pattern, itin>, REX_W;
737 class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
738              list<dag> pattern, InstrItinClass itin = NoItinerary>
739       : Ii32<o, F, outs, ins, asm, pattern, itin>, REX_W;
740
741 class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
742             list<dag> pattern, InstrItinClass itin = NoItinerary>
743   : X86Inst<o, f, Imm64, outs, ins, asm, itin>, REX_W {
744   let Pattern = pattern;
745   let CodeSize = 3;
746 }
747
748 class RIi64_NOREX<bits<8> o, Format f, dag outs, dag ins, string asm,
749             list<dag> pattern, InstrItinClass itin = NoItinerary>
750   : X86Inst<o, f, Imm64, outs, ins, asm, itin> {
751   let Pattern = pattern;
752   let CodeSize = 3;
753 }
754
755 class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
756            list<dag> pattern, InstrItinClass itin = NoItinerary>
757       : SSI<o, F, outs, ins, asm, pattern, itin>, REX_W;
758 class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
759            list<dag> pattern, InstrItinClass itin = NoItinerary>
760       : SDI<o, F, outs, ins, asm, pattern, itin>, REX_W;
761 class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
762            list<dag> pattern, InstrItinClass itin = NoItinerary>
763       : PDI<o, F, outs, ins, asm, pattern, itin>, REX_W;
764 class VRPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
765            list<dag> pattern, InstrItinClass itin = NoItinerary>
766       : VPDI<o, F, outs, ins, asm, pattern, itin>, VEX_W;
767 class RS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
768            list<dag> pattern, InstrItinClass itin = NoItinerary>
769       : S2I<o, F, outs, ins, asm, pattern, itin>, REX_W;
770 class VRS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
771            list<dag> pattern, InstrItinClass itin = NoItinerary>
772       : VS2I<o, F, outs, ins, asm, pattern, itin>, VEX_W;
773
774 // MMX Instruction templates
775 //
776
777 // MMXI   - MMX instructions with TB prefix.
778 // MMXI32 - MMX instructions with TB prefix valid only in 32 bit mode.
779 // MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
780 // MMX2I  - MMX / SSE2 instructions with TB and OpSize prefixes.
781 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
782 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
783 // MMXID  - MMX instructions with XD prefix.
784 // MMXIS  - MMX instructions with XS prefix.
785 class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm, 
786            list<dag> pattern, InstrItinClass itin = NoItinerary>
787       : I<o, F, outs, ins, asm, pattern, itin>, TB, Requires<[HasMMX]>;
788 class MMXI32<bits<8> o, Format F, dag outs, dag ins, string asm, 
789              list<dag> pattern, InstrItinClass itin = NoItinerary>
790       : I<o, F, outs, ins, asm, pattern, itin>, TB, Requires<[HasMMX,Not64BitMode]>;
791 class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm, 
792              list<dag> pattern, InstrItinClass itin = NoItinerary>
793       : I<o, F, outs, ins, asm, pattern, itin>, TB, Requires<[HasMMX,In64BitMode]>;
794 class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm, 
795             list<dag> pattern, InstrItinClass itin = NoItinerary>
796       : I<o, F, outs, ins, asm, pattern, itin>, TB, REX_W, Requires<[HasMMX]>;
797 class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm, 
798             list<dag> pattern, InstrItinClass itin = NoItinerary>
799       : I<o, F, outs, ins, asm, pattern, itin>, TB, OpSize, Requires<[HasMMX]>;
800 class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm, 
801              list<dag> pattern, InstrItinClass itin = NoItinerary>
802       : Ii8<o, F, outs, ins, asm, pattern, itin>, TB, Requires<[HasMMX]>;
803 class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm, 
804             list<dag> pattern, InstrItinClass itin = NoItinerary>
805       : Ii8<o, F, outs, ins, asm, pattern, itin>, XD, Requires<[HasMMX]>;
806 class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm, 
807             list<dag> pattern, InstrItinClass itin = NoItinerary>
808       : Ii8<o, F, outs, ins, asm, pattern, itin>, XS, Requires<[HasMMX]>;