blob: ddc8654359e89f83347b44e6a3b7ef1fbdf220f9 [file] [log] [blame]
Evan Chengc64a1a92007-07-31 08:04:03 +00001//===- X86InstrFormats.td - X86 Instruction Formats --------*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Chengc64a1a92007-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 Lenharthea7da502008-03-01 13:37:02 +000065class LOCK { bit hasLockPrefix = 1; }
Anton Korobeynikovef93cec2008-10-11 19:09:15 +000066class SegFS { bits<2> SegOvrBits = 1; }
67class SegGS { bits<2> SegOvrBits = 2; }
Evan Chengc64a1a92007-07-31 08:04:03 +000068class TB { bits<4> Prefix = 1; }
69class REP { bits<4> Prefix = 2; }
70class D8 { bits<4> Prefix = 3; }
71class D9 { bits<4> Prefix = 4; }
72class DA { bits<4> Prefix = 5; }
73class DB { bits<4> Prefix = 6; }
74class DC { bits<4> Prefix = 7; }
75class DD { bits<4> Prefix = 8; }
76class DE { bits<4> Prefix = 9; }
77class DF { bits<4> Prefix = 10; }
78class XD { bits<4> Prefix = 11; }
79class XS { bits<4> Prefix = 12; }
80class T8 { bits<4> Prefix = 13; }
81class TA { bits<4> Prefix = 14; }
Eric Christopherb4dc13c2009-08-08 21:55:08 +000082class TF { bits<4> Prefix = 15; }
Evan Chengc64a1a92007-07-31 08:04:03 +000083
84class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
85 string AsmStr>
86 : Instruction {
87 let Namespace = "X86";
88
89 bits<8> Opcode = opcod;
90 Format Form = f;
91 bits<6> FormBits = Form.Value;
92 ImmType ImmT = i;
93 bits<3> ImmTypeBits = ImmT.Value;
94
95 dag OutOperandList = outs;
96 dag InOperandList = ins;
97 string AsmString = AsmStr;
98
99 //
100 // Attributes specific to X86 instructions...
101 //
102 bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
103 bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix?
104
105 bits<4> Prefix = 0; // Which prefix byte does this inst have?
106 bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix?
107 FPFormat FPForm; // What flavor of FP instruction is this?
108 bits<3> FPFormBits = 0;
Dan Gohman1e684cf2008-08-20 13:46:21 +0000109 bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix?
Anton Korobeynikovef93cec2008-10-11 19:09:15 +0000110 bits<2> SegOvrBits = 0; // Segment override prefix.
Evan Chengc64a1a92007-07-31 08:04:03 +0000111}
112
113class I<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
114 : X86Inst<o, f, NoImm, outs, ins, asm> {
115 let Pattern = pattern;
116 let CodeSize = 3;
117}
118class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
119 : X86Inst<o, f, Imm8 , outs, ins, asm> {
120 let Pattern = pattern;
121 let CodeSize = 3;
122}
123class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
124 : X86Inst<o, f, Imm16, outs, ins, asm> {
125 let Pattern = pattern;
126 let CodeSize = 3;
127}
128class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
129 : X86Inst<o, f, Imm32, outs, ins, asm> {
130 let Pattern = pattern;
131 let CodeSize = 3;
132}
133
134// FPStack Instruction Templates:
135// FPI - Floating Point Instruction template.
136class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
137 : I<o, F, outs, ins, asm, []> {}
138
139// FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
140class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
141 : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
142 let FPForm = fp; let FPFormBits = FPForm.Value;
143 let Pattern = pattern;
144}
145
146// SSE1 Instruction Templates:
147//
148// SSI - SSE1 instructions with XS prefix.
149// PSI - SSE1 instructions with TB prefix.
150// PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
151
152class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
153 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
Chris Lattnerd7610e12007-12-16 20:12:41 +0000154class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
155 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
Evan Chengc64a1a92007-07-31 08:04:03 +0000156class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
157 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
158class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
159 list<dag> pattern>
160 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
161
162// SSE2 Instruction Templates:
163//
Bill Wendling1dd00862008-08-27 21:32:04 +0000164// SDI - SSE2 instructions with XD prefix.
165// SDIi8 - SSE2 instructions with ImmT == Imm8 and XD prefix.
166// SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
167// PDI - SSE2 instructions with TB and OpSize prefixes.
168// PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
Evan Chengc64a1a92007-07-31 08:04:03 +0000169
170class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
171 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
Evan Cheng700a0fb2007-12-20 19:57:09 +0000172class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
173 list<dag> pattern>
174 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
Bill Wendling1dd00862008-08-27 21:32:04 +0000175class SSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
176 list<dag> pattern>
177 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE2]>;
Evan Chengc64a1a92007-07-31 08:04:03 +0000178class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
179 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
180class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
181 list<dag> pattern>
182 : Ii8<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
183
184// SSE3 Instruction Templates:
185//
186// S3I - SSE3 instructions with TB and OpSize prefixes.
187// S3SI - SSE3 instructions with XS prefix.
188// S3DI - SSE3 instructions with XD prefix.
189
190class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
191 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE3]>;
192class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
193 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE3]>;
194class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
195 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE3]>;
196
197
Nate Begemancdd1eec2008-02-12 22:51:28 +0000198// SSSE3 Instruction Templates:
199//
200// SS38I - SSSE3 instructions with T8 prefix.
201// SS3AI - SSSE3 instructions with TA prefix.
202//
203// Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
204// uses the MMX registers. We put those instructions here because they better
205// fit into the SSSE3 instruction category rather than the MMX category.
206
207class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
208 list<dag> pattern>
209 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
210class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
211 list<dag> pattern>
212 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
213
214// SSE4.1 Instruction Templates:
215//
216// SS48I - SSE 4.1 instructions with T8 prefix.
Evan Cheng172b7942008-03-14 07:39:27 +0000217// SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
Nate Begemancdd1eec2008-02-12 22:51:28 +0000218//
219class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
220 list<dag> pattern>
221 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE41]>;
Evan Cheng172b7942008-03-14 07:39:27 +0000222class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
Nate Begemancdd1eec2008-02-12 22:51:28 +0000223 list<dag> pattern>
Evan Cheng172b7942008-03-14 07:39:27 +0000224 : Ii8<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE41]>;
Nate Begemancdd1eec2008-02-12 22:51:28 +0000225
Nate Begeman30a0de92008-07-17 16:51:19 +0000226// SSE4.2 Instruction Templates:
227//
228// SS428I - SSE 4.2 instructions with T8 prefix.
229class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
230 list<dag> pattern>
231 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE42]>;
Nate Begemancdd1eec2008-02-12 22:51:28 +0000232
Eric Christopherb4dc13c2009-08-08 21:55:08 +0000233// SS42FI - SSE 4.2 instructions with TF prefix.
234class SS42FI<bits<8> o, Format F, dag outs, dag ins, string asm,
235 list<dag> pattern>
236 : I<o, F, outs, ins, asm, pattern>, TF, Requires<[HasSSE42]>;
237
Eric Christopherb120ab42009-08-18 22:50:32 +0000238// SS42AI = SSE 4.2 instructions with TA prefix
239class SS42AI<bits<8> o, Format F, dag outs, dag ins, string asm,
240 list<dag> pattern>
241 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE42]>;
242
Evan Chengc64a1a92007-07-31 08:04:03 +0000243// X86-64 Instruction templates...
244//
245
246class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
247 : I<o, F, outs, ins, asm, pattern>, REX_W;
248class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
249 list<dag> pattern>
250 : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
251class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
252 list<dag> pattern>
253 : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
254
255class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
256 list<dag> pattern>
257 : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
258 let Pattern = pattern;
259 let CodeSize = 3;
260}
261
262class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
263 list<dag> pattern>
264 : SSI<o, F, outs, ins, asm, pattern>, REX_W;
265class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
266 list<dag> pattern>
267 : SDI<o, F, outs, ins, asm, pattern>, REX_W;
268class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
269 list<dag> pattern>
270 : PDI<o, F, outs, ins, asm, pattern>, REX_W;
271
272// MMX Instruction templates
273//
274
275// MMXI - MMX instructions with TB prefix.
Anton Korobeynikov017c2602008-08-23 15:53:19 +0000276// MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
Evan Chengc64a1a92007-07-31 08:04:03 +0000277// MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
278// MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
279// MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
280// MMXID - MMX instructions with XD prefix.
281// MMXIS - MMX instructions with XS prefix.
282class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
283 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
Anton Korobeynikov017c2602008-08-23 15:53:19 +0000284class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
285 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX,In64BitMode]>;
Evan Chengc64a1a92007-07-31 08:04:03 +0000286class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
287 : I<o, F, outs, ins, asm, pattern>, TB, REX_W, Requires<[HasMMX]>;
288class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
289 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
290class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
291 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
292class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
293 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasMMX]>;
294class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
295 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasMMX]>;