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