blob: 33f38e3b4e2a4a67ecf44b51e681c85f36654927 [file] [log] [blame]
Evan Cheng86ab7d32007-07-31 08:04:03 +00001//===- X86InstrFormats.td - X86 Instruction Formats --------*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Cheng86ab7d32007-07-31 08:04:03 +00007//
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.
17class Format<bits<6> val> {
18 bits<6> Value = val;
19}
20
21def Pseudo : Format<0>; def RawFrm : Format<1>;
22def AddRegFrm : Format<2>; def MRMDestReg : Format<3>;
23def MRMDestMem : Format<4>; def MRMSrcReg : Format<5>;
24def MRMSrcMem : Format<6>;
25def MRM0r : Format<16>; def MRM1r : Format<17>; def MRM2r : Format<18>;
26def MRM3r : Format<19>; def MRM4r : Format<20>; def MRM5r : Format<21>;
27def MRM6r : Format<22>; def MRM7r : Format<23>;
28def MRM0m : Format<24>; def MRM1m : Format<25>; def MRM2m : Format<26>;
29def MRM3m : Format<27>; def MRM4m : Format<28>; def MRM5m : Format<29>;
30def MRM6m : Format<30>; def MRM7m : Format<31>;
31def MRMInitReg : Format<32>;
32
33
34// ImmType - This specifies the immediate type used by an instruction. This is
35// part of the ad-hoc solution used to emit machine instruction encodings by our
36// machine code emitter.
37class ImmType<bits<3> val> {
38 bits<3> Value = val;
39}
40def NoImm : ImmType<0>;
41def Imm8 : ImmType<1>;
42def Imm16 : ImmType<2>;
43def Imm32 : ImmType<3>;
44def Imm64 : ImmType<4>;
45
46// FPFormat - This specifies what form this FP instruction has. This is used by
47// the Floating-Point stackifier pass.
48class FPFormat<bits<3> val> {
49 bits<3> Value = val;
50}
51def NotFP : FPFormat<0>;
52def ZeroArgFP : FPFormat<1>;
53def OneArgFP : FPFormat<2>;
54def OneArgFPRW : FPFormat<3>;
55def TwoArgFP : FPFormat<4>;
56def CompareFP : FPFormat<5>;
57def CondMovFP : FPFormat<6>;
58def SpecialFP : FPFormat<7>;
59
60// Prefix byte classes which are used to indicate to the ad-hoc machine code
61// emitter that various prefix bytes are required.
62class OpSize { bit hasOpSizePrefix = 1; }
63class AdSize { bit hasAdSizePrefix = 1; }
64class REX_W { bit hasREX_WPrefix = 1; }
Andrew Lenharth7a5a4b22008-03-01 13:37:02 +000065class LOCK { bit hasLockPrefix = 1; }
Evan Cheng86ab7d32007-07-31 08:04:03 +000066class TB { bits<4> Prefix = 1; }
67class REP { bits<4> Prefix = 2; }
68class D8 { bits<4> Prefix = 3; }
69class D9 { bits<4> Prefix = 4; }
70class DA { bits<4> Prefix = 5; }
71class DB { bits<4> Prefix = 6; }
72class DC { bits<4> Prefix = 7; }
73class DD { bits<4> Prefix = 8; }
74class DE { bits<4> Prefix = 9; }
75class DF { bits<4> Prefix = 10; }
76class XD { bits<4> Prefix = 11; }
77class XS { bits<4> Prefix = 12; }
78class T8 { bits<4> Prefix = 13; }
79class TA { bits<4> Prefix = 14; }
80
81class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
82 string AsmStr>
83 : Instruction {
84 let Namespace = "X86";
85
86 bits<8> Opcode = opcod;
87 Format Form = f;
88 bits<6> FormBits = Form.Value;
89 ImmType ImmT = i;
90 bits<3> ImmTypeBits = ImmT.Value;
91
92 dag OutOperandList = outs;
93 dag InOperandList = ins;
94 string AsmString = AsmStr;
95
96 //
97 // Attributes specific to X86 instructions...
98 //
99 bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
100 bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix?
101
102 bits<4> Prefix = 0; // Which prefix byte does this inst have?
103 bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix?
104 FPFormat FPForm; // What flavor of FP instruction is this?
105 bits<3> FPFormBits = 0;
Dan Gohmanaf8b7212008-08-20 13:46:21 +0000106 bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix?
Evan Cheng86ab7d32007-07-31 08:04:03 +0000107}
108
109class I<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
110 : X86Inst<o, f, NoImm, outs, ins, asm> {
111 let Pattern = pattern;
112 let CodeSize = 3;
113}
114class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
115 : X86Inst<o, f, Imm8 , outs, ins, asm> {
116 let Pattern = pattern;
117 let CodeSize = 3;
118}
119class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
120 : X86Inst<o, f, Imm16, outs, ins, asm> {
121 let Pattern = pattern;
122 let CodeSize = 3;
123}
124class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
125 : X86Inst<o, f, Imm32, outs, ins, asm> {
126 let Pattern = pattern;
127 let CodeSize = 3;
128}
129
130// FPStack Instruction Templates:
131// FPI - Floating Point Instruction template.
132class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
133 : I<o, F, outs, ins, asm, []> {}
134
135// FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
136class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
137 : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
138 let FPForm = fp; let FPFormBits = FPForm.Value;
139 let Pattern = pattern;
140}
141
142// SSE1 Instruction Templates:
143//
144// SSI - SSE1 instructions with XS prefix.
145// PSI - SSE1 instructions with TB prefix.
146// PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
147
148class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
149 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
Chris Lattnera9f545f2007-12-16 20:12:41 +0000150class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
151 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
Evan Cheng86ab7d32007-07-31 08:04:03 +0000152class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
153 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
154class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
155 list<dag> pattern>
156 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
157
158// SSE2 Instruction Templates:
159//
160// SDI - SSE2 instructions with XD prefix.
Evan Cheng653c7ac2007-12-20 19:57:09 +0000161// SDIi8 - SSE2 instructions with ImmT == Imm8 and XD prefix.
Evan Cheng86ab7d32007-07-31 08:04:03 +0000162// PDI - SSE2 instructions with TB and OpSize prefixes.
163// PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
164
165class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
166 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
Evan Cheng653c7ac2007-12-20 19:57:09 +0000167class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
168 list<dag> pattern>
169 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
Evan Cheng86ab7d32007-07-31 08:04:03 +0000170class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
171 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
172class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
173 list<dag> pattern>
174 : Ii8<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
175
176// SSE3 Instruction Templates:
177//
178// S3I - SSE3 instructions with TB and OpSize prefixes.
179// S3SI - SSE3 instructions with XS prefix.
180// S3DI - SSE3 instructions with XD prefix.
181
182class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
183 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE3]>;
184class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
185 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE3]>;
186class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
187 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE3]>;
188
189
Nate Begeman4294c1f2008-02-12 22:51:28 +0000190// SSSE3 Instruction Templates:
191//
192// SS38I - SSSE3 instructions with T8 prefix.
193// SS3AI - SSSE3 instructions with TA prefix.
194//
195// Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
196// uses the MMX registers. We put those instructions here because they better
197// fit into the SSSE3 instruction category rather than the MMX category.
198
199class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
200 list<dag> pattern>
201 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
202class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
203 list<dag> pattern>
204 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
205
206// SSE4.1 Instruction Templates:
207//
208// SS48I - SSE 4.1 instructions with T8 prefix.
Evan Cheng78d00612008-03-14 07:39:27 +0000209// SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
Nate Begeman4294c1f2008-02-12 22:51:28 +0000210//
211class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
212 list<dag> pattern>
213 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE41]>;
Evan Cheng78d00612008-03-14 07:39:27 +0000214class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
Nate Begeman4294c1f2008-02-12 22:51:28 +0000215 list<dag> pattern>
Evan Cheng78d00612008-03-14 07:39:27 +0000216 : Ii8<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE41]>;
Nate Begeman4294c1f2008-02-12 22:51:28 +0000217
Nate Begeman03605a02008-07-17 16:51:19 +0000218// SSE4.2 Instruction Templates:
219//
220// SS428I - SSE 4.2 instructions with T8 prefix.
221class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
222 list<dag> pattern>
223 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE42]>;
Nate Begeman4294c1f2008-02-12 22:51:28 +0000224
Evan Cheng86ab7d32007-07-31 08:04:03 +0000225// X86-64 Instruction templates...
226//
227
228class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
229 : I<o, F, outs, ins, asm, pattern>, REX_W;
230class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
231 list<dag> pattern>
232 : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
233class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
234 list<dag> pattern>
235 : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
236
237class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
238 list<dag> pattern>
239 : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
240 let Pattern = pattern;
241 let CodeSize = 3;
242}
243
244class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
245 list<dag> pattern>
246 : SSI<o, F, outs, ins, asm, pattern>, REX_W;
247class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
248 list<dag> pattern>
249 : SDI<o, F, outs, ins, asm, pattern>, REX_W;
250class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
251 list<dag> pattern>
252 : PDI<o, F, outs, ins, asm, pattern>, REX_W;
253
254// MMX Instruction templates
255//
256
257// MMXI - MMX instructions with TB prefix.
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000258// MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
Evan Cheng86ab7d32007-07-31 08:04:03 +0000259// MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
260// MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
261// MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
262// MMXID - MMX instructions with XD prefix.
263// MMXIS - MMX instructions with XS prefix.
264class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
265 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000266class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
267 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX,In64BitMode]>;
Evan Cheng86ab7d32007-07-31 08:04:03 +0000268class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
269 : I<o, F, outs, ins, asm, pattern>, TB, REX_W, Requires<[HasMMX]>;
270class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
271 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
272class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
273 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
274class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
275 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasMMX]>;
276class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
277 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasMMX]>;
278