1 //===- X86InstrFormats.td - X86 Instruction Formats --------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
11 // X86 Instruction Format Definitions.
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
17 class Format<bits<6> val> {
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 MRMInitReg : Format<32>;
32 def MRM_C1 : Format<33>;
33 def MRM_C2 : Format<34>;
34 def MRM_C3 : Format<35>;
35 def MRM_C4 : Format<36>;
36 def MRM_C8 : Format<37>;
37 def MRM_C9 : Format<38>;
38 def MRM_E8 : Format<39>;
39 def MRM_F0 : Format<40>;
40 def MRM_F8 : Format<41>;
41 def MRM_F9 : Format<42>;
43 // ImmType - This specifies the immediate type used by an instruction. This is
44 // part of the ad-hoc solution used to emit machine instruction encodings by our
45 // machine code emitter.
46 class ImmType<bits<3> val> {
49 def NoImm : ImmType<0>;
50 def Imm8 : ImmType<1>;
51 def Imm8PCRel : ImmType<2>;
52 def Imm16 : ImmType<3>;
53 def Imm16PCRel : ImmType<4>;
54 def Imm32 : ImmType<5>;
55 def Imm32PCRel : ImmType<6>;
56 def Imm64 : ImmType<7>;
58 // FPFormat - This specifies what form this FP instruction has. This is used by
59 // the Floating-Point stackifier pass.
60 class FPFormat<bits<3> val> {
63 def NotFP : FPFormat<0>;
64 def ZeroArgFP : FPFormat<1>;
65 def OneArgFP : FPFormat<2>;
66 def OneArgFPRW : FPFormat<3>;
67 def TwoArgFP : FPFormat<4>;
68 def CompareFP : FPFormat<5>;
69 def CondMovFP : FPFormat<6>;
70 def SpecialFP : FPFormat<7>;
72 // Class specifying the SSE execution domain, used by the SSEDomainFix pass.
73 // Keep in sync with tables in X86InstrInfo.cpp.
74 class Domain<bits<2> val> {
77 def GenericDomain : Domain<0>;
78 def SSEPackedSingle : Domain<1>;
79 def SSEPackedDouble : Domain<2>;
80 def SSEPackedInt : Domain<3>;
82 // Prefix byte classes which are used to indicate to the ad-hoc machine code
83 // emitter that various prefix bytes are required.
84 class OpSize { bit hasOpSizePrefix = 1; }
85 class AdSize { bit hasAdSizePrefix = 1; }
86 class REX_W { bit hasREX_WPrefix = 1; }
87 class LOCK { bit hasLockPrefix = 1; }
88 class SegFS { bits<2> SegOvrBits = 1; }
89 class SegGS { bits<2> SegOvrBits = 2; }
90 class TB { bits<4> Prefix = 1; }
91 class REP { bits<4> Prefix = 2; }
92 class D8 { bits<4> Prefix = 3; }
93 class D9 { bits<4> Prefix = 4; }
94 class DA { bits<4> Prefix = 5; }
95 class DB { bits<4> Prefix = 6; }
96 class DC { bits<4> Prefix = 7; }
97 class DD { bits<4> Prefix = 8; }
98 class DE { bits<4> Prefix = 9; }
99 class DF { bits<4> Prefix = 10; }
100 class XD { bits<4> Prefix = 11; }
101 class XS { bits<4> Prefix = 12; }
102 class T8 { bits<4> Prefix = 13; }
103 class TA { bits<4> Prefix = 14; }
104 class TF { bits<4> Prefix = 15; }
105 class VEX { bit hasVEXPrefix = 1; }
106 class VEX_W { bit hasVEX_WPrefix = 1; }
107 class VEX_4V : VEX { bit hasVEX_4VPrefix = 1; }
108 class VEX_I8IMM { bit hasVEX_i8ImmReg = 1; }
110 class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
111 string AsmStr, Domain d = GenericDomain>
113 let Namespace = "X86";
115 bits<8> Opcode = opcod;
117 bits<6> FormBits = Form.Value;
120 dag OutOperandList = outs;
121 dag InOperandList = ins;
122 string AsmString = AsmStr;
125 // Attributes specific to X86 instructions...
127 bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
128 bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix?
130 bits<4> Prefix = 0; // Which prefix byte does this inst have?
131 bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix?
132 FPFormat FPForm = NotFP; // What flavor of FP instruction is this?
133 bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix?
134 bits<2> SegOvrBits = 0; // Segment override prefix.
135 Domain ExeDomain = d;
136 bit hasVEXPrefix = 0; // Does this inst requires a VEX prefix?
137 bit hasVEX_WPrefix = 0; // Does this inst set the VEX_W field?
138 bit hasVEX_4VPrefix = 0; // Does this inst requires the VEX.VVVV field?
139 bit hasVEX_i8ImmReg = 0; // Does this inst requires the last source register
140 // to be encoded in a immediate field?
142 // TSFlags layout should be kept in sync with X86InstrInfo.h.
143 let TSFlags{5-0} = FormBits;
144 let TSFlags{6} = hasOpSizePrefix;
145 let TSFlags{7} = hasAdSizePrefix;
146 let TSFlags{11-8} = Prefix;
147 let TSFlags{12} = hasREX_WPrefix;
148 let TSFlags{15-13} = ImmT.Value;
149 let TSFlags{18-16} = FPForm.Value;
150 let TSFlags{19} = hasLockPrefix;
151 let TSFlags{21-20} = SegOvrBits;
152 let TSFlags{23-22} = ExeDomain.Value;
153 let TSFlags{31-24} = Opcode;
154 let TSFlags{32} = hasVEXPrefix;
155 let TSFlags{33} = hasVEX_WPrefix;
156 let TSFlags{34} = hasVEX_4VPrefix;
157 let TSFlags{35} = hasVEX_i8ImmReg;
160 class I<bits<8> o, Format f, dag outs, dag ins, string asm,
161 list<dag> pattern, Domain d = GenericDomain>
162 : X86Inst<o, f, NoImm, outs, ins, asm, d> {
163 let Pattern = pattern;
166 class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm,
167 list<dag> pattern, Domain d = GenericDomain>
168 : X86Inst<o, f, Imm8, outs, ins, asm, d> {
169 let Pattern = pattern;
172 class Ii8PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
174 : X86Inst<o, f, Imm8PCRel, outs, ins, asm> {
175 let Pattern = pattern;
178 class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm,
180 : X86Inst<o, f, Imm16, outs, ins, asm> {
181 let Pattern = pattern;
184 class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm,
186 : X86Inst<o, f, Imm32, outs, ins, asm> {
187 let Pattern = pattern;
191 class Ii16PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
193 : X86Inst<o, f, Imm16PCRel, outs, ins, asm> {
194 let Pattern = pattern;
198 class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
200 : X86Inst<o, f, Imm32PCRel, outs, ins, asm> {
201 let Pattern = pattern;
205 // FPStack Instruction Templates:
206 // FPI - Floating Point Instruction template.
207 class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
208 : I<o, F, outs, ins, asm, []> {}
210 // FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
211 class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
212 : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
214 let Pattern = pattern;
217 // Templates for instructions that use a 16- or 32-bit segmented address as
218 // their only operand: lcall (FAR CALL) and ljmp (FAR JMP)
220 // Iseg16 - 16-bit segment selector, 16-bit offset
221 // Iseg32 - 16-bit segment selector, 32-bit offset
223 class Iseg16 <bits<8> o, Format f, dag outs, dag ins, string asm,
224 list<dag> pattern> : X86Inst<o, f, NoImm, outs, ins, asm> {
225 let Pattern = pattern;
229 class Iseg32 <bits<8> o, Format f, dag outs, dag ins, string asm,
230 list<dag> pattern> : X86Inst<o, f, NoImm, outs, ins, asm> {
231 let Pattern = pattern;
235 // SI - SSE 1 & 2 scalar instructions
236 class SI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
237 : I<o, F, outs, ins, asm, pattern> {
238 let Predicates = !if(hasVEXPrefix /* VEX_4V */,
239 !if(!eq(Prefix, 11 /* XD */), [HasAVX, HasSSE2], [HasAVX, HasSSE1]),
240 !if(!eq(Prefix, 12 /* XS */), [HasSSE1], [HasSSE2]));
242 // AVX instructions have a 'v' prefix in the mnemonic
243 let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
246 // SIi8 - SSE 1 & 2 scalar instructions
247 class SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
249 : Ii8<o, F, outs, ins, asm, pattern> {
250 let Predicates = !if(hasVEXPrefix /* VEX_4V */,
251 !if(!eq(Prefix, 11 /* XD */), [HasAVX, HasSSE2], [HasAVX, HasSSE1]),
252 !if(!eq(Prefix, 12 /* XS */), [HasSSE1], [HasSSE2]));
254 // AVX instructions have a 'v' prefix in the mnemonic
255 let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
258 // PI - SSE 1 & 2 packed instructions
259 class PI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern,
261 : I<o, F, outs, ins, asm, pattern, d> {
262 let Predicates = !if(hasVEXPrefix /* VEX_4V */,
263 !if(hasOpSizePrefix /* OpSize */, [HasAVX, HasSSE2], [HasAVX, HasSSE1]),
264 !if(hasOpSizePrefix /* OpSize */, [HasSSE2], [HasSSE1]));
266 // AVX instructions have a 'v' prefix in the mnemonic
267 let AsmString = !if(hasVEXPrefix, !strconcat("v", asm), asm);
270 // PIi8 - SSE 1 & 2 packed instructions with immediate
271 class PIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
272 list<dag> pattern, Domain d>
273 : Ii8<o, F, outs, ins, asm, pattern, d> {
274 let Predicates = !if(hasVEX_4VPrefix /* VEX_4V */,
275 !if(hasOpSizePrefix /* OpSize */, [HasAVX, HasSSE2], [HasAVX, HasSSE1]),
276 !if(hasOpSizePrefix /* OpSize */, [HasSSE2], [HasSSE1]));
278 // AVX instructions have a 'v' prefix in the mnemonic
279 let AsmString = !if(hasVEX_4VPrefix, !strconcat("v", asm), asm);
282 // SSE1 Instruction Templates:
284 // SSI - SSE1 instructions with XS prefix.
285 // PSI - SSE1 instructions with TB prefix.
286 // PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
287 // VSSI - SSE1 instructions with XS prefix in AVX form.
288 // VPSI - SSE1 instructions with TB prefix in AVX form.
290 class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
291 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
292 class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
294 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
295 class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
296 : I<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB,
298 class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
300 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB,
302 class VSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
304 : I<o, F, outs, ins, !strconcat("v", asm), pattern>, XS,
305 Requires<[HasAVX, HasSSE1]>;
306 class VPSI<bits<8> o, Format F, dag outs, dag ins, string asm,
308 : I<o, F, outs, ins, !strconcat("v", asm), pattern, SSEPackedSingle>,
309 Requires<[HasAVX, HasSSE1]>;
311 // SSE2 Instruction Templates:
313 // SDI - SSE2 instructions with XD prefix.
314 // SDIi8 - SSE2 instructions with ImmT == Imm8 and XD prefix.
315 // SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
316 // PDI - SSE2 instructions with TB and OpSize prefixes.
317 // PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
318 // VSDI - SSE2 instructions with XD prefix in AVX form.
319 // VPDI - SSE2 instructions with TB and OpSize prefixes in AVX form.
321 class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
322 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
323 class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
325 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
326 class SSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
328 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE2]>;
329 class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
330 : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, OpSize,
332 class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
334 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, OpSize,
336 class VSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
338 : I<o, F, outs, ins, !strconcat("v", asm), pattern>, XD,
339 Requires<[HasAVX, HasSSE2]>;
340 class VPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
342 : I<o, F, outs, ins, !strconcat("v", asm), pattern, SSEPackedDouble>,
343 OpSize, Requires<[HasAVX, HasSSE2]>;
345 // SSE3 Instruction Templates:
347 // S3I - SSE3 instructions with TB and OpSize prefixes.
348 // S3SI - SSE3 instructions with XS prefix.
349 // S3DI - SSE3 instructions with XD prefix.
351 class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm,
353 : I<o, F, outs, ins, asm, pattern, SSEPackedSingle>, XS,
355 class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm,
357 : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, XD,
359 class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
360 : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, OpSize,
364 // SSSE3 Instruction Templates:
366 // SS38I - SSSE3 instructions with T8 prefix.
367 // SS3AI - SSSE3 instructions with TA prefix.
369 // Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
370 // uses the MMX registers. We put those instructions here because they better
371 // fit into the SSSE3 instruction category rather than the MMX category.
373 class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
375 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8,
376 Requires<[HasSSSE3]>;
377 class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
379 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA,
380 Requires<[HasSSSE3]>;
382 // SSE4.1 Instruction Templates:
384 // SS48I - SSE 4.1 instructions with T8 prefix.
385 // SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
387 class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
389 : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8,
390 Requires<[HasSSE41]>;
391 class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
393 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA,
394 Requires<[HasSSE41]>;
396 // SSE4.2 Instruction Templates:
398 // SS428I - SSE 4.2 instructions with T8 prefix.
399 class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
401 : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8,
402 Requires<[HasSSE42]>;
404 // SS42FI - SSE 4.2 instructions with TF prefix.
405 class SS42FI<bits<8> o, Format F, dag outs, dag ins, string asm,
407 : I<o, F, outs, ins, asm, pattern>, TF, Requires<[HasSSE42]>;
409 // SS42AI = SSE 4.2 instructions with TA prefix
410 class SS42AI<bits<8> o, Format F, dag outs, dag ins, string asm,
412 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA,
413 Requires<[HasSSE42]>;
415 // AES Instruction Templates:
418 // These use the same encoding as the SSE4.2 T8 and TA encodings.
419 class AES8I<bits<8> o, Format F, dag outs, dag ins, string asm,
421 : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8,
424 class AESAI<bits<8> o, Format F, dag outs, dag ins, string asm,
426 : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA,
429 // X86-64 Instruction templates...
432 class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
433 : I<o, F, outs, ins, asm, pattern>, REX_W;
434 class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
436 : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
437 class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
439 : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
441 class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
443 : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
444 let Pattern = pattern;
448 class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
450 : SSI<o, F, outs, ins, asm, pattern>, REX_W;
451 class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
453 : SDI<o, F, outs, ins, asm, pattern>, REX_W;
454 class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
456 : PDI<o, F, outs, ins, asm, pattern>, REX_W;
458 // MMX Instruction templates
461 // MMXI - MMX instructions with TB prefix.
462 // MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
463 // MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
464 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
465 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
466 // MMXID - MMX instructions with XD prefix.
467 // MMXIS - MMX instructions with XS prefix.
468 class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm,
470 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
471 class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm,
473 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX,In64BitMode]>;
474 class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm,
476 : I<o, F, outs, ins, asm, pattern>, TB, REX_W, Requires<[HasMMX]>;
477 class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm,
479 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
480 class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
482 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
483 class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm,
485 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasMMX]>;
486 class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm,
488 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasMMX]>;