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>;
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> {
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>;
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> {
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>;
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; }
83 class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
86 let Namespace = "X86";
88 bits<8> Opcode = opcod;
90 bits<6> FormBits = Form.Value;
92 bits<3> ImmTypeBits = ImmT.Value;
94 dag OutOperandList = outs;
95 dag InOperandList = ins;
96 string AsmString = AsmStr;
99 // Attributes specific to X86 instructions...
101 bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
102 bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix?
104 bits<4> Prefix = 0; // Which prefix byte does this inst have?
105 bit hasREX_WPrefix = 0; // Does this inst requires the REX.W prefix?
106 FPFormat FPForm; // What flavor of FP instruction is this?
107 bits<3> FPFormBits = 0;
108 bit hasLockPrefix = 0; // Does this inst have a 0xF0 prefix?
109 bits<2> SegOvrBits = 0; // Segment override prefix.
112 class I<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
113 : X86Inst<o, f, NoImm, outs, ins, asm> {
114 let Pattern = pattern;
117 class Ii8 <bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
118 : X86Inst<o, f, Imm8 , outs, ins, asm> {
119 let Pattern = pattern;
122 class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
123 : X86Inst<o, f, Imm16, outs, ins, asm> {
124 let Pattern = pattern;
127 class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
128 : X86Inst<o, f, Imm32, outs, ins, asm> {
129 let Pattern = pattern;
133 // FPStack Instruction Templates:
134 // FPI - Floating Point Instruction template.
135 class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
136 : I<o, F, outs, ins, asm, []> {}
138 // FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
139 class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
140 : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
141 let FPForm = fp; let FPFormBits = FPForm.Value;
142 let Pattern = pattern;
145 // SSE1 Instruction Templates:
147 // SSI - SSE1 instructions with XS prefix.
148 // PSI - SSE1 instructions with TB prefix.
149 // PSIi8 - SSE1 instructions with ImmT == Imm8 and TB prefix.
151 class SSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
152 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
153 class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
154 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE1]>;
155 class PSI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
156 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
157 class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
159 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasSSE1]>;
161 // SSE2 Instruction Templates:
163 // SDI - SSE2 instructions with XD prefix.
164 // SDIi8 - SSE2 instructions with ImmT == Imm8 and XD prefix.
165 // SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
166 // PDI - SSE2 instructions with TB and OpSize prefixes.
167 // PDIi8 - SSE2 instructions with ImmT == Imm8 and TB and OpSize prefixes.
169 class SDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
170 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
171 class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
173 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE2]>;
174 class SSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
176 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE2]>;
177 class PDI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
178 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
179 class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
181 : Ii8<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
183 // SSE3 Instruction Templates:
185 // S3I - SSE3 instructions with TB and OpSize prefixes.
186 // S3SI - SSE3 instructions with XS prefix.
187 // S3DI - SSE3 instructions with XD prefix.
189 class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
190 : I<o, F, outs, ins, asm, pattern>, XS, Requires<[HasSSE3]>;
191 class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
192 : I<o, F, outs, ins, asm, pattern>, XD, Requires<[HasSSE3]>;
193 class S3I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
194 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasSSE3]>;
197 // SSSE3 Instruction Templates:
199 // SS38I - SSSE3 instructions with T8 prefix.
200 // SS3AI - SSSE3 instructions with TA prefix.
202 // Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
203 // uses the MMX registers. We put those instructions here because they better
204 // fit into the SSSE3 instruction category rather than the MMX category.
206 class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
208 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
209 class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
211 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
213 // SSE4.1 Instruction Templates:
215 // SS48I - SSE 4.1 instructions with T8 prefix.
216 // SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
218 class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
220 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE41]>;
221 class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
223 : Ii8<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE41]>;
225 // SSE4.2 Instruction Templates:
227 // SS428I - SSE 4.2 instructions with T8 prefix.
228 class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
230 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE42]>;
232 // X86-64 Instruction templates...
235 class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
236 : I<o, F, outs, ins, asm, pattern>, REX_W;
237 class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
239 : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
240 class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
242 : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
244 class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
246 : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
247 let Pattern = pattern;
251 class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
253 : SSI<o, F, outs, ins, asm, pattern>, REX_W;
254 class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
256 : SDI<o, F, outs, ins, asm, pattern>, REX_W;
257 class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
259 : PDI<o, F, outs, ins, asm, pattern>, REX_W;
261 // MMX Instruction templates
264 // MMXI - MMX instructions with TB prefix.
265 // MMXI64 - MMX instructions with TB prefix valid only in 64 bit mode.
266 // MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
267 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
268 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
269 // MMXID - MMX instructions with XD prefix.
270 // MMXIS - MMX instructions with XS prefix.
271 class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
272 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
273 class MMXI64<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
274 : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX,In64BitMode]>;
275 class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
276 : I<o, F, outs, ins, asm, pattern>, TB, REX_W, Requires<[HasMMX]>;
277 class MMX2I<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
278 : I<o, F, outs, ins, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
279 class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
280 : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
281 class MMXID<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
282 : Ii8<o, F, outs, ins, asm, pattern>, XD, Requires<[HasMMX]>;
283 class MMXIS<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
284 : Ii8<o, F, outs, ins, asm, pattern>, XS, Requires<[HasMMX]>;