xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86InstrUtils.td (revision b59017c5cad90d0f09a59e68c00457b7faf93e7c)
1//===-- X86InstrUtils.td - X86 Instruction Utilities --------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides utilities for simplifying the instruction definitions.
10//
11//===----------------------------------------------------------------------===//
12
13//===----------------------------------------------------------------------===//
14// Classes for setting the fields of X86Inst
15//===----------------------------------------------------------------------===//
16
17// Prefix byte classes which are used to indicate to the ad-hoc machine code
18// emitter that various prefix bytes are required.
19class OpSize16 { OperandSize OpSize = OpSize16; }
20class OpSize32 { OperandSize OpSize = OpSize32; }
21class AdSize16 { AddressSize AdSize = AdSize16; }
22class AdSize32 { AddressSize AdSize = AdSize32; }
23class AdSize64 { AddressSize AdSize = AdSize64; }
24class REX_W  { bit hasREX_W = 1; }
25class LOCK   { bit hasLockPrefix = 1; }
26class REP    { bit hasREPPrefix = 1; }
27class TB     { Map OpMap = TB; }
28class T8     { Map OpMap = T8; }
29class TA     { Map OpMap = TA; }
30class T_MAP4 { Map OpMap = T_MAP4; }
31class T_MAP5 { Map OpMap = T_MAP5; }
32class T_MAP6 { Map OpMap = T_MAP6; }
33class T_MAP7 { Map OpMap = T_MAP7; }
34class XOP8   { Map OpMap = XOP8; }
35class XOP9   { Map OpMap = XOP9; }
36class XOPA   { Map OpMap = XOPA; }
37class ThreeDNow { Map OpMap = ThreeDNow; }
38class PS { Prefix OpPrefix = PS; }
39class PD { Prefix OpPrefix = PD; }
40class XD { Prefix OpPrefix = XD; }
41class XS { Prefix OpPrefix = XS; }
42class XOP { Encoding OpEnc = EncXOP; }
43class VEX { Encoding OpEnc = EncVEX; }
44class EVEX { Encoding OpEnc = EncEVEX; }
45class WIG  { bit IgnoresW = 1; }
46class VEX_L  { bit hasVEX_L = 1; }
47class VEX_LIG { bit ignoresVEX_L = 1; }
48class VVVV { bit hasVEX_4V = 1; }
49class EVEX_K { bit hasEVEX_K = 1; }
50class EVEX_KZ : EVEX_K { bit hasEVEX_Z = 1; }
51class EVEX_B { bit hasEVEX_B = 1; }
52class EVEX_NF { bit hasEVEX_NF = 1; }
53class EVEX_RC { bit hasEVEX_RC = 1; }
54class EVEX_V512 { bit hasEVEX_L2 = 1; bit hasVEX_L = 0; }
55class EVEX_V256 { bit hasEVEX_L2 = 0; bit hasVEX_L = 1; }
56class EVEX_V128 { bit hasEVEX_L2 = 0; bit hasVEX_L = 0; }
57class NOTRACK { bit hasNoTrackPrefix = 1; }
58class SIMD_EXC { list<Register> Uses = [MXCSR]; bit mayRaiseFPException = 1; }
59// Specify AVX512 8-bit compressed displacement encoding based on the vector
60// element size in bits (8, 16, 32, 64) and the CDisp8 form.
61class EVEX_CD8<int esize, CD8VForm form> {
62  int CD8_EltSize = !srl(esize, 3);
63  bits<3> CD8_Form = form.Value;
64}
65class NoCD8 { bits<7> CD8_Scale = 0; }
66
67class AVX512BIi8Base : TB, PD {
68  Domain ExeDomain = SSEPackedInt;
69  ImmType ImmT = Imm8;
70}
71class AVX512XSIi8Base : TB, XS {
72  Domain ExeDomain = SSEPackedInt;
73  ImmType ImmT = Imm8;
74}
75class AVX512XDIi8Base : TB, XD {
76  Domain ExeDomain = SSEPackedInt;
77  ImmType ImmT = Imm8;
78}
79class AVX512PSIi8Base : TB {
80  Domain ExeDomain = SSEPackedSingle;
81  ImmType ImmT = Imm8;
82}
83class AVX512PDIi8Base : TB, PD {
84  Domain ExeDomain = SSEPackedDouble;
85  ImmType ImmT = Imm8;
86}
87class ExplicitREX2Prefix { ExplicitOpPrefix explicitOpPrefix = ExplicitREX2; }
88class ExplicitVEXPrefix { ExplicitOpPrefix explicitOpPrefix = ExplicitVEX; }
89class ExplicitEVEXPrefix { ExplicitOpPrefix explicitOpPrefix = ExplicitEVEX; }
90class DefEFLAGS { list<Register> Defs = [EFLAGS]; }
91class UseEFLAGS { list<Register> Uses = [EFLAGS]; }
92class DisassembleOnly {
93  // The disassembler should know about this, but not the asmparser.
94  bit isCodeGenOnly = 1;
95  bit ForceDisassemble = 1;
96}
97
98defvar unaryop_args = "$src1";
99defvar unaryop_ndd_args = "{$src1, $dst|$dst, $src1}";
100defvar binop_args = "{$src2, $src1|$src1, $src2}";
101defvar binop_ndd_args = "{$src2, $src1, $dst|$dst, $src1, $src2}";
102defvar binop_cl_args = "{%cl, $src1|$src1, cl}";
103defvar binop_cl_ndd_args = "{%cl, $src1, $dst|$dst, $src1, cl}";
104defvar triop_args = "{$src3, $src2, $src1|$src1, $src2, $src3}";
105defvar triop_ndd_args = "{$src3, $src2, $src1, $dst|$dst, $src1, $src2, $src3}";
106defvar triop_cl_args = "{%cl, $src2, $src1|$src1, $src2, cl}";
107defvar triop_cl_ndd_args = "{%cl, $src2, $src1, $dst|$dst, $src1, $src2, cl}";
108defvar tie_dst_src1 = "$src1 = $dst";
109
110// NDD - Helper for new data destination instructions
111class NDD<bit ndd> {
112  string Constraints = !if(!eq(ndd, 0), tie_dst_src1, "");
113  Encoding OpEnc = !if(!eq(ndd, 0), EncNormal, EncEVEX);
114  bit hasEVEX_B = ndd;
115  bit hasVEX_4V = ndd;
116  Map OpMap = !if(!eq(ndd, 0), OB, T_MAP4);
117}
118// NF - Helper for NF (no flags update) instructions
119class NF: T_MAP4, EVEX, EVEX_NF;
120// PL - Helper for promoted legacy instructions
121class PL: T_MAP4, EVEX, ExplicitEVEXPrefix;
122// ZU - Helper for Zero Upper instructions
123class ZU: T_MAP4, EVEX, EVEX_B;
124
125//===----------------------------------------------------------------------===//
126// X86 Type infomation definitions
127//===----------------------------------------------------------------------===//
128
129/// X86TypeInfo - This is a bunch of information that describes relevant X86
130/// information about value types.  For example, it can tell you what the
131/// register class and preferred load to use.
132class X86TypeInfo<ValueType vt, string instrsuffix, RegisterClass regclass,
133                  PatFrag loadnode, X86MemOperand memoperand, ImmType immkind,
134                  Operand immoperand, SDPatternOperator immoperator,
135                  SDPatternOperator immnosuoperator, Operand imm8operand,
136                  SDPatternOperator imm8operator, SDPatternOperator imm8nosuoperator,
137                  bit hasEvenOpcode, bit hasREX_W> {
138  /// VT - This is the value type itself.
139  ValueType VT = vt;
140
141  /// InstrSuffix - This is the suffix used on instructions with this type.  For
142  /// example, i8 -> "b", i16 -> "w", i32 -> "l", i64 -> "q".
143  string InstrSuffix = instrsuffix;
144
145  /// RegClass - This is the register class associated with this type.  For
146  /// example, i8 -> GR8, i16 -> GR16, i32 -> GR32, i64 -> GR64.
147  RegisterClass RegClass = regclass;
148
149  /// LoadNode - This is the load node associated with this type.  For
150  /// example, i8 -> loadi8, i16 -> loadi16, i32 -> loadi32, i64 -> loadi64.
151  PatFrag LoadNode = loadnode;
152
153  /// MemOperand - This is the memory operand associated with this type.  For
154  /// example, i8 -> i8mem, i16 -> i16mem, i32 -> i32mem, i64 -> i64mem.
155  X86MemOperand MemOperand = memoperand;
156
157  /// ImmEncoding - This is the encoding of an immediate of this type.  For
158  /// example, i8 -> Imm8, i16 -> Imm16, i32 -> Imm32.  Note that i64 -> Imm32
159  /// since the immediate fields of i64 instructions is a 32-bit sign extended
160  /// value.
161  ImmType ImmEncoding = immkind;
162
163  /// ImmOperand - This is the operand kind of an immediate of this type.  For
164  /// example, i8 -> i8imm, i16 -> i16imm, i32 -> i32imm.  Note that i64 ->
165  /// i64i32imm since the immediate fields of i64 instructions is a 32-bit sign
166  /// extended value.
167  Operand ImmOperand = immoperand;
168
169  /// ImmOperator - This is the operator that should be used to match an
170  /// immediate of this kind in a pattern (e.g. imm, or i64immSExt32).
171  SDPatternOperator ImmOperator = immoperator;
172
173  SDPatternOperator ImmNoSuOperator = immnosuoperator;
174
175  /// Imm8Operand - This is the operand kind to use for an imm8 of this type.
176  /// For example, i8 -> <invalid>, i16 -> i16i8imm, i32 -> i32i8imm.  This is
177  /// only used for instructions that have a sign-extended imm8 field form.
178  Operand Imm8Operand = imm8operand;
179
180  /// Imm8Operator - This is the operator that should be used to match an 8-bit
181  /// sign extended immediate of this kind in a pattern (e.g. imm16immSExt8).
182  SDPatternOperator Imm8Operator = imm8operator;
183
184  SDPatternOperator Imm8NoSuOperator = imm8nosuoperator;
185
186  /// HasEvenOpcode - This bit is true if the instruction should have an even (as
187  /// opposed to odd) opcode.  Operations on i8 are even, operations on
188  /// other datatypes are usually odd.
189  bit HasEvenOpcode = hasEvenOpcode;
190
191  /// HasREX_W - This bit is set to true if the instruction should have
192  /// the 0x40 REX prefix.  This is set for i64 types.
193  bit HasREX_W = hasREX_W;
194}
195
196def invalid_node : SDNode<"<<invalid_node>>", SDTIntLeaf,[],"<<invalid_node>>">;
197
198def Xi8  : X86TypeInfo<i8, "b", GR8, loadi8, i8mem, Imm8, i8imm,
199                       imm_su, imm, i8imm, invalid_node, invalid_node,
200                       1, 0>;
201def Xi16 : X86TypeInfo<i16, "w", GR16, loadi16, i16mem, Imm16, i16imm,
202                       imm_su, imm, i16i8imm, i16immSExt8_su, i16immSExt8,
203                       0, 0>;
204def Xi32 : X86TypeInfo<i32, "l", GR32, loadi32, i32mem, Imm32, i32imm,
205                       imm_su, imm, i32i8imm, i32immSExt8_su, i32immSExt8,
206                       0, 0>;
207def Xi64 : X86TypeInfo<i64, "q", GR64, loadi64, i64mem, Imm32S, i64i32imm,
208                       i64immSExt32_su, i64immSExt32, i64i8imm, i64immSExt8_su,
209                       i64immSExt8, 0, 1>;
210
211// Group template arguments that can be derived from the vector type (EltNum x
212// EltVT).  These are things like the register class for the writemask, etc.
213// The idea is to pass one of these as the template argument rather than the
214// individual arguments.
215// The template is also used for scalar types, in this case numelts is 1.
216class X86VectorVTInfo<int numelts, ValueType eltvt, RegisterClass rc,
217                      string suffix = ""> {
218  RegisterClass RC = rc;
219  ValueType EltVT = eltvt;
220  int NumElts = numelts;
221
222  // Corresponding mask register class.
223  RegisterClass KRC = !cast<RegisterClass>("VK" # NumElts);
224
225  // Corresponding mask register pair class.
226  RegisterOperand KRPC = !if (!gt(NumElts, 16), ?,
227                              !cast<RegisterOperand>("VK" # NumElts # "Pair"));
228
229  // Corresponding write-mask register class.
230  RegisterClass KRCWM = !cast<RegisterClass>("VK" # NumElts # "WM");
231
232  // The mask VT.
233  ValueType KVT = !cast<ValueType>("v" # NumElts # "i1");
234
235  // Suffix used in the instruction mnemonic.
236  string Suffix = suffix;
237
238  // VTName is a string name for vector VT. For vector types it will be
239  // v # NumElts # EltVT, so for vector of 8 elements of i32 it will be v8i32
240  // It is a little bit complex for scalar types, where NumElts = 1.
241  // In this case we build v4f32 or v2f64
242  string VTName = "v" # !if (!eq (NumElts, 1),
243                        !if (!eq (EltVT.Size, 16), 8,
244                        !if (!eq (EltVT.Size, 32), 4,
245                        !if (!eq (EltVT.Size, 64), 2, NumElts))), NumElts) # EltVT;
246
247  // The vector VT.
248  ValueType VT = !cast<ValueType>(VTName);
249
250  string EltTypeName = !cast<string>(EltVT);
251  // Size of the element type in bits, e.g. 32 for v16i32.
252  string EltSizeName = !subst("i", "", !subst("f", "", !subst("b", "", EltTypeName)));
253  int EltSize = EltVT.Size;
254
255  // "i" for integer types and "f" for floating-point types
256  string TypeVariantName = !subst("b", "", !subst(EltSizeName, "", EltTypeName));
257
258  // Size of RC in bits, e.g. 512 for VR512.
259  int Size = VT.Size;
260
261  // The corresponding memory operand, e.g. i512mem for VR512.
262  X86MemOperand MemOp = !cast<X86MemOperand>(TypeVariantName # Size # "mem");
263  X86MemOperand ScalarMemOp = !cast<X86MemOperand>(!subst("b", "", EltTypeName) # "mem");
264  // FP scalar memory operand for intrinsics - ssmem/sdmem.
265  Operand IntScalarMemOp = !if (!eq (EltTypeName, "f16"), !cast<Operand>("shmem"),
266                           !if (!eq (EltTypeName, "bf16"), !cast<Operand>("shmem"),
267                           !if (!eq (EltTypeName, "f32"), !cast<Operand>("ssmem"),
268                           !if (!eq (EltTypeName, "f64"), !cast<Operand>("sdmem"), ?))));
269
270  // Load patterns
271  PatFrag LdFrag = !cast<PatFrag>("load" # VTName);
272
273  PatFrag AlignedLdFrag = !cast<PatFrag>("alignedload" # VTName);
274
275  PatFrag ScalarLdFrag = !cast<PatFrag>("load" # !subst("b", "", EltTypeName));
276  PatFrag BroadcastLdFrag = !cast<PatFrag>("X86VBroadcastld" # EltSizeName);
277
278  PatFrags ScalarIntMemFrags = !if (!eq (EltTypeName, "f16"), !cast<PatFrags>("sse_load_f16"),
279                               !if (!eq (EltTypeName, "bf16"), !cast<PatFrags>("sse_load_f16"),
280                               !if (!eq (EltTypeName, "f32"), !cast<PatFrags>("sse_load_f32"),
281                               !if (!eq (EltTypeName, "f64"), !cast<PatFrags>("sse_load_f64"), ?))));
282
283  // The string to specify embedded broadcast in assembly.
284  string BroadcastStr = "{1to" # NumElts # "}";
285
286  // 8-bit compressed displacement tuple/subvector format.  This is only
287  // defined for NumElts <= 8.
288  CD8VForm CD8TupleForm = !if (!eq (!srl(NumElts, 4), 0),
289                               !cast<CD8VForm>("CD8VT" # NumElts), ?);
290
291  SubRegIndex SubRegIdx = !if (!eq (Size, 128), sub_xmm,
292                          !if (!eq (Size, 256), sub_ymm, ?));
293
294  Domain ExeDomain = !if (!eq (EltTypeName, "f32"), SSEPackedSingle,
295                     !if (!eq (EltTypeName, "f64"), SSEPackedDouble,
296                     !if (!eq (EltTypeName, "f16"), SSEPackedSingle, // FIXME?
297                     !if (!eq (EltTypeName, "bf16"), SSEPackedSingle, // FIXME?
298                     SSEPackedInt))));
299
300  RegisterClass FRC = !if (!eq (EltTypeName, "f32"), FR32X,
301                      !if (!eq (EltTypeName, "f16"), FR16X,
302                      !if (!eq (EltTypeName, "bf16"), FR16X,
303                      FR64X)));
304
305  dag ImmAllZerosV = (VT immAllZerosV);
306
307  string ZSuffix = !if (!eq (Size, 128), "Z128",
308                   !if (!eq (Size, 256), "Z256", "Z"));
309}
310
311def v64i8_info  : X86VectorVTInfo<64,  i8, VR512, "b">;
312def v32i16_info : X86VectorVTInfo<32, i16, VR512, "w">;
313def v16i32_info : X86VectorVTInfo<16, i32, VR512, "d">;
314def v8i64_info  : X86VectorVTInfo<8,  i64, VR512, "q">;
315def v32f16_info : X86VectorVTInfo<32, f16, VR512, "ph">;
316def v32bf16_info: X86VectorVTInfo<32, bf16, VR512, "pbf">;
317def v16f32_info : X86VectorVTInfo<16, f32, VR512, "ps">;
318def v8f64_info  : X86VectorVTInfo<8,  f64, VR512, "pd">;
319
320// "x" in v32i8x_info means RC = VR256X
321def v32i8x_info  : X86VectorVTInfo<32,  i8, VR256X, "b">;
322def v16i16x_info : X86VectorVTInfo<16, i16, VR256X, "w">;
323def v8i32x_info  : X86VectorVTInfo<8,  i32, VR256X, "d">;
324def v4i64x_info  : X86VectorVTInfo<4,  i64, VR256X, "q">;
325def v16f16x_info : X86VectorVTInfo<16, f16, VR256X, "ph">;
326def v16bf16x_info: X86VectorVTInfo<16, bf16, VR256X, "pbf">;
327def v8f32x_info  : X86VectorVTInfo<8,  f32, VR256X, "ps">;
328def v4f64x_info  : X86VectorVTInfo<4,  f64, VR256X, "pd">;
329
330def v16i8x_info  : X86VectorVTInfo<16,  i8, VR128X, "b">;
331def v8i16x_info  : X86VectorVTInfo<8,  i16, VR128X, "w">;
332def v4i32x_info  : X86VectorVTInfo<4,  i32, VR128X, "d">;
333def v2i64x_info  : X86VectorVTInfo<2,  i64, VR128X, "q">;
334def v8f16x_info  : X86VectorVTInfo<8,  f16, VR128X, "ph">;
335def v8bf16x_info : X86VectorVTInfo<8,  bf16, VR128X, "pbf">;
336def v4f32x_info  : X86VectorVTInfo<4,  f32, VR128X, "ps">;
337def v2f64x_info  : X86VectorVTInfo<2,  f64, VR128X, "pd">;
338
339// We map scalar types to the smallest (128-bit) vector type
340// with the appropriate element type. This allows to use the same masking logic.
341def i32x_info    : X86VectorVTInfo<1,  i32, GR32, "si">;
342def i64x_info    : X86VectorVTInfo<1,  i64, GR64, "sq">;
343def f16x_info    : X86VectorVTInfo<1,  f16, VR128X, "sh">;
344def bf16x_info   : X86VectorVTInfo<1,  bf16, VR128X, "sbf">;
345def f32x_info    : X86VectorVTInfo<1,  f32, VR128X, "ss">;
346def f64x_info    : X86VectorVTInfo<1,  f64, VR128X, "sd">;
347
348class AVX512VLVectorVTInfo<X86VectorVTInfo i512, X86VectorVTInfo i256,
349                           X86VectorVTInfo i128> {
350  X86VectorVTInfo info512 = i512;
351  X86VectorVTInfo info256 = i256;
352  X86VectorVTInfo info128 = i128;
353}
354
355def avx512vl_i8_info  : AVX512VLVectorVTInfo<v64i8_info, v32i8x_info,
356                                             v16i8x_info>;
357def avx512vl_i16_info : AVX512VLVectorVTInfo<v32i16_info, v16i16x_info,
358                                             v8i16x_info>;
359def avx512vl_i32_info : AVX512VLVectorVTInfo<v16i32_info, v8i32x_info,
360                                             v4i32x_info>;
361def avx512vl_i64_info : AVX512VLVectorVTInfo<v8i64_info, v4i64x_info,
362                                             v2i64x_info>;
363def avx512vl_f16_info : AVX512VLVectorVTInfo<v32f16_info, v16f16x_info,
364                                             v8f16x_info>;
365def avx512vl_bf16_info : AVX512VLVectorVTInfo<v32bf16_info, v16bf16x_info,
366                                             v8bf16x_info>;
367def avx512vl_f32_info : AVX512VLVectorVTInfo<v16f32_info, v8f32x_info,
368                                             v4f32x_info>;
369def avx512vl_f64_info : AVX512VLVectorVTInfo<v8f64_info, v4f64x_info,
370                                             v2f64x_info>;
371
372class X86KVectorVTInfo<RegisterClass _krc, RegisterClass _krcwm,
373                       ValueType _vt> {
374  RegisterClass KRC = _krc;
375  RegisterClass KRCWM = _krcwm;
376  ValueType KVT = _vt;
377}
378
379def v1i1_info : X86KVectorVTInfo<VK1, VK1WM, v1i1>;
380def v2i1_info : X86KVectorVTInfo<VK2, VK2WM, v2i1>;
381def v4i1_info : X86KVectorVTInfo<VK4, VK4WM, v4i1>;
382def v8i1_info : X86KVectorVTInfo<VK8, VK8WM, v8i1>;
383def v16i1_info : X86KVectorVTInfo<VK16, VK16WM, v16i1>;
384def v32i1_info : X86KVectorVTInfo<VK32, VK32WM, v32i1>;
385def v64i1_info : X86KVectorVTInfo<VK64, VK64WM, v64i1>;
386
387// Subclasses of X86Inst
388class PseudoI<dag oops, dag iops, list<dag> pattern>
389  : X86Inst<0, Pseudo, NoImm, oops, iops, ""> {
390  let Pattern = pattern;
391}
392
393class I<bits<8> o, Format f, dag outs, dag ins, string asm,
394        list<dag> pattern, Domain d = GenericDomain>
395  : X86Inst<o, f, NoImm, outs, ins, asm, d> {
396  let Pattern = pattern;
397}
398class Ii8<bits<8> o, Format f, dag outs, dag ins, string asm,
399          list<dag> pattern, Domain d = GenericDomain>
400  : X86Inst<o, f, Imm8, outs, ins, asm, d> {
401  let Pattern = pattern;
402}
403class Ii8Reg<bits<8> o, Format f, dag outs, dag ins, string asm,
404             list<dag> pattern, Domain d = GenericDomain>
405  : X86Inst<o, f, Imm8Reg, outs, ins, asm, d> {
406  let Pattern = pattern;
407}
408class Ii8PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
409               list<dag> pattern>
410  : X86Inst<o, f, Imm8PCRel, outs, ins, asm> {
411  let Pattern = pattern;
412}
413class Ii16<bits<8> o, Format f, dag outs, dag ins, string asm,
414           list<dag> pattern>
415  : X86Inst<o, f, Imm16, outs, ins, asm> {
416  let Pattern = pattern;
417}
418class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm,
419           list<dag> pattern>
420  : X86Inst<o, f, Imm32, outs, ins, asm> {
421  let Pattern = pattern;
422}
423class Ii32S<bits<8> o, Format f, dag outs, dag ins, string asm,
424            list<dag> pattern>
425  : X86Inst<o, f, Imm32S, outs, ins, asm> {
426  let Pattern = pattern;
427}
428
429class Ii64<bits<8> o, Format f, dag outs, dag ins, string asm,
430           list<dag> pattern>
431  : X86Inst<o, f, Imm64, outs, ins, asm> {
432  let Pattern = pattern;
433}
434
435class Ii16PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
436           list<dag> pattern>
437           : X86Inst<o, f, Imm16PCRel, outs, ins, asm> {
438  let Pattern = pattern;
439}
440
441class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
442           list<dag> pattern>
443  : X86Inst<o, f, Imm32PCRel, outs, ins, asm> {
444  let Pattern = pattern;
445}
446
447// FPStack Instruction Templates:
448// FPI - Floating Point Instruction template.
449class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
450  : I<o, F, outs, ins, asm, []> {
451  let Defs = [FPSW];
452  let Predicates = [HasX87];
453}
454
455// FpI_ - Floating Point Pseudo Instruction template.
456class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
457  : PseudoI<outs, ins, pattern> {
458  let FPForm = fp;
459  let Defs = [FPSW];
460  let Predicates = [HasX87];
461}
462
463// Templates for instructions that use a 16- or 32-bit segmented address as
464//  their only operand: lcall (FAR CALL) and ljmp (FAR JMP)
465//
466//   Iseg16 - 16-bit segment selector, 16-bit offset
467//   Iseg32 - 16-bit segment selector, 32-bit offset
468
469class Iseg16 <bits<8> o, Format f, dag outs, dag ins, string asm,
470              list<dag> pattern>
471      : X86Inst<o, f, Imm16, outs, ins, asm> {
472  let Pattern = pattern;
473}
474
475class Iseg32 <bits<8> o, Format f, dag outs, dag ins, string asm,
476              list<dag> pattern>
477      : X86Inst<o, f, Imm32, outs, ins, asm> {
478  let Pattern = pattern;
479}
480
481// SI - SSE 1 & 2 scalar instructions
482class SI<bits<8> o, Format F, dag outs, dag ins, string asm,
483         list<dag> pattern, Domain d = GenericDomain>
484      : I<o, F, outs, ins, asm, pattern, d> {
485  let Predicates = !if(!eq(OpEnc.Value, EncEVEX.Value), [HasAVX512],
486                   !if(!eq(OpEnc.Value, EncVEX.Value), [UseAVX],
487                   !if(!eq(OpPrefix.Value, XS.Value), [UseSSE1],
488                   !if(!eq(OpPrefix.Value, XD.Value), [UseSSE2],
489                   !if(!eq(OpPrefix.Value, PD.Value), [UseSSE2],
490                   [UseSSE1])))));
491
492  // AVX instructions have a 'v' prefix in the mnemonic
493  let AsmString = !if(!eq(OpEnc.Value, EncEVEX.Value), !strconcat("v", asm),
494                  !if(!eq(OpEnc.Value, EncVEX.Value), !strconcat("v", asm),
495                  asm));
496}
497
498// SI - SSE 1 & 2 scalar intrinsics - vex form available on AVX512
499class SI_Int<bits<8> o, Format F, dag outs, dag ins, string asm,
500         list<dag> pattern, Domain d = GenericDomain>
501      : I<o, F, outs, ins, asm, pattern, d> {
502  let Predicates = !if(!eq(OpEnc.Value, EncEVEX.Value), [HasAVX512],
503                   !if(!eq(OpEnc.Value, EncVEX.Value), [UseAVX],
504                   !if(!eq(OpPrefix.Value, XS.Value), [UseSSE1],
505                   !if(!eq(OpPrefix.Value, XD.Value), [UseSSE2],
506                   !if(!eq(OpPrefix.Value, PD.Value), [UseSSE2],
507                   [UseSSE1])))));
508
509  // AVX instructions have a 'v' prefix in the mnemonic
510  let AsmString = !if(!eq(OpEnc.Value, EncEVEX.Value), !strconcat("v", asm),
511                  !if(!eq(OpEnc.Value, EncVEX.Value), !strconcat("v", asm),
512                  asm));
513}
514// SIi8 - SSE 1 & 2 scalar instructions - vex form available on AVX512
515class SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
516           list<dag> pattern>
517      : Ii8<o, F, outs, ins, asm, pattern> {
518  let Predicates = !if(!eq(OpEnc.Value, EncEVEX.Value), [HasAVX512],
519                   !if(!eq(OpEnc.Value, EncVEX.Value), [HasAVX],
520                   !if(!eq(OpPrefix.Value, XS.Value), [UseSSE1],
521                   [UseSSE2])));
522
523  // AVX instructions have a 'v' prefix in the mnemonic
524  let AsmString = !if(!eq(OpEnc.Value, EncEVEX.Value), !strconcat("v", asm),
525                  !if(!eq(OpEnc.Value, EncVEX.Value), !strconcat("v", asm),
526                  asm));
527}
528
529// PI - SSE 1 & 2 packed instructions
530class PI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern,
531         Domain d>
532      : I<o, F, outs, ins, asm, pattern, d> {
533  let Predicates = !if(!eq(OpEnc.Value, EncEVEX.Value), [HasAVX512],
534                   !if(!eq(OpEnc.Value, EncVEX.Value), [HasAVX],
535                   !if(!eq(OpPrefix.Value, PD.Value), [UseSSE2],
536                   [UseSSE1])));
537
538  // AVX instructions have a 'v' prefix in the mnemonic
539  let AsmString = !if(!eq(OpEnc.Value, EncEVEX.Value), !strconcat("v", asm),
540                  !if(!eq(OpEnc.Value, EncVEX.Value), !strconcat("v", asm),
541                  asm));
542}
543
544// MMXPI - SSE 1 & 2 packed instructions with MMX operands
545class MMXPI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern,
546            Domain d>
547      : I<o, F, outs, ins, asm, pattern, d> {
548  let Predicates = !if(!eq(OpPrefix.Value, PD.Value), [HasMMX, HasSSE2],
549                       [HasMMX, HasSSE1]);
550}
551
552// PIi8 - SSE 1 & 2 packed instructions with immediate
553class PIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
554           list<dag> pattern, Domain d>
555      : Ii8<o, F, outs, ins, asm, pattern, d> {
556  let Predicates = !if(!eq(OpEnc.Value, EncEVEX.Value), [HasAVX512],
557                   !if(!eq(OpEnc.Value, EncVEX.Value), [HasAVX],
558                   !if(!eq(OpPrefix.Value, PD.Value), [UseSSE2],
559                   [UseSSE1])));
560
561  // AVX instructions have a 'v' prefix in the mnemonic
562  let AsmString = !if(!eq(OpEnc.Value, EncEVEX.Value), !strconcat("v", asm),
563                  !if(!eq(OpEnc.Value, EncVEX.Value), !strconcat("v", asm),
564                  asm));
565}
566
567// SSE1 Instruction Templates:
568//
569//   SSI   - SSE1 instructions with XS prefix.
570//   PSI   - SSE1 instructions with PS prefix.
571//   PSIi8 - SSE1 instructions with ImmT == Imm8 and PS prefix.
572//   VSSI  - SSE1 instructions with XS prefix in AVX form.
573//   VPSI  - SSE1 instructions with PS prefix in AVX form, packed single.
574
575class SSI<bits<8> o, Format F, dag outs, dag ins, string asm,
576          list<dag> pattern>
577      : I<o, F, outs, ins, asm, pattern>, TB, XS, Requires<[UseSSE1]>;
578class SSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
579            list<dag> pattern>
580      : Ii8<o, F, outs, ins, asm, pattern>, TB, XS, Requires<[UseSSE1]>;
581class PSI<bits<8> o, Format F, dag outs, dag ins, string asm,
582          list<dag> pattern>
583      : I<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB,
584        Requires<[UseSSE1]>;
585class PSIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
586            list<dag> pattern>
587      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB,
588        Requires<[UseSSE1]>;
589class VSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
590           list<dag> pattern>
591      : I<o, F, outs, ins, !strconcat("v", asm), pattern>, TB, XS,
592        Requires<[HasAVX]>;
593class VPSI<bits<8> o, Format F, dag outs, dag ins, string asm,
594           list<dag> pattern>
595      : I<o, F, outs, ins, !strconcat("v", asm), pattern, SSEPackedSingle>,
596        TB, Requires<[HasAVX]>;
597
598// SSE2 Instruction Templates:
599//
600//   SDI    - SSE2 instructions with XD prefix.
601//   SDIi8  - SSE2 instructions with ImmT == Imm8 and XD prefix.
602//   S2SI   - SSE2 instructions with XS prefix.
603//   SSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix.
604//   PDI    - SSE2 instructions with PD prefix, packed double domain.
605//   PDIi8  - SSE2 instructions with ImmT == Imm8 and PD prefix.
606//   VSDI   - SSE2 scalar instructions with XD prefix in AVX form.
607//   VPDI   - SSE2 vector instructions with PD prefix in AVX form,
608//                 packed double domain.
609//   VS2I   - SSE2 scalar instructions with PD prefix in AVX form.
610//   S2I    - SSE2 scalar instructions with PD prefix.
611//   MMXSDIi8  - SSE2 instructions with ImmT == Imm8 and XD prefix as well as
612//               MMX operands.
613//   MMXSSDIi8 - SSE2 instructions with ImmT == Imm8 and XS prefix as well as
614//               MMX operands.
615
616class SDI<bits<8> o, Format F, dag outs, dag ins, string asm,
617          list<dag> pattern>
618      : I<o, F, outs, ins, asm, pattern>, TB, XD, Requires<[UseSSE2]>;
619class SDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
620            list<dag> pattern>
621      : Ii8<o, F, outs, ins, asm, pattern>, TB, XD, Requires<[UseSSE2]>;
622class S2SI<bits<8> o, Format F, dag outs, dag ins, string asm,
623           list<dag> pattern>
624      : I<o, F, outs, ins, asm, pattern>, TB, XS, Requires<[UseSSE2]>;
625class S2SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
626             list<dag> pattern>
627      : Ii8<o, F, outs, ins, asm, pattern>, TB, XS, Requires<[UseSSE2]>;
628class PDI<bits<8> o, Format F, dag outs, dag ins, string asm,
629          list<dag> pattern>
630      : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, PD,
631        Requires<[UseSSE2]>;
632class PDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
633            list<dag> pattern>
634      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, PD,
635        Requires<[UseSSE2]>;
636class VSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
637           list<dag> pattern>
638      : I<o, F, outs, ins, !strconcat("v", asm), pattern>, TB, XD,
639        Requires<[UseAVX]>;
640class VS2SI<bits<8> o, Format F, dag outs, dag ins, string asm,
641            list<dag> pattern>
642      : I<o, F, outs, ins, !strconcat("v", asm), pattern>, TB, XS,
643        Requires<[HasAVX]>;
644class VPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
645           list<dag> pattern>
646      : I<o, F, outs, ins, !strconcat("v", asm), pattern, SSEPackedDouble>,
647        TB, PD, Requires<[HasAVX]>;
648class VS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
649           list<dag> pattern>
650      : I<o, F, outs, ins, !strconcat("v", asm), pattern>, TB, PD,
651        Requires<[UseAVX]>;
652class S2I<bits<8> o, Format F, dag outs, dag ins, string asm,
653           list<dag> pattern>
654      : I<o, F, outs, ins, asm, pattern>, TB, PD, Requires<[UseSSE2]>;
655class MMXSDIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
656               list<dag> pattern>
657      : Ii8<o, F, outs, ins, asm, pattern>, TB, XD, Requires<[HasMMX, HasSSE2]>;
658class MMXS2SIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
659                list<dag> pattern>
660      : Ii8<o, F, outs, ins, asm, pattern>, TB, XS, Requires<[HasMMX, HasSSE2]>;
661
662// SSE3 Instruction Templates:
663//
664//   S3I   - SSE3 instructions with PD prefixes.
665//   S3SI  - SSE3 instructions with XS prefix.
666//   S3DI  - SSE3 instructions with XD prefix.
667
668class S3SI<bits<8> o, Format F, dag outs, dag ins, string asm,
669           list<dag> pattern>
670      : I<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB, XS,
671        Requires<[UseSSE3]>;
672class S3DI<bits<8> o, Format F, dag outs, dag ins, string asm,
673           list<dag> pattern>
674      : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, XD,
675        Requires<[UseSSE3]>;
676class S3I<bits<8> o, Format F, dag outs, dag ins, string asm,
677          list<dag> pattern>
678      : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, PD,
679        Requires<[UseSSE3]>;
680
681
682// SSSE3 Instruction Templates:
683//
684//   SS38I - SSSE3 instructions with T8 prefix.
685//   SS3AI - SSSE3 instructions with TA prefix.
686//   MMXSS38I - SSSE3 instructions with T8 prefix and MMX operands.
687//   MMXSS3AI - SSSE3 instructions with TA prefix and MMX operands.
688//
689// Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
690// uses the MMX registers. The 64-bit versions are grouped with the MMX
691// classes. They need to be enabled even if AVX is enabled.
692
693class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
694            list<dag> pattern>
695      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
696        Requires<[UseSSSE3]>;
697class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
698            list<dag> pattern>
699      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
700        Requires<[UseSSSE3]>;
701class MMXSS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
702               list<dag> pattern>
703      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8,
704        Requires<[HasMMX, HasSSSE3]>;
705class MMXSS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
706               list<dag> pattern>
707      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA,
708        Requires<[HasMMX, HasSSSE3]>;
709
710// SSE4.1 Instruction Templates:
711//
712//   SS48I - SSE 4.1 instructions with T8 prefix.
713//   SS41AIi8 - SSE 4.1 instructions with TA prefix and ImmT == Imm8.
714//
715class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
716            list<dag> pattern>
717      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
718        Requires<[UseSSE41]>;
719class SS4AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
720            list<dag> pattern>
721      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
722        Requires<[UseSSE41]>;
723
724// SSE4.2 Instruction Templates:
725//
726//   SS428I - SSE 4.2 instructions with T8 prefix.
727class SS428I<bits<8> o, Format F, dag outs, dag ins, string asm,
728             list<dag> pattern>
729      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
730        Requires<[UseSSE42]>;
731
732//   SS42AI = SSE 4.2 instructions with TA prefix
733class SS42AI<bits<8> o, Format F, dag outs, dag ins, string asm,
734             list<dag> pattern>
735      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
736        Requires<[UseSSE42]>;
737
738// AVX Instruction Templates:
739//   Instructions introduced in AVX (no SSE equivalent forms)
740//
741//   AVX8I - AVX instructions with T8, PD prefix.
742//   AVXAIi8 - AVX instructions with TA, PD prefix and ImmT = Imm8.
743class AVX8I<bits<8> o, Format F, dag outs, dag ins, string asm,
744            list<dag> pattern>
745      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
746        Requires<[HasAVX]>;
747class AVXAIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
748              list<dag> pattern>
749      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
750        Requires<[HasAVX]>;
751
752// AVX2 Instruction Templates:
753//   Instructions introduced in AVX2 (no SSE equivalent forms)
754//
755//   AVX28I - AVX2 instructions with T8, PD prefix.
756//   AVX2AIi8 - AVX2 instructions with TA, PD prefix and ImmT = Imm8.
757class AVX28I<bits<8> o, Format F, dag outs, dag ins, string asm,
758            list<dag> pattern>
759      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
760        Requires<[HasAVX2]>;
761class AVX2AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
762              list<dag> pattern>
763      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
764        Requires<[HasAVX2]>;
765
766
767// AVX-512 Instruction Templates:
768//   Instructions introduced in AVX-512 (no SSE equivalent forms)
769//
770//   AVX5128I - AVX-512 instructions with T8, PD prefix.
771//   AVX512AIi8 - AVX-512 instructions with TA, PD prefix and ImmT = Imm8.
772//   AVX512PDI  - AVX-512 instructions with PD, double packed.
773//   AVX512PSI  - AVX-512 instructions with PS, single packed.
774//   AVX512XS8I - AVX-512 instructions with T8 and XS prefixes.
775//   AVX512XSI  - AVX-512 instructions with XS prefix, generic domain.
776//   AVX512BI   - AVX-512 instructions with PD, int packed domain.
777//   AVX512SI   - AVX-512 scalar instructions with PD prefix.
778
779class AVX5128I<bits<8> o, Format F, dag outs, dag ins, string asm,
780            list<dag> pattern>
781      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
782        Requires<[HasAVX512]>;
783class AVX5128IBase : T8, PD {
784  Domain ExeDomain = SSEPackedInt;
785}
786class AVX512XS8I<bits<8> o, Format F, dag outs, dag ins, string asm,
787            list<dag> pattern>
788      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, XS,
789        Requires<[HasAVX512]>;
790class AVX512XSI<bits<8> o, Format F, dag outs, dag ins, string asm,
791            list<dag> pattern>
792      : I<o, F, outs, ins, asm, pattern>, TB, XS,
793        Requires<[HasAVX512]>;
794class AVX512XDI<bits<8> o, Format F, dag outs, dag ins, string asm,
795            list<dag> pattern>
796      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, TB, XD,
797        Requires<[HasAVX512]>;
798class AVX512BI<bits<8> o, Format F, dag outs, dag ins, string asm,
799            list<dag> pattern>
800      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, TB, PD,
801        Requires<[HasAVX512]>;
802class AVX512BIBase : TB, PD {
803  Domain ExeDomain = SSEPackedInt;
804}
805class AVX512BIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
806              list<dag> pattern>
807      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TB, PD,
808        Requires<[HasAVX512]>;
809class AVX512AIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
810              list<dag> pattern>
811      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
812        Requires<[HasAVX512]>;
813class AVX512AIi8Base : TA, PD {
814  ImmType ImmT = Imm8;
815}
816class AVX512Ii8<bits<8> o, Format F, dag outs, dag ins, string asm,
817              list<dag> pattern>
818      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>,
819        Requires<[HasAVX512]>;
820class AVX512PDI<bits<8> o, Format F, dag outs, dag ins, string asm,
821           list<dag> pattern>
822      : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>, TB, PD,
823        Requires<[HasAVX512]>;
824class AVX512PSI<bits<8> o, Format F, dag outs, dag ins, string asm,
825           list<dag> pattern>
826      : I<o, F, outs, ins, asm, pattern, SSEPackedSingle>, TB,
827        Requires<[HasAVX512]>;
828class AVX512PIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
829              list<dag> pattern, Domain d>
830      : Ii8<o, F, outs, ins, asm, pattern, d>, Requires<[HasAVX512]>;
831class AVX512PI<bits<8> o, Format F, dag outs, dag ins, string asm,
832              list<dag> pattern, Domain d>
833      : I<o, F, outs, ins, asm, pattern, d>, Requires<[HasAVX512]>;
834class AVX512FMA3S<bits<8> o, Format F, dag outs, dag ins, string asm,
835           list<dag>pattern>
836      : I<o, F, outs, ins, asm, pattern>, T8, PD,
837        EVEX, VVVV, Requires<[HasAVX512]>;
838
839class AVX512<bits<8> o, Format F, dag outs, dag ins, string asm,
840           list<dag>pattern>
841      : I<o, F, outs, ins, asm, pattern>, Requires<[HasAVX512]>;
842
843// AES Instruction Templates:
844//
845// AES8I
846// These use the same encoding as the SSE4.2 T8 and TA encodings.
847class AES8I<bits<8> o, Format F, dag outs, dag ins, string asm,
848            list<dag>pattern>
849      : I<o, F, outs, ins, asm, pattern, SSEPackedInt>, T8, PD,
850        Requires<[NoAVX, HasAES]>;
851
852class AESAI<bits<8> o, Format F, dag outs, dag ins, string asm,
853            list<dag> pattern>
854      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
855        Requires<[NoAVX, HasAES]>;
856
857// PCLMUL Instruction Templates
858class PCLMULIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
859               list<dag>pattern>
860      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD;
861
862// FMA3 Instruction Templates
863class FMA3<bits<8> o, Format F, dag outs, dag ins, string asm,
864           list<dag>pattern>
865      : I<o, F, outs, ins, asm, pattern>, T8, PD,
866        VEX, VVVV, FMASC, Requires<[HasFMA, NoFMA4, NoVLX]>;
867class FMA3S<bits<8> o, Format F, dag outs, dag ins, string asm,
868            list<dag>pattern>
869      : I<o, F, outs, ins, asm, pattern>, T8, PD,
870        VEX, VVVV, FMASC, Requires<[HasFMA, NoFMA4, NoAVX512]>;
871class FMA3S_Int<bits<8> o, Format F, dag outs, dag ins, string asm,
872                list<dag>pattern>
873      : I<o, F, outs, ins, asm, pattern>, T8, PD,
874        VEX, VVVV, FMASC, Requires<[HasFMA, NoAVX512]>;
875
876// FMA4 Instruction Templates
877class FMA4<bits<8> o, Format F, dag outs, dag ins, string asm,
878           list<dag>pattern>
879      : Ii8Reg<o, F, outs, ins, asm, pattern>, TA, PD,
880        VEX, VVVV, FMASC, Requires<[HasFMA4, NoVLX]>;
881class FMA4S<bits<8> o, Format F, dag outs, dag ins, string asm,
882            list<dag>pattern>
883      : Ii8Reg<o, F, outs, ins, asm, pattern>, TA, PD,
884        VEX, VVVV, FMASC, Requires<[HasFMA4, NoAVX512]>;
885class FMA4S_Int<bits<8> o, Format F, dag outs, dag ins, string asm,
886                list<dag>pattern>
887      : Ii8Reg<o, F, outs, ins, asm, pattern>, TA, PD,
888        VEX, VVVV, FMASC, Requires<[HasFMA4]>;
889
890// XOP 2, 3 and 4 Operand Instruction Template
891class IXOP<bits<8> o, Format F, dag outs, dag ins, string asm,
892           list<dag> pattern>
893      : I<o, F, outs, ins, asm, pattern, SSEPackedDouble>,
894         XOP9, Requires<[HasXOP]>;
895
896// XOP 2 and 3 Operand Instruction Templates with imm byte
897class IXOPi8<bits<8> o, Format F, dag outs, dag ins, string asm,
898           list<dag> pattern>
899      : Ii8<o, F, outs, ins, asm, pattern, SSEPackedDouble>,
900         XOP8, Requires<[HasXOP]>;
901// XOP 4 Operand Instruction Templates with imm byte
902class IXOPi8Reg<bits<8> o, Format F, dag outs, dag ins, string asm,
903           list<dag> pattern>
904      : Ii8Reg<o, F, outs, ins, asm, pattern, SSEPackedDouble>,
905         XOP8, Requires<[HasXOP]>;
906
907//  XOP 5 operand instruction (VEX encoding!)
908class IXOP5<bits<8> o, Format F, dag outs, dag ins, string asm,
909           list<dag>pattern>
910      : Ii8Reg<o, F, outs, ins, asm, pattern, SSEPackedInt>, TA, PD,
911        VEX, VVVV, Requires<[HasXOP]>;
912
913// X86-64 Instruction templates...
914//
915
916class RI<bits<8> o, Format F, dag outs, dag ins, string asm,
917         list<dag> pattern>
918      : I<o, F, outs, ins, asm, pattern>, REX_W;
919class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
920            list<dag> pattern>
921      : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
922class RIi16 <bits<8> o, Format F, dag outs, dag ins, string asm,
923            list<dag> pattern>
924      : Ii16<o, F, outs, ins, asm, pattern>, REX_W;
925class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
926             list<dag> pattern>
927      : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
928class RIi32S <bits<8> o, Format F, dag outs, dag ins, string asm,
929              list<dag> pattern>
930      : Ii32S<o, F, outs, ins, asm, pattern>, REX_W;
931class RIi64<bits<8> o, Format F, dag outs, dag ins, string asm,
932            list<dag> pattern>
933      : Ii64<o, F, outs, ins, asm, pattern>, REX_W;
934
935class RS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
936           list<dag> pattern>
937      : S2I<o, F, outs, ins, asm, pattern>, REX_W;
938class VRS2I<bits<8> o, Format F, dag outs, dag ins, string asm,
939           list<dag> pattern>
940      : VS2I<o, F, outs, ins, asm, pattern>, REX_W;
941
942// MMX Instruction templates
943//
944// MMXI   - MMX instructions with TB prefix.
945// MMXRI  - MMX instructions with TB prefix and REX.W.
946// MMXIi8 - MMX instructions with ImmT == Imm8 and PS prefix.
947class MMXI<bits<8> o, Format F, dag outs, dag ins, string asm,
948           list<dag> pattern>
949      : I<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
950class MMXRI<bits<8> o, Format F, dag outs, dag ins, string asm,
951            list<dag> pattern>
952      : I<o, F, outs, ins, asm, pattern>, TB, REX_W,
953        Requires<[HasMMX,In64BitMode]>;
954class MMXIi8<bits<8> o, Format F, dag outs, dag ins, string asm,
955             list<dag> pattern>
956      : Ii8<o, F, outs, ins, asm, pattern>, TB, Requires<[HasMMX]>;
957
958/// ITy - This instruction base class takes the type info for the instruction.
959/// Using this, it:
960/// 1. Concatenates together the instruction mnemonic with the appropriate
961///    suffix letter, a tab, and the arguments.
962/// 2. Infers whether the instruction should have a 0x40 REX_W prefix.
963/// 3. Infers whether the low bit of the opcode should be 0 (for i8 operations)
964///    or 1 (for i16,i32,i64 operations).
965class ITy<bits<8> o, Format f, X86TypeInfo t, dag outs, dag ins, string m,
966          string args, list<dag> p>
967  : I<{o{7}, o{6}, o{5}, o{4}, o{3}, o{2}, o{1},
968       !if(!eq(t.HasEvenOpcode, 1), 0, o{0})}, f, outs, ins,
969      !strconcat(m, "{", t.InstrSuffix, "}\t", args), p>, NoCD8 {
970  let hasSideEffects = 0;
971  let hasREX_W  = t.HasREX_W;
972  let IgnoresW = !if(!eq(t.VT, i8), 1, 0);
973}
974
975// BinOpRR - Instructions that read "reg, reg".
976class BinOpRR<bits<8> o, string m, string args, X86TypeInfo t, dag out, list<dag> p>
977  : ITy<o, MRMDestReg, t, out, (ins t.RegClass:$src1, t.RegClass:$src2), m,
978        args, p>, Sched<[WriteALU]>;
979// BinOpRR_F - Instructions that read "reg, reg" and write EFLAGS only.
980class BinOpRR_F<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
981  : BinOpRR<o, m, binop_args, t, (outs),
982            [(set EFLAGS, (node t.RegClass:$src1, t.RegClass:$src2))]>,
983    DefEFLAGS;
984// BinOpRR_F_Rev - Reversed encoding of BinOpRR_F
985class BinOpRR_F_Rev<bits<8> o, string m, X86TypeInfo t>
986  : BinOpRR_F<o, m, t, null_frag>, DisassembleOnly {
987  let Form = MRMSrcReg;
988}
989// BinOpRR_R - Instructions that read "reg, reg" and write "reg".
990class BinOpRR_R<bits<8> o, string m, X86TypeInfo t, bit ndd = 0>
991  : BinOpRR<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t,
992            (outs t.RegClass:$dst), []>, NDD<ndd>;
993// BinOpRR_R_Rev - Reversed encoding of BinOpRR_R
994class BinOpRR_R_Rev<bits<8> o, string m, X86TypeInfo t, bit ndd = 0>
995  : BinOpRR_R<o, m, t, ndd>, DisassembleOnly {
996  let Form = MRMSrcReg;
997}
998// BinOpRR_RF - Instructions that read "reg, reg", and write "reg", EFLAGS.
999class BinOpRR_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node, bit ndd = 0>
1000  : BinOpRR<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t,
1001            (outs t.RegClass:$dst),
1002            [(set t.RegClass:$dst, EFLAGS,
1003             (node t.RegClass:$src1, t.RegClass:$src2))]>, DefEFLAGS, NDD<ndd>;
1004// BinOpRR_RF_Rev - Reversed encoding of BinOpRR_RF.
1005class BinOpRR_RF_Rev<bits<8> o, string m, X86TypeInfo t, bit ndd = 0>
1006  : BinOpRR_RF<o, m, t, null_frag, ndd>, DisassembleOnly {
1007  let Form = MRMSrcReg;
1008}
1009// BinOpRRF_RF - Instructions that read "reg, reg", write "reg" and read/write
1010// EFLAGS.
1011class BinOpRRF_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node = null_frag, bit ndd = 0>
1012  : BinOpRR<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, (outs t.RegClass:$dst),
1013            [(set t.RegClass:$dst, EFLAGS,
1014             (node t.RegClass:$src1, t.RegClass:$src2,
1015             EFLAGS))]>, DefEFLAGS, UseEFLAGS, NDD<ndd> {
1016  let SchedRW = [WriteADC];
1017}
1018// BinOpRRF_RF_Rev - Reversed encoding of BinOpRRF_RF
1019class BinOpRRF_RF_Rev<bits<8> o, string m, X86TypeInfo t, bit ndd = 0>
1020  : BinOpRRF_RF<o, m, t, null_frag, ndd>, DisassembleOnly {
1021  let Form = MRMSrcReg;
1022}
1023
1024// BinOpRM - Instructions that read "reg, [mem]".
1025class BinOpRM<bits<8> o, string m, string args, X86TypeInfo t, dag out, list<dag> p>
1026  : ITy<o, MRMSrcMem, t, out, (ins t.RegClass:$src1, t.MemOperand:$src2), m,
1027        args, p>,
1028    Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]> {
1029  let mayLoad = 1;
1030}
1031// BinOpRM_F - Instructions that read "reg, [mem]" and write EFLAGS only.
1032class BinOpRM_F<bits<8> o, string m, X86TypeInfo t, SDNode node>
1033  : BinOpRM<o, m, binop_args, t, (outs),
1034            [(set EFLAGS, (node t.RegClass:$src1,
1035             (t.LoadNode addr:$src2)))]>, DefEFLAGS;
1036// BinOpRM_R - Instructions that read "reg, [mem]", and write "reg".
1037class BinOpRM_R<bits<8> o, string m, X86TypeInfo t, bit ndd = 0>
1038  : BinOpRM<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, (outs t.RegClass:$dst),
1039            []>, NDD<ndd>;
1040// BinOpRM_RF - Instructions that read "reg, [mem]", and write "reg", EFLAGS.
1041class BinOpRM_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node, bit ndd = 0>
1042  : BinOpRM<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, (outs t.RegClass:$dst),
1043            [(set t.RegClass:$dst, EFLAGS, (node t.RegClass:$src1,
1044             (t.LoadNode addr:$src2)))]>, DefEFLAGS, NDD<ndd>;
1045// BinOpRMF_RF - Instructions that read "reg, [mem]", write "reg" and read/write
1046// EFLAGS.
1047class BinOpRMF_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node = null_frag, bit ndd = 0>
1048  : BinOpRM<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, (outs t.RegClass:$dst),
1049            [(set t.RegClass:$dst, EFLAGS,
1050             (node t.RegClass:$src1, (t.LoadNode addr:$src2), EFLAGS))]>,
1051    DefEFLAGS, UseEFLAGS, NDD<ndd> {
1052  let SchedRW = [WriteADC.Folded, WriteADC.ReadAfterFold,
1053                 // base, scale, index, offset, segment.
1054                 ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
1055                 // implicit register read.
1056                 WriteADC.ReadAfterFold];
1057}
1058
1059// BinOpRI - Instructions that read "reg, imm".
1060class BinOpRI<bits<8> o, string m, string args, X86TypeInfo t, Format f, dag out, list<dag> p>
1061  : ITy<o, f, t, out, (ins t.RegClass:$src1, t.ImmOperand:$src2), m,
1062        args, p>, Sched<[WriteALU]> {
1063  let ImmT = t.ImmEncoding;
1064}
1065// BinOpRI_F - Instructions that read "reg, imm" and write EFLAGS only.
1066class BinOpRI_F<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node,
1067                Format f>
1068  : BinOpRI<o, m, binop_args, t, f, (outs),
1069            [(set EFLAGS, (node t.RegClass:$src1,
1070             t.ImmOperator:$src2))]>, DefEFLAGS;
1071// BinOpRI_R - Instructions that read "reg, imm" and write "reg".
1072class BinOpRI_R<bits<8> o, string m, X86TypeInfo t, Format f, bit ndd = 0>
1073  : BinOpRI<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst),
1074            []>, NDD<ndd>;
1075// BinOpRI8U_R - Instructions that read "reg, u8imm" and write "reg".
1076class BinOpRI8U_R<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag, bit ndd = 0>
1077  : ITy<0xC1, f, t, (outs t.RegClass:$dst), (ins t.RegClass:$src1, u8imm:$src2), m,
1078        !if(!eq(ndd, 0), binop_args, binop_ndd_args),
1079        [(set t.RegClass:$dst, (node t.RegClass:$src1, (i8 imm:$src2)))]>, NDD<ndd> {
1080  let ImmT = Imm8;
1081}
1082// BinOpRI_RF - Instructions that read "reg, imm" and write "reg", EFLAGS.
1083class BinOpRI_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node, Format f, bit ndd = 0>
1084  : BinOpRI<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst),
1085            [(set t.RegClass:$dst, EFLAGS,
1086             (node t.RegClass:$src1, t.ImmOperator:$src2))]>, DefEFLAGS, NDD<ndd>;
1087// BinOpRIF_RF - Instructions that read "reg, imm", write "reg" and read/write
1088// EFLAGS.
1089class BinOpRIF_RF<bits<8> o, string m, X86TypeInfo t, SDNode node, Format f, bit ndd = 0>
1090  : BinOpRI<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst),
1091            [(set t.RegClass:$dst, EFLAGS,
1092             (node t.RegClass:$src1, t.ImmOperator:$src2,
1093             EFLAGS))]>, DefEFLAGS, UseEFLAGS, NDD<ndd> {
1094  let SchedRW = [WriteADC];
1095}
1096// BinOpRI8 - Instructions that read "reg, imm8".
1097class BinOpRI8<bits<8> o, string m, string args, X86TypeInfo t, Format f, dag out>
1098  : ITy<o, f, t, out, (ins t.RegClass:$src1, t.Imm8Operand:$src2), m,
1099        args, []>, Sched<[WriteALU]> {
1100  let ImmT = Imm8;
1101}
1102// BinOpRI8_F - Instructions that read "reg, imm8" and write EFLAGS only.
1103class BinOpRI8_F<bits<8> o, string m, X86TypeInfo t, Format f>
1104  : BinOpRI8<o, m, binop_args, t, f, (outs)>, DefEFLAGS;
1105// BinOpRI8_R - Instructions that read "reg, imm8" and write "reg".
1106class BinOpRI8_R<bits<8> o, string m, X86TypeInfo t, Format f, bit ndd = 0>
1107  : BinOpRI8<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst)>, NDD<ndd>;
1108// BinOpRI8_RF - Instructions that read "reg, imm8" and write "reg", EFLAGS.
1109class BinOpRI8_RF<bits<8> o, string m, X86TypeInfo t, Format f, bit ndd = 0>
1110  : BinOpRI8<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst)>, DefEFLAGS, NDD<ndd>;
1111// BinOpRI8F_RF - Instructions that read "reg, imm", write "reg" and read/write
1112// EFLAGS.
1113class BinOpRI8F_RF<bits<8> o, string m, X86TypeInfo t, Format f, bit ndd = 0>
1114  : BinOpRI8<o, m, !if(!eq(ndd, 0), binop_args, binop_ndd_args), t, f, (outs t.RegClass:$dst)>, DefEFLAGS, UseEFLAGS, NDD<ndd> {
1115  let SchedRW = [WriteADC];
1116}
1117
1118// BinOpMR - Instructions that read "[mem], reg".
1119class BinOpMR<bits<8> o, string m, string args, X86TypeInfo t, dag out, list<dag> p>
1120  : ITy<o, MRMDestMem, t, out, (ins t.MemOperand:$src1, t.RegClass:$src2), m,
1121        args, p> {
1122  let mayLoad = 1;
1123  let SchedRW = [WriteALU.Folded, WriteALU.ReadAfterFold];
1124}
1125// BinOpMR_R - Instructions that read "[mem], reg", and write "reg".
1126class BinOpMR_R<bits<8> o, string m, X86TypeInfo t>
1127  : BinOpMR<o, m, binop_ndd_args, t, (outs t.RegClass:$dst), []>, NDD<1>;
1128// BinOpMR_RF - Instructions that read "[mem], reg", and write "reg", EFLAGS.
1129class BinOpMR_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
1130  : BinOpMR<o, m, binop_ndd_args, t, (outs t.RegClass:$dst),
1131            [(set t.RegClass:$dst, EFLAGS, (node (t.LoadNode addr:$src1),
1132             t.RegClass:$src2))]>, DefEFLAGS, NDD<1>;
1133// BinOpMR_F - Instructions that read "[mem], imm8" and write EFLAGS only.
1134class BinOpMR_F<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
1135  : BinOpMR<o, m, binop_args, t, (outs),
1136            [(set EFLAGS, (node (t.LoadNode addr:$src1), t.RegClass:$src2))]>,
1137    Sched<[WriteALU.Folded, ReadDefault, ReadDefault, ReadDefault,
1138            ReadDefault, ReadDefault, WriteALU.ReadAfterFold]>, DefEFLAGS;
1139// BinOpMR_M - Instructions that read "[mem], reg" and write "[mem]".
1140class BinOpMR_M<bits<8> o, string m, X86TypeInfo t>
1141  : BinOpMR<o, m, binop_args, t, (outs), []>,
1142    Sched<[WriteALURMW,
1143           // base, scale, index, offset, segment
1144           ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault]> {
1145  let mayStore = 1;
1146}
1147// BinOpMR_MF - Instructions that read "[mem], reg" and write "[mem]", EFLAGS.
1148class BinOpMR_MF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
1149  : BinOpMR<o, m, binop_args, t, (outs),
1150            [(store (node (load addr:$src1), t.RegClass:$src2), addr:$src1),
1151             (implicit EFLAGS)]>,
1152    Sched<[WriteALURMW,
1153           // base, scale, index, offset, segment
1154           ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
1155           WriteALU.ReadAfterFold]>, // reg
1156    DefEFLAGS {
1157  let mayStore = 1;
1158}
1159// BinOpMRF_RF - Instructions that read "[mem], reg", write "reg" and
1160// read/write EFLAGS.
1161class BinOpMRF_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
1162  : BinOpMR<o, m, binop_ndd_args, t, (outs t.RegClass:$dst),
1163            [(set t.RegClass:$dst, EFLAGS, (node (load addr:$src1),
1164             t.RegClass:$src2, EFLAGS))]>, DefEFLAGS, UseEFLAGS, NDD<1>,
1165    Sched<[WriteADC.Folded, WriteADC.ReadAfterFold]>;
1166// BinOpMRF_MF - Instructions that read "[mem], reg", write "[mem]" and
1167// read/write EFLAGS.
1168class BinOpMRF_MF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node>
1169  : BinOpMR<o, m, binop_args, t, (outs),
1170            [(store (node (load addr:$src1), t.RegClass:$src2, EFLAGS),
1171             addr:$src1), (implicit EFLAGS)]>,
1172    Sched<[WriteADCRMW,
1173          // base, scale, index, offset, segment
1174          ReadDefault, ReadDefault, ReadDefault,
1175          ReadDefault, ReadDefault,
1176          WriteALU.ReadAfterFold,    // reg
1177          WriteALU.ReadAfterFold]>,  // EFLAGS
1178    DefEFLAGS, UseEFLAGS {
1179  let mayStore = 1;
1180}
1181
1182// BinOpMI - Instructions that read "[mem], imm".
1183class BinOpMI<bits<8> o, string m, string args, X86TypeInfo t, Format f, dag out, list<dag> p>
1184  : ITy<o, f, t, out, (ins t.MemOperand:$src1, t.ImmOperand:$src2), m,
1185        args, p> {
1186  let ImmT = t.ImmEncoding;
1187  let mayLoad = 1;
1188}
1189// BinOpMI_F - Instructions that read "[mem], imm" and write EFLAGS only.
1190class BinOpMI_F<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node,
1191                Format f>
1192  : BinOpMI<o, m, binop_args, t, f, (outs),
1193            [(set EFLAGS, (node (t.LoadNode addr:$src1), t.ImmOperator:$src2))]>,
1194    Sched<[WriteALU.Folded]>, DefEFLAGS;
1195// BinOpMI_R - Instructions that read "[mem], imm" and write "reg".
1196class BinOpMI_R<bits<8> o, string m, X86TypeInfo t, Format f>
1197  : BinOpMI<o, m, binop_ndd_args, t, f, (outs t.RegClass:$dst), []>,
1198    Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, NDD<1>;
1199// BinOpMI_R - Instructions that read "[mem], imm" and write "reg", EFLAGS.
1200class BinOpMI_RF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node,
1201                Format f>
1202  : BinOpMI<o, m, binop_ndd_args, t, f, (outs t.RegClass:$dst),
1203            [(set t.RegClass:$dst, EFLAGS, (node (t.LoadNode addr:$src1), t.ImmOperator:$src2))]>,
1204    Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, DefEFLAGS, NDD<1>;
1205// BinOpMI_M - Instructions that read "[mem], imm" and write "[mem]".
1206class BinOpMI_M<bits<8> o, string m, X86TypeInfo t, Format f>
1207  : BinOpMI<o, m, binop_args, t, f, (outs), []>, Sched<[WriteALURMW]> {
1208  let mayStore = 1;
1209}
1210// BinOpMI_MF - Instructions that read "[mem], imm" and write "[mem]", EFLAGS.
1211class BinOpMI_MF<bits<8> o, string m, X86TypeInfo t, SDPatternOperator node, Format f>
1212  : BinOpMI<o, m, binop_args, t, f, (outs),
1213            [(store (node (t.VT (load addr:$src1)),
1214             t.ImmOperator:$src2), addr:$src1), (implicit EFLAGS)]>,
1215    Sched<[WriteALURMW]>, DefEFLAGS {
1216  let mayStore = 1;
1217}
1218// BinOpMIF_RF - Instructions that read "[mem], imm", write "reg" and
1219// read/write EFLAGS.
1220class BinOpMIF_RF<bits<8> o, string m, X86TypeInfo t, SDNode node, Format f>
1221  : BinOpMI<o, m, binop_ndd_args, t, f, (outs t.RegClass:$dst),
1222            [(set t.RegClass:$dst, EFLAGS, (node (t.VT (load addr:$src1)),
1223             t.ImmOperator:$src2, EFLAGS))]>,
1224    Sched<[WriteADC.Folded, WriteADC.ReadAfterFold]>, DefEFLAGS, UseEFLAGS, NDD<1>;
1225// BinOpMIF_MF - Instructions that read "[mem], imm", write "[mem]" and
1226// read/write EFLAGS.
1227class BinOpMIF_MF<bits<8> o, string m, X86TypeInfo t, SDNode node, Format f>
1228  : BinOpMI<o, m, binop_args, t, f, (outs),
1229            [(store (node (t.VT (load addr:$src1)),
1230             t.ImmOperator:$src2, EFLAGS), addr:$src1), (implicit EFLAGS)]>,
1231    Sched<[WriteADCRMW]>, DefEFLAGS, UseEFLAGS {
1232  let mayStore = 1;
1233}
1234
1235// BinOpMI8 - Instructions that read "[mem], imm8".
1236class BinOpMI8<string m, string args, X86TypeInfo t, Format f, dag out>
1237  : ITy<0x83, f, t, out, (ins t.MemOperand:$src1, t.Imm8Operand:$src2), m,
1238        args, []> {
1239  let ImmT = Imm8;
1240  let mayLoad = 1;
1241}
1242// BinOpMI8U - Instructions that read "[mem], u8imm".
1243class BinOpMI8U<string m, string args, X86TypeInfo t, Format f, dag out, list<dag> p>
1244  : ITy<0xC1, f, t, out, (ins t.MemOperand:$src1, u8imm:$src2), m, args, p> {
1245  let ImmT = Imm8;
1246  let mayLoad = 1;
1247}
1248// BinOpMI8_F - Instructions that read "[mem], imm8" and write EFLAGS only.
1249class BinOpMI8_F<string m, X86TypeInfo t, Format f>
1250  : BinOpMI8<m, binop_args, t, f, (outs)>, Sched<[WriteALU.Folded]>, DefEFLAGS;
1251// BinOpMI8_R - Instructions that read "[mem], imm8" and write "reg".
1252class BinOpMI8_R<string m, X86TypeInfo t, Format f>
1253  : BinOpMI8<m, binop_ndd_args, t, f, (outs t.RegClass:$dst)>, Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, NDD<1>;
1254// BinOpMI8U_R - Instructions that read "[mem], u8imm" and write "reg".
1255class BinOpMI8U_R<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag>
1256  : BinOpMI8U<m, binop_ndd_args, t, f, (outs t.RegClass:$dst),
1257              [(set t.RegClass:$dst, (node (t.LoadNode addr:$src1), (i8 imm:$src2)))]>, NDD<1>;
1258// BinOpMI8_RF - Instructions that read "[mem], imm8" and write "reg"/EFLAGS.
1259class BinOpMI8_RF<string m, X86TypeInfo t, Format f>
1260  : BinOpMI8<m, binop_ndd_args, t, f, (outs t.RegClass:$dst)>, Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, DefEFLAGS, NDD<1>;
1261// BinOpMI8_M - Instructions that read "[mem], imm8" and write "[mem]".
1262class BinOpMI8_M<string m, X86TypeInfo t, Format f>
1263  : BinOpMI8<m, binop_args, t, f, (outs)>, Sched<[WriteALURMW]> {
1264  let mayStore = 1;
1265}
1266// BinOpMI8U_M - Instructions that read "[mem], u8imm" and write "[mem]".
1267class BinOpMI8U_M<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag>
1268  : BinOpMI8U<m, binop_args, t, f, (outs),
1269              [(store (node (t.LoadNode addr:$src1), (i8 imm:$src2)), addr:$src1)]> {
1270  let mayStore = 1;
1271}
1272// BinOpMI8_MF - Instructions that read "[mem], imm8" and write "[mem]", EFLAGS.
1273class BinOpMI8_MF<string m, X86TypeInfo t, Format f>
1274  : BinOpMI8<m, binop_args, t, f, (outs)>, Sched<[WriteALURMW]>, DefEFLAGS {
1275  let mayStore = 1;
1276}
1277// BinOpMI8F_RF - Instructions that read "[mem], imm8", write "reg" and
1278// read/write EFLAGS.
1279class BinOpMI8F_RF<string m, X86TypeInfo t, Format f>
1280  : BinOpMI8<m, binop_ndd_args, t, f, (outs t.RegClass:$dst)>,
1281    Sched<[WriteADC.Folded, WriteADC.ReadAfterFold]>, DefEFLAGS, UseEFLAGS, NDD<1>;
1282// BinOpMI8F_MF - Instructions that read "[mem], imm8", write "[mem]" and
1283// read/write EFLAGS.
1284class BinOpMI8F_MF<string m, X86TypeInfo t, Format f>
1285  : BinOpMI8<m, binop_args, t, f, (outs)>, Sched<[WriteADCRMW]>, DefEFLAGS, UseEFLAGS {
1286  let mayStore = 1;
1287}
1288
1289// BinOpAI - Instructions that read "a-reg imm" (Accumulator register).
1290class BinOpAI<bits<8> o, string m, X86TypeInfo t, Register areg, string args>
1291  : ITy<o, RawFrm, t, (outs), (ins t.ImmOperand:$src), m, args, []>,
1292    Sched<[WriteALU]> {
1293  let ImmT = t.ImmEncoding;
1294  let Uses = [areg];
1295}
1296// BinOpAI_F - Instructions that read "a-reg imm" and write EFLAGS only.
1297class BinOpAI_F<bits<8> o, string m, X86TypeInfo t, Register areg, string args>
1298  : BinOpAI<o, m, t, areg, args>, DefEFLAGS;
1299
1300// BinOpAI_AF - Instructions that read "a-reg imm" and write a-reg/EFLAGS.
1301class BinOpAI_AF<bits<8> o, string m, X86TypeInfo t, Register areg,
1302                 string args> : BinOpAI<o, m, t, areg, args> {
1303  let Defs = [areg, EFLAGS];
1304}
1305// BinOpAIF_AF - Instructions that read "a-reg imm", write a-reg and read/write
1306// EFLAGS.
1307class BinOpAIF_AF<bits<8> o, string m, X86TypeInfo t, Register areg,
1308                  string args> : BinOpAI<o, m, t, areg, args> {
1309  let Uses = [areg, EFLAGS];
1310  let Defs = [areg, EFLAGS];
1311  let SchedRW = [WriteADC];
1312}
1313// BinOpRC_R - Instructions that read "reg, cl" and write reg.
1314class BinOpRC_R<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag, bit ndd = 0>
1315  : ITy<0xD3, f, t, (outs t.RegClass:$dst), (ins t.RegClass:$src1), m,
1316        !if(!eq(ndd, 0), binop_cl_args, binop_cl_ndd_args),
1317        [(set t.RegClass:$dst, (node t.RegClass:$src1, CL))]>, NDD<ndd> {
1318  let Uses = [CL];
1319}
1320// BinOpMC_M - Instructions that read "[mem], cl" and write [mem].
1321class BinOpMC_M<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag>
1322  : ITy<0xD3, f, t, (outs), (ins t.MemOperand:$src1), m, binop_cl_args,
1323        [(store (node (t.LoadNode addr:$src1), CL), addr:$src1)]> {
1324  let Uses = [CL];
1325  let mayLoad = 1;
1326  let mayStore = 1;
1327}
1328// BinOpMC_R - Instructions that read "[mem], cl" and write reg.
1329class BinOpMC_R<string m, Format f, X86TypeInfo t, SDPatternOperator node = null_frag>
1330  : ITy<0xD3, f, t, (outs t.RegClass:$dst), (ins t.MemOperand:$src1), m, binop_cl_ndd_args,
1331        [(set t.RegClass:$dst, (node (t.LoadNode addr:$src1), CL))]>, NDD<1> {
1332  let Uses = [CL];
1333  let mayLoad = 1;
1334}
1335
1336// UnaryOpR - Instructions that read "reg".
1337class UnaryOpR<bits<8> o, Format f, string m, string args, X86TypeInfo t,
1338               dag out, list<dag> p>
1339  : ITy<o, f, t, out, (ins t.RegClass:$src1), m, args, p>, Sched<[WriteALU]>;
1340// UnaryOpR_R - Instructions that read "reg" and write "reg".
1341class UnaryOpR_R<bits<8> o, Format f, string m, X86TypeInfo t,
1342                  SDPatternOperator node = null_frag, bit ndd = 0>
1343  : UnaryOpR<o, f, m, !if(!eq(ndd, 0), unaryop_args, unaryop_ndd_args), t,
1344             (outs t.RegClass:$dst),
1345             [(set t.RegClass:$dst, (node t.RegClass:$src1))]>, NDD<ndd>;
1346// UnaryOpR_RF - Instructions that read "reg" and write "reg"/EFLAGS.
1347class UnaryOpR_RF<bits<8> o, Format f, string m, X86TypeInfo t,
1348                  SDPatternOperator node = null_frag, bit ndd = 0>
1349  : UnaryOpR<o, f, m, !if(!eq(ndd, 0), unaryop_args, unaryop_ndd_args), t,
1350             (outs t.RegClass:$dst),
1351             [(set t.RegClass:$dst, (node t.RegClass:$src1)),
1352              (implicit EFLAGS)]>, DefEFLAGS, NDD<ndd>;
1353
1354// UnaryOpM - Instructions that read "[mem]".
1355class UnaryOpM<bits<8> o, Format f, string m, string args, X86TypeInfo t,
1356               dag out, list<dag> p>
1357  : ITy<o, f, t, out, (ins t.MemOperand:$src1), m, args, p> {
1358  let mayLoad = 1;
1359}
1360// UnaryOpM_R - Instructions that read "[mem]" and writes "reg".
1361class UnaryOpM_R<bits<8> o, Format f, string m, X86TypeInfo t,
1362                  SDPatternOperator node = null_frag>
1363  : UnaryOpM<o, f, m, unaryop_ndd_args, t, (outs t.RegClass:$dst),
1364             [(set t.RegClass:$dst, (node (t.LoadNode addr:$src1)))]>,
1365    Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, NDD<1>;
1366// UnaryOpM_RF - Instructions that read "[mem]" and writes "reg"/EFLAGS.
1367class UnaryOpM_RF<bits<8> o, Format f, string m, X86TypeInfo t,
1368                  SDPatternOperator node = null_frag>
1369  : UnaryOpM<o, f, m, unaryop_ndd_args, t, (outs t.RegClass:$dst),
1370             [(set t.RegClass:$dst, EFLAGS, (node (t.LoadNode addr:$src1)))]>,
1371    Sched<[WriteALU.Folded, WriteALU.ReadAfterFold]>, DefEFLAGS, NDD<1>;
1372// UnaryOpM_M - Instructions that read "[mem]" and writes "[mem]".
1373class UnaryOpM_M<bits<8> o, Format f, string m, X86TypeInfo t,
1374                  SDPatternOperator node = null_frag>
1375  : UnaryOpM<o, f, m, unaryop_args, t, (outs),
1376             [(store (node (t.LoadNode addr:$src1)), addr:$src1)]>,
1377    Sched<[WriteALURMW]>{
1378  let mayStore = 1;
1379}
1380// UnaryOpM_MF - Instructions that read "[mem]" and writes "[mem]"/EFLAGS.
1381class UnaryOpM_MF<bits<8> o, Format f, string m, X86TypeInfo t,
1382                  SDPatternOperator node = null_frag>
1383  : UnaryOpM<o, f, m, unaryop_args, t, (outs),
1384             [(store (node (t.LoadNode addr:$src1)), addr:$src1),
1385              (implicit EFLAGS)]>, Sched<[WriteALURMW]>, DefEFLAGS {
1386  let mayStore = 1;
1387}
1388