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