adc and sbb need an incoming flag to ensure it reads the carry flag
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===- X86InstrInfo.td - Describe the X86 Instruction Set -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the X86 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 // X86 specific DAG Nodes.
18 //
19
20 def SDTIntShiftDOp: SDTypeProfile<1, 3,
21                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22                                    SDTCisInt<0>, SDTCisInt<3>]>;
23
24 def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, FlagVT>, SDTCisSameAs<1, 2>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, FlagVT>]>;
29
30 def SDTX86BrCond  : SDTypeProfile<0, 3,
31                                   [SDTCisVT<0, OtherVT>,
32                                    SDTCisVT<1, i8>, SDTCisVT<2, FlagVT>]>;
33
34 def SDTX86SetCC   : SDTypeProfile<1, 2,
35                                   [SDTCisVT<0, i8>, SDTCisVT<1, i8>,
36                                    SDTCisVT<2, FlagVT>]>;
37
38 def SDTX86Ret     : SDTypeProfile<0, 1, [SDTCisVT<0, i16>]>;
39
40 def SDT_X86CallSeqStart : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
41 def SDT_X86CallSeqEnd   : SDTypeProfile<0, 2, [ SDTCisVT<0, i32>,
42                                                 SDTCisVT<1, i32> ]>;
43
44 def SDT_X86Call   : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
45
46 def SDTX86FpGet   : SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>;
47 def SDTX86FpSet   : SDTypeProfile<0, 1, [SDTCisFP<0>]>;
48
49 def SDTX86Fld     : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
50                                          SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
51 def SDTX86Fst     : SDTypeProfile<0, 3, [SDTCisFP<0>,
52                                          SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
53 def SDTX86Fild    : SDTypeProfile<1, 2, [SDTCisVT<0, f64>, SDTCisPtrTy<1>,
54                                          SDTCisVT<2, OtherVT>]>;
55 def SDTX86FpToIMem: SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
56
57 def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
58
59 def SDTX86RdTsc   : SDTypeProfile<0, 0, []>;
60
61 def X86addflag : SDNode<"X86ISD::ADD_FLAG", SDTIntBinOp ,
62                         [SDNPCommutative, SDNPAssociative, SDNPOutFlag]>;
63 def X86subflag : SDNode<"X86ISD::SUB_FLAG", SDTIntBinOp,
64                         [SDNPOutFlag]>;
65 def X86adc     : SDNode<"X86ISD::ADC" ,     SDTIntBinOp ,
66                         [SDNPCommutative, SDNPAssociative, SDNPInFlag]>;
67 def X86sbb     : SDNode<"X86ISD::SBB" ,     SDTIntBinOp,
68                         [SDNPInFlag]>;
69
70 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
71 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
72
73 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest,  []>;
74 def X86test    : SDNode<"X86ISD::TEST",     SDTX86CmpTest,  []>;
75
76 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov,    
77                         [SDNPOutFlag]>;
78 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
79                         [SDNPHasChain]>;
80 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC,
81                         [SDNPOutFlag]>;
82
83 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
84                         [SDNPHasChain, SDNPOptInFlag]>;
85
86 def X86callseq_start :
87                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
88                         [SDNPHasChain]>;
89 def X86callseq_end :
90                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
91                         [SDNPHasChain]>;
92
93 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
94                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
95
96 def X86fpget   : SDNode<"X86ISD::FP_GET_RESULT", SDTX86FpGet,
97                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
98 def X86fpset   : SDNode<"X86ISD::FP_SET_RESULT", SDTX86FpSet,
99                         [SDNPHasChain, SDNPOutFlag]>;
100
101 def X86fld     : SDNode<"X86ISD::FLD",      SDTX86Fld,
102                         [SDNPHasChain]>;
103 def X86fst     : SDNode<"X86ISD::FST",      SDTX86Fst,
104                         [SDNPHasChain, SDNPInFlag]>;
105 def X86fild    : SDNode<"X86ISD::FILD",     SDTX86Fild,
106                         [SDNPHasChain]>;
107 def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
108                         [SDNPHasChain]>;
109 def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
110                         [SDNPHasChain]>;
111 def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
112                         [SDNPHasChain]>;
113
114 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
115                         [SDNPHasChain, SDNPInFlag]>;
116 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
117                         [SDNPHasChain, SDNPInFlag]>;
118
119 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG",SDTX86RdTsc,
120                         [SDNPHasChain, SDNPOutFlag]>;
121
122 //===----------------------------------------------------------------------===//
123 // X86 Operand Definitions.
124 //
125
126 // *mem - Operand definitions for the funky X86 addressing mode operands.
127 //
128 class X86MemOperand<string printMethod> : Operand<i32> {
129   let PrintMethod = printMethod;
130   let NumMIOperands = 4;
131   let MIOperandInfo = (ops R32, i8imm, R32, i32imm);
132 }
133
134 def i8mem   : X86MemOperand<"printi8mem">;
135 def i16mem  : X86MemOperand<"printi16mem">;
136 def i32mem  : X86MemOperand<"printi32mem">;
137 def i64mem  : X86MemOperand<"printi64mem">;
138 def f32mem  : X86MemOperand<"printf32mem">;
139 def f64mem  : X86MemOperand<"printf64mem">;
140 def f80mem  : X86MemOperand<"printf80mem">;
141
142 def SSECC : Operand<i8> {
143   let PrintMethod = "printSSECC";
144 }
145
146 // A couple of more descriptive operand definitions.
147 // 16-bits but only 8 bits are significant.
148 def i16i8imm  : Operand<i16>;
149 // 32-bits but only 8 bits are significant.
150 def i32i8imm  : Operand<i32>;
151
152 // PCRelative calls need special operand formatting.
153 let PrintMethod = "printCallOperand" in
154   def calltarget : Operand<i32>;
155
156 // Branch targets have OtherVT type.
157 def brtarget : Operand<OtherVT>;
158
159 //===----------------------------------------------------------------------===//
160 // X86 Complex Pattern Definitions.
161 //
162
163 // Define X86 specific addressing mode.
164 def addr    : ComplexPattern<i32, 4, "SelectAddr", []>;
165 def leaaddr : ComplexPattern<i32, 4, "SelectLEAAddr",
166                              [add, frameindex, constpool]>;
167
168 //===----------------------------------------------------------------------===//
169 // X86 Instruction Format Definitions.
170 //
171
172 // Format specifies the encoding used by the instruction.  This is part of the
173 // ad-hoc solution used to emit machine instruction encodings by our machine
174 // code emitter.
175 class Format<bits<5> val> {
176   bits<5> Value = val;
177 }
178
179 def Pseudo     : Format<0>; def RawFrm     : Format<1>;
180 def AddRegFrm  : Format<2>; def MRMDestReg : Format<3>;
181 def MRMDestMem : Format<4>; def MRMSrcReg  : Format<5>;
182 def MRMSrcMem  : Format<6>;
183 def MRM0r  : Format<16>; def MRM1r  : Format<17>; def MRM2r  : Format<18>;
184 def MRM3r  : Format<19>; def MRM4r  : Format<20>; def MRM5r  : Format<21>;
185 def MRM6r  : Format<22>; def MRM7r  : Format<23>;
186 def MRM0m  : Format<24>; def MRM1m  : Format<25>; def MRM2m  : Format<26>;
187 def MRM3m  : Format<27>; def MRM4m  : Format<28>; def MRM5m  : Format<29>;
188 def MRM6m  : Format<30>; def MRM7m  : Format<31>;
189
190 //===----------------------------------------------------------------------===//
191 // X86 Instruction Predicate Definitions.
192 def HasSSE1 : Predicate<"X86Vector >= SSE">;
193 def HasSSE2 : Predicate<"X86Vector >= SSE2">;
194 def HasSSE3 : Predicate<"X86Vector >= SSE3">;
195 def FPStack : Predicate<"X86Vector < SSE2">;
196
197 //===----------------------------------------------------------------------===//
198 // X86 specific pattern fragments.
199 //
200
201 // ImmType - This specifies the immediate type used by an instruction. This is
202 // part of the ad-hoc solution used to emit machine instruction encodings by our
203 // machine code emitter.
204 class ImmType<bits<2> val> {
205   bits<2> Value = val;
206 }
207 def NoImm  : ImmType<0>;
208 def Imm8   : ImmType<1>;
209 def Imm16  : ImmType<2>;
210 def Imm32  : ImmType<3>;
211
212 // FPFormat - This specifies what form this FP instruction has.  This is used by
213 // the Floating-Point stackifier pass.
214 class FPFormat<bits<3> val> {
215   bits<3> Value = val;
216 }
217 def NotFP      : FPFormat<0>;
218 def ZeroArgFP  : FPFormat<1>;
219 def OneArgFP   : FPFormat<2>;
220 def OneArgFPRW : FPFormat<3>;
221 def TwoArgFP   : FPFormat<4>;
222 def CompareFP  : FPFormat<5>;
223 def CondMovFP  : FPFormat<6>;
224 def SpecialFP  : FPFormat<7>;
225
226
227 class X86Inst<bits<8> opcod, Format f, ImmType i, dag ops, string AsmStr>
228   : Instruction {
229   let Namespace = "X86";
230
231   bits<8> Opcode = opcod;
232   Format Form = f;
233   bits<5> FormBits = Form.Value;
234   ImmType ImmT = i;
235   bits<2> ImmTypeBits = ImmT.Value;
236
237   dag OperandList = ops;
238   string AsmString = AsmStr;
239
240   //
241   // Attributes specific to X86 instructions...
242   //
243   bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
244
245   bits<4> Prefix = 0;       // Which prefix byte does this inst have?
246   FPFormat FPForm;          // What flavor of FP instruction is this?
247   bits<3> FPFormBits = 0;
248 }
249
250 class Imp<list<Register> uses, list<Register> defs> {
251   list<Register> Uses = uses;
252   list<Register> Defs = defs;
253 }
254
255
256 // Prefix byte classes which are used to indicate to the ad-hoc machine code
257 // emitter that various prefix bytes are required.
258 class OpSize { bit hasOpSizePrefix = 1; }
259 class TB     { bits<4> Prefix = 1; }
260 class REP    { bits<4> Prefix = 2; }
261 class D8     { bits<4> Prefix = 3; }
262 class D9     { bits<4> Prefix = 4; }
263 class DA     { bits<4> Prefix = 5; }
264 class DB     { bits<4> Prefix = 6; }
265 class DC     { bits<4> Prefix = 7; }
266 class DD     { bits<4> Prefix = 8; }
267 class DE     { bits<4> Prefix = 9; }
268 class DF     { bits<4> Prefix = 10; }
269 class XD     { bits<4> Prefix = 11; }
270 class XS     { bits<4> Prefix = 12; }
271
272
273 //===----------------------------------------------------------------------===//
274 // Pattern fragments...
275 //
276
277 // X86 specific condition code. These correspond to CondCode in
278 // X86ISelLowering.h. They must be kept in synch.
279 def X86_COND_A   : PatLeaf<(i8 0)>;
280 def X86_COND_AE  : PatLeaf<(i8 1)>;
281 def X86_COND_B   : PatLeaf<(i8 2)>;
282 def X86_COND_BE  : PatLeaf<(i8 3)>;
283 def X86_COND_E   : PatLeaf<(i8 4)>;
284 def X86_COND_G   : PatLeaf<(i8 5)>;
285 def X86_COND_GE  : PatLeaf<(i8 6)>;
286 def X86_COND_L   : PatLeaf<(i8 7)>;
287 def X86_COND_LE  : PatLeaf<(i8 8)>;
288 def X86_COND_NE  : PatLeaf<(i8 9)>;
289 def X86_COND_NO  : PatLeaf<(i8 10)>;
290 def X86_COND_NP  : PatLeaf<(i8 11)>;
291 def X86_COND_NS  : PatLeaf<(i8 12)>;
292 def X86_COND_O   : PatLeaf<(i8 13)>;
293 def X86_COND_P   : PatLeaf<(i8 14)>;
294 def X86_COND_S   : PatLeaf<(i8 15)>;
295
296 def i16immSExt8  : PatLeaf<(i16 imm), [{
297   // i16immSExt8 predicate - True if the 16-bit immediate fits in a 8-bit
298   // sign extended field.
299   return (int)N->getValue() == (signed char)N->getValue();
300 }]>;
301
302 def i32immSExt8  : PatLeaf<(i32 imm), [{
303   // i32immSExt8 predicate - True if the 32-bit immediate fits in a 8-bit
304   // sign extended field.
305   return (int)N->getValue() == (signed char)N->getValue();
306 }]>;
307
308 def i16immZExt8  : PatLeaf<(i16 imm), [{
309   // i16immZExt8 predicate - True if the 16-bit immediate fits in a 8-bit zero
310   // extended field.
311   return (unsigned)N->getValue() == (unsigned char)N->getValue();
312 }]>;
313
314 def fp32imm0 : PatLeaf<(f32 fpimm), [{
315   return N->isExactlyValue(+0.0);
316 }]>;
317
318 def fp64imm0 : PatLeaf<(f64 fpimm), [{
319   return N->isExactlyValue(+0.0);
320 }]>;
321
322 def fp64immneg0 : PatLeaf<(f64 fpimm), [{
323   return N->isExactlyValue(-0.0);
324 }]>;
325
326 def fp64imm1 : PatLeaf<(f64 fpimm), [{
327   return N->isExactlyValue(+1.0);
328 }]>;
329
330 def fp64immneg1 : PatLeaf<(f64 fpimm), [{
331   return N->isExactlyValue(-1.0);
332 }]>;
333
334 // Helper fragments for loads.
335 def loadi8  : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
336 def loadi16 : PatFrag<(ops node:$ptr), (i16 (load node:$ptr))>;
337 def loadi32 : PatFrag<(ops node:$ptr), (i32 (load node:$ptr))>;
338 def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
339 def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
340
341 def sextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (sextload node:$ptr, i1))>;
342 def sextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i1))>;
343 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextload node:$ptr, i8))>;
344 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i8))>;
345 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i16))>;
346
347 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextload node:$ptr, i1))>;
348 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextload node:$ptr, i1))>;
349 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i1))>;
350 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextload node:$ptr, i8))>;
351 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i8))>;
352 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i16))>;
353
354 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extload node:$ptr, i1))>;
355 def extloadf64f32  : PatFrag<(ops node:$ptr), (f64 (extload node:$ptr, f32))>;
356
357 //===----------------------------------------------------------------------===//
358 // Instruction templates...
359
360 class I<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
361   : X86Inst<o, f, NoImm, ops, asm> {
362   let Pattern = pattern;
363 }
364 class Ii8 <bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
365   : X86Inst<o, f, Imm8 , ops, asm> {
366   let Pattern = pattern;
367 }
368 class Ii16<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
369   : X86Inst<o, f, Imm16, ops, asm> {
370   let Pattern = pattern;
371 }
372 class Ii32<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
373   : X86Inst<o, f, Imm32, ops, asm> {
374   let Pattern = pattern;
375 }
376
377 //===----------------------------------------------------------------------===//
378 // Instruction list...
379 //
380
381 // Pseudo-instructions:
382 def PHI : I<0, Pseudo, (ops variable_ops), "PHINODE", []>;        // PHI node.
383
384 def ADJCALLSTACKDOWN : I<0, Pseudo, (ops i32imm:$amt), "#ADJCALLSTACKDOWN",
385                          [(X86callseq_start imm:$amt)]>;
386 def ADJCALLSTACKUP   : I<0, Pseudo, (ops i32imm:$amt1, i32imm:$amt2),
387                          "#ADJCALLSTACKUP",
388                          [(X86callseq_end imm:$amt1, imm:$amt2)]>;
389 def IMPLICIT_USE     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_USE", []>;
390 def IMPLICIT_DEF     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_DEF", []>;
391 def IMPLICIT_DEF_R8  : I<0, Pseudo, (ops R8:$dst),
392                          "#IMPLICIT_DEF $dst",
393                          [(set R8:$dst, (undef))]>;
394 def IMPLICIT_DEF_R16  : I<0, Pseudo, (ops R16:$dst),
395                          "#IMPLICIT_DEF $dst",
396                          [(set R16:$dst, (undef))]>;
397 def IMPLICIT_DEF_R32  : I<0, Pseudo, (ops R32:$dst),
398                          "#IMPLICIT_DEF $dst",
399                          [(set R32:$dst, (undef))]>;
400 def IMPLICIT_DEF_FR32 : I<0, Pseudo, (ops FR32:$dst),
401                          "#IMPLICIT_DEF $dst",
402                          [(set FR32:$dst, (undef))]>, Requires<[HasSSE2]>;
403 def IMPLICIT_DEF_FR64 : I<0, Pseudo, (ops FR64:$dst),
404                          "#IMPLICIT_DEF $dst",
405                          [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
406
407
408 // CMOV* - Used to implement the SSE SELECT DAG operation.  Expanded by the
409 // scheduler into a branch sequence.
410 let usesCustomDAGSchedInserter = 1 in {  // Expanded by the scheduler.
411   def CMOV_FR32 : I<0, Pseudo,
412                     (ops FR32:$dst, FR32:$t, FR32:$f, i8imm:$cond),
413                     "#CMOV_FR32 PSEUDO!",
414                     [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
415                                       STATUS))]>;
416   def CMOV_FR64 : I<0, Pseudo,
417                     (ops FR64:$dst, FR64:$t, FR64:$f, i8imm:$cond),
418                     "#CMOV_FR64 PSEUDO!",
419                     [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
420                                       STATUS))]>;
421 }
422
423 let usesCustomDAGSchedInserter = 1 in {  // Expanded by the scheduler.
424   def FP_TO_INT16_IN_MEM : I<0, Pseudo,
425                             (ops i16mem:$dst, RFP:$src),
426                            "#FP_TO_INT16_IN_MEM PSEUDO!",
427                            [(X86fp_to_i16mem RFP:$src, addr:$dst)]>;
428   def FP_TO_INT32_IN_MEM : I<0, Pseudo,
429                             (ops i32mem:$dst, RFP:$src),
430                            "#FP_TO_INT32_IN_MEM PSEUDO!",
431                            [(X86fp_to_i32mem RFP:$src, addr:$dst)]>;
432   def FP_TO_INT64_IN_MEM : I<0, Pseudo,
433                             (ops i64mem:$dst, RFP:$src),
434                            "#FP_TO_INT64_IN_MEM PSEUDO!",
435                            [(X86fp_to_i64mem RFP:$src, addr:$dst)]>;
436 }
437
438
439 let isTerminator = 1 in
440   let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
441     def FP_REG_KILL  : I<0, Pseudo, (ops), "#FP_REG_KILL", []>;
442
443
444 // Nop
445 def NOOP : I<0x90, RawFrm, (ops), "nop", []>;
446
447 //===----------------------------------------------------------------------===//
448 //  Control Flow Instructions...
449 //
450
451 // Return instructions.
452 let isTerminator = 1, isReturn = 1, isBarrier = 1,
453     hasCtrlDep = 1, noResults = 1 in {
454   def RET    : I<0xC3, RawFrm, (ops), "ret", [(X86retflag 0)]>;
455   def RETI   : Ii16<0xC2, RawFrm, (ops i16imm:$amt), "ret $amt",
456                     [(X86retflag imm:$amt)]>;
457 }
458
459 // All branches are RawFrm, Void, Branch, and Terminators
460 let isBranch = 1, isTerminator = 1, noResults = 1 in
461   class IBr<bits<8> opcode, dag ops, string asm, list<dag> pattern> :
462         I<opcode, RawFrm, ops, asm, pattern>;
463
464 // Conditional branches
465 let isBarrier = 1 in
466   def JMP : IBr<0xE9, (ops brtarget:$dst), "jmp $dst", [(br bb:$dst)]>;
467
468 def JE  : IBr<0x84, (ops brtarget:$dst), "je $dst",
469               [(X86brcond bb:$dst, X86_COND_E, STATUS)]>, Imp<[STATUS],[]>, TB;
470 def JNE : IBr<0x85, (ops brtarget:$dst), "jne $dst",
471               [(X86brcond bb:$dst, X86_COND_NE, STATUS)]>, Imp<[STATUS],[]>, TB;
472 def JL  : IBr<0x8C, (ops brtarget:$dst), "jl $dst",
473               [(X86brcond bb:$dst, X86_COND_L, STATUS)]>, Imp<[STATUS],[]>, TB;
474 def JLE : IBr<0x8E, (ops brtarget:$dst), "jle $dst",
475               [(X86brcond bb:$dst, X86_COND_LE, STATUS)]>, Imp<[STATUS],[]>, TB;
476 def JG  : IBr<0x8F, (ops brtarget:$dst), "jg $dst",
477               [(X86brcond bb:$dst, X86_COND_G, STATUS)]>, Imp<[STATUS],[]>, TB;
478 def JGE : IBr<0x8D, (ops brtarget:$dst), "jge $dst",
479               [(X86brcond bb:$dst, X86_COND_GE, STATUS)]>, Imp<[STATUS],[]>, TB;
480
481 def JB  : IBr<0x82, (ops brtarget:$dst), "jb $dst",
482               [(X86brcond bb:$dst, X86_COND_B, STATUS)]>, Imp<[STATUS],[]>, TB;
483 def JBE : IBr<0x86, (ops brtarget:$dst), "jbe $dst",
484               [(X86brcond bb:$dst, X86_COND_BE, STATUS)]>, Imp<[STATUS],[]>, TB;
485 def JA  : IBr<0x87, (ops brtarget:$dst), "ja $dst",
486               [(X86brcond bb:$dst, X86_COND_A, STATUS)]>, Imp<[STATUS],[]>, TB;
487 def JAE : IBr<0x83, (ops brtarget:$dst), "jae $dst",
488               [(X86brcond bb:$dst, X86_COND_AE, STATUS)]>, Imp<[STATUS],[]>, TB;
489
490 def JS  : IBr<0x88, (ops brtarget:$dst), "js $dst",
491               [(X86brcond bb:$dst, X86_COND_S, STATUS)]>, Imp<[STATUS],[]>, TB;
492 def JNS : IBr<0x89, (ops brtarget:$dst), "jns $dst",
493               [(X86brcond bb:$dst, X86_COND_NS, STATUS)]>, Imp<[STATUS],[]>, TB;
494 def JP  : IBr<0x8A, (ops brtarget:$dst), "jp $dst",
495               [(X86brcond bb:$dst, X86_COND_P, STATUS)]>, Imp<[STATUS],[]>, TB;
496 def JNP : IBr<0x8B, (ops brtarget:$dst), "jnp $dst",
497               [(X86brcond bb:$dst, X86_COND_NP, STATUS)]>, Imp<[STATUS],[]>, TB;
498 def JO  : IBr<0x80, (ops brtarget:$dst), "jo $dst",
499               [(X86brcond bb:$dst, X86_COND_O, STATUS)]>, Imp<[STATUS],[]>, TB;
500 def JNO : IBr<0x81, (ops brtarget:$dst), "jno $dst",
501               [(X86brcond bb:$dst, X86_COND_NO, STATUS)]>, Imp<[STATUS],[]>, TB;
502
503 //===----------------------------------------------------------------------===//
504 //  Call Instructions...
505 //
506 let isCall = 1, noResults = 1 in
507   // All calls clobber the non-callee saved registers...
508   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
509               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7] in {
510     def CALLpcrel32 : I<0xE8, RawFrm, (ops calltarget:$dst), "call $dst",
511                       []>;
512     def CALL32r     : I<0xFF, MRM2r, (ops R32:$dst), "call {*}$dst",
513                       [(X86call R32:$dst)]>;
514     def CALL32m     : I<0xFF, MRM2m, (ops i32mem:$dst), "call {*}$dst",
515                       [(X86call (loadi32 addr:$dst))]>;
516   }
517
518 // Tail call stuff.
519 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
520   def TAILJMPd : IBr<0xE9, (ops calltarget:$dst), "jmp $dst  # TAIL CALL", []>;
521 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
522   def TAILJMPr : I<0xFF, MRM4r, (ops R32:$dst), "jmp {*}$dst  # TAIL CALL", []>;
523 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
524   def TAILJMPm : I<0xFF, MRM4m, (ops i32mem:$dst),
525                    "jmp {*}$dst  # TAIL CALL", []>;
526
527 // ADJSTACKPTRri - This is a standard ADD32ri instruction, identical in every
528 // way, except that it is marked as being a terminator.  This causes the epilog
529 // inserter to insert reloads of callee saved registers BEFORE this.  We need
530 // this until we have a more accurate way of tracking where the stack pointer is
531 // within a function.
532 let isTerminator = 1, isTwoAddress = 1 in
533   def ADJSTACKPTRri : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
534                            "add{l} {$src2, $dst|$dst, $src2}", []>;
535
536 //===----------------------------------------------------------------------===//
537 //  Miscellaneous Instructions...
538 //
539 def LEAVE    : I<0xC9, RawFrm,
540                  (ops), "leave", []>, Imp<[EBP,ESP],[EBP,ESP]>;
541 def POP32r   : I<0x58, AddRegFrm,
542                  (ops R32:$reg), "pop{l} $reg", []>, Imp<[ESP],[ESP]>;
543
544 let isTwoAddress = 1 in                               // R32 = bswap R32
545   def BSWAP32r : I<0xC8, AddRegFrm,
546                    (ops R32:$dst, R32:$src),
547                    "bswap{l} $dst", 
548                    [(set R32:$dst, (bswap R32:$src))]>, TB;
549
550 def XCHG8rr  : I<0x86, MRMDestReg,                    // xchg R8, R8
551                  (ops R8:$src1, R8:$src2),
552                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
553 def XCHG16rr : I<0x87, MRMDestReg,                    // xchg R16, R16
554                  (ops R16:$src1, R16:$src2),
555                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
556 def XCHG32rr : I<0x87, MRMDestReg,                    // xchg R32, R32
557                  (ops R32:$src1, R32:$src2),
558                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
559
560 def XCHG8mr  : I<0x86, MRMDestMem,
561                  (ops i8mem:$src1, R8:$src2),
562                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
563 def XCHG16mr : I<0x87, MRMDestMem,
564                  (ops i16mem:$src1, R16:$src2),
565                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
566 def XCHG32mr : I<0x87, MRMDestMem,
567                  (ops i32mem:$src1, R32:$src2),
568                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
569 def XCHG8rm  : I<0x86, MRMSrcMem,
570                  (ops R8:$src1, i8mem:$src2),
571                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
572 def XCHG16rm : I<0x87, MRMSrcMem,
573                  (ops R16:$src1, i16mem:$src2),
574                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
575 def XCHG32rm : I<0x87, MRMSrcMem,
576                  (ops R32:$src1, i32mem:$src2),
577                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
578
579 def LEA16r   : I<0x8D, MRMSrcMem,
580                  (ops R16:$dst, i32mem:$src),
581                  "lea{w} {$src|$dst}, {$dst|$src}", []>, OpSize;
582 def LEA32r   : I<0x8D, MRMSrcMem,
583                  (ops R32:$dst, i32mem:$src),
584                  "lea{l} {$src|$dst}, {$dst|$src}",
585                  [(set R32:$dst, leaaddr:$src)]>;
586
587 def REP_MOVSB : I<0xA4, RawFrm, (ops), "{rep;movsb|rep movsb}",
588                   [(X86rep_movs i8)]>,
589                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
590 def REP_MOVSW : I<0xA5, RawFrm, (ops), "{rep;movsw|rep movsw}",
591                   [(X86rep_movs i16)]>,
592                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP, OpSize;
593 def REP_MOVSD : I<0xA5, RawFrm, (ops), "{rep;movsd|rep movsd}",
594                   [(X86rep_movs i32)]>,
595                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
596
597 def REP_STOSB : I<0xAA, RawFrm, (ops), "{rep;stosb|rep stosb}",
598                   [(X86rep_stos i8)]>,
599                 Imp<[AL,ECX,EDI], [ECX,EDI]>, REP;
600 def REP_STOSW : I<0xAB, RawFrm, (ops), "{rep;stosw|rep stosw}",
601                   [(X86rep_stos i16)]>,
602                 Imp<[AX,ECX,EDI], [ECX,EDI]>, REP, OpSize;
603 def REP_STOSD : I<0xAB, RawFrm, (ops), "{rep;stosl|rep stosd}",
604                   [(X86rep_stos i32)]>,
605                 Imp<[EAX,ECX,EDI], [ECX,EDI]>, REP;
606
607
608 //===----------------------------------------------------------------------===//
609 //  Input/Output Instructions...
610 //
611 def IN8rr  : I<0xEC, RawFrm, (ops),
612                "in{b} {%dx, %al|%AL, %DX}",
613                [(set AL, (readport DX))]>,  Imp<[DX], [AL]>;
614 def IN16rr : I<0xED, RawFrm, (ops),
615                "in{w} {%dx, %ax|%AX, %DX}",
616                [(set AX, (readport DX))]>,  Imp<[DX], [AX]>, OpSize;
617 def IN32rr : I<0xED, RawFrm, (ops),
618                "in{l} {%dx, %eax|%EAX, %DX}",
619                [(set EAX, (readport DX))]>, Imp<[DX],[EAX]>;
620
621 def IN8ri  : Ii8<0xE4, RawFrm, (ops i16i8imm:$port),
622                   "in{b} {$port, %al|%AL, $port}",
623                  [(set AL, (readport i16immZExt8:$port))]>,
624              Imp<[], [AL]>;
625 def IN16ri : Ii8<0xE5, RawFrm, (ops i16i8imm:$port),
626                   "in{w} {$port, %ax|%AX, $port}",
627                  [(set AX, (readport i16immZExt8:$port))]>,
628              Imp<[], [AX]>, OpSize;
629 def IN32ri : Ii8<0xE5, RawFrm, (ops i16i8imm:$port),
630                   "in{l} {$port, %eax|%EAX, $port}",
631                  [(set EAX, (readport i16immZExt8:$port))]>,
632              Imp<[],[EAX]>;
633
634 def OUT8rr  : I<0xEE, RawFrm, (ops),
635                 "out{b} {%al, %dx|%DX, %AL}",
636                 [(writeport AL, DX)]>,  Imp<[DX,  AL], []>;
637 def OUT16rr : I<0xEF, RawFrm, (ops),
638                 "out{w} {%ax, %dx|%DX, %AX}",
639                 [(writeport AX, DX)]>,  Imp<[DX,  AX], []>, OpSize;
640 def OUT32rr : I<0xEF, RawFrm, (ops),
641                 "out{l} {%eax, %dx|%DX, %EAX}",
642                 [(writeport EAX, DX)]>, Imp<[DX, EAX], []>;
643
644 def OUT8ir  : Ii8<0xE6, RawFrm, (ops i16i8imm:$port),
645                    "out{b} {%al, $port|$port, %AL}",
646                    [(writeport AL, i16immZExt8:$port)]>,
647               Imp<[AL], []>;
648 def OUT16ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
649                    "out{w} {%ax, $port|$port, %AX}",
650                    [(writeport AX, i16immZExt8:$port)]>,
651               Imp<[AX], []>, OpSize;
652 def OUT32ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
653                    "out{l} {%eax, $port|$port, %EAX}",
654                    [(writeport EAX, i16immZExt8:$port)]>,
655               Imp<[EAX], []>;
656
657 //===----------------------------------------------------------------------===//
658 //  Move Instructions...
659 //
660 def MOV8rr  : I<0x88, MRMDestReg, (ops R8 :$dst, R8 :$src),
661                 "mov{b} {$src, $dst|$dst, $src}", []>;
662 def MOV16rr : I<0x89, MRMDestReg, (ops R16:$dst, R16:$src),
663                 "mov{w} {$src, $dst|$dst, $src}", []>, OpSize;
664 def MOV32rr : I<0x89, MRMDestReg, (ops R32:$dst, R32:$src),
665                 "mov{l} {$src, $dst|$dst, $src}", []>;
666 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (ops R8 :$dst, i8imm :$src),
667                    "mov{b} {$src, $dst|$dst, $src}",
668                    [(set R8:$dst, imm:$src)]>;
669 def MOV16ri : Ii16<0xB8, AddRegFrm, (ops R16:$dst, i16imm:$src),
670                    "mov{w} {$src, $dst|$dst, $src}",
671                    [(set R16:$dst, imm:$src)]>, OpSize;
672 def MOV32ri : Ii32<0xB8, AddRegFrm, (ops R32:$dst, i32imm:$src),
673                    "mov{l} {$src, $dst|$dst, $src}",
674                    [(set R32:$dst, imm:$src)]>;
675 def MOV8mi  : Ii8 <0xC6, MRM0m, (ops i8mem :$dst, i8imm :$src),
676                    "mov{b} {$src, $dst|$dst, $src}",
677                    [(store (i8 imm:$src), addr:$dst)]>;
678 def MOV16mi : Ii16<0xC7, MRM0m, (ops i16mem:$dst, i16imm:$src),
679                    "mov{w} {$src, $dst|$dst, $src}",
680                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
681 def MOV32mi : Ii32<0xC7, MRM0m, (ops i32mem:$dst, i32imm:$src),
682                    "mov{l} {$src, $dst|$dst, $src}",
683                    [(store (i32 imm:$src), addr:$dst)]>;
684
685 def MOV8rm  : I<0x8A, MRMSrcMem, (ops R8 :$dst, i8mem :$src),
686                 "mov{b} {$src, $dst|$dst, $src}",
687                 [(set R8:$dst, (load addr:$src))]>;
688 def MOV16rm : I<0x8B, MRMSrcMem, (ops R16:$dst, i16mem:$src),
689                 "mov{w} {$src, $dst|$dst, $src}",
690                 [(set R16:$dst, (load addr:$src))]>, OpSize;
691 def MOV32rm : I<0x8B, MRMSrcMem, (ops R32:$dst, i32mem:$src),
692                 "mov{l} {$src, $dst|$dst, $src}",
693                 [(set R32:$dst, (load addr:$src))]>;
694
695 def MOV8mr  : I<0x88, MRMDestMem, (ops i8mem :$dst, R8 :$src),
696                 "mov{b} {$src, $dst|$dst, $src}",
697                 [(store R8:$src, addr:$dst)]>;
698 def MOV16mr : I<0x89, MRMDestMem, (ops i16mem:$dst, R16:$src),
699                 "mov{w} {$src, $dst|$dst, $src}",
700                 [(store R16:$src, addr:$dst)]>, OpSize;
701 def MOV32mr : I<0x89, MRMDestMem, (ops i32mem:$dst, R32:$src),
702                 "mov{l} {$src, $dst|$dst, $src}",
703                 [(store R32:$src, addr:$dst)]>;
704                 
705 //===----------------------------------------------------------------------===//
706 //  Fixed-Register Multiplication and Division Instructions...
707 //
708
709 // Extra precision multiplication
710 def MUL8r  : I<0xF6, MRM4r, (ops R8:$src), "mul{b} $src",
711                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
712                // This probably ought to be moved to a def : Pat<> if the
713                // syntax can be accepted.
714                [(set AL, (mul AL, R8:$src))]>,
715              Imp<[AL],[AX]>;               // AL,AH = AL*R8
716 def MUL16r : I<0xF7, MRM4r, (ops R16:$src), "mul{w} $src", []>,
717              Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
718 def MUL32r : I<0xF7, MRM4r, (ops R32:$src), "mul{l} $src", []>,
719              Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
720 def MUL8m  : I<0xF6, MRM4m, (ops i8mem :$src),
721                "mul{b} $src",
722                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
723                // This probably ought to be moved to a def : Pat<> if the
724                // syntax can be accepted.
725                [(set AL, (mul AL, (loadi8 addr:$src)))]>,
726              Imp<[AL],[AX]>;          // AL,AH = AL*[mem8]
727 def MUL16m : I<0xF7, MRM4m, (ops i16mem:$src),
728                "mul{w} $src", []>, Imp<[AX],[AX,DX]>,
729                OpSize; // AX,DX = AX*[mem16]
730 def MUL32m : I<0xF7, MRM4m, (ops i32mem:$src),
731                "mul{l} $src", []>, Imp<[EAX],[EAX,EDX]>;// EAX,EDX = EAX*[mem32]
732
733 def IMUL8r  : I<0xF6, MRM5r, (ops R8:$src), "imul{b} $src", []>,
734               Imp<[AL],[AX]>;               // AL,AH = AL*R8
735 def IMUL16r : I<0xF7, MRM5r, (ops R16:$src), "imul{w} $src", []>,
736               Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
737 def IMUL32r : I<0xF7, MRM5r, (ops R32:$src), "imul{l} $src", []>,
738               Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
739 def IMUL8m  : I<0xF6, MRM5m, (ops i8mem :$src),
740                 "imul{b} $src", []>, Imp<[AL],[AX]>;        // AL,AH = AL*[mem8]
741 def IMUL16m : I<0xF7, MRM5m, (ops i16mem:$src),
742                 "imul{w} $src", []>, Imp<[AX],[AX,DX]>,
743                 OpSize; // AX,DX = AX*[mem16]
744 def IMUL32m : I<0xF7, MRM5m, (ops i32mem:$src),
745                 "imul{l} $src", []>,
746                 Imp<[EAX],[EAX,EDX]>;  // EAX,EDX = EAX*[mem32]
747
748 // unsigned division/remainder
749 def DIV8r  : I<0xF6, MRM6r, (ops R8:$src),          // AX/r8 = AL,AH
750                "div{b} $src", []>, Imp<[AX],[AX]>;
751 def DIV16r : I<0xF7, MRM6r, (ops R16:$src),         // DX:AX/r16 = AX,DX
752                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
753 def DIV32r : I<0xF7, MRM6r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
754                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
755 def DIV8m  : I<0xF6, MRM6m, (ops i8mem:$src),       // AX/[mem8] = AL,AH
756                "div{b} $src", []>, Imp<[AX],[AX]>;
757 def DIV16m : I<0xF7, MRM6m, (ops i16mem:$src),      // DX:AX/[mem16] = AX,DX
758                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
759 def DIV32m : I<0xF7, MRM6m, (ops i32mem:$src),      // EDX:EAX/[mem32] = EAX,EDX
760                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
761
762 // Signed division/remainder.
763 def IDIV8r : I<0xF6, MRM7r, (ops R8:$src),          // AX/r8 = AL,AH
764                "idiv{b} $src", []>, Imp<[AX],[AX]>;
765 def IDIV16r: I<0xF7, MRM7r, (ops R16:$src),         // DX:AX/r16 = AX,DX
766                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
767 def IDIV32r: I<0xF7, MRM7r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
768                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
769 def IDIV8m : I<0xF6, MRM7m, (ops i8mem:$src),      // AX/[mem8] = AL,AH
770                "idiv{b} $src", []>, Imp<[AX],[AX]>;
771 def IDIV16m: I<0xF7, MRM7m, (ops i16mem:$src),     // DX:AX/[mem16] = AX,DX
772                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
773 def IDIV32m: I<0xF7, MRM7m, (ops i32mem:$src),     // EDX:EAX/[mem32] = EAX,EDX
774                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
775
776 // Sign-extenders for division.
777 def CBW : I<0x98, RawFrm, (ops),
778             "{cbtw|cbw}", []>, Imp<[AL],[AH]>;   // AX = signext(AL)
779 def CWD : I<0x99, RawFrm, (ops),
780             "{cwtd|cwd}", []>, Imp<[AX],[DX]>;   // DX:AX = signext(AX)
781 def CDQ : I<0x99, RawFrm, (ops),
782             "{cltd|cdq}", []>, Imp<[EAX],[EDX]>; // EDX:EAX = signext(EAX)
783           
784
785 //===----------------------------------------------------------------------===//
786 //  Two address Instructions...
787 //
788 let isTwoAddress = 1 in {
789
790 // Conditional moves
791 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, R16 = R16
792                   (ops R16:$dst, R16:$src1, R16:$src2),
793                   "cmovb {$src2, $dst|$dst, $src2}",
794                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
795                                    X86_COND_B, STATUS))]>,
796                   Imp<[STATUS],[]>, TB, OpSize;
797 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, R16 = [mem16]
798                   (ops R16:$dst, R16:$src1, i16mem:$src2),
799                   "cmovb {$src2, $dst|$dst, $src2}",
800                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
801                                    X86_COND_B, STATUS))]>,
802                   Imp<[STATUS],[]>, TB, OpSize;
803 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, R32 = R32
804                   (ops R32:$dst, R32:$src1, R32:$src2),
805                   "cmovb {$src2, $dst|$dst, $src2}",
806                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
807                                    X86_COND_B, STATUS))]>,
808                   Imp<[STATUS],[]>,  TB;
809 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, R32 = [mem32]
810                   (ops R32:$dst, R32:$src1, i32mem:$src2),
811                   "cmovb {$src2, $dst|$dst, $src2}",
812                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
813                                    X86_COND_B, STATUS))]>,
814                   Imp<[STATUS],[]>,  TB;
815
816 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, R16 = R16
817                   (ops R16:$dst, R16:$src1, R16:$src2),
818                   "cmovae {$src2, $dst|$dst, $src2}",
819                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
820                                    X86_COND_AE, STATUS))]>,
821                   Imp<[STATUS],[]>,  TB, OpSize;
822 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, R16 = [mem16]
823                   (ops R16:$dst, R16:$src1, i16mem:$src2),
824                   "cmovae {$src2, $dst|$dst, $src2}",
825                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
826                                    X86_COND_AE, STATUS))]>,
827                   Imp<[STATUS],[]>,  TB, OpSize;
828 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, R32 = R32
829                   (ops R32:$dst, R32:$src1, R32:$src2),
830                   "cmovae {$src2, $dst|$dst, $src2}",
831                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
832                                    X86_COND_AE, STATUS))]>,
833                   Imp<[STATUS],[]>,  TB;
834 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, R32 = [mem32]
835                   (ops R32:$dst, R32:$src1, i32mem:$src2),
836                   "cmovae {$src2, $dst|$dst, $src2}",
837                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
838                                    X86_COND_AE, STATUS))]>,
839                   Imp<[STATUS],[]>,  TB;
840
841 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, R16 = R16
842                   (ops R16:$dst, R16:$src1, R16:$src2),
843                   "cmove {$src2, $dst|$dst, $src2}",
844                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
845                                    X86_COND_E, STATUS))]>,
846                   Imp<[STATUS],[]>,  TB, OpSize;
847 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, R16 = [mem16]
848                   (ops R16:$dst, R16:$src1, i16mem:$src2),
849                   "cmove {$src2, $dst|$dst, $src2}",
850                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
851                                    X86_COND_E, STATUS))]>,
852                   Imp<[STATUS],[]>,  TB, OpSize;
853 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, R32 = R32
854                   (ops R32:$dst, R32:$src1, R32:$src2),
855                   "cmove {$src2, $dst|$dst, $src2}",
856                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
857                                    X86_COND_E, STATUS))]>,
858                   Imp<[STATUS],[]>,  TB;
859 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, R32 = [mem32]
860                   (ops R32:$dst, R32:$src1, i32mem:$src2),
861                   "cmove {$src2, $dst|$dst, $src2}",
862                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
863                                    X86_COND_E, STATUS))]>,
864                   Imp<[STATUS],[]>,  TB;
865
866 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, R16 = R16
867                   (ops R16:$dst, R16:$src1, R16:$src2),
868                   "cmovne {$src2, $dst|$dst, $src2}",
869                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
870                                    X86_COND_NE, STATUS))]>,
871                   Imp<[STATUS],[]>,  TB, OpSize;
872 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, R16 = [mem16]
873                   (ops R16:$dst, R16:$src1, i16mem:$src2),
874                   "cmovne {$src2, $dst|$dst, $src2}",
875                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
876                                    X86_COND_NE, STATUS))]>,
877                   Imp<[STATUS],[]>,  TB, OpSize;
878 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, R32 = R32
879                   (ops R32:$dst, R32:$src1, R32:$src2),
880                   "cmovne {$src2, $dst|$dst, $src2}",
881                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
882                                    X86_COND_NE, STATUS))]>,
883                   Imp<[STATUS],[]>,  TB;
884 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, R32 = [mem32]
885                   (ops R32:$dst, R32:$src1, i32mem:$src2),
886                   "cmovne {$src2, $dst|$dst, $src2}",
887                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
888                                    X86_COND_NE, STATUS))]>,
889                   Imp<[STATUS],[]>,  TB;
890
891 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, R16 = R16
892                   (ops R16:$dst, R16:$src1, R16:$src2),
893                   "cmovbe {$src2, $dst|$dst, $src2}",
894                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
895                                    X86_COND_BE, STATUS))]>,
896                   Imp<[STATUS],[]>,  TB, OpSize;
897 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, R16 = [mem16]
898                   (ops R16:$dst, R16:$src1, i16mem:$src2),
899                   "cmovbe {$src2, $dst|$dst, $src2}",
900                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
901                                    X86_COND_BE, STATUS))]>,
902                   Imp<[STATUS],[]>,  TB, OpSize;
903 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, R32 = R32
904                   (ops R32:$dst, R32:$src1, R32:$src2),
905                   "cmovbe {$src2, $dst|$dst, $src2}",
906                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
907                                    X86_COND_BE, STATUS))]>,
908                   Imp<[STATUS],[]>,  TB;
909 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, R32 = [mem32]
910                   (ops R32:$dst, R32:$src1, i32mem:$src2),
911                   "cmovbe {$src2, $dst|$dst, $src2}",
912                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
913                                    X86_COND_BE, STATUS))]>,
914                   Imp<[STATUS],[]>,  TB;
915
916 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, R16 = R16
917                   (ops R16:$dst, R16:$src1, R16:$src2),
918                   "cmova {$src2, $dst|$dst, $src2}",
919                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
920                                    X86_COND_A, STATUS))]>,
921                   Imp<[STATUS],[]>,  TB, OpSize;
922 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, R16 = [mem16]
923                   (ops R16:$dst, R16:$src1, i16mem:$src2),
924                   "cmova {$src2, $dst|$dst, $src2}",
925                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
926                                    X86_COND_A, STATUS))]>,
927                   Imp<[STATUS],[]>,  TB, OpSize;
928 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, R32 = R32
929                   (ops R32:$dst, R32:$src1, R32:$src2),
930                   "cmova {$src2, $dst|$dst, $src2}",
931                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
932                                    X86_COND_A, STATUS))]>,
933                   Imp<[STATUS],[]>,  TB;
934 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, R32 = [mem32]
935                   (ops R32:$dst, R32:$src1, i32mem:$src2),
936                   "cmova {$src2, $dst|$dst, $src2}",
937                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
938                                    X86_COND_A, STATUS))]>,
939                   Imp<[STATUS],[]>,  TB;
940
941 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, R16 = R16
942                   (ops R16:$dst, R16:$src1, R16:$src2),
943                   "cmovl {$src2, $dst|$dst, $src2}",
944                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
945                                    X86_COND_L, STATUS))]>,
946                   Imp<[STATUS],[]>,  TB, OpSize;
947 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, R16 = [mem16]
948                   (ops R16:$dst, R16:$src1, i16mem:$src2),
949                   "cmovl {$src2, $dst|$dst, $src2}",
950                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
951                                    X86_COND_L, STATUS))]>,
952                   Imp<[STATUS],[]>,  TB, OpSize;
953 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, R32 = R32
954                   (ops R32:$dst, R32:$src1, R32:$src2),
955                   "cmovl {$src2, $dst|$dst, $src2}",
956                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
957                                    X86_COND_L, STATUS))]>,
958                   Imp<[STATUS],[]>,  TB;
959 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, R32 = [mem32]
960                   (ops R32:$dst, R32:$src1, i32mem:$src2),
961                   "cmovl {$src2, $dst|$dst, $src2}",
962                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
963                                    X86_COND_L, STATUS))]>,
964                   Imp<[STATUS],[]>,  TB;
965
966 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, R16 = R16
967                   (ops R16:$dst, R16:$src1, R16:$src2),
968                   "cmovge {$src2, $dst|$dst, $src2}",
969                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
970                                    X86_COND_GE, STATUS))]>,
971                   Imp<[STATUS],[]>,  TB, OpSize;
972 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, R16 = [mem16]
973                   (ops R16:$dst, R16:$src1, i16mem:$src2),
974                   "cmovge {$src2, $dst|$dst, $src2}",
975                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
976                                    X86_COND_GE, STATUS))]>,
977                   Imp<[STATUS],[]>,  TB, OpSize;
978 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, R32 = R32
979                   (ops R32:$dst, R32:$src1, R32:$src2),
980                   "cmovge {$src2, $dst|$dst, $src2}",
981                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
982                                    X86_COND_GE, STATUS))]>,
983                   Imp<[STATUS],[]>,  TB;
984 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, R32 = [mem32]
985                   (ops R32:$dst, R32:$src1, i32mem:$src2),
986                   "cmovge {$src2, $dst|$dst, $src2}",
987                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
988                                    X86_COND_GE, STATUS))]>,
989                   Imp<[STATUS],[]>,  TB;
990
991 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, R16 = R16
992                   (ops R16:$dst, R16:$src1, R16:$src2),
993                   "cmovle {$src2, $dst|$dst, $src2}",
994                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
995                                    X86_COND_LE, STATUS))]>,
996                   Imp<[STATUS],[]>,  TB, OpSize;
997 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, R16 = [mem16]
998                   (ops R16:$dst, R16:$src1, i16mem:$src2),
999                   "cmovle {$src2, $dst|$dst, $src2}",
1000                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1001                                    X86_COND_LE, STATUS))]>,
1002                   Imp<[STATUS],[]>,  TB, OpSize;
1003 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, R32 = R32
1004                   (ops R32:$dst, R32:$src1, R32:$src2),
1005                   "cmovle {$src2, $dst|$dst, $src2}",
1006                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1007                                    X86_COND_LE, STATUS))]>,
1008                   Imp<[STATUS],[]>,  TB;
1009 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, R32 = [mem32]
1010                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1011                   "cmovle {$src2, $dst|$dst, $src2}",
1012                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1013                                    X86_COND_LE, STATUS))]>,
1014                   Imp<[STATUS],[]>,  TB;
1015
1016 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, R16 = R16
1017                   (ops R16:$dst, R16:$src1, R16:$src2),
1018                   "cmovg {$src2, $dst|$dst, $src2}",
1019                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1020                                    X86_COND_G, STATUS))]>,
1021                   Imp<[STATUS],[]>,  TB, OpSize;
1022 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, R16 = [mem16]
1023                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1024                   "cmovg {$src2, $dst|$dst, $src2}",
1025                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1026                                    X86_COND_G, STATUS))]>,
1027                   Imp<[STATUS],[]>,  TB, OpSize;
1028 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, R32 = R32
1029                   (ops R32:$dst, R32:$src1, R32:$src2),
1030                   "cmovg {$src2, $dst|$dst, $src2}",
1031                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1032                                    X86_COND_G, STATUS))]>,
1033                   Imp<[STATUS],[]>,  TB;
1034 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, R32 = [mem32]
1035                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1036                   "cmovg {$src2, $dst|$dst, $src2}",
1037                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1038                                    X86_COND_G, STATUS))]>,
1039                   Imp<[STATUS],[]>,  TB;
1040
1041 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, R16 = R16
1042                   (ops R16:$dst, R16:$src1, R16:$src2),
1043                   "cmovs {$src2, $dst|$dst, $src2}",
1044                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1045                                    X86_COND_S, STATUS))]>,
1046                   Imp<[STATUS],[]>, TB, OpSize;
1047 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, R16 = [mem16]
1048                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1049                   "cmovs {$src2, $dst|$dst, $src2}",
1050                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1051                                    X86_COND_S, STATUS))]>,
1052                   Imp<[STATUS],[]>, TB, OpSize;
1053 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, R32 = R32
1054                   (ops R32:$dst, R32:$src1, R32:$src2),
1055                   "cmovs {$src2, $dst|$dst, $src2}",
1056                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1057                                    X86_COND_S, STATUS))]>,
1058                   Imp<[STATUS],[]>, TB;
1059 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, R32 = [mem32]
1060                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1061                   "cmovs {$src2, $dst|$dst, $src2}",
1062                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1063                                    X86_COND_S, STATUS))]>,
1064                   Imp<[STATUS],[]>, TB;
1065
1066 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, R16 = R16
1067                   (ops R16:$dst, R16:$src1, R16:$src2),
1068                   "cmovns {$src2, $dst|$dst, $src2}",
1069                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1070                                    X86_COND_NS, STATUS))]>,
1071                   Imp<[STATUS],[]>, TB, OpSize;
1072 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, R16 = [mem16]
1073                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1074                   "cmovns {$src2, $dst|$dst, $src2}",
1075                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1076                                    X86_COND_NS, STATUS))]>,
1077                   Imp<[STATUS],[]>, TB, OpSize;
1078 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, R32 = R32
1079                   (ops R32:$dst, R32:$src1, R32:$src2),
1080                   "cmovns {$src2, $dst|$dst, $src2}",
1081                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1082                                    X86_COND_NS, STATUS))]>,
1083                   Imp<[STATUS],[]>, TB;
1084 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, R32 = [mem32]
1085                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1086                   "cmovns {$src2, $dst|$dst, $src2}",
1087                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1088                                    X86_COND_NS, STATUS))]>,
1089                   Imp<[STATUS],[]>, TB;
1090
1091 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, R16 = R16
1092                   (ops R16:$dst, R16:$src1, R16:$src2),
1093                   "cmovp {$src2, $dst|$dst, $src2}",
1094                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1095                                    X86_COND_P, STATUS))]>,
1096                   Imp<[STATUS],[]>, TB, OpSize;
1097 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, R16 = [mem16]
1098                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1099                   "cmovp {$src2, $dst|$dst, $src2}",
1100                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1101                                    X86_COND_P, STATUS))]>,
1102                   Imp<[STATUS],[]>, TB, OpSize;
1103 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, R32 = R32
1104                   (ops R32:$dst, R32:$src1, R32:$src2),
1105                   "cmovp {$src2, $dst|$dst, $src2}",
1106                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1107                                    X86_COND_P, STATUS))]>,
1108                   Imp<[STATUS],[]>, TB;
1109 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, R32 = [mem32]
1110                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1111                   "cmovp {$src2, $dst|$dst, $src2}",
1112                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1113                                    X86_COND_P, STATUS))]>,
1114                   Imp<[STATUS],[]>, TB;
1115
1116 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, R16 = R16
1117                   (ops R16:$dst, R16:$src1, R16:$src2),
1118                   "cmovnp {$src2, $dst|$dst, $src2}",
1119                    [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1120                                     X86_COND_NP, STATUS))]>,
1121                   Imp<[STATUS],[]>, TB, OpSize;
1122 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, R16 = [mem16]
1123                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1124                   "cmovnp {$src2, $dst|$dst, $src2}",
1125                    [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1126                                     X86_COND_NP, STATUS))]>,
1127                   Imp<[STATUS],[]>, TB, OpSize;
1128 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, R32 = R32
1129                   (ops R32:$dst, R32:$src1, R32:$src2),
1130                   "cmovnp {$src2, $dst|$dst, $src2}",
1131                    [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1132                                     X86_COND_NP, STATUS))]>,
1133                   Imp<[STATUS],[]>, TB;
1134 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, R32 = [mem32]
1135                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1136                   "cmovnp {$src2, $dst|$dst, $src2}",
1137                    [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1138                                    X86_COND_NP, STATUS))]>,
1139                   Imp<[STATUS],[]>, TB;
1140
1141
1142 // unary instructions
1143 def NEG8r  : I<0xF6, MRM3r, (ops R8 :$dst, R8 :$src), "neg{b} $dst",
1144                [(set R8:$dst, (ineg R8:$src))]>;
1145 def NEG16r : I<0xF7, MRM3r, (ops R16:$dst, R16:$src), "neg{w} $dst",
1146                [(set R16:$dst, (ineg R16:$src))]>, OpSize;
1147 def NEG32r : I<0xF7, MRM3r, (ops R32:$dst, R32:$src), "neg{l} $dst",
1148                [(set R32:$dst, (ineg R32:$src))]>;
1149 let isTwoAddress = 0 in {
1150   def NEG8m  : I<0xF6, MRM3m, (ops i8mem :$dst), "neg{b} $dst",
1151                  [(store (ineg (loadi8 addr:$dst)), addr:$dst)]>;
1152   def NEG16m : I<0xF7, MRM3m, (ops i16mem:$dst), "neg{w} $dst",
1153                  [(store (ineg (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1154   def NEG32m : I<0xF7, MRM3m, (ops i32mem:$dst), "neg{l} $dst",
1155                  [(store (ineg (loadi32 addr:$dst)), addr:$dst)]>;
1156
1157 }
1158
1159 def NOT8r  : I<0xF6, MRM2r, (ops R8 :$dst, R8 :$src), "not{b} $dst",
1160                [(set R8:$dst, (not R8:$src))]>;
1161 def NOT16r : I<0xF7, MRM2r, (ops R16:$dst, R16:$src), "not{w} $dst",
1162                [(set R16:$dst, (not R16:$src))]>, OpSize;
1163 def NOT32r : I<0xF7, MRM2r, (ops R32:$dst, R32:$src), "not{l} $dst",
1164                [(set R32:$dst, (not R32:$src))]>;
1165 let isTwoAddress = 0 in {
1166   def NOT8m  : I<0xF6, MRM2m, (ops i8mem :$dst), "not{b} $dst",
1167                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1168   def NOT16m : I<0xF7, MRM2m, (ops i16mem:$dst), "not{w} $dst",
1169                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1170   def NOT32m : I<0xF7, MRM2m, (ops i32mem:$dst), "not{l} $dst",
1171                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1172 }
1173
1174 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1175 def INC8r  : I<0xFE, MRM0r, (ops R8 :$dst, R8 :$src), "inc{b} $dst",
1176                [(set R8:$dst, (add R8:$src, 1))]>;
1177 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1178 def INC16r : I<0xFF, MRM0r, (ops R16:$dst, R16:$src), "inc{w} $dst",
1179                [(set R16:$dst, (add R16:$src, 1))]>, OpSize;
1180 def INC32r : I<0xFF, MRM0r, (ops R32:$dst, R32:$src), "inc{l} $dst",
1181                [(set R32:$dst, (add R32:$src, 1))]>;
1182 }
1183 let isTwoAddress = 0 in {
1184   def INC8m  : I<0xFE, MRM0m, (ops i8mem :$dst), "inc{b} $dst",
1185                [(store (add (loadi8 addr:$dst), 1), addr:$dst)]>;
1186   def INC16m : I<0xFF, MRM0m, (ops i16mem:$dst), "inc{w} $dst",
1187                [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>, OpSize;
1188   def INC32m : I<0xFF, MRM0m, (ops i32mem:$dst), "inc{l} $dst",
1189                [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>;
1190 }
1191
1192 def DEC8r  : I<0xFE, MRM1r, (ops R8 :$dst, R8 :$src), "dec{b} $dst",
1193                [(set R8:$dst, (add R8:$src, -1))]>;
1194 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1195 def DEC16r : I<0xFF, MRM1r, (ops R16:$dst, R16:$src), "dec{w} $dst",
1196                [(set R16:$dst, (add R16:$src, -1))]>, OpSize;
1197 def DEC32r : I<0xFF, MRM1r, (ops R32:$dst, R32:$src), "dec{l} $dst",
1198                [(set R32:$dst, (add R32:$src, -1))]>;
1199 }
1200
1201 let isTwoAddress = 0 in {
1202   def DEC8m  : I<0xFE, MRM1m, (ops i8mem :$dst), "dec{b} $dst",
1203                [(store (add (loadi8 addr:$dst), -1), addr:$dst)]>;
1204   def DEC16m : I<0xFF, MRM1m, (ops i16mem:$dst), "dec{w} $dst",
1205                [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>, OpSize;
1206   def DEC32m : I<0xFF, MRM1m, (ops i32mem:$dst), "dec{l} $dst",
1207                [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>;
1208 }
1209
1210 // Logical operators...
1211 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1212 def AND8rr   : I<0x20, MRMDestReg,
1213                 (ops R8 :$dst, R8 :$src1, R8 :$src2),
1214                 "and{b} {$src2, $dst|$dst, $src2}",
1215                 [(set R8:$dst, (and R8:$src1, R8:$src2))]>;
1216 def AND16rr  : I<0x21, MRMDestReg,
1217                  (ops R16:$dst, R16:$src1, R16:$src2),
1218                  "and{w} {$src2, $dst|$dst, $src2}",
1219                  [(set R16:$dst, (and R16:$src1, R16:$src2))]>, OpSize;
1220 def AND32rr  : I<0x21, MRMDestReg, 
1221                  (ops R32:$dst, R32:$src1, R32:$src2),
1222                  "and{l} {$src2, $dst|$dst, $src2}",
1223                  [(set R32:$dst, (and R32:$src1, R32:$src2))]>;
1224 }
1225
1226 def AND8rm   : I<0x22, MRMSrcMem, 
1227                  (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1228                  "and{b} {$src2, $dst|$dst, $src2}",
1229                 [(set R8:$dst, (and R8:$src1, (load addr:$src2)))]>;
1230 def AND16rm  : I<0x23, MRMSrcMem, 
1231                  (ops R16:$dst, R16:$src1, i16mem:$src2),
1232                  "and{w} {$src2, $dst|$dst, $src2}",
1233                 [(set R16:$dst, (and R16:$src1, (load addr:$src2)))]>, OpSize;
1234 def AND32rm  : I<0x23, MRMSrcMem,
1235                  (ops R32:$dst, R32:$src1, i32mem:$src2),
1236                  "and{l} {$src2, $dst|$dst, $src2}",
1237                 [(set R32:$dst, (and R32:$src1, (load addr:$src2)))]>;
1238
1239 def AND8ri   : Ii8<0x80, MRM4r, 
1240                    (ops R8 :$dst, R8 :$src1, i8imm :$src2),
1241                    "and{b} {$src2, $dst|$dst, $src2}",
1242                    [(set R8:$dst, (and R8:$src1, imm:$src2))]>;
1243 def AND16ri  : Ii16<0x81, MRM4r, 
1244                     (ops R16:$dst, R16:$src1, i16imm:$src2),
1245                     "and{w} {$src2, $dst|$dst, $src2}",
1246                     [(set R16:$dst, (and R16:$src1, imm:$src2))]>, OpSize;
1247 def AND32ri  : Ii32<0x81, MRM4r, 
1248                     (ops R32:$dst, R32:$src1, i32imm:$src2),
1249                     "and{l} {$src2, $dst|$dst, $src2}",
1250                     [(set R32:$dst, (and R32:$src1, imm:$src2))]>;
1251 def AND16ri8 : Ii8<0x83, MRM4r, 
1252                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1253                    "and{w} {$src2, $dst|$dst, $src2}",
1254                    [(set R16:$dst, (and R16:$src1, i16immSExt8:$src2))]>,
1255                    OpSize;
1256 def AND32ri8 : Ii8<0x83, MRM4r, 
1257                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1258                    "and{l} {$src2, $dst|$dst, $src2}",
1259                    [(set R32:$dst, (and R32:$src1, i32immSExt8:$src2))]>;
1260
1261 let isTwoAddress = 0 in {
1262   def AND8mr   : I<0x20, MRMDestMem,
1263                    (ops i8mem :$dst, R8 :$src),
1264                    "and{b} {$src, $dst|$dst, $src}",
1265                    [(store (and (load addr:$dst), R8:$src), addr:$dst)]>;
1266   def AND16mr  : I<0x21, MRMDestMem,
1267                    (ops i16mem:$dst, R16:$src),
1268                    "and{w} {$src, $dst|$dst, $src}",
1269                    [(store (and (load addr:$dst), R16:$src), addr:$dst)]>,
1270                    OpSize;
1271   def AND32mr  : I<0x21, MRMDestMem,
1272                    (ops i32mem:$dst, R32:$src),
1273                    "and{l} {$src, $dst|$dst, $src}",
1274                    [(store (and (load addr:$dst), R32:$src), addr:$dst)]>;
1275   def AND8mi   : Ii8<0x80, MRM4m,
1276                      (ops i8mem :$dst, i8imm :$src),
1277                      "and{b} {$src, $dst|$dst, $src}",
1278                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1279   def AND16mi  : Ii16<0x81, MRM4m,
1280                       (ops i16mem:$dst, i16imm:$src),
1281                       "and{w} {$src, $dst|$dst, $src}",
1282                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1283                       OpSize;
1284   def AND32mi  : Ii32<0x81, MRM4m,
1285                       (ops i32mem:$dst, i32imm:$src),
1286                       "and{l} {$src, $dst|$dst, $src}",
1287                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1288   def AND16mi8 : Ii8<0x83, MRM4m,
1289                      (ops i16mem:$dst, i16i8imm :$src),
1290                      "and{w} {$src, $dst|$dst, $src}",
1291                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1292                      OpSize;
1293   def AND32mi8 : Ii8<0x83, MRM4m,
1294                      (ops i32mem:$dst, i32i8imm :$src),
1295                      "and{l} {$src, $dst|$dst, $src}",
1296                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1297 }
1298
1299
1300 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1301 def OR8rr    : I<0x08, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1302                  "or{b} {$src2, $dst|$dst, $src2}",
1303                  [(set R8:$dst, (or R8:$src1, R8:$src2))]>;
1304 def OR16rr   : I<0x09, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1305                  "or{w} {$src2, $dst|$dst, $src2}",
1306                  [(set R16:$dst, (or R16:$src1, R16:$src2))]>, OpSize;
1307 def OR32rr   : I<0x09, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1308                  "or{l} {$src2, $dst|$dst, $src2}",
1309                  [(set R32:$dst, (or R32:$src1, R32:$src2))]>;
1310 }
1311 def OR8rm    : I<0x0A, MRMSrcMem , (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1312                  "or{b} {$src2, $dst|$dst, $src2}",
1313                 [(set R8:$dst, (or R8:$src1, (load addr:$src2)))]>;
1314 def OR16rm   : I<0x0B, MRMSrcMem , (ops R16:$dst, R16:$src1, i16mem:$src2),
1315                  "or{w} {$src2, $dst|$dst, $src2}",
1316                 [(set R16:$dst, (or R16:$src1, (load addr:$src2)))]>, OpSize;
1317 def OR32rm   : I<0x0B, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
1318                  "or{l} {$src2, $dst|$dst, $src2}",
1319                 [(set R32:$dst, (or R32:$src1, (load addr:$src2)))]>;
1320
1321 def OR8ri    : Ii8 <0x80, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1322                     "or{b} {$src2, $dst|$dst, $src2}",
1323                     [(set R8:$dst, (or R8:$src1, imm:$src2))]>;
1324 def OR16ri   : Ii16<0x81, MRM1r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1325                     "or{w} {$src2, $dst|$dst, $src2}", 
1326                     [(set R16:$dst, (or R16:$src1, imm:$src2))]>, OpSize;
1327 def OR32ri   : Ii32<0x81, MRM1r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1328                     "or{l} {$src2, $dst|$dst, $src2}",
1329                     [(set R32:$dst, (or R32:$src1, imm:$src2))]>;
1330
1331 def OR16ri8  : Ii8<0x83, MRM1r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1332                    "or{w} {$src2, $dst|$dst, $src2}",
1333                    [(set R16:$dst, (or R16:$src1, i16immSExt8:$src2))]>, OpSize;
1334 def OR32ri8  : Ii8<0x83, MRM1r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1335                    "or{l} {$src2, $dst|$dst, $src2}",
1336                    [(set R32:$dst, (or R32:$src1, i32immSExt8:$src2))]>;
1337 let isTwoAddress = 0 in {
1338   def OR8mr  : I<0x08, MRMDestMem, (ops i8mem:$dst, R8:$src),
1339                  "or{b} {$src, $dst|$dst, $src}",
1340                  [(store (or (load addr:$dst), R8:$src), addr:$dst)]>;
1341   def OR16mr : I<0x09, MRMDestMem, (ops i16mem:$dst, R16:$src),
1342                  "or{w} {$src, $dst|$dst, $src}",
1343                  [(store (or (load addr:$dst), R16:$src), addr:$dst)]>, OpSize;
1344   def OR32mr : I<0x09, MRMDestMem, (ops i32mem:$dst, R32:$src),
1345                  "or{l} {$src, $dst|$dst, $src}",
1346                  [(store (or (load addr:$dst), R32:$src), addr:$dst)]>;
1347   def OR8mi    : Ii8<0x80, MRM1m, (ops i8mem :$dst, i8imm:$src),
1348                  "or{b} {$src, $dst|$dst, $src}",
1349                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1350   def OR16mi   : Ii16<0x81, MRM1m, (ops i16mem:$dst, i16imm:$src),
1351                  "or{w} {$src, $dst|$dst, $src}",
1352                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1353                  OpSize;
1354   def OR32mi   : Ii32<0x81, MRM1m, (ops i32mem:$dst, i32imm:$src),
1355                  "or{l} {$src, $dst|$dst, $src}",
1356                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1357   def OR16mi8  : Ii8<0x83, MRM1m, (ops i16mem:$dst, i16i8imm:$src),
1358                  "or{w} {$src, $dst|$dst, $src}",
1359                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1360                      OpSize;
1361   def OR32mi8  : Ii8<0x83, MRM1m, (ops i32mem:$dst, i32i8imm:$src),
1362                  "or{l} {$src, $dst|$dst, $src}",
1363                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1364 }
1365
1366
1367 let isCommutable = 1 in {   // X = XOR Y, Z   --> X = XOR Z, Y
1368 def XOR8rr   : I<0x30, MRMDestReg,
1369                  (ops R8 :$dst, R8 :$src1, R8 :$src2),
1370                  "xor{b} {$src2, $dst|$dst, $src2}",
1371                  [(set R8:$dst, (xor R8:$src1, R8:$src2))]>;
1372 def XOR16rr  : I<0x31, MRMDestReg, 
1373                  (ops R16:$dst, R16:$src1, R16:$src2), 
1374                  "xor{w} {$src2, $dst|$dst, $src2}",
1375                  [(set R16:$dst, (xor R16:$src1, R16:$src2))]>, OpSize;
1376 def XOR32rr  : I<0x31, MRMDestReg, 
1377                  (ops R32:$dst, R32:$src1, R32:$src2), 
1378                  "xor{l} {$src2, $dst|$dst, $src2}",
1379                  [(set R32:$dst, (xor R32:$src1, R32:$src2))]>;
1380 }
1381
1382 def XOR8rm   : I<0x32, MRMSrcMem , 
1383                  (ops R8 :$dst, R8:$src1, i8mem :$src2), 
1384                  "xor{b} {$src2, $dst|$dst, $src2}",
1385                  [(set R8:$dst, (xor R8:$src1, (load addr:$src2)))]>;
1386 def XOR16rm  : I<0x33, MRMSrcMem , 
1387                  (ops R16:$dst, R16:$src1, i16mem:$src2), 
1388                  "xor{w} {$src2, $dst|$dst, $src2}",
1389                  [(set R16:$dst, (xor R16:$src1, (load addr:$src2)))]>, OpSize;
1390 def XOR32rm  : I<0x33, MRMSrcMem , 
1391                  (ops R32:$dst, R32:$src1, i32mem:$src2), 
1392                  "xor{l} {$src2, $dst|$dst, $src2}",
1393                  [(set R32:$dst, (xor R32:$src1, (load addr:$src2)))]>;
1394
1395 def XOR8ri   : Ii8<0x80, MRM6r, 
1396                    (ops R8:$dst, R8:$src1, i8imm:$src2), 
1397                    "xor{b} {$src2, $dst|$dst, $src2}",
1398                    [(set R8:$dst, (xor R8:$src1, imm:$src2))]>;
1399 def XOR16ri  : Ii16<0x81, MRM6r, 
1400                     (ops R16:$dst, R16:$src1, i16imm:$src2), 
1401                     "xor{w} {$src2, $dst|$dst, $src2}",
1402                     [(set R16:$dst, (xor R16:$src1, imm:$src2))]>, OpSize;
1403 def XOR32ri  : Ii32<0x81, MRM6r, 
1404                     (ops R32:$dst, R32:$src1, i32imm:$src2), 
1405                     "xor{l} {$src2, $dst|$dst, $src2}",
1406                     [(set R32:$dst, (xor R32:$src1, imm:$src2))]>;
1407 def XOR16ri8 : Ii8<0x83, MRM6r, 
1408                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1409                    "xor{w} {$src2, $dst|$dst, $src2}",
1410                    [(set R16:$dst, (xor R16:$src1, i16immSExt8:$src2))]>,
1411                    OpSize;
1412 def XOR32ri8 : Ii8<0x83, MRM6r, 
1413                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1414                    "xor{l} {$src2, $dst|$dst, $src2}",
1415                    [(set R32:$dst, (xor R32:$src1, i32immSExt8:$src2))]>;
1416 let isTwoAddress = 0 in {
1417   def XOR8mr   : I<0x30, MRMDestMem,
1418                    (ops i8mem :$dst, R8 :$src),
1419                    "xor{b} {$src, $dst|$dst, $src}",
1420                    [(store (xor (load addr:$dst), R8:$src), addr:$dst)]>;
1421   def XOR16mr  : I<0x31, MRMDestMem,
1422                    (ops i16mem:$dst, R16:$src),
1423                    "xor{w} {$src, $dst|$dst, $src}",
1424                    [(store (xor (load addr:$dst), R16:$src), addr:$dst)]>,
1425                    OpSize;
1426   def XOR32mr  : I<0x31, MRMDestMem,
1427                    (ops i32mem:$dst, R32:$src),
1428                    "xor{l} {$src, $dst|$dst, $src}",
1429                    [(store (xor (load addr:$dst), R32:$src), addr:$dst)]>;
1430   def XOR8mi   : Ii8<0x80, MRM6m,
1431                      (ops i8mem :$dst, i8imm :$src),
1432                      "xor{b} {$src, $dst|$dst, $src}",
1433                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1434   def XOR16mi  : Ii16<0x81, MRM6m,
1435                       (ops i16mem:$dst, i16imm:$src),
1436                       "xor{w} {$src, $dst|$dst, $src}",
1437                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1438                       OpSize;
1439   def XOR32mi  : Ii32<0x81, MRM6m,
1440                       (ops i32mem:$dst, i32imm:$src),
1441                       "xor{l} {$src, $dst|$dst, $src}",
1442                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1443   def XOR16mi8 : Ii8<0x83, MRM6m,
1444                      (ops i16mem:$dst, i16i8imm :$src),
1445                      "xor{w} {$src, $dst|$dst, $src}",
1446                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1447                      OpSize;
1448   def XOR32mi8 : Ii8<0x83, MRM6m,
1449                      (ops i32mem:$dst, i32i8imm :$src),
1450                      "xor{l} {$src, $dst|$dst, $src}",
1451                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1452 }
1453
1454 // Shift instructions
1455 def SHL8rCL  : I<0xD2, MRM4r, (ops R8 :$dst, R8 :$src),
1456                  "shl{b} {%cl, $dst|$dst, %CL}",
1457                  [(set R8:$dst, (shl R8:$src, CL))]>, Imp<[CL],[]>;
1458 def SHL16rCL : I<0xD3, MRM4r, (ops R16:$dst, R16:$src),
1459                  "shl{w} {%cl, $dst|$dst, %CL}",
1460                  [(set R16:$dst, (shl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1461 def SHL32rCL : I<0xD3, MRM4r, (ops R32:$dst, R32:$src),
1462                  "shl{l} {%cl, $dst|$dst, %CL}",
1463                  [(set R32:$dst, (shl R32:$src, CL))]>, Imp<[CL],[]>;
1464
1465 def SHL8ri   : Ii8<0xC0, MRM4r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1466                    "shl{b} {$src2, $dst|$dst, $src2}",
1467                    [(set R8:$dst, (shl R8:$src1, (i8 imm:$src2)))]>;
1468 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1469 def SHL16ri  : Ii8<0xC1, MRM4r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1470                    "shl{w} {$src2, $dst|$dst, $src2}",
1471                    [(set R16:$dst, (shl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1472 def SHL32ri  : Ii8<0xC1, MRM4r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1473                    "shl{l} {$src2, $dst|$dst, $src2}",
1474                    [(set R32:$dst, (shl R32:$src1, (i8 imm:$src2)))]>;
1475 }
1476
1477 let isTwoAddress = 0 in {
1478   def SHL8mCL  : I<0xD2, MRM4m, (ops i8mem :$dst),
1479                    "shl{b} {%cl, $dst|$dst, %CL}",
1480                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>,
1481                    Imp<[CL],[]>;
1482   def SHL16mCL : I<0xD3, MRM4m, (ops i16mem:$dst),
1483                    "shl{w} {%cl, $dst|$dst, %CL}",
1484                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>,
1485                    Imp<[CL],[]>, OpSize;
1486   def SHL32mCL : I<0xD3, MRM4m, (ops i32mem:$dst),
1487                    "shl{l} {%cl, $dst|$dst, %CL}",
1488                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>,
1489                    Imp<[CL],[]>;
1490   def SHL8mi   : Ii8<0xC0, MRM4m, (ops i8mem :$dst, i8imm:$src),
1491                      "shl{b} {$src, $dst|$dst, $src}",
1492                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1493   def SHL16mi  : Ii8<0xC1, MRM4m, (ops i16mem:$dst, i8imm:$src),
1494                      "shl{w} {$src, $dst|$dst, $src}",
1495                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1496                      OpSize;
1497   def SHL32mi  : Ii8<0xC1, MRM4m, (ops i32mem:$dst, i8imm:$src),
1498                      "shl{l} {$src, $dst|$dst, $src}",
1499                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1500 }
1501
1502 def SHR8rCL  : I<0xD2, MRM5r, (ops R8 :$dst, R8 :$src),
1503                  "shr{b} {%cl, $dst|$dst, %CL}",
1504                  [(set R8:$dst, (srl R8:$src, CL))]>, Imp<[CL],[]>;
1505 def SHR16rCL : I<0xD3, MRM5r, (ops R16:$dst, R16:$src),
1506                  "shr{w} {%cl, $dst|$dst, %CL}",
1507                  [(set R16:$dst, (srl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1508 def SHR32rCL : I<0xD3, MRM5r, (ops R32:$dst, R32:$src),
1509                  "shr{l} {%cl, $dst|$dst, %CL}",
1510                  [(set R32:$dst, (srl R32:$src, CL))]>, Imp<[CL],[]>;
1511
1512 def SHR8ri   : Ii8<0xC0, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1513                    "shr{b} {$src2, $dst|$dst, $src2}",
1514                    [(set R8:$dst, (srl R8:$src1, (i8 imm:$src2)))]>;
1515 def SHR16ri  : Ii8<0xC1, MRM5r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1516                    "shr{w} {$src2, $dst|$dst, $src2}",
1517                    [(set R16:$dst, (srl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1518 def SHR32ri  : Ii8<0xC1, MRM5r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1519                    "shr{l} {$src2, $dst|$dst, $src2}",
1520                    [(set R32:$dst, (srl R32:$src1, (i8 imm:$src2)))]>;
1521
1522 let isTwoAddress = 0 in {
1523   def SHR8mCL  : I<0xD2, MRM5m, (ops i8mem :$dst),
1524                    "shr{b} {%cl, $dst|$dst, %CL}",
1525                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>,
1526                    Imp<[CL],[]>;
1527   def SHR16mCL : I<0xD3, MRM5m, (ops i16mem:$dst),
1528                    "shr{w} {%cl, $dst|$dst, %CL}",
1529                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
1530                    Imp<[CL],[]>, OpSize;
1531   def SHR32mCL : I<0xD3, MRM5m, (ops i32mem:$dst),
1532                    "shr{l} {%cl, $dst|$dst, %CL}",
1533                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>,
1534                    Imp<[CL],[]>;
1535   def SHR8mi   : Ii8<0xC0, MRM5m, (ops i8mem :$dst, i8imm:$src),
1536                      "shr{b} {$src, $dst|$dst, $src}",
1537                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1538   def SHR16mi  : Ii8<0xC1, MRM5m, (ops i16mem:$dst, i8imm:$src),
1539                      "shr{w} {$src, $dst|$dst, $src}",
1540                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1541                      OpSize;
1542   def SHR32mi  : Ii8<0xC1, MRM5m, (ops i32mem:$dst, i8imm:$src),
1543                      "shr{l} {$src, $dst|$dst, $src}",
1544                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1545 }
1546
1547 def SAR8rCL  : I<0xD2, MRM7r, (ops R8 :$dst, R8 :$src),
1548                  "sar{b} {%cl, $dst|$dst, %CL}",
1549                  [(set R8:$dst, (sra R8:$src, CL))]>, Imp<[CL],[]>;
1550 def SAR16rCL : I<0xD3, MRM7r, (ops R16:$dst, R16:$src),
1551                  "sar{w} {%cl, $dst|$dst, %CL}",
1552                  [(set R16:$dst, (sra R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1553 def SAR32rCL : I<0xD3, MRM7r, (ops R32:$dst, R32:$src),
1554                  "sar{l} {%cl, $dst|$dst, %CL}",
1555                  [(set R32:$dst, (sra R32:$src, CL))]>, Imp<[CL],[]>;
1556
1557 def SAR8ri   : Ii8<0xC0, MRM7r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1558                    "sar{b} {$src2, $dst|$dst, $src2}",
1559                    [(set R8:$dst, (sra R8:$src1, (i8 imm:$src2)))]>;
1560 def SAR16ri  : Ii8<0xC1, MRM7r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1561                    "sar{w} {$src2, $dst|$dst, $src2}",
1562                    [(set R16:$dst, (sra R16:$src1, (i8 imm:$src2)))]>,
1563                    OpSize;
1564 def SAR32ri  : Ii8<0xC1, MRM7r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1565                    "sar{l} {$src2, $dst|$dst, $src2}",
1566                    [(set R32:$dst, (sra R32:$src1, (i8 imm:$src2)))]>;
1567 let isTwoAddress = 0 in {
1568   def SAR8mCL  : I<0xD2, MRM7m, (ops i8mem :$dst),
1569                    "sar{b} {%cl, $dst|$dst, %CL}",
1570                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>,
1571                    Imp<[CL],[]>;
1572   def SAR16mCL : I<0xD3, MRM7m, (ops i16mem:$dst),
1573                    "sar{w} {%cl, $dst|$dst, %CL}",
1574                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>,
1575                    Imp<[CL],[]>, OpSize;
1576   def SAR32mCL : I<0xD3, MRM7m, (ops i32mem:$dst), 
1577                    "sar{l} {%cl, $dst|$dst, %CL}",
1578                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>,
1579                    Imp<[CL],[]>;
1580   def SAR8mi   : Ii8<0xC0, MRM7m, (ops i8mem :$dst, i8imm:$src),
1581                      "sar{b} {$src, $dst|$dst, $src}",
1582                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1583   def SAR16mi  : Ii8<0xC1, MRM7m, (ops i16mem:$dst, i8imm:$src),
1584                      "sar{w} {$src, $dst|$dst, $src}",
1585                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1586                      OpSize;
1587   def SAR32mi  : Ii8<0xC1, MRM7m, (ops i32mem:$dst, i8imm:$src),
1588                      "sar{l} {$src, $dst|$dst, $src}",
1589                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1590 }
1591
1592 // Rotate instructions
1593 // FIXME: provide shorter instructions when imm8 == 1
1594 def ROL8rCL  : I<0xD2, MRM0r, (ops R8 :$dst, R8 :$src),
1595                  "rol{b} {%cl, $dst|$dst, %CL}",
1596                  [(set R8:$dst, (rotl R8:$src, CL))]>, Imp<[CL],[]>;
1597 def ROL16rCL : I<0xD3, MRM0r, (ops R16:$dst, R16:$src),
1598                  "rol{w} {%cl, $dst|$dst, %CL}",
1599                  [(set R16:$dst, (rotl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1600 def ROL32rCL : I<0xD3, MRM0r, (ops R32:$dst, R32:$src),
1601                  "rol{l} {%cl, $dst|$dst, %CL}",
1602                  [(set R32:$dst, (rotl R32:$src, CL))]>, Imp<[CL],[]>;
1603
1604 def ROL8ri   : Ii8<0xC0, MRM0r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1605                    "rol{b} {$src2, $dst|$dst, $src2}",
1606                    [(set R8:$dst, (rotl R8:$src1, (i8 imm:$src2)))]>;
1607 def ROL16ri  : Ii8<0xC1, MRM0r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1608                    "rol{w} {$src2, $dst|$dst, $src2}",
1609                    [(set R16:$dst, (rotl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1610 def ROL32ri  : Ii8<0xC1, MRM0r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1611                    "rol{l} {$src2, $dst|$dst, $src2}",
1612                    [(set R32:$dst, (rotl R32:$src1, (i8 imm:$src2)))]>;
1613
1614 let isTwoAddress = 0 in {
1615   def ROL8mCL  : I<0xD2, MRM0m, (ops i8mem :$dst),
1616                    "rol{b} {%cl, $dst|$dst, %CL}",
1617                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>,
1618                    Imp<[CL],[]>;
1619   def ROL16mCL : I<0xD3, MRM0m, (ops i16mem:$dst),
1620                    "rol{w} {%cl, $dst|$dst, %CL}",
1621                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>,
1622                    Imp<[CL],[]>, OpSize;
1623   def ROL32mCL : I<0xD3, MRM0m, (ops i32mem:$dst),
1624                    "rol{l} {%cl, $dst|$dst, %CL}",
1625                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>,
1626                    Imp<[CL],[]>;
1627   def ROL8mi   : Ii8<0xC0, MRM0m, (ops i8mem :$dst, i8imm:$src),
1628                      "rol{b} {$src, $dst|$dst, $src}",
1629                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1630   def ROL16mi  : Ii8<0xC1, MRM0m, (ops i16mem:$dst, i8imm:$src),
1631                      "rol{w} {$src, $dst|$dst, $src}",
1632                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1633                      OpSize;
1634   def ROL32mi  : Ii8<0xC1, MRM0m, (ops i32mem:$dst, i8imm:$src),
1635                      "rol{l} {$src, $dst|$dst, $src}",
1636                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1637 }
1638
1639 def ROR8rCL  : I<0xD2, MRM1r, (ops R8 :$dst, R8 :$src),
1640                  "ror{b} {%cl, $dst|$dst, %CL}",
1641                  [(set R8:$dst, (rotr R8:$src, CL))]>, Imp<[CL],[]>;
1642 def ROR16rCL : I<0xD3, MRM1r, (ops R16:$dst, R16:$src),
1643                  "ror{w} {%cl, $dst|$dst, %CL}",
1644                  [(set R16:$dst, (rotr R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1645 def ROR32rCL : I<0xD3, MRM1r, (ops R32:$dst, R32:$src),
1646                  "ror{l} {%cl, $dst|$dst, %CL}",
1647                  [(set R32:$dst, (rotr R32:$src, CL))]>, Imp<[CL],[]>;
1648
1649 def ROR8ri   : Ii8<0xC0, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1650                    "ror{b} {$src2, $dst|$dst, $src2}",
1651                    [(set R8:$dst, (rotr R8:$src1, (i8 imm:$src2)))]>;
1652 def ROR16ri  : Ii8<0xC1, MRM1r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1653                    "ror{w} {$src2, $dst|$dst, $src2}",
1654                    [(set R16:$dst, (rotr R16:$src1, (i8 imm:$src2)))]>, OpSize;
1655 def ROR32ri  : Ii8<0xC1, MRM1r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1656                    "ror{l} {$src2, $dst|$dst, $src2}",
1657                    [(set R32:$dst, (rotr R32:$src1, (i8 imm:$src2)))]>;
1658 let isTwoAddress = 0 in {
1659   def ROR8mCL  : I<0xD2, MRM1m, (ops i8mem :$dst),
1660                    "ror{b} {%cl, $dst|$dst, %CL}",
1661                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>,
1662                    Imp<[CL],[]>;
1663   def ROR16mCL : I<0xD3, MRM1m, (ops i16mem:$dst),
1664                    "ror{w} {%cl, $dst|$dst, %CL}",
1665                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>,
1666                    Imp<[CL],[]>, OpSize;
1667   def ROR32mCL : I<0xD3, MRM1m, (ops i32mem:$dst), 
1668                    "ror{l} {%cl, $dst|$dst, %CL}",
1669                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>,
1670                    Imp<[CL],[]>;
1671   def ROR8mi   : Ii8<0xC0, MRM1m, (ops i8mem :$dst, i8imm:$src),
1672                      "ror{b} {$src, $dst|$dst, $src}",
1673                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1674   def ROR16mi  : Ii8<0xC1, MRM1m, (ops i16mem:$dst, i8imm:$src),
1675                      "ror{w} {$src, $dst|$dst, $src}",
1676                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1677                      OpSize;
1678   def ROR32mi  : Ii8<0xC1, MRM1m, (ops i32mem:$dst, i8imm:$src),
1679                      "ror{l} {$src, $dst|$dst, $src}",
1680                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1681 }
1682
1683
1684
1685 // Double shift instructions (generalizations of rotate)
1686
1687 def SHLD32rrCL : I<0xA5, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1688                    "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1689                    [(set R32:$dst, (X86shld R32:$src1, R32:$src2, CL))]>,
1690                    Imp<[CL],[]>, TB;
1691 def SHRD32rrCL : I<0xAD, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1692                    "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1693                    [(set R32:$dst, (X86shrd R32:$src1, R32:$src2, CL))]>,
1694                    Imp<[CL],[]>, TB;
1695 def SHLD16rrCL : I<0xA5, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1696                    "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1697                    [(set R16:$dst, (X86shld R16:$src1, R16:$src2, CL))]>,
1698                    Imp<[CL],[]>, TB, OpSize;
1699 def SHRD16rrCL : I<0xAD, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1700                    "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1701                    [(set R16:$dst, (X86shrd R16:$src1, R16:$src2, CL))]>,
1702                    Imp<[CL],[]>, TB, OpSize;
1703
1704 let isCommutable = 1 in {  // These instructions commute to each other.
1705 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
1706                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1707                      "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1708                      [(set R32:$dst, (X86shld R32:$src1, R32:$src2,
1709                                       (i8 imm:$src3)))]>,
1710                  TB;
1711 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
1712                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1713                      "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1714                      [(set R32:$dst, (X86shrd R32:$src1, R32:$src2,
1715                                       (i8 imm:$src3)))]>,
1716                  TB;
1717 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
1718                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1719                      "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1720                      [(set R16:$dst, (X86shld R16:$src1, R16:$src2,
1721                                       (i8 imm:$src3)))]>,
1722                      TB, OpSize;
1723 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
1724                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1725                      "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1726                      [(set R16:$dst, (X86shrd R16:$src1, R16:$src2,
1727                                       (i8 imm:$src3)))]>,
1728                      TB, OpSize;
1729 }
1730
1731 let isTwoAddress = 0 in {
1732   def SHLD32mrCL : I<0xA5, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1733                      "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1734                      [(store (X86shld (loadi32 addr:$dst), R32:$src2, CL),
1735                        addr:$dst)]>,
1736                      Imp<[CL],[]>, TB;
1737   def SHRD32mrCL : I<0xAD, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1738                     "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1739                     [(store (X86shrd (loadi32 addr:$dst), R32:$src2, CL),
1740                       addr:$dst)]>,
1741                     Imp<[CL],[]>, TB;
1742   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
1743                       (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1744                       "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1745                       [(store (X86shld (loadi32 addr:$dst), R32:$src2,
1746                                         (i8 imm:$src3)), addr:$dst)]>,
1747                       TB;
1748   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
1749                        (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1750                        "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1751                        [(store (X86shrd (loadi32 addr:$dst), R32:$src2,
1752                                          (i8 imm:$src3)), addr:$dst)]>,
1753                        TB;
1754
1755   def SHLD16mrCL : I<0xA5, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1756                      "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1757                      [(store (X86shld (loadi16 addr:$dst), R16:$src2, CL),
1758                        addr:$dst)]>,
1759                      Imp<[CL],[]>, TB, OpSize;
1760   def SHRD16mrCL : I<0xAD, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1761                     "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1762                     [(store (X86shrd (loadi16 addr:$dst), R16:$src2, CL),
1763                       addr:$dst)]>,
1764                     Imp<[CL],[]>, TB, OpSize;
1765   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
1766                       (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1767                       "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1768                       [(store (X86shld (loadi16 addr:$dst), R16:$src2,
1769                                         (i8 imm:$src3)), addr:$dst)]>,
1770                       TB, OpSize;
1771   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
1772                        (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1773                        "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1774                       [(store (X86shrd (loadi16 addr:$dst), R16:$src2,
1775                                         (i8 imm:$src3)), addr:$dst)]>,
1776                        TB, OpSize;
1777 }
1778
1779
1780 // Arithmetic.
1781 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
1782 def ADD8rr   : I<0x00, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1783                  "add{b} {$src2, $dst|$dst, $src2}",
1784                  [(set R8:$dst, (add R8:$src1, R8:$src2))]>;
1785 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1786 def ADD16rr  : I<0x01, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1787                  "add{w} {$src2, $dst|$dst, $src2}",
1788                  [(set R16:$dst, (add R16:$src1, R16:$src2))]>, OpSize;
1789 def ADD32rr  : I<0x01, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1790                  "add{l} {$src2, $dst|$dst, $src2}",
1791                  [(set R32:$dst, (add R32:$src1, R32:$src2))]>;
1792 } // end isConvertibleToThreeAddress
1793 } // end isCommutable
1794 def ADD8rm   : I<0x02, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1795                  "add{b} {$src2, $dst|$dst, $src2}",
1796                  [(set R8:$dst, (add R8:$src1, (load addr:$src2)))]>;
1797 def ADD16rm  : I<0x03, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1798                  "add{w} {$src2, $dst|$dst, $src2}",
1799                  [(set R16:$dst, (add R16:$src1, (load addr:$src2)))]>, OpSize;
1800 def ADD32rm  : I<0x03, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1801                  "add{l} {$src2, $dst|$dst, $src2}",
1802                  [(set R32:$dst, (add R32:$src1, (load addr:$src2)))]>;
1803
1804 def ADD8ri   : Ii8<0x80, MRM0r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1805                    "add{b} {$src2, $dst|$dst, $src2}",
1806                    [(set R8:$dst, (add R8:$src1, imm:$src2))]>;
1807
1808 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1809 def ADD16ri  : Ii16<0x81, MRM0r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1810                     "add{w} {$src2, $dst|$dst, $src2}",
1811                     [(set R16:$dst, (add R16:$src1, imm:$src2))]>, OpSize;
1812 def ADD32ri  : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1813                     "add{l} {$src2, $dst|$dst, $src2}",
1814                     [(set R32:$dst, (add R32:$src1, imm:$src2))]>;
1815 }
1816
1817 // FIXME: move ADD16ri8 above ADD16ri to optimize for space.
1818 def ADD16ri8 : Ii8<0x83, MRM0r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1819                    "add{w} {$src2, $dst|$dst, $src2}",
1820                    [(set R16:$dst, (add R16:$src1, i16immSExt8:$src2))]>,
1821                    OpSize;
1822 def ADD32ri8 : Ii8<0x83, MRM0r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1823                    "add{l} {$src2, $dst|$dst, $src2}",
1824                    [(set R32:$dst, (add R32:$src1, i32immSExt8:$src2))]>;
1825
1826 let isTwoAddress = 0 in {
1827   def ADD8mr   : I<0x00, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1828                    "add{b} {$src2, $dst|$dst, $src2}",
1829                    [(store (add (load addr:$dst), R8:$src2), addr:$dst)]>;
1830   def ADD16mr  : I<0x01, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1831                    "add{w} {$src2, $dst|$dst, $src2}",
1832                    [(store (add (load addr:$dst), R16:$src2), addr:$dst)]>,
1833                    OpSize;
1834   def ADD32mr  : I<0x01, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1835                    "add{l} {$src2, $dst|$dst, $src2}",
1836                    [(store (add (load addr:$dst), R32:$src2), addr:$dst)]>;
1837   def ADD8mi   : Ii8<0x80, MRM0m, (ops i8mem :$dst, i8imm :$src2),
1838                      "add{b} {$src2, $dst|$dst, $src2}",
1839                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1840   def ADD16mi  : Ii16<0x81, MRM0m, (ops i16mem:$dst, i16imm:$src2),
1841                       "add{w} {$src2, $dst|$dst, $src2}",
1842                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1843                    OpSize;
1844   def ADD32mi  : Ii32<0x81, MRM0m, (ops i32mem:$dst, i32imm:$src2),
1845                       "add{l} {$src2, $dst|$dst, $src2}",
1846                   [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1847   def ADD16mi8 : Ii8<0x83, MRM0m, (ops i16mem:$dst, i16i8imm :$src2),
1848                      "add{w} {$src2, $dst|$dst, $src2}",
1849                 [(store (add (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1850                    OpSize;
1851   def ADD32mi8 : Ii8<0x83, MRM0m, (ops i32mem:$dst, i32i8imm :$src2),
1852                      "add{l} {$src2, $dst|$dst, $src2}",
1853                 [(store (add (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1854 }
1855
1856 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
1857 def ADC32rr  : I<0x11, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1858                  "adc{l} {$src2, $dst|$dst, $src2}",
1859                  [(set R32:$dst, (X86adc R32:$src1, R32:$src2))]>;
1860 }
1861 def ADC32rm  : I<0x13, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
1862                  "adc{l} {$src2, $dst|$dst, $src2}",
1863                  [(set R32:$dst, (X86adc R32:$src1, (load addr:$src2)))]>;
1864 def ADC32ri  : Ii32<0x81, MRM2r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1865                     "adc{l} {$src2, $dst|$dst, $src2}",
1866                  [(set R32:$dst, (X86adc R32:$src1, imm:$src2))]>;
1867 def ADC32ri8 : Ii8<0x83, MRM2r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1868                    "adc{l} {$src2, $dst|$dst, $src2}",
1869                  [(set R32:$dst, (X86adc R32:$src1, i32immSExt8:$src2))]>;
1870
1871 let isTwoAddress = 0 in {
1872   def ADC32mr  : I<0x11, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1873                    "adc{l} {$src2, $dst|$dst, $src2}",
1874                    [(store (X86adc (load addr:$dst), R32:$src2), addr:$dst)]>;
1875   def ADC32mi  : Ii32<0x81, MRM2m, (ops i32mem:$dst, i32imm:$src2),
1876                       "adc{l} {$src2, $dst|$dst, $src2}",
1877                   [(store (X86adc (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1878   def ADC32mi8 : Ii8<0x83, MRM2m, (ops i32mem:$dst, i32i8imm :$src2),
1879                      "adc{l} {$src2, $dst|$dst, $src2}",
1880              [(store (X86adc (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1881 }
1882
1883 def SUB8rr   : I<0x28, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1884                  "sub{b} {$src2, $dst|$dst, $src2}",
1885                  [(set R8:$dst, (sub R8:$src1, R8:$src2))]>;
1886 def SUB16rr  : I<0x29, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1887                  "sub{w} {$src2, $dst|$dst, $src2}",
1888                  [(set R16:$dst, (sub R16:$src1, R16:$src2))]>, OpSize;
1889 def SUB32rr  : I<0x29, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1890                  "sub{l} {$src2, $dst|$dst, $src2}",
1891                  [(set R32:$dst, (sub R32:$src1, R32:$src2))]>;
1892 def SUB8rm   : I<0x2A, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1893                  "sub{b} {$src2, $dst|$dst, $src2}",
1894                  [(set R8:$dst, (sub R8:$src1, (load addr:$src2)))]>;
1895 def SUB16rm  : I<0x2B, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1896                  "sub{w} {$src2, $dst|$dst, $src2}",
1897                  [(set R16:$dst, (sub R16:$src1, (load addr:$src2)))]>, OpSize;
1898 def SUB32rm  : I<0x2B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1899                  "sub{l} {$src2, $dst|$dst, $src2}",
1900                  [(set R32:$dst, (sub R32:$src1, (load addr:$src2)))]>;
1901
1902 def SUB8ri   : Ii8 <0x80, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1903                     "sub{b} {$src2, $dst|$dst, $src2}",
1904                     [(set R8:$dst, (sub R8:$src1, imm:$src2))]>;
1905 def SUB16ri  : Ii16<0x81, MRM5r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1906                     "sub{w} {$src2, $dst|$dst, $src2}",
1907                     [(set R16:$dst, (sub R16:$src1, imm:$src2))]>, OpSize;
1908 def SUB32ri  : Ii32<0x81, MRM5r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1909                     "sub{l} {$src2, $dst|$dst, $src2}",
1910                     [(set R32:$dst, (sub R32:$src1, imm:$src2))]>;
1911 def SUB16ri8 : Ii8<0x83, MRM5r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1912                    "sub{w} {$src2, $dst|$dst, $src2}",
1913                    [(set R16:$dst, (sub R16:$src1, i16immSExt8:$src2))]>,
1914                    OpSize;
1915 def SUB32ri8 : Ii8<0x83, MRM5r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1916                    "sub{l} {$src2, $dst|$dst, $src2}",
1917                    [(set R32:$dst, (sub R32:$src1, i32immSExt8:$src2))]>;
1918 let isTwoAddress = 0 in {
1919   def SUB8mr   : I<0x28, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1920                    "sub{b} {$src2, $dst|$dst, $src2}",
1921                    [(store (sub (load addr:$dst), R8:$src2), addr:$dst)]>;
1922   def SUB16mr  : I<0x29, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1923                    "sub{w} {$src2, $dst|$dst, $src2}",
1924                    [(store (sub (load addr:$dst), R16:$src2), addr:$dst)]>,
1925                    OpSize;
1926   def SUB32mr  : I<0x29, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1927                    "sub{l} {$src2, $dst|$dst, $src2}",
1928                    [(store (sub (load addr:$dst), R32:$src2), addr:$dst)]>;
1929   def SUB8mi   : Ii8<0x80, MRM5m, (ops i8mem :$dst, i8imm:$src2), 
1930                      "sub{b} {$src2, $dst|$dst, $src2}",
1931                    [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1932   def SUB16mi  : Ii16<0x81, MRM5m, (ops i16mem:$dst, i16imm:$src2), 
1933                       "sub{w} {$src2, $dst|$dst, $src2}",
1934                   [(store (sub (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1935                    OpSize;
1936   def SUB32mi  : Ii32<0x81, MRM5m, (ops i32mem:$dst, i32imm:$src2), 
1937                       "sub{l} {$src2, $dst|$dst, $src2}",
1938                   [(store (sub (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1939   def SUB16mi8 : Ii8<0x83, MRM5m, (ops i16mem:$dst, i16i8imm :$src2), 
1940                      "sub{w} {$src2, $dst|$dst, $src2}",
1941                 [(store (sub (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1942                    OpSize;
1943   def SUB32mi8 : Ii8<0x83, MRM5m, (ops i32mem:$dst, i32i8imm :$src2), 
1944                      "sub{l} {$src2, $dst|$dst, $src2}",
1945                 [(store (sub (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1946 }
1947
1948 def SBB32rr    : I<0x19, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1949                   "sbb{l} {$src2, $dst|$dst, $src2}",
1950                   [(set R32:$dst, (X86sbb R32:$src1, R32:$src2))]>;
1951
1952 let isTwoAddress = 0 in {
1953   def SBB32mr  : I<0x19, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1954                    "sbb{l} {$src2, $dst|$dst, $src2}",
1955                    [(store (X86sbb (load addr:$dst), R32:$src2), addr:$dst)]>;
1956   def SBB8mi  : Ii32<0x80, MRM3m, (ops i8mem:$dst, i8imm:$src2), 
1957                       "sbb{b} {$src2, $dst|$dst, $src2}",
1958                    [(store (X86sbb (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1959   def SBB16mi  : Ii32<0x81, MRM3m, (ops i16mem:$dst, i16imm:$src2), 
1960                       "sbb{w} {$src2, $dst|$dst, $src2}",
1961                   [(store (X86sbb (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1962                      OpSize;
1963   def SBB32mi  : Ii32<0x81, MRM3m, (ops i32mem:$dst, i32imm:$src2), 
1964                       "sbb{l} {$src2, $dst|$dst, $src2}",
1965                   [(store (X86sbb (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1966   def SBB16mi8 : Ii8<0x83, MRM3m, (ops i16mem:$dst, i16i8imm :$src2), 
1967                      "sbb{w} {$src2, $dst|$dst, $src2}",
1968              [(store (X86sbb (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1969                      OpSize;
1970   def SBB32mi8 : Ii8<0x83, MRM3m, (ops i32mem:$dst, i32i8imm :$src2), 
1971                      "sbb{l} {$src2, $dst|$dst, $src2}",
1972              [(store (X86sbb (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1973 }
1974 def SBB8ri   : Ii8<0x80, MRM3r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1975                     "sbb{b} {$src2, $dst|$dst, $src2}",
1976                     [(set R8:$dst, (X86sbb R8:$src1, imm:$src2))]>;
1977 def SBB16ri  : Ii16<0x81, MRM3r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1978                     "sbb{w} {$src2, $dst|$dst, $src2}",
1979                     [(set R16:$dst, (X86sbb R16:$src1, imm:$src2))]>, OpSize;
1980
1981 def SBB32rm  : I<0x1B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1982                     "sbb{l} {$src2, $dst|$dst, $src2}",
1983                     [(set R32:$dst, (X86sbb R32:$src1, (load addr:$src2)))]>;
1984 def SBB32ri  : Ii32<0x81, MRM3r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1985                     "sbb{l} {$src2, $dst|$dst, $src2}",
1986                     [(set R32:$dst, (X86sbb R32:$src1, imm:$src2))]>;
1987
1988 def SBB16ri8 : Ii8<0x83, MRM3r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1989                    "sbb{w} {$src2, $dst|$dst, $src2}",
1990                    [(set R16:$dst, (X86sbb R16:$src1, i16immSExt8:$src2))]>,
1991                    OpSize;
1992 def SBB32ri8 : Ii8<0x83, MRM3r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1993                    "sbb{l} {$src2, $dst|$dst, $src2}",
1994                    [(set R32:$dst, (X86sbb R32:$src1, i32immSExt8:$src2))]>;
1995
1996 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
1997 def IMUL16rr : I<0xAF, MRMSrcReg, (ops R16:$dst, R16:$src1, R16:$src2),
1998                  "imul{w} {$src2, $dst|$dst, $src2}",
1999                  [(set R16:$dst, (mul R16:$src1, R16:$src2))]>, TB, OpSize;
2000 def IMUL32rr : I<0xAF, MRMSrcReg, (ops R32:$dst, R32:$src1, R32:$src2),
2001                  "imul{l} {$src2, $dst|$dst, $src2}",
2002                  [(set R32:$dst, (mul R32:$src1, R32:$src2))]>, TB;
2003 }
2004 def IMUL16rm : I<0xAF, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
2005                  "imul{w} {$src2, $dst|$dst, $src2}",
2006                  [(set R16:$dst, (mul R16:$src1, (load addr:$src2)))]>,
2007                  TB, OpSize;
2008 def IMUL32rm : I<0xAF, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
2009                  "imul{l} {$src2, $dst|$dst, $src2}",
2010                  [(set R32:$dst, (mul R32:$src1, (load addr:$src2)))]>, TB;
2011
2012 } // end Two Address instructions
2013
2014 // Suprisingly enough, these are not two address instructions!
2015 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // R16 = R16*I16
2016                       (ops R16:$dst, R16:$src1, i16imm:$src2),
2017                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
2018                       [(set R16:$dst, (mul R16:$src1, imm:$src2))]>, OpSize;
2019 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // R32 = R32*I32
2020                       (ops R32:$dst, R32:$src1, i32imm:$src2),
2021                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
2022                       [(set R32:$dst, (mul R32:$src1, imm:$src2))]>;
2023 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // R16 = R16*I8
2024                      (ops R16:$dst, R16:$src1, i16i8imm:$src2),
2025                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
2026                      [(set R16:$dst, (mul R16:$src1, i16immSExt8:$src2))]>,
2027                      OpSize;
2028 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // R32 = R32*I8
2029                      (ops R32:$dst, R32:$src1, i32i8imm:$src2),
2030                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
2031                      [(set R32:$dst, (mul R32:$src1, i32immSExt8:$src2))]>;
2032
2033 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                      // R16 = [mem16]*I16
2034                       (ops R16:$dst, i16mem:$src1, i16imm:$src2),
2035                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
2036                       [(set R16:$dst, (mul (load addr:$src1), imm:$src2))]>,
2037                       OpSize;
2038 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                      // R32 = [mem32]*I32
2039                       (ops R32:$dst, i32mem:$src1, i32imm:$src2),
2040                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
2041                       [(set R32:$dst, (mul (load addr:$src1), imm:$src2))]>;
2042 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // R16 = [mem16]*I8
2043                      (ops R16:$dst, i16mem:$src1, i16i8imm :$src2),
2044                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
2045                   [(set R16:$dst, (mul (load addr:$src1), i16immSExt8:$src2))]>,
2046                      OpSize;
2047 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // R32 = [mem32]*I8
2048                      (ops R32:$dst, i32mem:$src1, i32i8imm: $src2),
2049                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
2050                   [(set R32:$dst, (mul (load addr:$src1), i32immSExt8:$src2))]>;
2051
2052 //===----------------------------------------------------------------------===//
2053 // Test instructions are just like AND, except they don't generate a result.
2054 //
2055 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
2056 def TEST8rr  : I<0x84, MRMDestReg, (ops R8:$src1, R8:$src2),
2057                  "test{b} {$src2, $src1|$src1, $src2}",
2058                  [(set STATUS, (X86test R8:$src1, R8:$src2))]>,
2059                Imp<[],[STATUS]>;
2060 def TEST16rr : I<0x85, MRMDestReg, (ops R16:$src1, R16:$src2),
2061                  "test{w} {$src2, $src1|$src1, $src2}",
2062                  [(set STATUS, (X86test R16:$src1, R16:$src2))]>,
2063                Imp<[],[STATUS]>, OpSize;
2064 def TEST32rr : I<0x85, MRMDestReg, (ops R32:$src1, R32:$src2),
2065                  "test{l} {$src2, $src1|$src1, $src2}",
2066                  [(set STATUS, (X86test R32:$src1, R32:$src2))]>,
2067                Imp<[],[STATUS]>;
2068 }
2069 def TEST8mr  : I<0x84, MRMDestMem, (ops i8mem :$src1, R8 :$src2),
2070                  "test{b} {$src2, $src1|$src1, $src2}",
2071                  [(set STATUS, (X86test (loadi8 addr:$src1), R8:$src2))]>,
2072                Imp<[],[STATUS]>;
2073 def TEST16mr : I<0x85, MRMDestMem, (ops i16mem:$src1, R16:$src2),
2074                  "test{w} {$src2, $src1|$src1, $src2}",
2075                  [(set STATUS, (X86test (loadi16 addr:$src1), R16:$src2))]>,
2076                Imp<[],[STATUS]>, OpSize;
2077 def TEST32mr : I<0x85, MRMDestMem, (ops i32mem:$src1, R32:$src2),
2078                  "test{l} {$src2, $src1|$src1, $src2}",
2079                  [(set STATUS, (X86test (loadi32 addr:$src1), R32:$src2))]>,
2080                Imp<[],[STATUS]>;
2081 def TEST8rm  : I<0x84, MRMSrcMem, (ops R8 :$src1, i8mem :$src2),
2082                  "test{b} {$src2, $src1|$src1, $src2}",
2083                  [(set STATUS, (X86test R8:$src1, (loadi8 addr:$src2)))]>,
2084                Imp<[],[STATUS]>;
2085 def TEST16rm : I<0x85, MRMSrcMem, (ops R16:$src1, i16mem:$src2),
2086                  "test{w} {$src2, $src1|$src1, $src2}",
2087                  [(set STATUS, (X86test R16:$src1, (loadi16 addr:$src2)))]>,
2088                Imp<[],[STATUS]>, OpSize;
2089 def TEST32rm : I<0x85, MRMSrcMem, (ops R32:$src1, i32mem:$src2),
2090                  "test{l} {$src2, $src1|$src1, $src2}",
2091                  [(set STATUS, (X86test R32:$src1, (loadi32 addr:$src2)))]>,
2092                Imp<[],[STATUS]>;
2093
2094 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = R8  & imm8
2095                     (ops R8:$src1, i8imm:$src2),
2096                     "test{b} {$src2, $src1|$src1, $src2}",
2097                     [(set STATUS, (X86test R8:$src1, imm:$src2))]>,
2098                    Imp<[],[STATUS]>;
2099 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = R16 & imm16
2100                     (ops R16:$src1, i16imm:$src2),
2101                     "test{w} {$src2, $src1|$src1, $src2}",
2102                     [(set STATUS, (X86test R16:$src1, imm:$src2))]>,
2103                    Imp<[],[STATUS]>, OpSize;
2104 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = R32 & imm32
2105                     (ops R32:$src1, i32imm:$src2),
2106                     "test{l} {$src2, $src1|$src1, $src2}",
2107                     [(set STATUS, (X86test R32:$src1, imm:$src2))]>,
2108                    Imp<[],[STATUS]>;
2109 def TEST8mi  : Ii8 <0xF6, MRM0m,                     // flags = [mem8]  & imm8
2110                     (ops i8mem:$src1, i8imm:$src2),
2111                     "test{b} {$src2, $src1|$src1, $src2}",
2112                     [(set STATUS, (X86test (loadi8 addr:$src1), imm:$src2))]>,
2113                    Imp<[],[STATUS]>;
2114 def TEST16mi : Ii16<0xF7, MRM0m,                     // flags = [mem16] & imm16
2115                     (ops i16mem:$src1, i16imm:$src2),
2116                     "test{w} {$src2, $src1|$src1, $src2}",
2117                     [(set STATUS, (X86test (loadi16 addr:$src1), imm:$src2))]>,
2118                    Imp<[],[STATUS]>, OpSize;
2119 def TEST32mi : Ii32<0xF7, MRM0m,                     // flags = [mem32] & imm32
2120                     (ops i32mem:$src1, i32imm:$src2),
2121                     "test{l} {$src2, $src1|$src1, $src2}",
2122                     [(set STATUS, (X86test (loadi32 addr:$src1), imm:$src2))]>,
2123                    Imp<[],[STATUS]>;
2124
2125
2126 // Condition code ops, incl. set if equal/not equal/...
2127 def SAHF     : I<0x9E, RawFrm, (ops), "sahf", []>, Imp<[AH],[]>;  // flags = AH
2128 def LAHF     : I<0x9F, RawFrm, (ops), "lahf", []>, Imp<[],[AH]>;  // AH = flags
2129
2130 def SETEr    : I<0x94, MRM0r, 
2131                  (ops R8   :$dst),
2132                  "sete $dst",
2133                  [(set R8:$dst, (X86setcc X86_COND_E, STATUS))]>,
2134                TB;                        // R8 = ==
2135 def SETEm    : I<0x94, MRM0m, 
2136                  (ops i8mem:$dst),
2137                  "sete $dst",
2138                  [(store (X86setcc X86_COND_E, STATUS), addr:$dst)]>,
2139                TB;                        // [mem8] = ==
2140 def SETNEr   : I<0x95, MRM0r, 
2141                  (ops R8   :$dst),
2142                  "setne $dst",
2143                  [(set R8:$dst, (X86setcc X86_COND_NE, STATUS))]>,
2144                TB;                        // R8 = !=
2145 def SETNEm   : I<0x95, MRM0m, 
2146                  (ops i8mem:$dst),
2147                  "setne $dst",
2148                  [(store (X86setcc X86_COND_NE, STATUS), addr:$dst)]>,
2149                TB;                        // [mem8] = !=
2150 def SETLr    : I<0x9C, MRM0r, 
2151                  (ops R8   :$dst),
2152                  "setl $dst",
2153                  [(set R8:$dst, (X86setcc X86_COND_L, STATUS))]>,
2154                TB;                        // R8 = <  signed
2155 def SETLm    : I<0x9C, MRM0m, 
2156                  (ops i8mem:$dst),
2157                  "setl $dst",
2158                  [(store (X86setcc X86_COND_L, STATUS), addr:$dst)]>,
2159                TB;                        // [mem8] = <  signed
2160 def SETGEr   : I<0x9D, MRM0r, 
2161                  (ops R8   :$dst),
2162                  "setge $dst",
2163                  [(set R8:$dst, (X86setcc X86_COND_GE, STATUS))]>,
2164                TB;                        // R8 = >= signed
2165 def SETGEm   : I<0x9D, MRM0m, 
2166                  (ops i8mem:$dst),
2167                  "setge $dst",
2168                  [(store (X86setcc X86_COND_GE, STATUS), addr:$dst)]>,
2169                TB;                        // [mem8] = >= signed
2170 def SETLEr   : I<0x9E, MRM0r, 
2171                  (ops R8   :$dst),
2172                  "setle $dst",
2173                  [(set R8:$dst, (X86setcc X86_COND_LE, STATUS))]>,
2174                TB;                        // R8 = <= signed
2175 def SETLEm   : I<0x9E, MRM0m, 
2176                  (ops i8mem:$dst),
2177                  "setle $dst",
2178                  [(store (X86setcc X86_COND_LE, STATUS), addr:$dst)]>,
2179                TB;                        // [mem8] = <= signed
2180 def SETGr    : I<0x9F, MRM0r, 
2181                  (ops R8   :$dst),
2182                  "setg $dst",
2183                  [(set R8:$dst, (X86setcc X86_COND_G, STATUS))]>,
2184                TB;                        // R8 = >  signed
2185 def SETGm    : I<0x9F, MRM0m, 
2186                  (ops i8mem:$dst),
2187                  "setg $dst",
2188                  [(store (X86setcc X86_COND_G, STATUS), addr:$dst)]>,
2189                TB;                        // [mem8] = >  signed
2190
2191 def SETBr    : I<0x92, MRM0r,
2192                  (ops R8   :$dst),
2193                  "setb $dst",
2194                  [(set R8:$dst, (X86setcc X86_COND_B, STATUS))]>,
2195                TB;                        // R8 = <  unsign
2196 def SETBm    : I<0x92, MRM0m,
2197                  (ops i8mem:$dst),
2198                  "setb $dst",
2199                  [(store (X86setcc X86_COND_B, STATUS), addr:$dst)]>,
2200                TB;                        // [mem8] = <  unsign
2201 def SETAEr   : I<0x93, MRM0r, 
2202                  (ops R8   :$dst),
2203                  "setae $dst",
2204                  [(set R8:$dst, (X86setcc X86_COND_AE, STATUS))]>,
2205                TB;                        // R8 = >= unsign
2206 def SETAEm   : I<0x93, MRM0m, 
2207                  (ops i8mem:$dst),
2208                  "setae $dst",
2209                  [(store (X86setcc X86_COND_AE, STATUS), addr:$dst)]>,
2210                TB;                        // [mem8] = >= unsign
2211 def SETBEr   : I<0x96, MRM0r, 
2212                  (ops R8   :$dst),
2213                  "setbe $dst",
2214                  [(set R8:$dst, (X86setcc X86_COND_BE, STATUS))]>,
2215                TB;                        // R8 = <= unsign
2216 def SETBEm   : I<0x96, MRM0m, 
2217                  (ops i8mem:$dst),
2218                  "setbe $dst",
2219                  [(store (X86setcc X86_COND_BE, STATUS), addr:$dst)]>,
2220                TB;                        // [mem8] = <= unsign
2221 def SETAr    : I<0x97, MRM0r, 
2222                  (ops R8   :$dst),
2223                  "seta $dst",
2224                  [(set R8:$dst, (X86setcc X86_COND_A, STATUS))]>,
2225                TB;                        // R8 = >  signed
2226 def SETAm    : I<0x97, MRM0m, 
2227                  (ops i8mem:$dst),
2228                  "seta $dst",
2229                  [(store (X86setcc X86_COND_A, STATUS), addr:$dst)]>,
2230                TB;                        // [mem8] = >  signed
2231
2232 def SETSr    : I<0x98, MRM0r, 
2233                  (ops R8   :$dst),
2234                  "sets $dst",
2235                  [(set R8:$dst, (X86setcc X86_COND_S, STATUS))]>,
2236                TB;                        // R8 = <sign bit>
2237 def SETSm    : I<0x98, MRM0m, 
2238                  (ops i8mem:$dst),
2239                  "sets $dst",
2240                  [(store (X86setcc X86_COND_S, STATUS), addr:$dst)]>,
2241                TB;                        // [mem8] = <sign bit>
2242 def SETNSr   : I<0x99, MRM0r, 
2243                  (ops R8   :$dst),
2244                  "setns $dst",
2245                  [(set R8:$dst, (X86setcc X86_COND_NS, STATUS))]>,
2246                TB;                        // R8 = !<sign bit>
2247 def SETNSm   : I<0x99, MRM0m, 
2248                  (ops i8mem:$dst),
2249                  "setns $dst",
2250                  [(store (X86setcc X86_COND_NS, STATUS), addr:$dst)]>,
2251                TB;                        // [mem8] = !<sign bit>
2252 def SETPr    : I<0x9A, MRM0r, 
2253                  (ops R8   :$dst),
2254                  "setp $dst",
2255                  [(set R8:$dst, (X86setcc X86_COND_P, STATUS))]>,
2256                TB;                        // R8 = parity
2257 def SETPm    : I<0x9A, MRM0m, 
2258                  (ops i8mem:$dst),
2259                  "setp $dst",
2260                  [(store (X86setcc X86_COND_P, STATUS), addr:$dst)]>,
2261                TB;                        // [mem8] = parity
2262 def SETNPr   : I<0x9B, MRM0r, 
2263                  (ops R8   :$dst),
2264                  "setnp $dst",
2265                  [(set R8:$dst, (X86setcc X86_COND_NP, STATUS))]>,
2266                TB;                        // R8 = not parity
2267 def SETNPm   : I<0x9B, MRM0m, 
2268                  (ops i8mem:$dst),
2269                  "setnp $dst",
2270                  [(store (X86setcc X86_COND_NP, STATUS), addr:$dst)]>,
2271                TB;                        // [mem8] = not parity
2272
2273 // Integer comparisons
2274 def CMP8rr  : I<0x38, MRMDestReg,
2275                 (ops R8 :$src1, R8 :$src2),
2276                 "cmp{b} {$src2, $src1|$src1, $src2}",
2277                 [(set STATUS, (X86cmp R8:$src1, R8:$src2))]>,
2278               Imp<[],[STATUS]>;
2279 def CMP16rr : I<0x39, MRMDestReg,
2280                 (ops R16:$src1, R16:$src2),
2281                 "cmp{w} {$src2, $src1|$src1, $src2}",
2282                 [(set STATUS, (X86cmp R16:$src1, R16:$src2))]>,
2283               Imp<[],[STATUS]>, OpSize;
2284 def CMP32rr : I<0x39, MRMDestReg,
2285                 (ops R32:$src1, R32:$src2),
2286                 "cmp{l} {$src2, $src1|$src1, $src2}",
2287                 [(set STATUS, (X86cmp R32:$src1, R32:$src2))]>,
2288               Imp<[],[STATUS]>;
2289 def CMP8mr  : I<0x38, MRMDestMem,
2290                 (ops i8mem :$src1, R8 :$src2),
2291                 "cmp{b} {$src2, $src1|$src1, $src2}",
2292                 [(set STATUS, (X86cmp (loadi8 addr:$src1), R8:$src2))]>,
2293               Imp<[],[STATUS]>;
2294 def CMP16mr : I<0x39, MRMDestMem,
2295                 (ops i16mem:$src1, R16:$src2),
2296                 "cmp{w} {$src2, $src1|$src1, $src2}",
2297                 [(set STATUS, (X86cmp (loadi16 addr:$src1), R16:$src2))]>,
2298               Imp<[],[STATUS]>, OpSize;
2299 def CMP32mr : I<0x39, MRMDestMem,
2300                 (ops i32mem:$src1, R32:$src2),
2301                 "cmp{l} {$src2, $src1|$src1, $src2}",
2302                 [(set STATUS, (X86cmp (loadi32 addr:$src1), R32:$src2))]>,
2303               Imp<[],[STATUS]>;
2304 def CMP8rm  : I<0x3A, MRMSrcMem,
2305                 (ops R8 :$src1, i8mem :$src2),
2306                 "cmp{b} {$src2, $src1|$src1, $src2}",
2307                 [(set STATUS, (X86cmp R8:$src1, (loadi8 addr:$src2)))]>,
2308               Imp<[],[STATUS]>;
2309 def CMP16rm : I<0x3B, MRMSrcMem,
2310                 (ops R16:$src1, i16mem:$src2),
2311                 "cmp{w} {$src2, $src1|$src1, $src2}",
2312                 [(set STATUS, (X86cmp R16:$src1, (loadi16 addr:$src2)))]>,
2313                 Imp<[],[STATUS]>, OpSize;
2314 def CMP32rm : I<0x3B, MRMSrcMem,
2315                 (ops R32:$src1, i32mem:$src2),
2316                 "cmp{l} {$src2, $src1|$src1, $src2}",
2317                 [(set STATUS, (X86cmp R32:$src1, (loadi32 addr:$src2)))]>,
2318               Imp<[],[STATUS]>;
2319 def CMP8ri  : Ii8<0x80, MRM7r,
2320                   (ops R8:$src1, i8imm:$src2),
2321                   "cmp{b} {$src2, $src1|$src1, $src2}",
2322                   [(set STATUS, (X86cmp R8:$src1, imm:$src2))]>,
2323               Imp<[],[STATUS]>;
2324 def CMP16ri : Ii16<0x81, MRM7r,
2325                    (ops R16:$src1, i16imm:$src2),
2326                    "cmp{w} {$src2, $src1|$src1, $src2}",
2327                    [(set STATUS, (X86cmp R16:$src1, imm:$src2))]>,
2328               Imp<[],[STATUS]>, OpSize;
2329 def CMP32ri : Ii32<0x81, MRM7r,
2330                    (ops R32:$src1, i32imm:$src2),
2331                    "cmp{l} {$src2, $src1|$src1, $src2}",
2332                    [(set STATUS, (X86cmp R32:$src1, imm:$src2))]>,
2333               Imp<[],[STATUS]>;
2334 def CMP8mi  : Ii8 <0x80, MRM7m,
2335                    (ops i8mem :$src1, i8imm :$src2),
2336                    "cmp{b} {$src2, $src1|$src1, $src2}",
2337                    [(set STATUS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>,
2338               Imp<[],[STATUS]>;
2339 def CMP16mi : Ii16<0x81, MRM7m,
2340                    (ops i16mem:$src1, i16imm:$src2),
2341                    "cmp{w} {$src2, $src1|$src1, $src2}",
2342                    [(set STATUS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
2343               Imp<[],[STATUS]>, OpSize;
2344 def CMP32mi : Ii32<0x81, MRM7m,
2345                    (ops i32mem:$src1, i32imm:$src2),
2346                    "cmp{l} {$src2, $src1|$src1, $src2}",
2347                    [(set STATUS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>,
2348               Imp<[],[STATUS]>;
2349
2350 // Sign/Zero extenders
2351 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (ops R16:$dst, R8 :$src),
2352                    "movs{bw|x} {$src, $dst|$dst, $src}",
2353                    [(set R16:$dst, (sext R8:$src))]>, TB, OpSize;
2354 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (ops R16:$dst, i8mem :$src),
2355                    "movs{bw|x} {$src, $dst|$dst, $src}",
2356                    [(set R16:$dst, (sextloadi16i8 addr:$src))]>, TB, OpSize;
2357 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (ops R32:$dst, R8 :$src),
2358                    "movs{bl|x} {$src, $dst|$dst, $src}",
2359                    [(set R32:$dst, (sext R8:$src))]>, TB;
2360 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (ops R32:$dst, i8mem :$src),
2361                    "movs{bl|x} {$src, $dst|$dst, $src}",
2362                    [(set R32:$dst, (sextloadi32i8 addr:$src))]>, TB;
2363 def MOVSX32rr16: I<0xBF, MRMSrcReg, (ops R32:$dst, R16:$src),
2364                    "movs{wl|x} {$src, $dst|$dst, $src}",
2365                    [(set R32:$dst, (sext R16:$src))]>, TB;
2366 def MOVSX32rm16: I<0xBF, MRMSrcMem, (ops R32:$dst, i16mem:$src),
2367                    "movs{wl|x} {$src, $dst|$dst, $src}",
2368                    [(set R32:$dst, (sextloadi32i16 addr:$src))]>, TB;
2369
2370 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (ops R16:$dst, R8 :$src),
2371                    "movz{bw|x} {$src, $dst|$dst, $src}",
2372                    [(set R16:$dst, (zext R8:$src))]>, TB, OpSize;
2373 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (ops R16:$dst, i8mem :$src),
2374                    "movz{bw|x} {$src, $dst|$dst, $src}",
2375                    [(set R16:$dst, (zextloadi16i8 addr:$src))]>, TB, OpSize;
2376 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (ops R32:$dst, R8 :$src),
2377                    "movz{bl|x} {$src, $dst|$dst, $src}",
2378                    [(set R32:$dst, (zext R8:$src))]>, TB;
2379 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (ops R32:$dst, i8mem :$src),
2380                    "movz{bl|x} {$src, $dst|$dst, $src}",
2381                    [(set R32:$dst, (zextloadi32i8 addr:$src))]>, TB;
2382 def MOVZX32rr16: I<0xB7, MRMSrcReg, (ops R32:$dst, R16:$src),
2383                    "movz{wl|x} {$src, $dst|$dst, $src}",
2384                    [(set R32:$dst, (zext R16:$src))]>, TB;
2385 def MOVZX32rm16: I<0xB7, MRMSrcMem, (ops R32:$dst, i16mem:$src),
2386                    "movz{wl|x} {$src, $dst|$dst, $src}",
2387                    [(set R32:$dst, (zextloadi32i16 addr:$src))]>, TB;
2388
2389 //===----------------------------------------------------------------------===//
2390 // XMM Floating point support (requires SSE / SSE2)
2391 //===----------------------------------------------------------------------===//
2392
2393 def MOVSSrr : I<0x10, MRMSrcReg, (ops FR32:$dst, FR32:$src),
2394                 "movss {$src, $dst|$dst, $src}", []>,
2395               Requires<[HasSSE1]>, XS;
2396 def MOVSDrr : I<0x10, MRMSrcReg, (ops FR64:$dst, FR64:$src),
2397                 "movsd {$src, $dst|$dst, $src}", []>,
2398               Requires<[HasSSE2]>, XD;
2399
2400 def MOVSSrm : I<0x10, MRMSrcMem, (ops FR32:$dst, f32mem:$src),
2401                 "movss {$src, $dst|$dst, $src}",
2402                 [(set FR32:$dst, (loadf32 addr:$src))]>,
2403               Requires<[HasSSE1]>, XS;
2404 def MOVSSmr : I<0x11, MRMDestMem, (ops f32mem:$dst, FR32:$src),
2405                 "movss {$src, $dst|$dst, $src}",
2406                 [(store FR32:$src, addr:$dst)]>,
2407               Requires<[HasSSE1]>, XS;
2408 def MOVSDrm : I<0x10, MRMSrcMem, (ops FR64:$dst, f64mem:$src),
2409                 "movsd {$src, $dst|$dst, $src}",
2410                 [(set FR64:$dst, (loadf64 addr:$src))]>,
2411               Requires<[HasSSE2]>, XD;
2412 def MOVSDmr : I<0x11, MRMDestMem, (ops f64mem:$dst, FR64:$src),
2413                 "movsd {$src, $dst|$dst, $src}",
2414                 [(store FR64:$src, addr:$dst)]>,
2415               Requires<[HasSSE2]>, XD;
2416
2417 def CVTTSD2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, FR64:$src),
2418                    "cvttsd2si {$src, $dst|$dst, $src}",
2419                    [(set R32:$dst, (fp_to_sint FR64:$src))]>,
2420                  Requires<[HasSSE2]>, XD;
2421 def CVTTSD2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f64mem:$src),
2422                    "cvttsd2si {$src, $dst|$dst, $src}",
2423                    [(set R32:$dst, (fp_to_sint (loadf64 addr:$src)))]>,
2424                  Requires<[HasSSE2]>, XD;
2425 def CVTTSS2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, FR32:$src),
2426                    "cvttss2si {$src, $dst|$dst, $src}",
2427                    [(set R32:$dst, (fp_to_sint FR32:$src))]>,
2428                  Requires<[HasSSE1]>, XS;
2429 def CVTTSS2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f32mem:$src),
2430                    "cvttss2si {$src, $dst|$dst, $src}",
2431                    [(set R32:$dst, (fp_to_sint (loadf32 addr:$src)))]>,
2432                  Requires<[HasSSE1]>, XS;
2433 def CVTSD2SSrr: I<0x5A, MRMSrcReg, (ops FR32:$dst, FR64:$src),
2434                   "cvtsd2ss {$src, $dst|$dst, $src}",
2435                   [(set FR32:$dst, (fround FR64:$src))]>,
2436                 Requires<[HasSSE2]>, XS;
2437 def CVTSD2SSrm: I<0x5A, MRMSrcMem, (ops FR32:$dst, f64mem:$src), 
2438                   "cvtsd2ss {$src, $dst|$dst, $src}",
2439                   [(set FR32:$dst, (fround (loadf64 addr:$src)))]>,
2440                 Requires<[HasSSE2]>, XS;
2441 def CVTSS2SDrr: I<0x5A, MRMSrcReg, (ops FR64:$dst, FR32:$src),
2442                   "cvtss2sd {$src, $dst|$dst, $src}",
2443                   [(set FR64:$dst, (fextend FR32:$src))]>,
2444                 Requires<[HasSSE2]>, XD;
2445 def CVTSS2SDrm: I<0x5A, MRMSrcMem, (ops FR64:$dst, f32mem:$src),
2446                   "cvtss2sd {$src, $dst|$dst, $src}",
2447                   [(set FR64:$dst, (fextend (loadf32 addr:$src)))]>,
2448                 Requires<[HasSSE2]>, XD;
2449 def CVTSI2SSrr: I<0x2A, MRMSrcReg, (ops FR32:$dst, R32:$src),
2450                   "cvtsi2ss {$src, $dst|$dst, $src}",
2451                   [(set FR32:$dst, (sint_to_fp R32:$src))]>,
2452                 Requires<[HasSSE2]>, XS;
2453 def CVTSI2SSrm: I<0x2A, MRMSrcMem, (ops FR32:$dst, i32mem:$src),
2454                   "cvtsi2ss {$src, $dst|$dst, $src}",
2455                   [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>,
2456                 Requires<[HasSSE2]>, XS;
2457 def CVTSI2SDrr: I<0x2A, MRMSrcReg, (ops FR64:$dst, R32:$src),
2458                   "cvtsi2sd {$src, $dst|$dst, $src}",
2459                   [(set FR64:$dst, (sint_to_fp R32:$src))]>,
2460                 Requires<[HasSSE2]>, XD;
2461 def CVTSI2SDrm: I<0x2A, MRMSrcMem, (ops FR64:$dst, i32mem:$src),
2462                   "cvtsi2sd {$src, $dst|$dst, $src}",
2463                   [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>,
2464                 Requires<[HasSSE2]>, XD;
2465
2466 def SQRTSSrm : I<0x51, MRMSrcMem, (ops FR32:$dst, f32mem:$src),
2467                  "sqrtss {$src, $dst|$dst, $src}",
2468                  [(set FR32:$dst, (fsqrt (loadf32 addr:$src)))]>,
2469                Requires<[HasSSE1]>, XS;
2470 def SQRTSSrr : I<0x51, MRMSrcReg, (ops FR32:$dst, FR32:$src),
2471                  "sqrtss {$src, $dst|$dst, $src}",
2472                  [(set FR32:$dst, (fsqrt FR32:$src))]>,
2473                Requires<[HasSSE1]>, XS;
2474 def SQRTSDrm : I<0x51, MRMSrcMem, (ops FR64:$dst, f64mem:$src),
2475                  "sqrtsd {$src, $dst|$dst, $src}",
2476                  [(set FR64:$dst, (fsqrt (loadf64 addr:$src)))]>,
2477                Requires<[HasSSE2]>, XD;
2478 def SQRTSDrr : I<0x51, MRMSrcReg, (ops FR64:$dst, FR64:$src),
2479                  "sqrtsd {$src, $dst|$dst, $src}",
2480                  [(set FR64:$dst, (fsqrt FR64:$src))]>,
2481                Requires<[HasSSE2]>, XD;
2482
2483 def UCOMISDrr: I<0x2E, MRMSrcReg, (ops FR64:$src1, FR64:$src2),
2484                  "ucomisd {$src2, $src1|$src1, $src2}",
2485                  [(set STATUS, (X86cmp FR64:$src1, FR64:$src2))]>,
2486                Requires<[HasSSE2]>, TB, OpSize;
2487 def UCOMISDrm: I<0x2E, MRMSrcMem, (ops FR64:$src1, f64mem:$src2),
2488                  "ucomisd {$src2, $src1|$src1, $src2}",
2489                  [(set STATUS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>,
2490                Imp<[],[STATUS]>, Requires<[HasSSE2]>, TB, OpSize;
2491 def UCOMISSrr: I<0x2E, MRMSrcReg, (ops FR32:$src1, FR32:$src2),
2492                  "ucomiss {$src2, $src1|$src1, $src2}",
2493                  [(set STATUS, (X86cmp FR32:$src1, FR32:$src2))]>,
2494                Imp<[],[STATUS]>, Requires<[HasSSE1]>, TB;
2495 def UCOMISSrm: I<0x2E, MRMSrcMem, (ops FR32:$src1, f32mem:$src2),
2496                  "ucomiss {$src2, $src1|$src1, $src2}",
2497                  [(set STATUS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>,
2498                Imp<[],[STATUS]>, Requires<[HasSSE1]>, TB;
2499
2500 // Pseudo-instructions that map fld0 to xorps/xorpd for sse.
2501 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2502 def FLD0SS : I<0x57, MRMSrcReg, (ops FR32:$dst),
2503                "xorps $dst, $dst", [(set FR32:$dst, fp32imm0)]>,
2504              Requires<[HasSSE1]>, TB;
2505 def FLD0SD : I<0x57, MRMSrcReg, (ops FR64:$dst),
2506                "xorpd $dst, $dst", [(set FR64:$dst, fp64imm0)]>,
2507              Requires<[HasSSE2]>, TB, OpSize;
2508
2509 let isTwoAddress = 1 in {
2510 // SSE Scalar Arithmetic
2511 let isCommutable = 1 in {
2512 def ADDSSrr : I<0x58, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2513                 "addss {$src2, $dst|$dst, $src2}",
2514                 [(set FR32:$dst, (fadd FR32:$src1, FR32:$src2))]>,
2515               Requires<[HasSSE1]>, XS;
2516 def ADDSDrr : I<0x58, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2517                 "addsd {$src2, $dst|$dst, $src2}",
2518                 [(set FR64:$dst, (fadd FR64:$src1, FR64:$src2))]>,
2519               Requires<[HasSSE2]>, XD;
2520 def MULSSrr : I<0x59, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2521                 "mulss {$src2, $dst|$dst, $src2}",
2522                 [(set FR32:$dst, (fmul FR32:$src1, FR32:$src2))]>,
2523               Requires<[HasSSE1]>, XS;
2524 def MULSDrr : I<0x59, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2525                 "mulsd {$src2, $dst|$dst, $src2}",
2526                 [(set FR64:$dst, (fmul FR64:$src1, FR64:$src2))]>,
2527               Requires<[HasSSE2]>, XD;
2528 }
2529
2530 def ADDSSrm : I<0x58, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2531                 "addss {$src2, $dst|$dst, $src2}",
2532                 [(set FR32:$dst, (fadd FR32:$src1, (loadf32 addr:$src2)))]>,
2533               Requires<[HasSSE1]>, XS;
2534 def ADDSDrm : I<0x58, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2535                 "addsd {$src2, $dst|$dst, $src2}",
2536                 [(set FR64:$dst, (fadd FR64:$src1, (loadf64 addr:$src2)))]>,
2537               Requires<[HasSSE2]>, XD;
2538 def MULSSrm : I<0x59, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2539                 "mulss {$src2, $dst|$dst, $src2}",
2540                 [(set FR32:$dst, (fmul FR32:$src1, (loadf32 addr:$src2)))]>,
2541               Requires<[HasSSE1]>, XS;
2542 def MULSDrm : I<0x59, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2543                 "mulsd {$src2, $dst|$dst, $src2}",
2544                 [(set FR64:$dst, (fmul FR64:$src1, (loadf64 addr:$src2)))]>,
2545               Requires<[HasSSE2]>, XD;
2546
2547 def DIVSSrr : I<0x5E, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2548                 "divss {$src2, $dst|$dst, $src2}",
2549                 [(set FR32:$dst, (fdiv FR32:$src1, FR32:$src2))]>,
2550               Requires<[HasSSE1]>, XS;
2551 def DIVSSrm : I<0x5E, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2552                 "divss {$src2, $dst|$dst, $src2}",
2553                 [(set FR32:$dst, (fdiv FR32:$src1, (loadf32 addr:$src2)))]>,
2554               Requires<[HasSSE1]>, XS;
2555 def DIVSDrr : I<0x5E, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2556                 "divsd {$src2, $dst|$dst, $src2}",
2557                 [(set FR64:$dst, (fdiv FR64:$src1, FR64:$src2))]>,
2558               Requires<[HasSSE2]>, XD;
2559 def DIVSDrm : I<0x5E, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2560                 "divsd {$src2, $dst|$dst, $src2}",
2561                 [(set FR64:$dst, (fdiv FR64:$src1, (loadf64 addr:$src2)))]>,
2562               Requires<[HasSSE2]>, XD;
2563
2564 def SUBSSrr : I<0x5C, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2565                 "subss {$src2, $dst|$dst, $src2}",
2566                 [(set FR32:$dst, (fsub FR32:$src1, FR32:$src2))]>,
2567               Requires<[HasSSE1]>, XS;
2568 def SUBSSrm : I<0x5C, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2569                 "subss {$src2, $dst|$dst, $src2}",
2570                 [(set FR32:$dst, (fsub FR32:$src1, (loadf32 addr:$src2)))]>,
2571               Requires<[HasSSE1]>, XS;
2572 def SUBSDrr : I<0x5C, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2573                 "subsd {$src2, $dst|$dst, $src2}",
2574                 [(set FR64:$dst, (fsub FR64:$src1, FR64:$src2))]>,
2575               Requires<[HasSSE2]>, XD;
2576 def SUBSDrm : I<0x5C, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2577                 "subsd {$src2, $dst|$dst, $src2}",
2578                 [(set FR64:$dst, (fsub FR64:$src1, (loadf64 addr:$src2)))]>,
2579               Requires<[HasSSE2]>, XD;
2580
2581 // SSE Logical
2582 let isCommutable = 1 in {
2583 def ANDPSrr : I<0x54, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2584                 "andps {$src2, $dst|$dst, $src2}", []>,
2585               Requires<[HasSSE1]>, TB;
2586 def ANDPDrr : I<0x54, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2587                 "andpd {$src2, $dst|$dst, $src2}", []>,
2588               Requires<[HasSSE2]>, TB, OpSize;
2589 def ORPSrr : I<0x56, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2590                 "orps {$src2, $dst|$dst, $src2}", []>,
2591              Requires<[HasSSE1]>, TB;
2592 def ORPDrr : I<0x56, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2593                 "orpd {$src2, $dst|$dst, $src2}", []>,
2594              Requires<[HasSSE2]>, TB, OpSize;
2595 def XORPSrr : I<0x57, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2596                 "xorps {$src2, $dst|$dst, $src2}", []>,
2597               Requires<[HasSSE1]>, TB;
2598 def XORPDrr : I<0x57, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2599                 "xorpd {$src2, $dst|$dst, $src2}", []>,
2600               Requires<[HasSSE2]>, TB, OpSize;
2601 }
2602 def ANDNPSrr : I<0x55, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2603                 "andnps {$src2, $dst|$dst, $src2}", []>,
2604                Requires<[HasSSE1]>, TB;
2605 def ANDNPDrr : I<0x55, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2606                 "andnpd {$src2, $dst|$dst, $src2}", []>,
2607                Requires<[HasSSE2]>, TB, OpSize;
2608
2609 def CMPSSrr : I<0xC2, MRMSrcReg, 
2610                 (ops FR32:$dst, FR32:$src1, FR32:$src, SSECC:$cc),
2611                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>,
2612               Requires<[HasSSE1]>, XS;
2613 def CMPSSrm : I<0xC2, MRMSrcMem, 
2614                 (ops FR32:$dst, FR32:$src1, f32mem:$src, SSECC:$cc),
2615                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>,
2616               Requires<[HasSSE1]>, XS;
2617 def CMPSDrr : I<0xC2, MRMSrcReg, 
2618                 (ops FR64:$dst, FR64:$src1, FR64:$src, SSECC:$cc),
2619                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>,
2620               Requires<[HasSSE1]>, XD;
2621 def CMPSDrm : I<0xC2, MRMSrcMem, 
2622                 (ops FR64:$dst, FR64:$src1, f64mem:$src, SSECC:$cc),
2623                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>,
2624               Requires<[HasSSE2]>, XD;
2625 }
2626
2627 //===----------------------------------------------------------------------===//
2628 // Floating Point Stack Support
2629 //===----------------------------------------------------------------------===//
2630
2631 // Floating point support.  All FP Stack operations are represented with two 
2632 // instructions here.  The first instruction, generated by the instruction
2633 // selector, uses "RFP" registers: a traditional register file to reference
2634 // floating point values.  These instructions are all psuedo instructions and
2635 // use the "Fp" prefix.  The second instruction is defined with FPI, which is
2636 // the actual instruction emitted by the assembler.  The FP stackifier pass
2637 // converts one to the other after register allocation occurs.
2638 //
2639 // Note that the FpI instruction should have instruction selection info (e.g.
2640 // a pattern) and the FPI instruction should have emission info (e.g. opcode
2641 // encoding and asm printing info).
2642
2643 // FPI - Floating Point Instruction template.
2644 class FPI<bits<8> o, Format F, dag ops, string asm> : I<o, F, ops, asm, []> {}
2645
2646 // FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
2647 class FpI_<dag ops, FPFormat fp, list<dag> pattern>
2648   : X86Inst<0, Pseudo, NoImm, ops, ""> {
2649   let FPForm = fp; let FPFormBits = FPForm.Value;
2650   let Pattern = pattern;
2651 }
2652
2653 // Random Pseudo Instructions.
2654 def FpGETRESULT : FpI_<(ops RFP:$dst), SpecialFP,
2655                   [(set RFP:$dst, X86fpget)]>;                    // FPR = ST(0)
2656
2657 let noResults = 1 in 
2658   def FpSETRESULT : FpI_<(ops RFP:$src), SpecialFP,
2659                         [(X86fpset RFP:$src)]>, Imp<[], [ST0]>;   // ST(0) = FPR
2660
2661 // FpI - Floating Point Psuedo Instruction template. Predicated on FPStack.
2662 class FpI<dag ops, FPFormat fp, list<dag> pattern> :
2663   FpI_<ops, fp, pattern>, Requires<[FPStack]>;
2664
2665
2666 def FpMOV       : FpI<(ops RFP:$dst, RFP:$src), SpecialFP, []>; // f1 = fmov f2
2667
2668 // Arithmetic
2669 // Add, Sub, Mul, Div.
2670 def FpADD : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2671                 [(set RFP:$dst, (fadd RFP:$src1, RFP:$src2))]>;
2672 def FpSUB : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2673                 [(set RFP:$dst, (fsub RFP:$src1, RFP:$src2))]>;
2674 def FpMUL : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2675                 [(set RFP:$dst, (fmul RFP:$src1, RFP:$src2))]>;
2676 def FpDIV : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2677                 [(set RFP:$dst, (fdiv RFP:$src1, RFP:$src2))]>;
2678
2679 class FPST0rInst<bits<8> o, string asm>
2680   : FPI<o, AddRegFrm, (ops RST:$op), asm>, D8;
2681 class FPrST0Inst<bits<8> o, string asm>
2682   : FPI<o, AddRegFrm, (ops RST:$op), asm>, DC;
2683 class FPrST0PInst<bits<8> o, string asm>
2684   : FPI<o, AddRegFrm, (ops RST:$op), asm>, DE;
2685
2686 // Binary Ops with a memory source.
2687 def FpADD32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2688                     [(set RFP:$dst, (fadd RFP:$src1,
2689                                      (extloadf64f32 addr:$src2)))]>;
2690                 // ST(0) = ST(0) + [mem32]
2691 def FpADD64m  : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2692                     [(set RFP:$dst, (fadd RFP:$src1, (loadf64 addr:$src2)))]>;
2693                 // ST(0) = ST(0) + [mem64]
2694 def FpMUL32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2695                     [(set RFP:$dst, (fmul RFP:$src1,
2696                                      (extloadf64f32 addr:$src2)))]>;
2697                 // ST(0) = ST(0) * [mem32]
2698 def FpMUL64m  : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2699                     [(set RFP:$dst, (fmul RFP:$src1, (loadf64 addr:$src2)))]>;
2700                 // ST(0) = ST(0) * [mem64]
2701 def FpSUB32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2702                     [(set RFP:$dst, (fsub RFP:$src1,
2703                                     (extloadf64f32 addr:$src2)))]>;
2704                 // ST(0) = ST(0) - [mem32]
2705 def FpSUB64m  : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2706                     [(set RFP:$dst, (fsub RFP:$src1, (loadf64 addr:$src2)))]>;
2707                 // ST(0) = ST(0) - [mem64]
2708 def FpSUBR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2709                     [(set RFP:$dst, (fsub (extloadf64f32 addr:$src2),
2710                                      RFP:$src1))]>;
2711                 // ST(0) = [mem32] - ST(0)
2712 def FpSUBR64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2713                     [(set RFP:$dst, (fsub (loadf64 addr:$src2), RFP:$src1))]>;
2714                 // ST(0) = [mem64] - ST(0)
2715 def FpDIV32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2716                     [(set RFP:$dst, (fdiv RFP:$src1,
2717                                     (extloadf64f32 addr:$src2)))]>;
2718                 // ST(0) = ST(0) / [mem32]
2719 def FpDIV64m  : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2720                     [(set RFP:$dst, (fdiv RFP:$src1, (loadf64 addr:$src2)))]>;
2721                 // ST(0) = ST(0) / [mem64]
2722 def FpDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2723                     [(set RFP:$dst, (fdiv (extloadf64f32 addr:$src2),
2724                                      RFP:$src1))]>;
2725                 // ST(0) = [mem32] / ST(0)
2726 def FpDIVR64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
2727                     [(set RFP:$dst, (fdiv (loadf64 addr:$src2), RFP:$src1))]>;
2728                 // ST(0) = [mem64] / ST(0)
2729
2730
2731 def FADD32m  : FPI<0xD8, MRM0m, (ops f32mem:$src), "fadd{s} $src">;
2732 def FADD64m  : FPI<0xDC, MRM0m, (ops f64mem:$src), "fadd{l} $src">;
2733 def FMUL32m  : FPI<0xD8, MRM1m, (ops f32mem:$src), "fmul{s} $src">;
2734 def FMUL64m  : FPI<0xDC, MRM1m, (ops f64mem:$src), "fmul{l} $src">;
2735 def FSUB32m  : FPI<0xD8, MRM4m, (ops f32mem:$src), "fsub{s} $src">;
2736 def FSUB64m  : FPI<0xDC, MRM4m, (ops f64mem:$src), "fsub{l} $src">;
2737 def FSUBR32m : FPI<0xD8, MRM5m, (ops f32mem:$src), "fsubr{s} $src">;
2738 def FSUBR64m : FPI<0xDC, MRM5m, (ops f64mem:$src), "fsubr{l} $src">;
2739 def FDIV32m  : FPI<0xD8, MRM6m, (ops f32mem:$src), "fdiv{s} $src">;
2740 def FDIV64m  : FPI<0xDC, MRM6m, (ops f64mem:$src), "fdiv{l} $src">;
2741 def FDIVR32m : FPI<0xD8, MRM7m, (ops f32mem:$src), "fdivr{s} $src">;
2742 def FDIVR64m : FPI<0xDC, MRM7m, (ops f64mem:$src), "fdivr{l} $src">;
2743
2744 def FpIADD16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2745                     [(set RFP:$dst, (fadd RFP:$src1,
2746                                      (X86fild addr:$src2, i16)))]>;
2747                 // ST(0) = ST(0) + [mem16int]
2748 def FpIADD32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2749                     [(set RFP:$dst, (fadd RFP:$src1,
2750                                      (X86fild addr:$src2, i32)))]>;
2751                 // ST(0) = ST(0) + [mem32int]
2752 def FpIMUL16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2753                     [(set RFP:$dst, (fmul RFP:$src1,
2754                                      (X86fild addr:$src2, i16)))]>;
2755                 // ST(0) = ST(0) * [mem16int]
2756 def FpIMUL32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2757                     [(set RFP:$dst, (fmul RFP:$src1,
2758                                      (X86fild addr:$src2, i32)))]>;
2759                 // ST(0) = ST(0) * [mem32int]
2760 def FpISUB16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2761                     [(set RFP:$dst, (fsub RFP:$src1,
2762                                      (X86fild addr:$src2, i16)))]>;
2763                 // ST(0) = ST(0) - [mem16int]
2764 def FpISUB32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2765                     [(set RFP:$dst, (fsub RFP:$src1,
2766                                      (X86fild addr:$src2, i32)))]>;
2767                 // ST(0) = ST(0) - [mem32int]
2768 def FpISUBR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2769                      [(set RFP:$dst, (fsub (X86fild addr:$src2, i16),
2770                                       RFP:$src1))]>;
2771                 // ST(0) = [mem16int] - ST(0)
2772 def FpISUBR32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2773                      [(set RFP:$dst, (fsub (X86fild addr:$src2, i32),
2774                                       RFP:$src1))]>;
2775                 // ST(0) = [mem32int] - ST(0)
2776 def FpIDIV16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2777                     [(set RFP:$dst, (fdiv RFP:$src1,
2778                                      (X86fild addr:$src2, i16)))]>;
2779                 // ST(0) = ST(0) / [mem16int]
2780 def FpIDIV32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2781                     [(set RFP:$dst, (fdiv RFP:$src1,
2782                                      (X86fild addr:$src2, i32)))]>;
2783                 // ST(0) = ST(0) / [mem32int]
2784 def FpIDIVR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2785                      [(set RFP:$dst, (fdiv (X86fild addr:$src2, i16),
2786                                       RFP:$src1))]>;
2787                 // ST(0) = [mem16int] / ST(0)
2788 def FpIDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
2789                      [(set RFP:$dst, (fdiv (X86fild addr:$src2, i32),
2790                                       RFP:$src1))]>;
2791                 // ST(0) = [mem32int] / ST(0)
2792
2793 def FIADD16m  : FPI<0xDE, MRM0m, (ops i16mem:$src), "fiadd{s} $src">;
2794 def FIADD32m  : FPI<0xDA, MRM0m, (ops i32mem:$src), "fiadd{l} $src">;
2795 def FIMUL16m  : FPI<0xDE, MRM1m, (ops i16mem:$src), "fimul{s} $src">;
2796 def FIMUL32m  : FPI<0xDA, MRM1m, (ops i32mem:$src), "fimul{l} $src">;
2797 def FISUB16m  : FPI<0xDE, MRM4m, (ops i16mem:$src), "fisub{s} $src">;
2798 def FISUB32m  : FPI<0xDA, MRM4m, (ops i32mem:$src), "fisub{l} $src">;
2799 def FISUBR16m : FPI<0xDE, MRM5m, (ops i16mem:$src), "fisubr{s} $src">;
2800 def FISUBR32m : FPI<0xDA, MRM5m, (ops i32mem:$src), "fisubr{l} $src">;
2801 def FIDIV16m  : FPI<0xDE, MRM6m, (ops i16mem:$src), "fidiv{s} $src">;
2802 def FIDIV32m  : FPI<0xDA, MRM6m, (ops i32mem:$src), "fidiv{l} $src">;
2803 def FIDIVR16m : FPI<0xDE, MRM7m, (ops i16mem:$src), "fidivr{s} $src">;
2804 def FIDIVR32m : FPI<0xDA, MRM7m, (ops i32mem:$src), "fidivr{l} $src">;
2805
2806 // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
2807 // of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
2808 // we have to put some 'r's in and take them out of weird places.
2809 def FADDST0r   : FPST0rInst <0xC0, "fadd $op">;
2810 def FADDrST0   : FPrST0Inst <0xC0, "fadd {%ST(0), $op|$op, %ST(0)}">;
2811 def FADDPrST0  : FPrST0PInst<0xC0, "faddp $op">;
2812 def FSUBRST0r  : FPST0rInst <0xE8, "fsubr $op">;
2813 def FSUBrST0   : FPrST0Inst <0xE8, "fsub{r} {%ST(0), $op|$op, %ST(0)}">;
2814 def FSUBPrST0  : FPrST0PInst<0xE8, "fsub{r}p $op">;
2815 def FSUBST0r   : FPST0rInst <0xE0, "fsub $op">;
2816 def FSUBRrST0  : FPrST0Inst <0xE0, "fsub{|r} {%ST(0), $op|$op, %ST(0)}">;
2817 def FSUBRPrST0 : FPrST0PInst<0xE0, "fsub{|r}p $op">;
2818 def FMULST0r   : FPST0rInst <0xC8, "fmul $op">;
2819 def FMULrST0   : FPrST0Inst <0xC8, "fmul {%ST(0), $op|$op, %ST(0)}">;
2820 def FMULPrST0  : FPrST0PInst<0xC8, "fmulp $op">;
2821 def FDIVRST0r  : FPST0rInst <0xF8, "fdivr $op">;
2822 def FDIVrST0   : FPrST0Inst <0xF8, "fdiv{r} {%ST(0), $op|$op, %ST(0)}">;
2823 def FDIVPrST0  : FPrST0PInst<0xF8, "fdiv{r}p $op">;
2824 def FDIVST0r   : FPST0rInst <0xF0, "fdiv $op">;
2825 def FDIVRrST0  : FPrST0Inst <0xF0, "fdiv{|r} {%ST(0), $op|$op, %ST(0)}">;
2826 def FDIVRPrST0 : FPrST0PInst<0xF0, "fdiv{|r}p $op">;
2827
2828
2829 // Unary operations.
2830 def FpCHS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2831                  [(set RFP:$dst, (fneg RFP:$src))]>;
2832 def FpABS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2833                  [(set RFP:$dst, (fabs RFP:$src))]>;
2834 def FpSQRT : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2835                  [(set RFP:$dst, (fsqrt RFP:$src))]>;
2836 def FpSIN  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2837                  [(set RFP:$dst, (fsin RFP:$src))]>;
2838 def FpCOS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2839                  [(set RFP:$dst, (fcos RFP:$src))]>;
2840 def FpTST  : FpI<(ops RFP:$src), OneArgFP,
2841                  []>;
2842
2843 def FCHS  : FPI<0xE0, RawFrm, (ops), "fchs">, D9;
2844 def FABS  : FPI<0xE1, RawFrm, (ops), "fabs">, D9;
2845 def FSQRT : FPI<0xFA, RawFrm, (ops), "fsqrt">, D9;
2846 def FSIN  : FPI<0xFE, RawFrm, (ops), "fsin">, D9;
2847 def FCOS  : FPI<0xFF, RawFrm, (ops), "fcos">, D9;
2848 def FTST  : FPI<0xE4, RawFrm, (ops), "ftst">, D9;
2849
2850
2851 // Floating point cmovs.
2852 let isTwoAddress = 1 in {
2853   def FpCMOVB  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2854                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2855                                       X86_COND_B, STATUS))]>;
2856   def FpCMOVBE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2857                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2858                                       X86_COND_BE, STATUS))]>;
2859   def FpCMOVE  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2860                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2861                                       X86_COND_E, STATUS))]>;
2862   def FpCMOVP  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2863                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2864                                       X86_COND_P, STATUS))]>;
2865   def FpCMOVAE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2866                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2867                                       X86_COND_AE, STATUS))]>;
2868   def FpCMOVA  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2869                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2870                                       X86_COND_A, STATUS))]>;
2871   def FpCMOVNE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2872                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2873                                       X86_COND_NE, STATUS))]>;
2874   def FpCMOVNP : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2875                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2876                                       X86_COND_NP, STATUS))]>;
2877 }
2878
2879 def FCMOVB  : FPI<0xC0, AddRegFrm, (ops RST:$op),
2880                   "fcmovb {$op, %ST(0)|%ST(0), $op}">, DA;
2881 def FCMOVBE : FPI<0xD0, AddRegFrm, (ops RST:$op),
2882                   "fcmovbe {$op, %ST(0)|%ST(0), $op}">, DA;
2883 def FCMOVE  : FPI<0xC8, AddRegFrm, (ops RST:$op),
2884                   "fcmove {$op, %ST(0)|%ST(0), $op}">, DA;
2885 def FCMOVP  : FPI<0xD8, AddRegFrm, (ops RST:$op),
2886                   "fcmovu  {$op, %ST(0)|%ST(0), $op}">, DA;
2887 def FCMOVAE : FPI<0xC0, AddRegFrm, (ops RST:$op),
2888                   "fcmovae {$op, %ST(0)|%ST(0), $op}">, DB;
2889 def FCMOVA  : FPI<0xD0, AddRegFrm, (ops RST:$op),
2890                   "fcmova {$op, %ST(0)|%ST(0), $op}">, DB;
2891 def FCMOVNE : FPI<0xC8, AddRegFrm, (ops RST:$op),
2892                   "fcmovne {$op, %ST(0)|%ST(0), $op}">, DB;
2893 def FCMOVNP : FPI<0xD8, AddRegFrm, (ops RST:$op),
2894                   "fcmovnu {$op, %ST(0)|%ST(0), $op}">, DB;
2895
2896 // Floating point loads & stores.
2897 def FpLD32m  : FpI<(ops RFP:$dst, f32mem:$src), ZeroArgFP,
2898                    [(set RFP:$dst, (extloadf64f32 addr:$src))]>;
2899 def FpLD64m  : FpI<(ops RFP:$dst, f64mem:$src), ZeroArgFP,
2900                    [(set RFP:$dst, (loadf64 addr:$src))]>;
2901 def FpILD16m : FpI<(ops RFP:$dst, i16mem:$src), ZeroArgFP,
2902                    [(set RFP:$dst, (X86fild addr:$src, i16))]>;
2903 def FpILD32m : FpI<(ops RFP:$dst, i32mem:$src), ZeroArgFP,
2904                    [(set RFP:$dst, (X86fild addr:$src, i32))]>;
2905 def FpILD64m : FpI<(ops RFP:$dst, i64mem:$src), ZeroArgFP,
2906                    [(set RFP:$dst, (X86fild addr:$src, i64))]>;
2907
2908 def FpST32m   : FpI<(ops f32mem:$op, RFP:$src), OneArgFP,
2909                 [(truncstore RFP:$src, addr:$op, f32)]>;
2910 def FpST64m   : FpI<(ops f64mem:$op, RFP:$src), OneArgFP,
2911                 [(store RFP:$src, addr:$op)]>;
2912
2913 def FpSTP32m  : FpI<(ops f32mem:$op, RFP:$src), OneArgFP, []>;
2914 def FpSTP64m  : FpI<(ops f64mem:$op, RFP:$src), OneArgFP, []>;
2915 def FpIST16m  : FpI<(ops i16mem:$op, RFP:$src), OneArgFP, []>;
2916 def FpIST32m  : FpI<(ops i32mem:$op, RFP:$src), OneArgFP, []>;
2917 def FpIST64m  : FpI<(ops i64mem:$op, RFP:$src), OneArgFP, []>;
2918
2919 def FLD32m   : FPI<0xD9, MRM0m, (ops f32mem:$src), "fld{s} $src">;
2920 def FLD64m   : FPI<0xDD, MRM0m, (ops f64mem:$src), "fld{l} $src">;
2921 def FILD16m  : FPI<0xDF, MRM0m, (ops i16mem:$src), "fild{s} $src">;
2922 def FILD32m  : FPI<0xDB, MRM0m, (ops i32mem:$src), "fild{l} $src">;
2923 def FILD64m  : FPI<0xDF, MRM5m, (ops i64mem:$src), "fild{ll} $src">;
2924 def FST32m   : FPI<0xD9, MRM2m, (ops f32mem:$dst), "fst{s} $dst">;
2925 def FST64m   : FPI<0xDD, MRM2m, (ops f64mem:$dst), "fst{l} $dst">;
2926 def FSTP32m  : FPI<0xD9, MRM3m, (ops f32mem:$dst), "fstp{s} $dst">;
2927 def FSTP64m  : FPI<0xDD, MRM3m, (ops f64mem:$dst), "fstp{l} $dst">;
2928 def FIST16m  : FPI<0xDF, MRM2m, (ops i16mem:$dst), "fist{s} $dst">;
2929 def FIST32m  : FPI<0xDB, MRM2m, (ops i32mem:$dst), "fist{l} $dst">;
2930 def FISTP16m : FPI<0xDF, MRM3m, (ops i16mem:$dst), "fistp{s} $dst">;
2931 def FISTP32m : FPI<0xDB, MRM3m, (ops i32mem:$dst), "fistp{l} $dst">;
2932 def FISTP64m : FPI<0xDF, MRM7m, (ops i64mem:$dst), "fistp{ll} $dst">;
2933
2934 // FP Stack manipulation instructions.
2935 def FLDrr   : FPI<0xC0, AddRegFrm, (ops RST:$op), "fld $op">, D9;
2936 def FSTrr   : FPI<0xD0, AddRegFrm, (ops RST:$op), "fst $op">, DD;
2937 def FSTPrr  : FPI<0xD8, AddRegFrm, (ops RST:$op), "fstp $op">, DD;
2938 def FXCH    : FPI<0xC8, AddRegFrm, (ops RST:$op), "fxch $op">, D9;
2939
2940 // Floating point constant loads.
2941 def FpLD0 : FpI<(ops RFP:$dst), ZeroArgFP,
2942                 [(set RFP:$dst, fp64imm0)]>;
2943 def FpLD1 : FpI<(ops RFP:$dst), ZeroArgFP,
2944                 [(set RFP:$dst, fp64imm1)]>;
2945
2946 def FLD0 : FPI<0xEE, RawFrm, (ops), "fldz">, D9;
2947 def FLD1 : FPI<0xE8, RawFrm, (ops), "fld1">, D9;
2948
2949
2950 // Floating point compares.
2951 def FpUCOMr   : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
2952                     []>;  // FPSW = cmp ST(0) with ST(i)
2953 def FpUCOMIr  : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
2954                     [(set STATUS, (X86cmp RFP:$lhs, RFP:$rhs))]>,
2955                 Imp<[],[STATUS]>;       // CC = cmp ST(0) with ST(i)
2956
2957 def FUCOMr    : FPI<0xE0, AddRegFrm,    // FPSW = cmp ST(0) with ST(i)
2958                     (ops RST:$reg),
2959                     "fucom $reg">, DD, Imp<[ST0],[]>;
2960 def FUCOMPr   : FPI<0xE8, AddRegFrm,    // FPSW = cmp ST(0) with ST(i), pop
2961                   (ops RST:$reg),
2962                   "fucomp $reg">, DD, Imp<[ST0],[]>;
2963 def FUCOMPPr  : FPI<0xE9, RawFrm,       // cmp ST(0) with ST(1), pop, pop
2964                   (ops),
2965                   "fucompp">, DA, Imp<[ST0],[]>;
2966
2967 def FUCOMIr  : FPI<0xE8, AddRegFrm,     // CC = cmp ST(0) with ST(i)
2968                    (ops RST:$reg),
2969                    "fucomi {$reg, %ST(0)|%ST(0), $reg}">, DB, Imp<[ST0],[]>;
2970 def FUCOMIPr : FPI<0xE8, AddRegFrm,     // CC = cmp ST(0) with ST(i), pop
2971                  (ops RST:$reg),
2972                  "fucomip {$reg, %ST(0)|%ST(0), $reg}">, DF, Imp<[ST0],[]>;
2973
2974
2975 // Floating point flag ops.
2976 def FNSTSW8r  : I<0xE0, RawFrm,                  // AX = fp flags
2977                   (ops), "fnstsw", []>, DF, Imp<[],[AX]>;
2978
2979 def FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
2980                   (ops i16mem:$dst), "fnstcw $dst", []>;
2981 def FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
2982                   (ops i16mem:$dst), "fldcw $dst", []>;
2983
2984
2985 //===----------------------------------------------------------------------===//
2986 // Miscellaneous Instructions
2987 //===----------------------------------------------------------------------===//
2988
2989 def RDTSC : I<0x31, RawFrm, (ops), "rdtsc", [(X86rdtsc)]>,
2990             TB, Imp<[],[EAX,EDX]>;
2991
2992
2993 //===----------------------------------------------------------------------===//
2994 // Non-Instruction Patterns
2995 //===----------------------------------------------------------------------===//
2996
2997 // GlobalAddress and ExternalSymbol
2998 def : Pat<(i32 globaladdr:$dst),  (MOV32ri tglobaladdr:$dst)>;
2999 def : Pat<(i32 externalsym:$dst), (MOV32ri texternalsym:$dst)>;
3000
3001 // Calls
3002 def : Pat<(X86call tglobaladdr:$dst),
3003           (CALLpcrel32 tglobaladdr:$dst)>;
3004 def : Pat<(X86call texternalsym:$dst),
3005           (CALLpcrel32 texternalsym:$dst)>;
3006
3007 // X86 specific add which produces a flag.
3008 def : Pat<(X86addflag R32:$src1, R32:$src2),
3009           (ADD32rr R32:$src1, R32:$src2)>;
3010 def : Pat<(X86addflag R32:$src1, (load addr:$src2)),
3011           (ADD32rm R32:$src1, addr:$src2)>;
3012 def : Pat<(X86addflag R32:$src1, imm:$src2),
3013           (ADD32ri R32:$src1, imm:$src2)>;
3014 def : Pat<(X86addflag R32:$src1, i32immSExt8:$src2),
3015           (ADD32ri8 R32:$src1, i32immSExt8:$src2)>;
3016
3017 def : Pat<(X86subflag R32:$src1, R32:$src2),
3018           (SUB32rr R32:$src1, R32:$src2)>;
3019 def : Pat<(X86subflag R32:$src1, (load addr:$src2)),
3020           (SUB32rm R32:$src1, addr:$src2)>;
3021 def : Pat<(X86subflag R32:$src1, imm:$src2),
3022           (SUB32ri R32:$src1, imm:$src2)>;
3023 def : Pat<(X86subflag R32:$src1, i32immSExt8:$src2),
3024           (SUB32ri8 R32:$src1, i32immSExt8:$src2)>;
3025
3026 def : Pat<(truncstore (i8 imm:$src), addr:$dst, i1), 
3027           (MOV8mi addr:$dst, imm:$src)>;
3028 def : Pat<(truncstore R8:$src, addr:$dst, i1), 
3029           (MOV8mr addr:$dst, R8:$src)>;
3030
3031 // {s|z}extload bool -> {s|z}extload byte
3032 def : Pat<(sextloadi16i1 addr:$src), (MOVSX16rm8 addr:$src)>;
3033 def : Pat<(sextloadi32i1 addr:$src), (MOVSX32rm8 addr:$src)>;
3034 def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
3035 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
3036 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
3037
3038 // extload bool -> extload byte
3039 def : Pat<(extloadi8i1 addr:$src), (MOV8rm addr:$src)>;
3040
3041 // anyext -> zext
3042 def : Pat<(i16 (anyext R8 :$src)), (MOVZX16rr8  R8 :$src)>;
3043 def : Pat<(i32 (anyext R8 :$src)), (MOVZX32rr8  R8 :$src)>;
3044 def : Pat<(i32 (anyext R16:$src)), (MOVZX32rr16 R16:$src)>;
3045
3046 // Required for RET of f32 / f64 values.
3047 def : Pat<(X86fld addr:$src, f32), (FpLD32m addr:$src)>;
3048 def : Pat<(X86fld addr:$src, f64), (FpLD64m addr:$src)>;
3049
3050 // Required for CALL which return f32 / f64 values.
3051 def : Pat<(X86fst RFP:$src, addr:$op, f32), (FpST32m addr:$op, RFP:$src)>;
3052 def : Pat<(X86fst RFP:$src, addr:$op, f64), (FpST64m addr:$op, RFP:$src)>;
3053
3054 // Floatin point constant -0.0 and -1.0
3055 def : Pat<(f64 fp64immneg0), (FpCHS (FpLD0))>, Requires<[FPStack]>;
3056 def : Pat<(f64 fp64immneg1), (FpCHS (FpLD1))>, Requires<[FPStack]>;
3057
3058 // RFP undef
3059 def : Pat<(f64 (undef)), (FpLD0)>,  Requires<[FPStack]>;
3060
3061
3062 //===----------------------------------------------------------------------===//
3063 // Some peepholes
3064 //===----------------------------------------------------------------------===//
3065
3066 // (shl x, 1) ==> (add x, x)
3067 def : Pat<(shl R8 :$src1, (i8 1)), (ADD8rr  R8 :$src1, R8 :$src1)>;
3068 def : Pat<(shl R16:$src1, (i8 1)), (ADD16rr R16:$src1, R16:$src1)>;
3069 def : Pat<(shl R32:$src1, (i8 1)), (ADD32rr R32:$src1, R32:$src1)>;
3070
3071 // (or (x >> c) | (y << (32 - c))) ==> (shrd x, y, c)
3072 def : Pat<(or (srl R32:$src1, CL:$amt),
3073               (shl R32:$src2, (sub 32, CL:$amt))),
3074           (SHRD32rrCL R32:$src1, R32:$src2)>;
3075
3076 // (or (x << c) | (y >> (32 - c))) ==> (shld x, y, c)
3077 def : Pat<(or (shl R32:$src1, CL:$amt),
3078               (srl R32:$src2, (sub 32, CL:$amt))),
3079           (SHLD32rrCL R32:$src1, R32:$src2)>;