enhance the immediate field encoding to know whether the immediate
[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 MRMInitReg : Format<32>;
32 def MRM_C1 : Format<33>;
33 def MRM_C8 : Format<34>;
34 def MRM_C9 : Format<35>;
35 def MRM_E8 : Format<36>;
36 def MRM_F0 : Format<37>;
37
38
39 // ImmType - This specifies the immediate type used by an instruction. This is
40 // part of the ad-hoc solution used to emit machine instruction encodings by our
41 // machine code emitter.
42 class ImmType<bits<3> val> {
43   bits<3> Value = val;
44 }
45 def NoImm      : ImmType<0>;
46 def Imm8       : ImmType<1>;
47 def Imm8PCRel  : ImmType<2>;
48 def Imm16      : ImmType<3>;
49 def Imm32      : ImmType<4>;
50 def Imm32PCRel : ImmType<5>;
51 def Imm64      : ImmType<6>;
52
53 // FPFormat - This specifies what form this FP instruction has.  This is used by
54 // the Floating-Point stackifier pass.
55 class FPFormat<bits<3> val> {
56   bits<3> Value = val;
57 }
58 def NotFP      : FPFormat<0>;
59 def ZeroArgFP  : FPFormat<1>;
60 def OneArgFP   : FPFormat<2>;
61 def OneArgFPRW : FPFormat<3>;
62 def TwoArgFP   : FPFormat<4>;
63 def CompareFP  : FPFormat<5>;
64 def CondMovFP  : FPFormat<6>;
65 def SpecialFP  : FPFormat<7>;
66
67 // Prefix byte classes which are used to indicate to the ad-hoc machine code
68 // emitter that various prefix bytes are required.
69 class OpSize { bit hasOpSizePrefix = 1; }
70 class AdSize { bit hasAdSizePrefix = 1; }
71 class REX_W  { bit hasREX_WPrefix = 1; }
72 class LOCK   { bit hasLockPrefix = 1; }
73 class SegFS  { bits<2> SegOvrBits = 1; }
74 class SegGS  { bits<2> SegOvrBits = 2; }
75 class TB     { bits<4> Prefix = 1; }
76 class REP    { bits<4> Prefix = 2; }
77 class D8     { bits<4> Prefix = 3; }
78 class D9     { bits<4> Prefix = 4; }
79 class DA     { bits<4> Prefix = 5; }
80 class DB     { bits<4> Prefix = 6; }
81 class DC     { bits<4> Prefix = 7; }
82 class DD     { bits<4> Prefix = 8; }
83 class DE     { bits<4> Prefix = 9; }
84 class DF     { bits<4> Prefix = 10; }
85 class XD     { bits<4> Prefix = 11; }
86 class XS     { bits<4> Prefix = 12; }
87 class T8     { bits<4> Prefix = 13; }
88 class TA     { bits<4> Prefix = 14; }
89 class TF     { bits<4> Prefix = 15; }
90
91 class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
92               string AsmStr>
93   : Instruction {
94   let Namespace = "X86";
95
96   bits<8> Opcode = opcod;
97   Format Form = f;
98   bits<6> FormBits = Form.Value;
99   ImmType ImmT = i;
100   bits<3> ImmTypeBits = ImmT.Value;
101
102   dag OutOperandList = outs;
103   dag InOperandList = ins;
104   string AsmString = AsmStr;
105
106   //
107   // Attributes specific to X86 instructions...
108   //
109   bit hasOpSizePrefix = 0;  // Does this inst have a 0x66 prefix?
110   bit hasAdSizePrefix = 0;  // Does this inst have a 0x67 prefix?
111
112   bits<4> Prefix = 0;       // Which prefix byte does this inst have?
113   bit hasREX_WPrefix  = 0;  // Does this inst requires the REX.W prefix?
114   FPFormat FPForm;          // What flavor of FP instruction is this?
115   bits<3> FPFormBits = 0;
116   bit hasLockPrefix = 0;    // Does this inst have a 0xF0 prefix?
117   bits<2> SegOvrBits = 0;   // Segment override prefix.
118 }
119
120 class I<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
121   : X86Inst<o, f, NoImm, outs, ins, asm> {
122   let Pattern = pattern;
123   let CodeSize = 3;
124 }
125 class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm, 
126            list<dag> pattern>
127   : X86Inst<o, f, Imm8 , outs, ins, asm> {
128   let Pattern = pattern;
129   let CodeSize = 3;
130 }
131 class Ii8PCRel<bits<8> o, Format f, dag outs, dag ins, string asm, 
132                list<dag> pattern>
133   : X86Inst<o, f, Imm8PCRel, outs, ins, asm> {
134   let Pattern = pattern;
135   let CodeSize = 3;
136 }
137 class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm, 
138            list<dag> pattern>
139   : X86Inst<o, f, Imm16, outs, ins, asm> {
140   let Pattern = pattern;
141   let CodeSize = 3;
142 }
143 class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm, 
144            list<dag> pattern>
145   : X86Inst<o, f, Imm32, outs, ins, asm> {
146   let Pattern = pattern;
147   let CodeSize = 3;
148 }
149
150 class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm, 
151            list<dag> pattern>
152   : X86Inst<o, f, Imm32PCRel, outs, ins, asm> {
153   let Pattern = pattern;
154   let CodeSize = 3;
155 }
156
157 // FPStack Instruction Templates:
158 // FPI - Floating Point Instruction template.
159 class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
160   : I<o, F, outs, ins, asm, []> {}
161
162 // FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
163 class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
164   : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
165   let FPForm = fp; let FPFormBits = FPForm.Value;
166   let Pattern = pattern;
167 }
168
169 // Templates for instructions that use a 16- or 32-bit segmented address as
170 //  their only operand: lcall (FAR CALL) and ljmp (FAR JMP)
171 //
172 //   Iseg16 - 16-bit segment selector, 16-bit offset
173 //   Iseg32 - 16-bit segment selector, 32-bit offset
174
175 class Iseg16 <bits<8> o, Format f, dag outs, dag ins, string asm, 
176               list<dag> pattern> : X86Inst<o, f, NoImm, outs, ins, asm> {
177   let Pattern = pattern;
178   let CodeSize = 3;
179 }
180
181 class Iseg32 <bits<8> o, Format f, dag outs, dag ins, string asm, 
182               list<dag> pattern> : X86Inst<o, f, NoImm, outs, ins, asm> {
183   let Pattern = pattern;
184   let CodeSize = 3;
185 }
186
187 // SSE1 Instruction Templates:
188 // 
189 //   SSI   - SSE1 instructions with XS prefix.
190 //   PSI   - SSE1 instructions with TB prefix.
191 //   PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
192
193 class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
194       : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
195 class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm, 
196             list<dag> pattern>
197       : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
198 class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
199       : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
200 class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
201             list<dag> pattern>
202       : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
203
204 // SSE2 Instruction Templates:
205 // 
206 //   SDI    - SSE2 instructions with XD prefix.
207 //   SDIi8  - SSE2 instructions with ImmT == Imm8 and XD prefix.
208 //   SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
209 //   PDI    - SSE2 instructions with TB and OpSize prefixes.
210 //   PDIi8  - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
211
212 class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
213       : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
214 class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
215             list<dag> pattern>
216       : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
217 class SSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
218              list<dag> pattern>
219       : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE2]>;
220 class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
221       : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
222 class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
223             list<dag> pattern>
224       : Ii8<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
225
226 // SSE3 Instruction Templates:
227 // 
228 //   S3I   - SSE3 instructions with TB and OpSize prefixes.
229 //   S3SI  - SSE3 instructions with XS prefix.
230 //   S3DI  - SSE3 instructions with XD prefix.
231
232 class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, 
233            list<dag> pattern>
234       : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE3]>;
235 class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, 
236            list<dag> pattern>
237       : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE3]>;
238 class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
239       : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE3]>;
240
241
242 // SSSE3 Instruction Templates:
243 // 
244 //   SS38I - SSSE3 instructions with T8 prefix.
245 //   SS3AI - SSSE3 instructions with TA prefix.
246 //
247 // Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
248 // uses the MMX registers. We put those instructions here because they better
249 // fit into the SSSE3 instruction category rather than the MMX category.
250
251 class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
252             list<dag> pattern>
253       : Ii8<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
254 class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
255             list<dag> pattern>
256       : Ii8<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
257
258 // SSE4.1 Instruction Templates:
259 // 
260 //   SS48I - SSE 4.1 instructions with T8 prefix.
261 //   SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
262 //
263 class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
264             list<dag> pattern>
265       : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE41]>;
266 class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
267             list<dag> pattern>
268       : Ii8<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE41]>;
269
270 // SSE4.2 Instruction Templates:
271 // 
272 //   SS428I - SSE 4.2 instructions with T8 prefix.
273 class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
274              list<dag> pattern>
275       : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE42]>;
276
277 //   SS42FI - SSE 4.2 instructions with TF prefix.
278 class SS42FI<bits<8> o, Format F, dag outs, dag ins, string asm,
279               list<dag> pattern>
280       : I<o, F, outs, ins, asm, pattern>, TF, Requires<[HasSSE42]>;
281       
282 //   SS42AI = SSE 4.2 instructions with TA prefix
283 class SS42AI<bits<8> o, Format F, dag outs, dag ins, string asm,
284              list<dag> pattern>
285       : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE42]>;
286
287 // X86-64 Instruction templates...
288 //
289
290 class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
291       : I<o, F, outs, ins, asm, pattern>, REX_W;
292 class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
293             list<dag> pattern>
294       : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
295 class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
296              list<dag> pattern>
297       : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
298
299 class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
300             list<dag> pattern>
301   : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
302   let Pattern = pattern;
303   let CodeSize = 3;
304 }
305
306 class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
307            list<dag> pattern>
308       : SSI<o, F, outs, ins, asm, pattern>, REX_W;
309 class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
310            list<dag> pattern>
311       : SDI<o, F, outs, ins, asm, pattern>, REX_W;
312 class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
313            list<dag> pattern>
314       : PDI<o, F, outs, ins, asm, pattern>, REX_W;
315
316 // MMX Instruction templates
317 //
318
319 // MMXI   - MMX instructions with TB prefix.
320 // MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
321 // MMX2I  - MMX / SSE2 instructions with TB and OpSize prefixes.
322 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
323 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
324 // MMXID  - MMX instructions with XD prefix.
325 // MMXIS  - MMX instructions with XS prefix.
326 class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm, 
327            list<dag> pattern>
328       : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
329 class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm, 
330              list<dag> pattern>
331       : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX,In64BitMode]>;
332 class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm, 
333             list<dag> pattern>
334       : I<o, F, outs, ins, asm, pattern>, TB, REX_W, Requires<[HasMMX]>;
335 class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm, 
336             list<dag> pattern>
337       : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
338 class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm, 
339              list<dag> pattern>
340       : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
341 class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm, 
342             list<dag> pattern>
343       : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasMMX]>;
344 class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm, 
345             list<dag> pattern>
346       : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasMMX]>;