A few helper fragments for loads. e.g. (i8 (load addr:$src)) -> (loadi8 addr:$src...
[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 // *mem - Operand definitions for the funky X86 addressing mode operands.
17 //
18 class X86MemOperand<ValueType Ty, string printMethod> : Operand<Ty> {
19   let PrintMethod = printMethod;
20   let NumMIOperands = 4;
21   let MIOperandInfo = (ops R32, i8imm, R32, i32imm);
22 }
23
24 def i8mem   : X86MemOperand<i32, "printi8mem">;
25 def i16mem  : X86MemOperand<i32, "printi16mem">;
26 def i32mem  : X86MemOperand<i32, "printi32mem">;
27 def i64mem  : X86MemOperand<i32, "printi64mem">;
28 def f32mem  : X86MemOperand<i32, "printf32mem">;
29 def f64mem  : X86MemOperand<i32, "printf64mem">;
30 def f80mem  : X86MemOperand<i32, "printf80mem">;
31
32 def SSECC : Operand<i8> {
33   let PrintMethod = "printSSECC";
34 }
35
36 // A couple of more descriptive operand definitions.
37 // 16-bits but only 8 bits are significant.
38 def i16i8imm  : Operand<i16>;
39 // 32-bits but only 8 bits are significant.
40 def i32i8imm  : Operand<i32>;
41
42 // PCRelative calls need special operand formatting.
43 let PrintMethod = "printCallOperand" in
44   def calltarget : Operand<i32>;
45
46 // Branch targets have OtherVT type.
47 def brtarget : Operand<OtherVT>;
48
49 // Define X86 specific addressing mode.
50 def addr    : ComplexPattern<i32, 4, "SelectAddr", []>;
51 def leaaddr : ComplexPattern<i32, 4, "SelectLEAAddr", [add]>;
52
53 // Format specifies the encoding used by the instruction.  This is part of the
54 // ad-hoc solution used to emit machine instruction encodings by our machine
55 // code emitter.
56 class Format<bits<5> val> {
57   bits<5> Value = val;
58 }
59
60 def Pseudo     : Format<0>; def RawFrm     : Format<1>;
61 def AddRegFrm  : Format<2>; def MRMDestReg : Format<3>;
62 def MRMDestMem : Format<4>; def MRMSrcReg  : Format<5>;
63 def MRMSrcMem  : Format<6>;
64 def MRM0r  : Format<16>; def MRM1r  : Format<17>; def MRM2r  : Format<18>;
65 def MRM3r  : Format<19>; def MRM4r  : Format<20>; def MRM5r  : Format<21>;
66 def MRM6r  : Format<22>; def MRM7r  : Format<23>;
67 def MRM0m  : Format<24>; def MRM1m  : Format<25>; def MRM2m  : Format<26>;
68 def MRM3m  : Format<27>; def MRM4m  : Format<28>; def MRM5m  : Format<29>;
69 def MRM6m  : Format<30>; def MRM7m  : Format<31>;
70
71 // ImmType - This specifies the immediate type used by an instruction. This is
72 // part of the ad-hoc solution used to emit machine instruction encodings by our
73 // machine code emitter.
74 class ImmType<bits<2> val> {
75   bits<2> Value = val;
76 }
77 def NoImm  : ImmType<0>;
78 def Imm8   : ImmType<1>;
79 def Imm16  : ImmType<2>;
80 def Imm32  : ImmType<3>;
81
82 // FPFormat - This specifies what form this FP instruction has.  This is used by
83 // the Floating-Point stackifier pass.
84 class FPFormat<bits<3> val> {
85   bits<3> Value = val;
86 }
87 def NotFP      : FPFormat<0>;
88 def ZeroArgFP  : FPFormat<1>;
89 def OneArgFP   : FPFormat<2>;
90 def OneArgFPRW : FPFormat<3>;
91 def TwoArgFP   : FPFormat<4>;
92 def CompareFP  : FPFormat<5>;
93 def CondMovFP  : FPFormat<6>;
94 def SpecialFP  : FPFormat<7>;
95
96
97 class X86Inst<bits<8> opcod, Format f, ImmType i, dag ops, string AsmStr>
98   : Instruction {
99   let Namespace = "X86";
100
101   bits<8> Opcode = opcod;
102   Format Form = f;
103   bits<5> FormBits = Form.Value;
104   ImmType ImmT = i;
105   bits<2> ImmTypeBits = ImmT.Value;
106
107   dag OperandList = ops;
108   string AsmString = AsmStr;
109
110   //
111   // Attributes specific to X86 instructions...
112   //
113   bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
114
115   bits<4> Prefix = 0;       // Which prefix byte does this inst have?
116   FPFormat FPForm;          // What flavor of FP instruction is this?
117   bits<3> FPFormBits = 0;
118 }
119
120 class Imp<list<Register> uses, list<Register> defs> {
121   list<Register> Uses = uses;
122   list<Register> Defs = defs;
123 }
124
125
126 // Prefix byte classes which are used to indicate to the ad-hoc machine code
127 // emitter that various prefix bytes are required.
128 class OpSize { bit hasOpSizePrefix = 1; }
129 class TB     { bits<4> Prefix = 1; }
130 class REP    { bits<4> Prefix = 2; }
131 class D8     { bits<4> Prefix = 3; }
132 class D9     { bits<4> Prefix = 4; }
133 class DA     { bits<4> Prefix = 5; }
134 class DB     { bits<4> Prefix = 6; }
135 class DC     { bits<4> Prefix = 7; }
136 class DD     { bits<4> Prefix = 8; }
137 class DE     { bits<4> Prefix = 9; }
138 class DF     { bits<4> Prefix = 10; }
139 class XD     { bits<4> Prefix = 11; }
140 class XS     { bits<4> Prefix = 12; }
141
142
143 //===----------------------------------------------------------------------===//
144 // Pattern fragments...
145 //
146 def i16immSExt8  : PatLeaf<(i16 imm), [{
147   // i16immSExt8 predicate - True if the 16-bit immediate fits in a 8-bit
148   // sign extended field.
149   return (int)N->getValue() == (signed char)N->getValue();
150 }]>;
151
152 def i32immSExt8  : PatLeaf<(i32 imm), [{
153   // i32immSExt8 predicate - True if the 32-bit immediate fits in a 8-bit
154   // sign extended field.
155   return (int)N->getValue() == (signed char)N->getValue();
156 }]>;
157
158 def i16immZExt8  : PatLeaf<(i16 imm), [{
159   // i16immZExt8 predicate - True if the 16-bit immediate fits in a 8-bit zero
160   // extended field.
161   return (unsigned)N->getValue() == (unsigned char)N->getValue();
162 }]>;
163
164 // Helper fragments for loads.
165 def loadi8   : PatFrag<(ops node:$in), (i8  (load node:$in))>;
166 def loadi16  : PatFrag<(ops node:$in), (i16 (load node:$in))>;
167 def loadi32  : PatFrag<(ops node:$in), (i32 (load node:$in))>;
168
169 //===----------------------------------------------------------------------===//
170 // Instruction templates...
171
172 class I<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
173   : X86Inst<o, f, NoImm, ops, asm> {
174   let Pattern = pattern;
175 }
176 class Ii8 <bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
177   : X86Inst<o, f, Imm8 , ops, asm> {
178   let Pattern = pattern;
179 }
180 class Ii16<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
181   : X86Inst<o, f, Imm16, ops, asm> {
182   let Pattern = pattern;
183 }
184 class Ii32<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
185   : X86Inst<o, f, Imm32, ops, asm> {
186   let Pattern = pattern;
187 }
188
189 //===----------------------------------------------------------------------===//
190 // Instruction list...
191 //
192
193 def PHI : I<0, Pseudo, (ops variable_ops), "PHINODE", []>;        // PHI node.
194 def NOOP : I<0x90, RawFrm, (ops), "nop", []>; // nop
195
196 def ADJCALLSTACKDOWN : I<0, Pseudo, (ops i32imm:$amt), "#ADJCALLSTACKDOWN", []>;
197 def ADJCALLSTACKUP   : I<0, Pseudo, (ops i32imm:$amt1, i32imm:$amt2),
198                          "#ADJCALLSTACKUP", []>;
199 def IMPLICIT_USE     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_USE", []>;
200 def IMPLICIT_DEF     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_DEF", []>;
201 let isTerminator = 1 in
202   let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
203     def FP_REG_KILL  : I<0, Pseudo, (ops), "#FP_REG_KILL", []>;
204
205 //===----------------------------------------------------------------------===//
206 //  Control Flow Instructions...
207 //
208
209 // Return instructions.
210 let isTerminator = 1, isReturn = 1, isBarrier = 1 in
211   def RET : I<0xC3, RawFrm, (ops), "ret", [(ret)]>;
212 let isTerminator = 1, isReturn = 1, isBarrier = 1 in
213   def RETI : Ii16<0xC2, RawFrm, (ops i16imm:$amt), "ret $amt", []>;
214
215 // All branches are RawFrm, Void, Branch, and Terminators
216 let isBranch = 1, isTerminator = 1 in
217   class IBr<bits<8> opcode, dag ops, string asm, list<dag> pattern> :
218         I<opcode, RawFrm, ops, asm, pattern>;
219
220 let isBarrier = 1 in
221   def JMP : IBr<0xE9, (ops brtarget:$dst), "jmp $dst", [(br bb:$dst)]>;
222 def JB  : IBr<0x82, (ops brtarget:$dst), "jb $dst",
223               []>, TB;
224 def JAE : IBr<0x83, (ops brtarget:$dst), "jae $dst", []>, TB;
225 def JE  : IBr<0x84, (ops brtarget:$dst), "je $dst", []>, TB;
226 def JNE : IBr<0x85, (ops brtarget:$dst), "jne $dst", []>, TB;
227 def JBE : IBr<0x86, (ops brtarget:$dst), "jbe $dst", []>, TB;
228 def JA  : IBr<0x87, (ops brtarget:$dst), "ja $dst", []>, TB;
229 def JS  : IBr<0x88, (ops brtarget:$dst), "js $dst", []>, TB;
230 def JNS : IBr<0x89, (ops brtarget:$dst), "jns $dst", []>, TB;
231 def JP  : IBr<0x8A, (ops brtarget:$dst), "jp $dst", []>, TB;
232 def JNP : IBr<0x8B, (ops brtarget:$dst), "jnp $dst", []>, TB;
233 def JL  : IBr<0x8C, (ops brtarget:$dst), "jl $dst", []>, TB;
234 def JGE : IBr<0x8D, (ops brtarget:$dst), "jge $dst", []>, TB;
235 def JLE : IBr<0x8E, (ops brtarget:$dst), "jle $dst", []>, TB;
236 def JG  : IBr<0x8F, (ops brtarget:$dst), "jg $dst", []>, TB;
237
238 //===----------------------------------------------------------------------===//
239 //  Call Instructions...
240 //
241 let isCall = 1 in
242   // All calls clobber the non-callee saved registers...
243   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
244               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7] in {
245     def CALLpcrel32 : I<0xE8, RawFrm, (ops calltarget:$dst), "call $dst", []>;
246     def CALL32r     : I<0xFF, MRM2r, (ops R32:$dst), "call {*}$dst", []>;
247     def CALL32m     : I<0xFF, MRM2m, (ops i32mem:$dst), "call {*}$dst", []>;
248   }
249
250 // Tail call stuff.
251 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
252   def TAILJMPd : IBr<0xE9, (ops calltarget:$dst), "jmp $dst  # TAIL CALL", []>;
253 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
254   def TAILJMPr : I<0xFF, MRM4r, (ops R32:$dst), "jmp {*}$dst  # TAIL CALL", []>;
255 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
256   def TAILJMPm : I<0xFF, MRM4m, (ops i32mem:$dst),
257                    "jmp {*}$dst  # TAIL CALL", []>;
258
259 // ADJSTACKPTRri - This is a standard ADD32ri instruction, identical in every
260 // way, except that it is marked as being a terminator.  This causes the epilog
261 // inserter to insert reloads of callee saved registers BEFORE this.  We need
262 // this until we have a more accurate way of tracking where the stack pointer is
263 // within a function.
264 let isTerminator = 1, isTwoAddress = 1 in
265   def ADJSTACKPTRri : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
266                            "add{l} {$src2, $dst|$dst, $src2}", []>;
267
268 //===----------------------------------------------------------------------===//
269 //  Miscellaneous Instructions...
270 //
271 def LEAVE    : I<0xC9, RawFrm,
272                  (ops), "leave", []>, Imp<[EBP,ESP],[EBP,ESP]>;
273 def POP32r   : I<0x58, AddRegFrm,
274                  (ops R32:$reg), "pop{l} $reg", []>, Imp<[ESP],[ESP]>;
275
276 let isTwoAddress = 1 in                               // R32 = bswap R32
277   def BSWAP32r : I<0xC8, AddRegFrm,
278                    (ops R32:$dst, R32:$src), "bswap{l} $dst", []>, TB;
279
280 def XCHG8rr  : I<0x86, MRMDestReg,                    // xchg R8, R8
281                  (ops R8:$src1, R8:$src2),
282                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
283 def XCHG16rr : I<0x87, MRMDestReg,                    // xchg R16, R16
284                  (ops R16:$src1, R16:$src2),
285                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
286 def XCHG32rr : I<0x87, MRMDestReg,                    // xchg R32, R32
287                  (ops R32:$src1, R32:$src2),
288                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
289
290 def XCHG8mr  : I<0x86, MRMDestMem,
291                  (ops i8mem:$src1, R8:$src2),
292                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
293 def XCHG16mr : I<0x87, MRMDestMem,
294                  (ops i16mem:$src1, R16:$src2),
295                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
296 def XCHG32mr : I<0x87, MRMDestMem,
297                  (ops i32mem:$src1, R32:$src2),
298                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
299 def XCHG8rm  : I<0x86, MRMSrcMem,
300                  (ops R8:$src1, i8mem:$src2),
301                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
302 def XCHG16rm : I<0x87, MRMSrcMem,
303                  (ops R16:$src1, i16mem:$src2),
304                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
305 def XCHG32rm : I<0x87, MRMSrcMem,
306                  (ops R32:$src1, i32mem:$src2),
307                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
308
309 def LEA16r   : I<0x8D, MRMSrcMem,
310                  (ops R16:$dst, i32mem:$src),
311                  "lea{w} {$src|$dst}, {$dst|$src}", []>, OpSize;
312 def LEA32r   : I<0x8D, MRMSrcMem,
313                  (ops R32:$dst, i32mem:$src),
314                  "lea{l} {$src|$dst}, {$dst|$src}",
315                  [(set R32:$dst, leaaddr:$src)]>;
316
317
318 def REP_MOVSB : I<0xA4, RawFrm, (ops), "{rep;movsb|rep movsb}", []>,
319                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
320 def REP_MOVSW : I<0xA5, RawFrm, (ops), "{rep;movsw|rep movsw}", []>,
321                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP, OpSize;
322 def REP_MOVSD : I<0xA5, RawFrm, (ops), "{rep;movsd|rep movsd}", []>,
323                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
324
325 def REP_STOSB : I<0xAA, RawFrm, (ops), "{rep;stosb|rep stosb}", []>,
326                 Imp<[AL,ECX,EDI], [ECX,EDI]>, REP;
327 def REP_STOSW : I<0xAB, RawFrm, (ops), "{rep;stosw|rep stosw}", []>,
328                 Imp<[AX,ECX,EDI], [ECX,EDI]>, REP, OpSize;
329 def REP_STOSD : I<0xAB, RawFrm, (ops), "{rep;stosl|rep stosd}", []>,
330                 Imp<[EAX,ECX,EDI], [ECX,EDI]>, REP;
331
332
333 //===----------------------------------------------------------------------===//
334 //  Input/Output Instructions...
335 //
336 def IN8rr  : I<0xEC, RawFrm, (ops),
337                "in{b} {%dx, %al|%AL, %DX}", []>,  Imp<[DX], [AL]>;
338 def IN16rr : I<0xED, RawFrm, (ops),
339                "in{w} {%dx, %ax|%AX, %DX}", []>,  Imp<[DX], [AX]>, OpSize;
340 def IN32rr : I<0xED, RawFrm, (ops),
341                "in{l} {%dx, %eax|%EAX, %DX}", []>, Imp<[DX],[EAX]>;
342
343 def IN8ri  : Ii8<0xE4, RawFrm, (ops i8imm:$port),
344                   "in{b} {$port, %al|%AL, $port}", []>,  Imp<[], [AL]>;
345 def IN16ri : Ii8<0xE5, RawFrm, (ops i8imm:$port),
346                   "in{w} {$port, %ax|%AX, $port}", []>,  Imp<[], [AX]>, OpSize;
347 def IN32ri : Ii8<0xE5, RawFrm, (ops i8imm:$port),
348                   "in{l} {$port, %eax|%EAX, $port}", []>, Imp<[],[EAX]>;
349
350 def OUT8rr  : I<0xEE, RawFrm, (ops),
351                 "out{b} {%al, %dx|%DX, %AL}",
352                 [(writeport AL, DX)]>,  Imp<[DX,  AL], []>;
353 def OUT16rr : I<0xEF, RawFrm, (ops),
354                 "out{w} {%ax, %dx|%DX, %AX}",
355                 [(writeport AX, DX)]>,  Imp<[DX,  AX], []>, OpSize;
356 def OUT32rr : I<0xEF, RawFrm, (ops),
357                 "out{l} {%eax, %dx|%DX, %EAX}",
358                 [(writeport EAX, DX)]>, Imp<[DX, EAX], []>;
359
360 def OUT8ir  : Ii8<0xE6, RawFrm, (ops i16i8imm:$port),
361                    "out{b} {%al, $port|$port, %AL}",
362                    [(writeport AL, i16immZExt8:$port)]>,
363                    Imp<[AL], []>;
364 def OUT16ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
365                    "out{w} {%ax, $port|$port, %AX}",
366                    [(writeport AX, i16immZExt8:$port)]>,
367                    Imp<[AX], []>, OpSize;
368 def OUT32ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
369                    "out{l} {%eax, $port|$port, %EAX}",
370                    [(writeport EAX, i16immZExt8:$port)]>,
371                    Imp<[EAX], []>;
372
373 //===----------------------------------------------------------------------===//
374 //  Move Instructions...
375 //
376 def MOV8rr  : I<0x88, MRMDestReg, (ops R8 :$dst, R8 :$src),
377                 "mov{b} {$src, $dst|$dst, $src}", []>;
378 def MOV16rr : I<0x89, MRMDestReg, (ops R16:$dst, R16:$src),
379                 "mov{w} {$src, $dst|$dst, $src}", []>, OpSize;
380 def MOV32rr : I<0x89, MRMDestReg, (ops R32:$dst, R32:$src),
381                 "mov{l} {$src, $dst|$dst, $src}", []>;
382 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (ops R8 :$dst, i8imm :$src),
383                    "mov{b} {$src, $dst|$dst, $src}",
384                    [(set R8:$dst, imm:$src)]>;
385 def MOV16ri : Ii16<0xB8, AddRegFrm, (ops R16:$dst, i16imm:$src),
386                    "mov{w} {$src, $dst|$dst, $src}",
387                    [(set R16:$dst, imm:$src)]>, OpSize;
388 def MOV32ri : Ii32<0xB8, AddRegFrm, (ops R32:$dst, i32imm:$src),
389                    "mov{l} {$src, $dst|$dst, $src}",
390                    [(set R32:$dst, imm:$src)]>;
391 def MOV8mi  : Ii8 <0xC6, MRM0m, (ops i8mem :$dst, i8imm :$src),
392                    "mov{b} {$src, $dst|$dst, $src}",
393                    [(store (i8 imm:$src), addr:$dst)]>;
394 def MOV16mi : Ii16<0xC7, MRM0m, (ops i16mem:$dst, i16imm:$src),
395                    "mov{w} {$src, $dst|$dst, $src}",
396                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
397 def MOV32mi : Ii32<0xC7, MRM0m, (ops i32mem:$dst, i32imm:$src),
398                    "mov{l} {$src, $dst|$dst, $src}",
399                    [(store (i32 imm:$src), addr:$dst)]>;
400
401 def MOV8rm  : I<0x8A, MRMSrcMem, (ops R8 :$dst, i8mem :$src),
402                 "mov{b} {$src, $dst|$dst, $src}",
403                 [(set R8:$dst, (load addr:$src))]>;
404 def MOV16rm : I<0x8B, MRMSrcMem, (ops R16:$dst, i16mem:$src),
405                 "mov{w} {$src, $dst|$dst, $src}",
406                 [(set R16:$dst, (load addr:$src))]>, OpSize;
407 def MOV32rm : I<0x8B, MRMSrcMem, (ops R32:$dst, i32mem:$src),
408                 "mov{l} {$src, $dst|$dst, $src}",
409                 [(set R32:$dst, (load addr:$src))]>;
410
411 def MOV8mr  : I<0x88, MRMDestMem, (ops i8mem :$dst, R8 :$src),
412                 "mov{b} {$src, $dst|$dst, $src}",
413                 [(store R8:$src, addr:$dst)]>;
414 def MOV16mr : I<0x89, MRMDestMem, (ops i16mem:$dst, R16:$src),
415                 "mov{w} {$src, $dst|$dst, $src}",
416                 [(store R16:$src, addr:$dst)]>, OpSize;
417 def MOV32mr : I<0x89, MRMDestMem, (ops i32mem:$dst, R32:$src),
418                 "mov{l} {$src, $dst|$dst, $src}",
419                 [(store R32:$src, addr:$dst)]>;
420                 
421 //===----------------------------------------------------------------------===//
422 //  Fixed-Register Multiplication and Division Instructions...
423 //
424
425 // Extra precision multiplication
426 def MUL8r  : I<0xF6, MRM4r, (ops R8:$src), "mul{b} $src", []>,
427              Imp<[AL],[AX]>;               // AL,AH = AL*R8
428 def MUL16r : I<0xF7, MRM4r, (ops R16:$src), "mul{w} $src", []>,
429              Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
430 def MUL32r : I<0xF7, MRM4r, (ops R32:$src), "mul{l} $src", []>,
431              Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
432 def MUL8m  : I<0xF6, MRM4m, (ops i8mem :$src),
433                "mul{b} $src", []>, Imp<[AL],[AX]>;          // AL,AH = AL*[mem8]
434 def MUL16m : I<0xF7, MRM4m, (ops i16mem:$src),
435                "mul{w} $src", []>, Imp<[AX],[AX,DX]>,
436                OpSize; // AX,DX = AX*[mem16]
437 def MUL32m : I<0xF7, MRM4m, (ops i32mem:$src),
438                "mul{l} $src", []>, Imp<[EAX],[EAX,EDX]>;// EAX,EDX = EAX*[mem32]
439
440 def IMUL8r  : I<0xF6, MRM5r, (ops R8:$src), "imul{b} $src", []>,
441               Imp<[AL],[AX]>;               // AL,AH = AL*R8
442 def IMUL16r : I<0xF7, MRM5r, (ops R16:$src), "imul{w} $src", []>,
443               Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
444 def IMUL32r : I<0xF7, MRM5r, (ops R32:$src), "imul{l} $src", []>,
445               Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
446 def IMUL8m  : I<0xF6, MRM5m, (ops i8mem :$src),
447                 "imul{b} $src", []>, Imp<[AL],[AX]>;        // AL,AH = AL*[mem8]
448 def IMUL16m : I<0xF7, MRM5m, (ops i16mem:$src),
449                 "imul{w} $src", []>, Imp<[AX],[AX,DX]>,
450                 OpSize; // AX,DX = AX*[mem16]
451 def IMUL32m : I<0xF7, MRM5m, (ops i32mem:$src),
452                 "imul{l} $src", []>,
453                 Imp<[EAX],[EAX,EDX]>;  // EAX,EDX = EAX*[mem32]
454
455 // unsigned division/remainder
456 def DIV8r  : I<0xF6, MRM6r, (ops R8:$src),          // AX/r8 = AL,AH
457                "div{b} $src", []>, Imp<[AX],[AX]>;
458 def DIV16r : I<0xF7, MRM6r, (ops R16:$src),         // DX:AX/r16 = AX,DX
459                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
460 def DIV32r : I<0xF7, MRM6r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
461                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
462 def DIV8m  : I<0xF6, MRM6m, (ops i8mem:$src),       // AX/[mem8] = AL,AH
463                "div{b} $src", []>, Imp<[AX],[AX]>;
464 def DIV16m : I<0xF7, MRM6m, (ops i16mem:$src),      // DX:AX/[mem16] = AX,DX
465                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
466 def DIV32m : I<0xF7, MRM6m, (ops i32mem:$src),      // EDX:EAX/[mem32] = EAX,EDX
467                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
468
469 // Signed division/remainder.
470 def IDIV8r : I<0xF6, MRM7r, (ops R8:$src),          // AX/r8 = AL,AH
471                "idiv{b} $src", []>, Imp<[AX],[AX]>;
472 def IDIV16r: I<0xF7, MRM7r, (ops R16:$src),         // DX:AX/r16 = AX,DX
473                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
474 def IDIV32r: I<0xF7, MRM7r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
475                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
476 def IDIV8m : I<0xF6, MRM7m, (ops i8mem:$src),      // AX/[mem8] = AL,AH
477                "idiv{b} $src", []>, Imp<[AX],[AX]>;
478 def IDIV16m: I<0xF7, MRM7m, (ops i16mem:$src),     // DX:AX/[mem16] = AX,DX
479                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
480 def IDIV32m: I<0xF7, MRM7m, (ops i32mem:$src),     // EDX:EAX/[mem32] = EAX,EDX
481                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
482
483 // Sign-extenders for division.
484 def CBW : I<0x98, RawFrm, (ops),
485             "{cbtw|cbw}", []>, Imp<[AL],[AH]>;   // AX = signext(AL)
486 def CWD : I<0x99, RawFrm, (ops),
487             "{cwtd|cwd}", []>, Imp<[AX],[DX]>;   // DX:AX = signext(AX)
488 def CDQ : I<0x99, RawFrm, (ops),
489             "{cltd|cdq}", []>, Imp<[EAX],[EDX]>; // EDX:EAX = signext(EAX)
490           
491
492 //===----------------------------------------------------------------------===//
493 //  Two address Instructions...
494 //
495 let isTwoAddress = 1 in {
496
497 // Conditional moves
498 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, R16 = R16
499                   (ops R16:$dst, R16:$src1, R16:$src2),
500                   "cmovb {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
501 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, R16 = [mem16]
502                   (ops R16:$dst, R16:$src1, i16mem:$src2),
503                   "cmovb {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
504 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, R32 = R32
505                   (ops R32:$dst, R32:$src1, R32:$src2),
506                   "cmovb {$src2, $dst|$dst, $src2}", []>, TB;
507 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, R32 = [mem32]
508                   (ops R32:$dst, R32:$src1, i32mem:$src2),
509                   "cmovb {$src2, $dst|$dst, $src2}", []>, TB;
510
511 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, R16 = R16
512                   (ops R16:$dst, R16:$src1, R16:$src2),
513                   "cmovae {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
514 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, R16 = [mem16]
515                   (ops R16:$dst, R16:$src1, i16mem:$src2),
516                   "cmovae {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
517 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, R32 = R32
518                   (ops R32:$dst, R32:$src1, R32:$src2),
519                   "cmovae {$src2, $dst|$dst, $src2}", []>, TB;
520 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, R32 = [mem32]
521                   (ops R32:$dst, R32:$src1, i32mem:$src2),
522                   "cmovae {$src2, $dst|$dst, $src2}", []>, TB;
523
524 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, R16 = R16
525                   (ops R16:$dst, R16:$src1, R16:$src2),
526                   "cmove {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
527 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, R16 = [mem16]
528                   (ops R16:$dst, R16:$src1, i16mem:$src2),
529                   "cmove {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
530 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, R32 = R32
531                   (ops R32:$dst, R32:$src1, R32:$src2),
532                   "cmove {$src2, $dst|$dst, $src2}", []>, TB;
533 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, R32 = [mem32]
534                   (ops R32:$dst, R32:$src1, i32mem:$src2),
535                   "cmove {$src2, $dst|$dst, $src2}", []>, TB;
536
537 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, R16 = R16
538                   (ops R16:$dst, R16:$src1, R16:$src2),
539                   "cmovne {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
540 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, R16 = [mem16]
541                   (ops R16:$dst, R16:$src1, i16mem:$src2),
542                   "cmovne {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
543 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, R32 = R32
544                   (ops R32:$dst, R32:$src1, R32:$src2),
545                   "cmovne {$src2, $dst|$dst, $src2}", []>, TB;
546 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, R32 = [mem32]
547                   (ops R32:$dst, R32:$src1, i32mem:$src2),
548                   "cmovne {$src2, $dst|$dst, $src2}", []>, TB;
549
550 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, R16 = R16
551                   (ops R16:$dst, R16:$src1, R16:$src2),
552                   "cmovbe {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
553 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, R16 = [mem16]
554                   (ops R16:$dst, R16:$src1, i16mem:$src2),
555                   "cmovbe {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
556 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, R32 = R32
557                   (ops R32:$dst, R32:$src1, R32:$src2),
558                   "cmovbe {$src2, $dst|$dst, $src2}", []>, TB;
559 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, R32 = [mem32]
560                   (ops R32:$dst, R32:$src1, i32mem:$src2),
561                   "cmovbe {$src2, $dst|$dst, $src2}", []>, TB;
562
563 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, R16 = R16
564                   (ops R16:$dst, R16:$src1, R16:$src2),
565                   "cmova {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
566 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, R16 = [mem16]
567                   (ops R16:$dst, R16:$src1, i16mem:$src2),
568                   "cmova {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
569 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, R32 = R32
570                   (ops R32:$dst, R32:$src1, R32:$src2),
571                   "cmova {$src2, $dst|$dst, $src2}", []>, TB;
572 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, R32 = [mem32]
573                   (ops R32:$dst, R32:$src1, i32mem:$src2),
574                   "cmova {$src2, $dst|$dst, $src2}", []>, TB;
575
576 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, R16 = R16
577                   (ops R16:$dst, R16:$src1, R16:$src2),
578                   "cmovs {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
579 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, R16 = [mem16]
580                   (ops R16:$dst, R16:$src1, i16mem:$src2),
581                   "cmovs {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
582 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, R32 = R32
583                   (ops R32:$dst, R32:$src1, R32:$src2),
584                   "cmovs {$src2, $dst|$dst, $src2}", []>, TB;
585 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, R32 = [mem32]
586                   (ops R32:$dst, R32:$src1, i32mem:$src2),
587                   "cmovs {$src2, $dst|$dst, $src2}", []>, TB;
588
589 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, R16 = R16
590                   (ops R16:$dst, R16:$src1, R16:$src2),
591                   "cmovns {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
592 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, R16 = [mem16]
593                   (ops R16:$dst, R16:$src1, i16mem:$src2),
594                   "cmovns {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
595 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, R32 = R32
596                   (ops R32:$dst, R32:$src1, R32:$src2),
597                   "cmovns {$src2, $dst|$dst, $src2}", []>, TB;
598 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, R32 = [mem32]
599                   (ops R32:$dst, R32:$src1, i32mem:$src2),
600                   "cmovns {$src2, $dst|$dst, $src2}", []>, TB;
601
602 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, R16 = R16
603                   (ops R16:$dst, R16:$src1, R16:$src2),
604                   "cmovp {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
605 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, R16 = [mem16]
606                   (ops R16:$dst, R16:$src1, i16mem:$src2),
607                   "cmovp {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
608 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, R32 = R32
609                   (ops R32:$dst, R32:$src1, R32:$src2),
610                   "cmovp {$src2, $dst|$dst, $src2}", []>, TB;
611 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, R32 = [mem32]
612                   (ops R32:$dst, R32:$src1, i32mem:$src2),
613                   "cmovp {$src2, $dst|$dst, $src2}", []>, TB;
614
615  
616 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, R16 = R16
617                   (ops R16:$dst, R16:$src1, R16:$src2),
618                   "cmovnp {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
619 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, R16 = [mem16]
620                   (ops R16:$dst, R16:$src1, i16mem:$src2),
621                   "cmovnp {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
622 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, R32 = R32
623                   (ops R32:$dst, R32:$src1, R32:$src2),
624                   "cmovnp {$src2, $dst|$dst, $src2}", []>, TB;
625 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, R32 = [mem32]
626                   (ops R32:$dst, R32:$src1, i32mem:$src2),
627                   "cmovnp {$src2, $dst|$dst, $src2}", []>, TB;
628
629
630 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, R16 = R16
631                   (ops R16:$dst, R16:$src1, R16:$src2),
632                   "cmovl {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
633 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, R16 = [mem16]
634                   (ops R16:$dst, R16:$src1, i16mem:$src2),
635                   "cmovl {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
636 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, R32 = R32
637                   (ops R32:$dst, R32:$src1, R32:$src2),
638                   "cmovl {$src2, $dst|$dst, $src2}", []>, TB;
639 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, R32 = [mem32]
640                   (ops R32:$dst, R32:$src1, i32mem:$src2),
641                   "cmovl {$src2, $dst|$dst, $src2}", []>, TB;
642
643 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, R16 = R16
644                   (ops R16:$dst, R16:$src1, R16:$src2),
645                   "cmovge {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
646 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, R16 = [mem16]
647                   (ops R16:$dst, R16:$src1, i16mem:$src2),
648                   "cmovge {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
649 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, R32 = R32
650                   (ops R32:$dst, R32:$src1, R32:$src2),
651                   "cmovge {$src2, $dst|$dst, $src2}", []>, TB;
652 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, R32 = [mem32]
653                   (ops R32:$dst, R32:$src1, i32mem:$src2),
654                   "cmovge {$src2, $dst|$dst, $src2}", []>, TB;
655
656 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, R16 = R16
657                   (ops R16:$dst, R16:$src1, R16:$src2),
658                   "cmovle {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
659 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, R16 = [mem16]
660                   (ops R16:$dst, R16:$src1, i16mem:$src2),
661                   "cmovle {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
662 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, R32 = R32
663                   (ops R32:$dst, R32:$src1, R32:$src2),
664                   "cmovle {$src2, $dst|$dst, $src2}", []>, TB;
665 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, R32 = [mem32]
666                   (ops R32:$dst, R32:$src1, i32mem:$src2),
667                   "cmovle {$src2, $dst|$dst, $src2}", []>, TB;
668
669 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, R16 = R16
670                   (ops R16:$dst, R16:$src1, R16:$src2),
671                   "cmovg {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
672 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, R16 = [mem16]
673                   (ops R16:$dst, R16:$src1, i16mem:$src2),
674                   "cmovg {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
675 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, R32 = R32
676                   (ops R32:$dst, R32:$src1, R32:$src2),
677                   "cmovg {$src2, $dst|$dst, $src2}", []>, TB;
678 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, R32 = [mem32]
679                   (ops R32:$dst, R32:$src1, i32mem:$src2),
680                   "cmovg {$src2, $dst|$dst, $src2}", []>, TB;
681
682 // unary instructions
683 def NEG8r  : I<0xF6, MRM3r, (ops R8 :$dst, R8 :$src), "neg{b} $dst",
684                [(set R8:$dst, (ineg R8:$src))]>;
685 def NEG16r : I<0xF7, MRM3r, (ops R16:$dst, R16:$src), "neg{w} $dst",
686                [(set R16:$dst, (ineg R16:$src))]>, OpSize;
687 def NEG32r : I<0xF7, MRM3r, (ops R32:$dst, R32:$src), "neg{l} $dst",
688                [(set R32:$dst, (ineg R32:$src))]>;
689 let isTwoAddress = 0 in {
690   def NEG8m  : I<0xF6, MRM3m, (ops i8mem :$dst), "neg{b} $dst",
691                  [(store (ineg (loadi8 addr:$dst)), addr:$dst)]>;
692   def NEG16m : I<0xF7, MRM3m, (ops i16mem:$dst), "neg{w} $dst",
693                  [(store (ineg (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
694   def NEG32m : I<0xF7, MRM3m, (ops i32mem:$dst), "neg{l} $dst",
695                  [(store (ineg (loadi32 addr:$dst)), addr:$dst)]>;
696
697 }
698
699 def NOT8r  : I<0xF6, MRM2r, (ops R8 :$dst, R8 :$src), "not{b} $dst",
700                [(set R8:$dst, (not R8:$src))]>;
701 def NOT16r : I<0xF7, MRM2r, (ops R16:$dst, R16:$src), "not{w} $dst",
702                [(set R16:$dst, (not R16:$src))]>, OpSize;
703 def NOT32r : I<0xF7, MRM2r, (ops R32:$dst, R32:$src), "not{l} $dst",
704                [(set R32:$dst, (not R32:$src))]>;
705 let isTwoAddress = 0 in {
706   def NOT8m  : I<0xF6, MRM2m, (ops i8mem :$dst), "not{b} $dst",
707                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
708   def NOT16m : I<0xF7, MRM2m, (ops i16mem:$dst), "not{w} $dst",
709                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
710   def NOT32m : I<0xF7, MRM2m, (ops i32mem:$dst), "not{l} $dst",
711                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
712 }
713
714 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
715 def INC8r  : I<0xFE, MRM0r, (ops R8 :$dst, R8 :$src), "inc{b} $dst",
716                [(set R8:$dst, (add R8:$src, 1))]>;
717 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
718 def INC16r : I<0xFF, MRM0r, (ops R16:$dst, R16:$src), "inc{w} $dst",
719                [(set R16:$dst, (add R16:$src, 1))]>, OpSize;
720 def INC32r : I<0xFF, MRM0r, (ops R32:$dst, R32:$src), "inc{l} $dst",
721                [(set R32:$dst, (add R32:$src, 1))]>;
722 }
723 let isTwoAddress = 0 in {
724   def INC8m  : I<0xFE, MRM0m, (ops i8mem :$dst), "inc{b} $dst",
725                [(store (add (loadi8 addr:$dst), 1), addr:$dst)]>;
726   def INC16m : I<0xFF, MRM0m, (ops i16mem:$dst), "inc{w} $dst",
727                [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>, OpSize;
728   def INC32m : I<0xFF, MRM0m, (ops i32mem:$dst), "inc{l} $dst",
729                [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>;
730 }
731
732 def DEC8r  : I<0xFE, MRM1r, (ops R8 :$dst, R8 :$src), "dec{b} $dst",
733                [(set R8:$dst, (add R8:$src, -1))]>;
734 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
735 def DEC16r : I<0xFF, MRM1r, (ops R16:$dst, R16:$src), "dec{w} $dst",
736                [(set R16:$dst, (add R16:$src, -1))]>, OpSize;
737 def DEC32r : I<0xFF, MRM1r, (ops R32:$dst, R32:$src), "dec{l} $dst",
738                [(set R32:$dst, (add R32:$src, -1))]>;
739 }
740
741 let isTwoAddress = 0 in {
742   def DEC8m  : I<0xFE, MRM1m, (ops i8mem :$dst), "dec{b} $dst",
743                [(store (add (loadi8 addr:$dst), -1), addr:$dst)]>;
744   def DEC16m : I<0xFF, MRM1m, (ops i16mem:$dst), "dec{w} $dst",
745                [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>, OpSize;
746   def DEC32m : I<0xFF, MRM1m, (ops i32mem:$dst), "dec{l} $dst",
747                [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>;
748 }
749
750 // Logical operators...
751 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
752 def AND8rr   : I<0x20, MRMDestReg,
753                 (ops R8 :$dst, R8 :$src1, R8 :$src2),
754                 "and{b} {$src2, $dst|$dst, $src2}",
755                 [(set R8:$dst, (and R8:$src1, R8:$src2))]>;
756 def AND16rr  : I<0x21, MRMDestReg,
757                  (ops R16:$dst, R16:$src1, R16:$src2),
758                  "and{w} {$src2, $dst|$dst, $src2}",
759                  [(set R16:$dst, (and R16:$src1, R16:$src2))]>, OpSize;
760 def AND32rr  : I<0x21, MRMDestReg, 
761                  (ops R32:$dst, R32:$src1, R32:$src2),
762                  "and{l} {$src2, $dst|$dst, $src2}",
763                  [(set R32:$dst, (and R32:$src1, R32:$src2))]>;
764 }
765
766 def AND8rm   : I<0x22, MRMSrcMem, 
767                  (ops R8 :$dst, R8 :$src1, i8mem :$src2),
768                  "and{b} {$src2, $dst|$dst, $src2}",
769                 [(set R8:$dst, (and R8:$src1, (load addr:$src2)))]>;
770 def AND16rm  : I<0x23, MRMSrcMem, 
771                  (ops R16:$dst, R16:$src1, i16mem:$src2),
772                  "and{w} {$src2, $dst|$dst, $src2}",
773                 [(set R16:$dst, (and R16:$src1, (load addr:$src2)))]>, OpSize;
774 def AND32rm  : I<0x23, MRMSrcMem,
775                  (ops R32:$dst, R32:$src1, i32mem:$src2),
776                  "and{l} {$src2, $dst|$dst, $src2}",
777                 [(set R32:$dst, (and R32:$src1, (load addr:$src2)))]>;
778
779 def AND8ri   : Ii8<0x80, MRM4r, 
780                    (ops R8 :$dst, R8 :$src1, i8imm :$src2),
781                    "and{b} {$src2, $dst|$dst, $src2}",
782                    [(set R8:$dst, (and R8:$src1, imm:$src2))]>;
783 def AND16ri  : Ii16<0x81, MRM4r, 
784                     (ops R16:$dst, R16:$src1, i16imm:$src2),
785                     "and{w} {$src2, $dst|$dst, $src2}",
786                     [(set R16:$dst, (and R16:$src1, imm:$src2))]>, OpSize;
787 def AND32ri  : Ii32<0x81, MRM4r, 
788                     (ops R32:$dst, R32:$src1, i32imm:$src2),
789                     "and{l} {$src2, $dst|$dst, $src2}",
790                     [(set R32:$dst, (and R32:$src1, imm:$src2))]>;
791 def AND16ri8 : Ii8<0x83, MRM4r, 
792                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
793                    "and{w} {$src2, $dst|$dst, $src2}",
794                    [(set R16:$dst, (and R16:$src1, i16immSExt8:$src2))]>,
795                    OpSize;
796 def AND32ri8 : Ii8<0x83, MRM4r, 
797                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
798                    "and{l} {$src2, $dst|$dst, $src2}",
799                    [(set R32:$dst, (and R32:$src1, i32immSExt8:$src2))]>;
800
801 let isTwoAddress = 0 in {
802   def AND8mr   : I<0x20, MRMDestMem,
803                    (ops i8mem :$dst, R8 :$src),
804                    "and{b} {$src, $dst|$dst, $src}",
805                    [(store (and (load addr:$dst), R8:$src), addr:$dst)]>;
806   def AND16mr  : I<0x21, MRMDestMem,
807                    (ops i16mem:$dst, R16:$src),
808                    "and{w} {$src, $dst|$dst, $src}",
809                    [(store (and (load addr:$dst), R16:$src), addr:$dst)]>,
810                    OpSize;
811   def AND32mr  : I<0x21, MRMDestMem,
812                    (ops i32mem:$dst, R32:$src),
813                    "and{l} {$src, $dst|$dst, $src}",
814                    [(store (and (load addr:$dst), R32:$src), addr:$dst)]>;
815   def AND8mi   : Ii8<0x80, MRM4m,
816                      (ops i8mem :$dst, i8imm :$src),
817                      "and{b} {$src, $dst|$dst, $src}",
818                    [(store (and (load addr:$dst), (i8 imm:$src)), addr:$dst)]>;
819   def AND16mi  : Ii16<0x81, MRM4m,
820                       (ops i16mem:$dst, i16imm:$src),
821                       "and{w} {$src, $dst|$dst, $src}",
822                   [(store (and (load addr:$dst), (i16 imm:$src)), addr:$dst)]>,
823                       OpSize;
824   def AND32mi  : Ii32<0x81, MRM4m,
825                       (ops i32mem:$dst, i32imm:$src),
826                       "and{l} {$src, $dst|$dst, $src}",
827                   [(store (and (load addr:$dst), (i32 imm:$src)), addr:$dst)]>;
828   def AND16mi8 : Ii8<0x83, MRM4m,
829                      (ops i16mem:$dst, i16i8imm :$src),
830                      "and{w} {$src, $dst|$dst, $src}",
831                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
832                      OpSize;
833   def AND32mi8 : Ii8<0x83, MRM4m,
834                      (ops i32mem:$dst, i32i8imm :$src),
835                      "and{l} {$src, $dst|$dst, $src}",
836                 [(store (add (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
837 }
838
839
840 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
841 def OR8rr    : I<0x08, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
842                  "or{b} {$src2, $dst|$dst, $src2}",
843                  [(set R8:$dst, (or R8:$src1, R8:$src2))]>;
844 def OR16rr   : I<0x09, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
845                  "or{w} {$src2, $dst|$dst, $src2}",
846                  [(set R16:$dst, (or R16:$src1, R16:$src2))]>, OpSize;
847 def OR32rr   : I<0x09, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
848                  "or{l} {$src2, $dst|$dst, $src2}",
849                  [(set R32:$dst, (or R32:$src1, R32:$src2))]>;
850 }
851 def OR8rm    : I<0x0A, MRMSrcMem , (ops R8 :$dst, R8 :$src1, i8mem :$src2),
852                  "or{b} {$src2, $dst|$dst, $src2}",
853                 [(set R8:$dst, (or R8:$src1, (load addr:$src2)))]>;
854 def OR16rm   : I<0x0B, MRMSrcMem , (ops R16:$dst, R16:$src1, i16mem:$src2),
855                  "or{w} {$src2, $dst|$dst, $src2}",
856                 [(set R16:$dst, (or R16:$src1, (load addr:$src2)))]>, OpSize;
857 def OR32rm   : I<0x0B, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
858                  "or{l} {$src2, $dst|$dst, $src2}",
859                 [(set R32:$dst, (or R32:$src1, (load addr:$src2)))]>;
860
861 def OR8ri    : Ii8 <0x80, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
862                     "or{b} {$src2, $dst|$dst, $src2}",
863                     [(set R8:$dst, (or R8:$src1, imm:$src2))]>;
864 def OR16ri   : Ii16<0x81, MRM1r, (ops R16:$dst, R16:$src1, i16imm:$src2),
865                     "or{w} {$src2, $dst|$dst, $src2}", 
866                     [(set R16:$dst, (or R16:$src1, imm:$src2))]>, OpSize;
867 def OR32ri   : Ii32<0x81, MRM1r, (ops R32:$dst, R32:$src1, i32imm:$src2),
868                     "or{l} {$src2, $dst|$dst, $src2}",
869                     [(set R32:$dst, (or R32:$src1, imm:$src2))]>;
870
871 def OR16ri8  : Ii8<0x83, MRM1r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
872                    "or{w} {$src2, $dst|$dst, $src2}",
873                    [(set R16:$dst, (or R16:$src1, i16immSExt8:$src2))]>, OpSize;
874 def OR32ri8  : Ii8<0x83, MRM1r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
875                    "or{l} {$src2, $dst|$dst, $src2}",
876                    [(set R32:$dst, (or R32:$src1, i32immSExt8:$src2))]>;
877 let isTwoAddress = 0 in {
878   def OR8mr  : I<0x08, MRMDestMem, (ops i8mem:$dst, R8:$src),
879                  "or{b} {$src, $dst|$dst, $src}",
880                  [(store (or (load addr:$dst), R8:$src), addr:$dst)]>;
881   def OR16mr : I<0x09, MRMDestMem, (ops i16mem:$dst, R16:$src),
882                  "or{w} {$src, $dst|$dst, $src}",
883                  [(store (or (load addr:$dst), R16:$src), addr:$dst)]>, OpSize;
884   def OR32mr : I<0x09, MRMDestMem, (ops i32mem:$dst, R32:$src),
885                  "or{l} {$src, $dst|$dst, $src}",
886                  [(store (or (load addr:$dst), R32:$src), addr:$dst)]>;
887   def OR8mi    : Ii8<0x80, MRM1m, (ops i8mem :$dst, i8imm:$src),
888                  "or{b} {$src, $dst|$dst, $src}",
889                  [(store (or (load addr:$dst), (i8 imm:$src)), addr:$dst)]>;
890   def OR16mi   : Ii16<0x81, MRM1m, (ops i16mem:$dst, i16imm:$src),
891                  "or{w} {$src, $dst|$dst, $src}",
892                  [(store (or (load addr:$dst), (i16 imm:$src)), addr:$dst)]>,
893                  OpSize;
894   def OR32mi   : Ii32<0x81, MRM1m, (ops i32mem:$dst, i32imm:$src),
895                  "or{l} {$src, $dst|$dst, $src}",
896                  [(store (or (load addr:$dst), (i32 imm:$src)), addr:$dst)]>;
897   def OR16mi8  : Ii8<0x83, MRM1m, (ops i16mem:$dst, i16i8imm:$src),
898                  "or{w} {$src, $dst|$dst, $src}",
899                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
900                      OpSize;
901   def OR32mi8  : Ii8<0x83, MRM1m, (ops i32mem:$dst, i32i8imm:$src),
902                  "or{l} {$src, $dst|$dst, $src}",
903                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
904 }
905
906
907 let isCommutable = 1 in {   // X = XOR Y, Z   --> X = XOR Z, Y
908 def XOR8rr   : I<0x30, MRMDestReg,
909                  (ops R8 :$dst, R8 :$src1, R8 :$src2),
910                  "xor{b} {$src2, $dst|$dst, $src2}",
911                  [(set R8:$dst, (xor R8:$src1, R8:$src2))]>;
912 def XOR16rr  : I<0x31, MRMDestReg, 
913                  (ops R16:$dst, R16:$src1, R16:$src2), 
914                  "xor{w} {$src2, $dst|$dst, $src2}",
915                  [(set R16:$dst, (xor R16:$src1, R16:$src2))]>, OpSize;
916 def XOR32rr  : I<0x31, MRMDestReg, 
917                  (ops R32:$dst, R32:$src1, R32:$src2), 
918                  "xor{l} {$src2, $dst|$dst, $src2}",
919                  [(set R32:$dst, (xor R32:$src1, R32:$src2))]>;
920 }
921
922 def XOR8rm   : I<0x32, MRMSrcMem , 
923                  (ops R8 :$dst, R8:$src1, i8mem :$src2), 
924                  "xor{b} {$src2, $dst|$dst, $src2}",
925                  [(set R8:$dst, (xor R8:$src1, (load addr:$src2)))]>;
926 def XOR16rm  : I<0x33, MRMSrcMem , 
927                  (ops R16:$dst, R16:$src1, i16mem:$src2), 
928                  "xor{w} {$src2, $dst|$dst, $src2}",
929                  [(set R16:$dst, (xor R16:$src1, (load addr:$src2)))]>, OpSize;
930 def XOR32rm  : I<0x33, MRMSrcMem , 
931                  (ops R32:$dst, R32:$src1, i32mem:$src2), 
932                  "xor{l} {$src2, $dst|$dst, $src2}",
933                  [(set R32:$dst, (xor R32:$src1, (load addr:$src2)))]>;
934
935 def XOR8ri   : Ii8<0x80, MRM6r, 
936                    (ops R8:$dst, R8:$src1, i8imm:$src2), 
937                    "xor{b} {$src2, $dst|$dst, $src2}",
938                    [(set R8:$dst, (xor R8:$src1, imm:$src2))]>;
939 def XOR16ri  : Ii16<0x81, MRM6r, 
940                     (ops R16:$dst, R16:$src1, i16imm:$src2), 
941                     "xor{w} {$src2, $dst|$dst, $src2}",
942                     [(set R16:$dst, (xor R16:$src1, imm:$src2))]>, OpSize;
943 def XOR32ri  : Ii32<0x81, MRM6r, 
944                     (ops R32:$dst, R32:$src1, i32imm:$src2), 
945                     "xor{l} {$src2, $dst|$dst, $src2}",
946                     [(set R32:$dst, (xor R32:$src1, imm:$src2))]>;
947 def XOR16ri8 : Ii8<0x83, MRM6r, 
948                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
949                    "xor{w} {$src2, $dst|$dst, $src2}",
950                    [(set R16:$dst, (xor R16:$src1, i16immSExt8:$src2))]>,
951                    OpSize;
952 def XOR32ri8 : Ii8<0x83, MRM6r, 
953                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
954                    "xor{l} {$src2, $dst|$dst, $src2}",
955                    [(set R32:$dst, (xor R32:$src1, i32immSExt8:$src2))]>;
956 let isTwoAddress = 0 in {
957   def XOR8mr   : I<0x30, MRMDestMem,
958                    (ops i8mem :$dst, R8 :$src),
959                    "xor{b} {$src, $dst|$dst, $src}",
960                    [(store (xor (load addr:$dst), R8:$src), addr:$dst)]>;
961   def XOR16mr  : I<0x31, MRMDestMem,
962                    (ops i16mem:$dst, R16:$src),
963                    "xor{w} {$src, $dst|$dst, $src}",
964                    [(store (xor (load addr:$dst), R16:$src), addr:$dst)]>,
965                    OpSize;
966   def XOR32mr  : I<0x31, MRMDestMem,
967                    (ops i32mem:$dst, R32:$src),
968                    "xor{l} {$src, $dst|$dst, $src}",
969                    [(store (xor (load addr:$dst), R32:$src), addr:$dst)]>;
970   def XOR8mi   : Ii8<0x80, MRM6m,
971                      (ops i8mem :$dst, i8imm :$src),
972                      "xor{b} {$src, $dst|$dst, $src}",
973                     [(store (xor (load addr:$dst), (i8 imm:$src)), addr:$dst)]>;
974   def XOR16mi  : Ii16<0x81, MRM6m,
975                       (ops i16mem:$dst, i16imm:$src),
976                       "xor{w} {$src, $dst|$dst, $src}",
977                    [(store (xor (load addr:$dst), (i16 imm:$src)), addr:$dst)]>,
978                       OpSize;
979   def XOR32mi  : Ii32<0x81, MRM6m,
980                       (ops i32mem:$dst, i32imm:$src),
981                       "xor{l} {$src, $dst|$dst, $src}",
982                    [(store (xor (load addr:$dst), (i32 imm:$src)), addr:$dst)]>;
983   def XOR16mi8 : Ii8<0x83, MRM6m,
984                      (ops i16mem:$dst, i16i8imm :$src),
985                      "xor{w} {$src, $dst|$dst, $src}",
986                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
987                      OpSize;
988   def XOR32mi8 : Ii8<0x83, MRM6m,
989                      (ops i32mem:$dst, i32i8imm :$src),
990                      "xor{l} {$src, $dst|$dst, $src}",
991                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
992 }
993
994 // Shift instructions
995 // FIXME: provide shorter instructions when imm8 == 1
996 def SHL8rCL  : I<0xD2, MRM4r, (ops R8 :$dst, R8 :$src),
997                  "shl{b} {%cl, $dst|$dst, %CL}",
998                  [(set R8:$dst, (shl R8:$src, CL))]>, Imp<[CL],[]>;
999 def SHL16rCL : I<0xD3, MRM4r, (ops R16:$dst, R16:$src),
1000                  "shl{w} {%cl, $dst|$dst, %CL}",
1001                  [(set R16:$dst, (shl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1002 def SHL32rCL : I<0xD3, MRM4r, (ops R32:$dst, R32:$src),
1003                  "shl{l} {%cl, $dst|$dst, %CL}",
1004                  [(set R32:$dst, (shl R32:$src, CL))]>, Imp<[CL],[]>;
1005
1006 def SHL8ri   : Ii8<0xC0, MRM4r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1007                    "shl{b} {$src2, $dst|$dst, $src2}",
1008                    [(set R8:$dst, (shl R8:$src1, (i8 imm:$src2)))]>;
1009 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1010 def SHL16ri  : Ii8<0xC1, MRM4r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1011                    "shl{w} {$src2, $dst|$dst, $src2}",
1012                    [(set R16:$dst, (shl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1013 def SHL32ri  : Ii8<0xC1, MRM4r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1014                    "shl{l} {$src2, $dst|$dst, $src2}",
1015                    [(set R32:$dst, (shl R32:$src1, (i8 imm:$src2)))]>;
1016 }
1017
1018 let isTwoAddress = 0 in {
1019   def SHL8mCL  : I<0xD2, MRM4m, (ops i8mem :$dst),
1020                    "shl{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1021   def SHL16mCL : I<0xD3, MRM4m, (ops i16mem:$dst),
1022                    "shl{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1023   def SHL32mCL : I<0xD3, MRM4m, (ops i32mem:$dst),
1024                    "shl{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1025   def SHL8mi   : Ii8<0xC0, MRM4m, (ops i8mem :$dst, i8imm:$src),
1026                      "shl{b} {$src, $dst|$dst, $src}", []>;
1027   def SHL16mi  : Ii8<0xC1, MRM4m, (ops i16mem:$dst, i8imm:$src),
1028                      "shl{w} {$src, $dst|$dst, $src}", []>, OpSize;
1029   def SHL32mi  : Ii8<0xC1, MRM4m, (ops i32mem:$dst, i8imm:$src),
1030                      "shl{l} {$src, $dst|$dst, $src}", []>;
1031 }
1032
1033 def SHR8rCL  : I<0xD2, MRM5r, (ops R8 :$dst, R8 :$src),
1034                  "shr{b} {%cl, $dst|$dst, %CL}",
1035                  [(set R8:$dst, (srl R8:$src, CL))]>, Imp<[CL],[]>;
1036 def SHR16rCL : I<0xD3, MRM5r, (ops R16:$dst, R16:$src),
1037                  "shr{w} {%cl, $dst|$dst, %CL}",
1038                  [(set R16:$dst, (srl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1039 def SHR32rCL : I<0xD3, MRM5r, (ops R32:$dst, R32:$src),
1040                  "shr{l} {%cl, $dst|$dst, %CL}",
1041                  [(set R32:$dst, (srl R32:$src, CL))]>, Imp<[CL],[]>;
1042
1043 def SHR8ri   : Ii8<0xC0, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1044                    "shr{b} {$src2, $dst|$dst, $src2}",
1045                    [(set R8:$dst, (srl R8:$src1, (i8 imm:$src2)))]>;
1046 def SHR16ri  : Ii8<0xC1, MRM5r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1047                    "shr{w} {$src2, $dst|$dst, $src2}",
1048                    [(set R16:$dst, (srl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1049 def SHR32ri  : Ii8<0xC1, MRM5r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1050                    "shr{l} {$src2, $dst|$dst, $src2}",
1051                    [(set R32:$dst, (srl R32:$src1, (i8 imm:$src2)))]>;
1052
1053 let isTwoAddress = 0 in {
1054   def SHR8mCL  : I<0xD2, MRM5m, (ops i8mem :$dst),
1055                    "shr{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1056   def SHR16mCL : I<0xD3, MRM5m, (ops i16mem:$dst),
1057                    "shr{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1058   def SHR32mCL : I<0xD3, MRM5m, (ops i32mem:$dst),
1059                    "shr{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1060   def SHR8mi   : Ii8<0xC0, MRM5m, (ops i8mem :$dst, i8imm:$src),
1061                      "shr{b} {$src, $dst|$dst, $src}", []>;
1062   def SHR16mi  : Ii8<0xC1, MRM5m, (ops i16mem:$dst, i8imm:$src),
1063                      "shr{w} {$src, $dst|$dst, $src}", []>, OpSize;
1064   def SHR32mi  : Ii8<0xC1, MRM5m, (ops i32mem:$dst, i8imm:$src),
1065                      "shr{l} {$src, $dst|$dst, $src}", []>;
1066 }
1067
1068 def SAR8rCL  : I<0xD2, MRM7r, (ops R8 :$dst, R8 :$src),
1069                  "sar{b} {%cl, $dst|$dst, %CL}",
1070                  [(set R8:$dst, (sra R8:$src, CL))]>, Imp<[CL],[]>;
1071 def SAR16rCL : I<0xD3, MRM7r, (ops R16:$dst, R16:$src),
1072                  "sar{w} {%cl, $dst|$dst, %CL}",
1073                  [(set R16:$dst, (sra R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1074 def SAR32rCL : I<0xD3, MRM7r, (ops R32:$dst, R32:$src),
1075                  "sar{l} {%cl, $dst|$dst, %CL}",
1076                  [(set R32:$dst, (sra R32:$src, CL))]>, Imp<[CL],[]>;
1077
1078 def SAR8ri   : Ii8<0xC0, MRM7r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1079                    "sar{b} {$src2, $dst|$dst, $src2}",
1080                    [(set R8:$dst, (sra R8:$src1, (i8 imm:$src2)))]>;
1081 def SAR16ri  : Ii8<0xC1, MRM7r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1082                    "sar{w} {$src2, $dst|$dst, $src2}",
1083                    [(set R16:$dst, (sra R16:$src1, (i8 imm:$src2)))]>,
1084                    OpSize;
1085 def SAR32ri  : Ii8<0xC1, MRM7r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1086                    "sar{l} {$src2, $dst|$dst, $src2}",
1087                    [(set R32:$dst, (sra R32:$src1, (i8 imm:$src2)))]>;
1088 let isTwoAddress = 0 in {
1089   def SAR8mCL  : I<0xD2, MRM7m, (ops i8mem :$dst),
1090                    "sar{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1091   def SAR16mCL : I<0xD3, MRM7m, (ops i16mem:$dst),
1092                    "sar{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1093   def SAR32mCL : I<0xD3, MRM7m, (ops i32mem:$dst), 
1094                    "sar{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1095   def SAR8mi   : Ii8<0xC0, MRM7m, (ops i8mem :$dst, i8imm:$src),
1096                      "sar{b} {$src, $dst|$dst, $src}", []>;
1097   def SAR16mi  : Ii8<0xC1, MRM7m, (ops i16mem:$dst, i8imm:$src),
1098                      "sar{w} {$src, $dst|$dst, $src}", []>, OpSize;
1099   def SAR32mi  : Ii8<0xC1, MRM7m, (ops i32mem:$dst, i8imm:$src),
1100                      "sar{l} {$src, $dst|$dst, $src}", []>;
1101 }
1102
1103 // Rotate instructions
1104 // FIXME: provide shorter instructions when imm8 == 1
1105 def ROL8rCL  : I<0xD2, MRM0r, (ops R8 :$dst, R8 :$src),
1106                  "rol{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1107 def ROL16rCL : I<0xD3, MRM0r, (ops R16:$dst, R16:$src),
1108                  "rol{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1109 def ROL32rCL : I<0xD3, MRM0r, (ops R32:$dst, R32:$src),
1110                  "rol{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1111
1112 def ROL8ri   : Ii8<0xC0, MRM0r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1113                    "rol{b} {$src2, $dst|$dst, $src2}", []>;
1114 def ROL16ri  : Ii8<0xC1, MRM0r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1115                    "rol{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1116 def ROL32ri  : Ii8<0xC1, MRM0r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1117                    "rol{l} {$src2, $dst|$dst, $src2}", []>;
1118
1119 let isTwoAddress = 0 in {
1120   def ROL8mCL  : I<0xD2, MRM0m, (ops i8mem :$dst),
1121                    "rol{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1122   def ROL16mCL : I<0xD3, MRM0m, (ops i16mem:$dst),
1123                    "rol{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1124   def ROL32mCL : I<0xD3, MRM0m, (ops i32mem:$dst),
1125                    "rol{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1126   def ROL8mi   : Ii8<0xC0, MRM0m, (ops i8mem :$dst, i8imm:$src),
1127                      "rol{b} {$src, $dst|$dst, $src}", []>;
1128   def ROL16mi  : Ii8<0xC1, MRM0m, (ops i16mem:$dst, i8imm:$src),
1129                      "rol{w} {$src, $dst|$dst, $src}", []>, OpSize;
1130   def ROL32mi  : Ii8<0xC1, MRM0m, (ops i32mem:$dst, i8imm:$src),
1131                      "rol{l} {$src, $dst|$dst, $src}", []>;
1132 }
1133
1134 def ROR8rCL  : I<0xD2, MRM1r, (ops R8 :$dst, R8 :$src),
1135                  "ror{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1136 def ROR16rCL : I<0xD3, MRM1r, (ops R16:$dst, R16:$src),
1137                  "ror{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1138 def ROR32rCL : I<0xD3, MRM1r, (ops R32:$dst, R32:$src),
1139                  "ror{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1140
1141 def ROR8ri   : Ii8<0xC0, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1142                    "ror{b} {$src2, $dst|$dst, $src2}", []>;
1143 def ROR16ri  : Ii8<0xC1, MRM1r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1144                    "ror{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1145 def ROR32ri  : Ii8<0xC1, MRM1r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1146                    "ror{l} {$src2, $dst|$dst, $src2}", []>;
1147 let isTwoAddress = 0 in {
1148   def ROR8mCL  : I<0xD2, MRM1m, (ops i8mem :$dst),
1149                    "ror{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1150   def ROR16mCL : I<0xD3, MRM1m, (ops i16mem:$dst),
1151                    "ror{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1152   def ROR32mCL : I<0xD3, MRM1m, (ops i32mem:$dst), 
1153                    "ror{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1154   def ROR8mi   : Ii8<0xC0, MRM1m, (ops i8mem :$dst, i8imm:$src),
1155                      "ror{b} {$src, $dst|$dst, $src}", []>;
1156   def ROR16mi  : Ii8<0xC1, MRM1m, (ops i16mem:$dst, i8imm:$src),
1157                      "ror{w} {$src, $dst|$dst, $src}", []>, OpSize;
1158   def ROR32mi  : Ii8<0xC1, MRM1m, (ops i32mem:$dst, i8imm:$src),
1159                      "ror{l} {$src, $dst|$dst, $src}", []>;
1160 }
1161
1162
1163
1164 // Double shift instructions (generalizations of rotate)
1165
1166 def SHLD32rrCL : I<0xA5, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1167                    "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1168                    Imp<[CL],[]>, TB;
1169 def SHRD32rrCL : I<0xAD, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1170                    "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1171                    Imp<[CL],[]>, TB;
1172 def SHLD16rrCL : I<0xA5, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1173                    "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1174                    Imp<[CL],[]>, TB, OpSize;
1175 def SHRD16rrCL : I<0xAD, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1176                    "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1177                    Imp<[CL],[]>, TB, OpSize;
1178
1179 let isCommutable = 1 in {  // These instructions commute to each other.
1180 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
1181                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1182                      "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}", []>, TB;
1183 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
1184                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1185                      "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}", []>, TB;
1186 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
1187                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1188                      "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1189                      TB, OpSize;
1190 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
1191                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1192                      "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1193                      TB, OpSize;
1194 }
1195
1196 let isTwoAddress = 0 in {
1197   def SHLD32mrCL : I<0xA5, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1198                      "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1199                      Imp<[CL],[]>, TB;
1200   def SHRD32mrCL : I<0xAD, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1201                     "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1202                     Imp<[CL],[]>, TB;
1203   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
1204                       (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1205                       "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1206                       TB;
1207   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
1208                        (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1209                        "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1210                        TB;
1211
1212   def SHLD16mrCL : I<0xA5, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1213                      "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1214                      Imp<[CL],[]>, TB, OpSize;
1215   def SHRD16mrCL : I<0xAD, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1216                     "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
1217                     Imp<[CL],[]>, TB, OpSize;
1218   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
1219                       (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1220                       "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1221                       TB, OpSize;
1222   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
1223                        (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1224                        "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
1225                        TB, OpSize;
1226 }
1227
1228
1229 // Arithmetic.
1230 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
1231 def ADD8rr   : I<0x00, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1232                  "add{b} {$src2, $dst|$dst, $src2}",
1233                  [(set R8:$dst, (add R8:$src1, R8:$src2))]>;
1234 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1235 def ADD16rr  : I<0x01, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1236                  "add{w} {$src2, $dst|$dst, $src2}",
1237                  [(set R16:$dst, (add R16:$src1, R16:$src2))]>, OpSize;
1238 def ADD32rr  : I<0x01, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1239                  "add{l} {$src2, $dst|$dst, $src2}",
1240                  [(set R32:$dst, (add R32:$src1, R32:$src2))]>;
1241 } // end isConvertibleToThreeAddress
1242 } // end isCommutable
1243 def ADD8rm   : I<0x02, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1244                  "add{b} {$src2, $dst|$dst, $src2}",
1245                  [(set R8:$dst, (add R8:$src1, (load addr:$src2)))]>;
1246 def ADD16rm  : I<0x03, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1247                  "add{w} {$src2, $dst|$dst, $src2}",
1248                  [(set R16:$dst, (add R16:$src1, (load addr:$src2)))]>, OpSize;
1249 def ADD32rm  : I<0x03, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1250                  "add{l} {$src2, $dst|$dst, $src2}",
1251                  [(set R32:$dst, (add R32:$src1, (load addr:$src2)))]>;
1252
1253 def ADD8ri   : Ii8<0x80, MRM0r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1254                    "add{b} {$src2, $dst|$dst, $src2}",
1255                    [(set R8:$dst, (add R8:$src1, imm:$src2))]>;
1256
1257 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1258 def ADD16ri  : Ii16<0x81, MRM0r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1259                     "add{w} {$src2, $dst|$dst, $src2}",
1260                     [(set R16:$dst, (add R16:$src1, imm:$src2))]>, OpSize;
1261 def ADD32ri  : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1262                     "add{l} {$src2, $dst|$dst, $src2}",
1263                     [(set R32:$dst, (add R32:$src1, imm:$src2))]>;
1264 }
1265
1266 // FIXME: move ADD16ri8 above ADD16ri to optimize for space.
1267 def ADD16ri8 : Ii8<0x83, MRM0r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1268                    "add{w} {$src2, $dst|$dst, $src2}",
1269                    [(set R16:$dst, (add R16:$src1, i16immSExt8:$src2))]>,
1270                    OpSize;
1271 def ADD32ri8 : Ii8<0x83, MRM0r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1272                    "add{l} {$src2, $dst|$dst, $src2}",
1273                    [(set R32:$dst, (add R32:$src1, i32immSExt8:$src2))]>;
1274
1275 let isTwoAddress = 0 in {
1276   def ADD8mr   : I<0x00, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1277                    "add{b} {$src2, $dst|$dst, $src2}",
1278                    [(store (add (load addr:$dst), R8:$src2), addr:$dst)]>;
1279   def ADD16mr  : I<0x01, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1280                    "add{w} {$src2, $dst|$dst, $src2}",
1281                    [(store (add (load addr:$dst), R16:$src2), addr:$dst)]>,
1282                    OpSize;
1283   def ADD32mr  : I<0x01, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1284                    "add{l} {$src2, $dst|$dst, $src2}",
1285                    [(store (add (load addr:$dst), R32:$src2), addr:$dst)]>;
1286   def ADD8mi   : Ii8<0x80, MRM0m, (ops i8mem :$dst, i8imm :$src2),
1287                      "add{b} {$src2, $dst|$dst, $src2}",
1288                    [(store (add (load addr:$dst), (i8 imm:$src2)), addr:$dst)]>;
1289   def ADD16mi  : Ii16<0x81, MRM0m, (ops i16mem:$dst, i16imm:$src2),
1290                       "add{w} {$src2, $dst|$dst, $src2}",
1291                   [(store (add (load addr:$dst), (i16 imm:$src2)), addr:$dst)]>,
1292                    OpSize;
1293   def ADD32mi  : Ii32<0x81, MRM0m, (ops i32mem:$dst, i32imm:$src2),
1294                       "add{l} {$src2, $dst|$dst, $src2}",
1295                   [(store (add (load addr:$dst), (i32 imm:$src2)), addr:$dst)]>;
1296   def ADD16mi8 : Ii8<0x83, MRM0m, (ops i16mem:$dst, i16i8imm :$src2),
1297                      "add{w} {$src2, $dst|$dst, $src2}",
1298                 [(store (add (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1299                    OpSize;
1300   def ADD32mi8 : Ii8<0x83, MRM0m, (ops i32mem:$dst, i32i8imm :$src2),
1301                      "add{l} {$src2, $dst|$dst, $src2}",
1302                 [(store (add (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1303 }
1304
1305 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
1306 def ADC32rr  : I<0x11, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1307                  "adc{l} {$src2, $dst|$dst, $src2}", []>;
1308 }
1309 def ADC32rm  : I<0x13, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
1310                  "adc{l} {$src2, $dst|$dst, $src2}", []>;
1311 def ADC32ri  : Ii32<0x81, MRM2r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1312                     "adc{l} {$src2, $dst|$dst, $src2}", []>;
1313 def ADC32ri8 : Ii8<0x83, MRM2r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1314                    "adc{l} {$src2, $dst|$dst, $src2}", []>;
1315
1316 let isTwoAddress = 0 in {
1317   def ADC32mr  : I<0x11, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1318                    "adc{l} {$src2, $dst|$dst, $src2}", []>;
1319   def ADC32mi  : Ii32<0x81, MRM2m, (ops i32mem:$dst, i32imm:$src2),
1320                       "adc{l} {$src2, $dst|$dst, $src2}", []>;
1321   def ADC32mi8 : Ii8<0x83, MRM2m, (ops i32mem:$dst, i8imm :$src2),
1322                      "adc{l} {$src2, $dst|$dst, $src2}", []>;
1323 }
1324
1325 def SUB8rr   : I<0x28, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1326                  "sub{b} {$src2, $dst|$dst, $src2}",
1327                  [(set R8:$dst, (sub R8:$src1, R8:$src2))]>;
1328 def SUB16rr  : I<0x29, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1329                  "sub{w} {$src2, $dst|$dst, $src2}",
1330                  [(set R16:$dst, (sub R16:$src1, R16:$src2))]>, OpSize;
1331 def SUB32rr  : I<0x29, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1332                  "sub{l} {$src2, $dst|$dst, $src2}",
1333                  [(set R32:$dst, (sub R32:$src1, R32:$src2))]>;
1334 def SUB8rm   : I<0x2A, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1335                  "sub{b} {$src2, $dst|$dst, $src2}",
1336                  [(set R8:$dst, (sub R8:$src1, (load addr:$src2)))]>;
1337 def SUB16rm  : I<0x2B, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1338                  "sub{w} {$src2, $dst|$dst, $src2}",
1339                  [(set R16:$dst, (sub R16:$src1, (load addr:$src2)))]>, OpSize;
1340 def SUB32rm  : I<0x2B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1341                  "sub{l} {$src2, $dst|$dst, $src2}",
1342                  [(set R32:$dst, (sub R32:$src1, (load addr:$src2)))]>;
1343
1344 def SUB8ri   : Ii8 <0x80, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1345                     "sub{b} {$src2, $dst|$dst, $src2}",
1346                     [(set R8:$dst, (sub R8:$src1, imm:$src2))]>;
1347 def SUB16ri  : Ii16<0x81, MRM5r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1348                     "sub{w} {$src2, $dst|$dst, $src2}",
1349                     [(set R16:$dst, (sub R16:$src1, imm:$src2))]>, OpSize;
1350 def SUB32ri  : Ii32<0x81, MRM5r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1351                     "sub{l} {$src2, $dst|$dst, $src2}",
1352                     [(set R32:$dst, (sub R32:$src1, imm:$src2))]>;
1353 def SUB16ri8 : Ii8<0x83, MRM5r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1354                    "sub{w} {$src2, $dst|$dst, $src2}",
1355                    [(set R16:$dst, (sub R16:$src1, i16immSExt8:$src2))]>,
1356                    OpSize;
1357 def SUB32ri8 : Ii8<0x83, MRM5r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1358                    "sub{l} {$src2, $dst|$dst, $src2}",
1359                    [(set R32:$dst, (sub R32:$src1, i32immSExt8:$src2))]>;
1360 let isTwoAddress = 0 in {
1361   def SUB8mr   : I<0x28, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1362                    "sub{b} {$src2, $dst|$dst, $src2}",
1363                    [(store (sub (load addr:$dst), R8:$src2), addr:$dst)]>;
1364   def SUB16mr  : I<0x29, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1365                    "sub{w} {$src2, $dst|$dst, $src2}",
1366                    [(store (sub (load addr:$dst), R16:$src2), addr:$dst)]>,
1367                    OpSize;
1368   def SUB32mr  : I<0x29, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1369                    "sub{l} {$src2, $dst|$dst, $src2}",
1370                    [(store (sub (load addr:$dst), R32:$src2), addr:$dst)]>;
1371   def SUB8mi   : Ii8<0x80, MRM5m, (ops i8mem :$dst, i8imm:$src2), 
1372                      "sub{b} {$src2, $dst|$dst, $src2}",
1373                    [(store (sub (load addr:$dst), (i8 imm:$src2)), addr:$dst)]>;
1374   def SUB16mi  : Ii16<0x81, MRM5m, (ops i16mem:$dst, i16imm:$src2), 
1375                       "sub{w} {$src2, $dst|$dst, $src2}",
1376                   [(store (sub (load addr:$dst), (i16 imm:$src2)), addr:$dst)]>,
1377                    OpSize;
1378   def SUB32mi  : Ii32<0x81, MRM5m, (ops i32mem:$dst, i32imm:$src2), 
1379                       "sub{l} {$src2, $dst|$dst, $src2}",
1380                   [(store (sub (load addr:$dst), (i32 imm:$src2)), addr:$dst)]>;
1381   def SUB16mi8 : Ii8<0x83, MRM5m, (ops i16mem:$dst, i16i8imm :$src2), 
1382                      "sub{w} {$src2, $dst|$dst, $src2}",
1383                 [(store (sub (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1384                    OpSize;
1385   def SUB32mi8 : Ii8<0x83, MRM5m, (ops i32mem:$dst, i32i8imm :$src2), 
1386                      "sub{l} {$src2, $dst|$dst, $src2}",
1387                 [(store (sub (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1388 }
1389
1390 def SBB32rr    : I<0x19, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1391                   "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1392
1393 let isTwoAddress = 0 in {
1394   def SBB32mr  : I<0x19, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1395                    "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1396   def SBB8mi  : Ii32<0x80, MRM3m, (ops i8mem:$dst, i8imm:$src2), 
1397                       "sbb{b} {$src2, $dst|$dst, $src2}", []>;
1398   def SBB16mi  : Ii32<0x81, MRM3m, (ops i16mem:$dst, i16imm:$src2), 
1399                       "sbb{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1400   def SBB32mi  : Ii32<0x81, MRM3m, (ops i32mem:$dst, i32imm:$src2), 
1401                       "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1402   def SBB16mi8 : Ii8<0x83, MRM3m, (ops i16mem:$dst, i8imm :$src2), 
1403                      "sbb{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1404   def SBB32mi8 : Ii8<0x83, MRM3m, (ops i32mem:$dst, i8imm :$src2), 
1405                      "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1406 }
1407 def SBB8ri   : Ii8<0x80, MRM3r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1408                     "sbb{b} {$src2, $dst|$dst, $src2}", []>;
1409 def SBB16ri  : Ii16<0x81, MRM3r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1410                     "sbb{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1411
1412 def SBB32rm  : I<0x1B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1413                     "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1414 def SBB32ri  : Ii32<0x81, MRM3r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1415                     "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1416
1417 def SBB16ri8 : Ii8<0x83, MRM3r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1418                    "sbb{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1419 def SBB32ri8 : Ii8<0x83, MRM3r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1420                    "sbb{l} {$src2, $dst|$dst, $src2}", []>;
1421
1422 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
1423 def IMUL16rr : I<0xAF, MRMSrcReg, (ops R16:$dst, R16:$src1, R16:$src2),
1424                  "imul{w} {$src2, $dst|$dst, $src2}",
1425                  [(set R16:$dst, (mul R16:$src1, R16:$src2))]>, TB, OpSize;
1426 def IMUL32rr : I<0xAF, MRMSrcReg, (ops R32:$dst, R32:$src1, R32:$src2),
1427                  "imul{l} {$src2, $dst|$dst, $src2}",
1428                  [(set R32:$dst, (mul R32:$src1, R32:$src2))]>, TB;
1429 }
1430 def IMUL16rm : I<0xAF, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1431                  "imul{w} {$src2, $dst|$dst, $src2}",
1432                  [(set R16:$dst, (mul R16:$src1, (load addr:$src2)))]>,
1433                  TB, OpSize;
1434 def IMUL32rm : I<0xAF, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1435                  "imul{l} {$src2, $dst|$dst, $src2}",
1436                  [(set R32:$dst, (mul R32:$src1, (load addr:$src2)))]>, TB;
1437
1438 } // end Two Address instructions
1439
1440 // Suprisingly enough, these are not two address instructions!
1441 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // R16 = R16*I16
1442                       (ops R16:$dst, R16:$src1, i16imm:$src2),
1443                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1444                       [(set R16:$dst, (mul R16:$src1, imm:$src2))]>, OpSize;
1445 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // R32 = R32*I32
1446                       (ops R32:$dst, R32:$src1, i32imm:$src2),
1447                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1448                       [(set R32:$dst, (mul R32:$src1, imm:$src2))]>;
1449 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // R16 = R16*I8
1450                      (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1451                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1452                      [(set R16:$dst, (mul R16:$src1, i16immSExt8:$src2))]>,
1453                      OpSize;
1454 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // R32 = R32*I8
1455                      (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1456                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1457                      [(set R32:$dst, (mul R32:$src1, i32immSExt8:$src2))]>;
1458
1459 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                      // R16 = [mem16]*I16
1460                       (ops R16:$dst, i16mem:$src1, i16imm:$src2),
1461                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1462                       [(set R16:$dst, (mul (load addr:$src1), imm:$src2))]>,
1463                       OpSize;
1464 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                      // R32 = [mem32]*I32
1465                       (ops R32:$dst, i32mem:$src1, i32imm:$src2),
1466                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1467                       [(set R32:$dst, (mul (load addr:$src1), imm:$src2))]>;
1468 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // R16 = [mem16]*I8
1469                      (ops R16:$dst, i16mem:$src1, i16i8imm :$src2),
1470                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1471                   [(set R16:$dst, (mul (load addr:$src1), i16immSExt8:$src2))]>,
1472                      OpSize;
1473 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // R32 = [mem32]*I8
1474                      (ops R32:$dst, i32mem:$src1, i32i8imm: $src2),
1475                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1476                   [(set R32:$dst, (mul (load addr:$src1), i32immSExt8:$src2))]>;
1477
1478 //===----------------------------------------------------------------------===//
1479 // Test instructions are just like AND, except they don't generate a result.
1480 //
1481 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
1482 def TEST8rr  : I<0x84, MRMDestReg, (ops R8:$src1, R8:$src2),
1483                  "test{b} {$src2, $src1|$src1, $src2}", []>;
1484 def TEST16rr : I<0x85, MRMDestReg, (ops R16:$src1, R16:$src2),
1485                  "test{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1486 def TEST32rr : I<0x85, MRMDestReg, (ops R32:$src1, R32:$src2),
1487                  "test{l} {$src2, $src1|$src1, $src2}", []>;
1488 }
1489 def TEST8mr  : I<0x84, MRMDestMem, (ops i8mem :$src1, R8 :$src2),
1490                  "test{b} {$src2, $src1|$src1, $src2}", []>;
1491 def TEST16mr : I<0x85, MRMDestMem, (ops i16mem:$src1, R16:$src2),
1492                  "test{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1493 def TEST32mr : I<0x85, MRMDestMem, (ops i32mem:$src1, R32:$src2),
1494                  "test{l} {$src2, $src1|$src1, $src2}", []>;
1495 def TEST8rm  : I<0x84, MRMSrcMem, (ops R8 :$src1, i8mem :$src2),
1496                  "test{b} {$src2, $src1|$src1, $src2}", []>;
1497 def TEST16rm : I<0x85, MRMSrcMem, (ops R16:$src1, i16mem:$src2),
1498                  "test{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1499 def TEST32rm : I<0x85, MRMSrcMem, (ops R32:$src1, i32mem:$src2),
1500                  "test{l} {$src2, $src1|$src1, $src2}", []>;
1501
1502 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = R8  & imm8
1503                     (ops R8:$src1, i8imm:$src2),
1504                     "test{b} {$src2, $src1|$src1, $src2}", []>;
1505 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = R16 & imm16
1506                     (ops R16:$src1, i16imm:$src2),
1507                     "test{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1508 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = R32 & imm32
1509                     (ops R32:$src1, i32imm:$src2),
1510                     "test{l} {$src2, $src1|$src1, $src2}", []>;
1511 def TEST8mi  : Ii8 <0xF6, MRM0m,                     // flags = [mem8]  & imm8
1512                     (ops i32mem:$src1, i8imm:$src2),
1513                     "test{b} {$src2, $src1|$src1, $src2}", []>;
1514 def TEST16mi : Ii16<0xF7, MRM0m,                     // flags = [mem16] & imm16
1515                     (ops i16mem:$src1, i16imm:$src2),
1516                     "test{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1517 def TEST32mi : Ii32<0xF7, MRM0m,                     // flags = [mem32] & imm32
1518                     (ops i32mem:$src1, i32imm:$src2),
1519                     "test{l} {$src2, $src1|$src1, $src2}", []>;
1520
1521
1522
1523 // Condition code ops, incl. set if equal/not equal/...
1524 def SAHF     : I<0x9E, RawFrm, (ops), "sahf", []>, Imp<[AH],[]>;  // flags = AH
1525 def LAHF     : I<0x9F, RawFrm, (ops), "lahf", []>, Imp<[],[AH]>;  // AH = flags
1526
1527 def SETBr    : I<0x92, MRM0r,
1528                  (ops R8   :$dst), "setb $dst", []>, TB;    // R8 = <  unsign
1529 def SETBm    : I<0x92, MRM0m,
1530                  (ops i8mem:$dst), "setb $dst", []>, TB;    // [mem8] = <  unsign
1531 def SETAEr   : I<0x93, MRM0r, 
1532                  (ops R8   :$dst), "setae $dst", []>, TB;   // R8 = >= unsign
1533 def SETAEm   : I<0x93, MRM0m, 
1534                  (ops i8mem:$dst), "setae $dst", []>, TB;   // [mem8] = >= unsign
1535 def SETEr    : I<0x94, MRM0r, 
1536                  (ops R8   :$dst), "sete $dst", []>, TB;    // R8 = ==
1537 def SETEm    : I<0x94, MRM0m, 
1538                  (ops i8mem:$dst), "sete $dst", []>, TB;    // [mem8] = ==
1539 def SETNEr   : I<0x95, MRM0r, 
1540                  (ops R8   :$dst), "setne $dst", []>, TB;   // R8 = !=
1541 def SETNEm   : I<0x95, MRM0m, 
1542                  (ops i8mem:$dst), "setne $dst", []>, TB;   // [mem8] = !=
1543 def SETBEr   : I<0x96, MRM0r, 
1544                  (ops R8   :$dst), "setbe $dst", []>, TB;   // R8 = <= unsign
1545 def SETBEm   : I<0x96, MRM0m, 
1546                  (ops i8mem:$dst), "setbe $dst", []>, TB;   // [mem8] = <= unsign
1547 def SETAr    : I<0x97, MRM0r, 
1548                  (ops R8   :$dst), "seta $dst", []>, TB;    // R8 = >  signed
1549 def SETAm    : I<0x97, MRM0m, 
1550                  (ops i8mem:$dst), "seta $dst", []>, TB;    // [mem8] = >  signed
1551 def SETSr    : I<0x98, MRM0r, 
1552                  (ops R8   :$dst), "sets $dst", []>, TB;    // R8 = <sign bit>
1553 def SETSm    : I<0x98, MRM0m, 
1554                  (ops i8mem:$dst), "sets $dst", []>, TB;    // [mem8] = <sign bit>
1555 def SETNSr   : I<0x99, MRM0r, 
1556                  (ops R8   :$dst), "setns $dst", []>, TB;   // R8 = !<sign bit>
1557 def SETNSm   : I<0x99, MRM0m, 
1558                  (ops i8mem:$dst), "setns $dst", []>, TB;   // [mem8] = !<sign bit>
1559 def SETPr    : I<0x9A, MRM0r, 
1560                  (ops R8   :$dst), "setp $dst", []>, TB;    // R8 = parity
1561 def SETPm    : I<0x9A, MRM0m, 
1562                  (ops i8mem:$dst), "setp $dst", []>, TB;    // [mem8] = parity
1563 def SETNPr   : I<0x9B, MRM0r, 
1564                  (ops R8   :$dst), "setnp $dst", []>, TB;   // R8 = not parity
1565 def SETNPm   : I<0x9B, MRM0m, 
1566                  (ops i8mem:$dst), "setnp $dst", []>, TB;   // [mem8] = not parity
1567 def SETLr    : I<0x9C, MRM0r, 
1568                  (ops R8   :$dst), "setl $dst", []>, TB;    // R8 = <  signed
1569 def SETLm    : I<0x9C, MRM0m, 
1570                  (ops i8mem:$dst), "setl $dst", []>, TB;    // [mem8] = <  signed
1571 def SETGEr   : I<0x9D, MRM0r, 
1572                  (ops R8   :$dst), "setge $dst", []>, TB;   // R8 = >= signed
1573 def SETGEm   : I<0x9D, MRM0m, 
1574                  (ops i8mem:$dst), "setge $dst", []>, TB;   // [mem8] = >= signed
1575 def SETLEr   : I<0x9E, MRM0r, 
1576                  (ops R8   :$dst), "setle $dst", []>, TB;   // R8 = <= signed
1577 def SETLEm   : I<0x9E, MRM0m, 
1578                  (ops i8mem:$dst), "setle $dst", []>, TB;   // [mem8] = <= signed
1579 def SETGr    : I<0x9F, MRM0r, 
1580                  (ops R8   :$dst), "setg $dst", []>, TB;    // R8 = <  signed
1581 def SETGm    : I<0x9F, MRM0m, 
1582                  (ops i8mem:$dst), "setg $dst", []>, TB;    // [mem8] = <  signed
1583
1584 // Integer comparisons
1585 def CMP8rr  : I<0x38, MRMDestReg,
1586                 (ops R8 :$src1, R8 :$src2),
1587                 "cmp{b} {$src2, $src1|$src1, $src2}", []>;
1588 def CMP16rr : I<0x39, MRMDestReg,
1589                 (ops R16:$src1, R16:$src2),
1590                 "cmp{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1591 def CMP32rr : I<0x39, MRMDestReg,
1592                 (ops R32:$src1, R32:$src2),
1593                 "cmp{l} {$src2, $src1|$src1, $src2}", []>;
1594 def CMP8mr  : I<0x38, MRMDestMem,
1595                 (ops i8mem :$src1, R8 :$src2),
1596                 "cmp{b} {$src2, $src1|$src1, $src2}", []>;
1597 def CMP16mr : I<0x39, MRMDestMem,
1598                 (ops i16mem:$src1, R16:$src2),
1599                 "cmp{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1600 def CMP32mr : I<0x39, MRMDestMem,
1601                 (ops i32mem:$src1, R32:$src2),
1602                 "cmp{l} {$src2, $src1|$src1, $src2}", []>;
1603 def CMP8rm  : I<0x3A, MRMSrcMem,
1604                 (ops R8 :$src1, i8mem :$src2),
1605                 "cmp{b} {$src2, $src1|$src1, $src2}", []>;
1606 def CMP16rm : I<0x3B, MRMSrcMem,
1607                 (ops R16:$src1, i16mem:$src2),
1608                 "cmp{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1609 def CMP32rm : I<0x3B, MRMSrcMem,
1610                 (ops R32:$src1, i32mem:$src2),
1611                 "cmp{l} {$src2, $src1|$src1, $src2}", []>;
1612 def CMP8ri  : Ii8<0x80, MRM7r,
1613                   (ops R16:$src1, i8imm:$src2),
1614                   "cmp{b} {$src2, $src1|$src1, $src2}", []>;
1615 def CMP16ri : Ii16<0x81, MRM7r,
1616                    (ops R16:$src1, i16imm:$src2),
1617                    "cmp{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1618 def CMP32ri : Ii32<0x81, MRM7r,
1619                    (ops R32:$src1, i32imm:$src2),
1620                    "cmp{l} {$src2, $src1|$src1, $src2}", []>;
1621 def CMP8mi  : Ii8 <0x80, MRM7m,
1622                    (ops i8mem :$src1, i8imm :$src2),
1623                    "cmp{b} {$src2, $src1|$src1, $src2}", []>;
1624 def CMP16mi : Ii16<0x81, MRM7m,
1625                    (ops i16mem:$src1, i16imm:$src2),
1626                    "cmp{w} {$src2, $src1|$src1, $src2}", []>, OpSize;
1627 def CMP32mi : Ii32<0x81, MRM7m,
1628                    (ops i32mem:$src1, i32imm:$src2),
1629                    "cmp{l} {$src2, $src1|$src1, $src2}", []>;
1630
1631 // Sign/Zero extenders
1632 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (ops R16:$dst, R8 :$src),
1633                    "movs{bw|x} {$src, $dst|$dst, $src}",
1634                    [(set R16:$dst, (sext R8:$src))]>, TB, OpSize;
1635 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (ops R16:$dst, i8mem :$src),
1636                    "movs{bw|x} {$src, $dst|$dst, $src}", []>, TB, OpSize;
1637 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (ops R32:$dst, R8 :$src),
1638                    "movs{bl|x} {$src, $dst|$dst, $src}",
1639                    [(set R32:$dst, (sext R8:$src))]>, TB;
1640 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (ops R32:$dst, i8mem :$src),
1641                    "movs{bl|x} {$src, $dst|$dst, $src}", []>, TB;
1642 def MOVSX32rr16: I<0xBF, MRMSrcReg, (ops R32:$dst, R16:$src),
1643                    "movs{wl|x} {$src, $dst|$dst, $src}",
1644                    [(set R32:$dst, (sext R16:$src))]>, TB;
1645 def MOVSX32rm16: I<0xBF, MRMSrcMem, (ops R32:$dst, i16mem:$src),
1646                    "movs{wl|x} {$src, $dst|$dst, $src}", []>, TB;
1647
1648 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (ops R16:$dst, R8 :$src),
1649                    "movz{bw|x} {$src, $dst|$dst, $src}",
1650                    [(set R16:$dst, (zext R8:$src))]>, TB, OpSize;
1651 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (ops R16:$dst, i8mem :$src),
1652                    "movz{bw|x} {$src, $dst|$dst, $src}", []>, TB, OpSize;
1653 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (ops R32:$dst, R8 :$src),
1654                    "movz{bl|x} {$src, $dst|$dst, $src}",
1655                    [(set R32:$dst, (zext R8:$src))]>, TB;
1656 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (ops R32:$dst, i8mem :$src),
1657                    "movz{bl|x} {$src, $dst|$dst, $src}", []>, TB;
1658 def MOVZX32rr16: I<0xB7, MRMSrcReg, (ops R32:$dst, R16:$src),
1659                    "movz{wl|x} {$src, $dst|$dst, $src}",
1660                    [(set R32:$dst, (zext R16:$src))]>, TB;
1661 def MOVZX32rm16: I<0xB7, MRMSrcMem, (ops R32:$dst, i16mem:$src),
1662                    "movz{wl|x} {$src, $dst|$dst, $src}", []>, TB;
1663
1664 //===----------------------------------------------------------------------===//
1665 // XMM Floating point support (requires SSE2)
1666 //===----------------------------------------------------------------------===//
1667
1668 def MOVSSrr : I<0x10, MRMSrcReg, (ops V4F4:$dst, V4F4:$src),
1669                 "movss {$src, $dst|$dst, $src}", []>, XS;
1670 def MOVSSrm : I<0x10, MRMSrcMem, (ops V4F4:$dst, f32mem:$src),
1671                 "movss {$src, $dst|$dst, $src}", []>, XS;
1672 def MOVSSmr : I<0x11, MRMDestMem, (ops f32mem:$dst, V4F4:$src),
1673                 "movss {$src, $dst|$dst, $src}", []>, XS;
1674 def MOVSDrr : I<0x10, MRMSrcReg, (ops V2F8:$dst, V2F8:$src),
1675                 "movsd {$src, $dst|$dst, $src}", []>, XD;
1676 def MOVSDrm : I<0x10, MRMSrcMem, (ops V2F8:$dst, f64mem:$src),
1677                 "movsd {$src, $dst|$dst, $src}", []>, XD;
1678 def MOVSDmr : I<0x11, MRMDestMem, (ops f64mem:$dst, V2F8:$src),
1679                 "movsd {$src, $dst|$dst, $src}", []>, XD;
1680
1681 def CVTTSD2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, V2F8:$src),
1682                 "cvttsd2si {$src, $dst|$dst, $src}",
1683                 [(set R32:$dst, (fp_to_sint V2F8:$src))]>, XD;
1684 def CVTTSD2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f64mem:$src),
1685                 "cvttsd2si {$src, $dst|$dst, $src}", []>, XD;
1686 def CVTTSS2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, V4F4:$src),
1687                 "cvttss2si {$src, $dst|$dst, $src}",
1688                 [(set R32:$dst, (fp_to_sint V4F4:$src))]>, XS;
1689 def CVTTSS2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f32mem:$src),
1690                 "cvttss2si {$src, $dst|$dst, $src}", []>, XS;
1691 def CVTSD2SSrr: I<0x5A, MRMSrcReg, (ops V4F4:$dst, V2F8:$src),
1692                 "cvtsd2ss {$src, $dst|$dst, $src}",
1693                 [(set V4F4:$dst, (fround V2F8:$src))]>, XS;
1694 def CVTSD2SSrm: I<0x5A, MRMSrcMem, (ops V4F4:$dst, f64mem:$src), 
1695                 "cvtsd2ss {$src, $dst|$dst, $src}", []>, XS;
1696 def CVTSS2SDrr: I<0x5A, MRMSrcReg, (ops V2F8:$dst, V4F4:$src),
1697                 "cvtss2sd {$src, $dst|$dst, $src}",
1698                 [(set V2F8:$dst, (fextend V4F4:$src))]>, XD;
1699 def CVTSS2SDrm: I<0x5A, MRMSrcMem, (ops V2F8:$dst, f32mem:$src),
1700                 "cvtss2sd {$src, $dst|$dst, $src}", []>, XD;
1701 def CVTSI2SSrr: I<0x2A, MRMSrcReg, (ops V4F4:$dst, R32:$src),
1702                 "cvtsi2ss {$src, $dst|$dst, $src}",
1703                 [(set V4F4:$dst, (sint_to_fp R32:$src))]>, XS;
1704 def CVTSI2SSrm: I<0x2A, MRMSrcMem, (ops V4F4:$dst, i32mem:$src),
1705                 "cvtsi2ss {$src, $dst|$dst, $src}", []>, XS;
1706 def CVTSI2SDrr: I<0x2A, MRMSrcReg, (ops V2F8:$dst, R32:$src),
1707                 "cvtsi2sd {$src, $dst|$dst, $src}",
1708                 [(set V2F8:$dst, (sint_to_fp R32:$src))]>, XD;
1709 def CVTSI2SDrm: I<0x2A, MRMSrcMem, (ops V2F8:$dst, i32mem:$src),
1710                 "cvtsi2sd {$src, $dst|$dst, $src}", []>, XD;
1711
1712 def SQRTSSrm : I<0x51, MRMSrcMem, (ops V4F4:$dst, f32mem:$src),
1713                 "sqrtss {$src, $dst|$dst, $src}", []>, XS;
1714 def SQRTSSrr : I<0x51, MRMSrcReg, (ops V4F4:$dst, V4F4:$src),
1715                 "sqrtss {$src, $dst|$dst, $src}",
1716                 [(set V4F4:$dst, (fsqrt V4F4:$src))]>, XS;
1717 def SQRTSDrm : I<0x51, MRMSrcMem, (ops V2F8:$dst, f64mem:$src),
1718                 "sqrtsd {$src, $dst|$dst, $src}", []>, XD;
1719 def SQRTSDrr : I<0x51, MRMSrcReg, (ops V2F8:$dst, V2F8:$src),
1720                 "sqrtsd {$src, $dst|$dst, $src}",
1721                 [(set V2F8:$dst, (fsqrt V2F8:$src))]>, XD;
1722
1723 def UCOMISDrr: I<0x2E, MRMSrcReg, (ops V2F8:$dst, V2F8:$src),
1724                 "ucomisd {$src, $dst|$dst, $src}", []>, TB, OpSize;
1725 def UCOMISDrm: I<0x2E, MRMSrcMem, (ops V2F8:$dst, f64mem:$src),
1726                 "ucomisd {$src, $dst|$dst, $src}", []>, TB, OpSize;
1727 def UCOMISSrr: I<0x2E, MRMSrcReg, (ops V4F4:$dst, V4F4:$src),
1728                 "ucomiss {$src, $dst|$dst, $src}", []>, TB;
1729 def UCOMISSrm: I<0x2E, MRMSrcMem, (ops V4F4:$dst, f32mem:$src),
1730                 "ucomiss {$src, $dst|$dst, $src}", []>, TB;
1731
1732 // Pseudo-instructions that map fld0 to xorps/xorpd for sse.
1733 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1734 def FLD0SS : I<0x57, MRMSrcReg, (ops V4F4:$dst),
1735                 "xorps $dst, $dst", []>, TB;
1736 def FLD0SD : I<0x57, MRMSrcReg, (ops V2F8:$dst),
1737                 "xorpd $dst, $dst", []>, TB, OpSize;
1738
1739 let isTwoAddress = 1 in {
1740 let isCommutable = 1 in {
1741 def ADDSSrr : I<0x58, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1742                 "addss {$src2, $dst|$dst, $src2}",
1743                 [(set V4F4:$dst, (fadd V4F4:$src1, V4F4:$src2))]>, XS;
1744 def ADDSDrr : I<0x58, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1745                 "addsd {$src2, $dst|$dst, $src2}",
1746                 [(set V2F8:$dst, (fadd V2F8:$src1, V2F8:$src2))]>, XD;
1747 def ANDPSrr : I<0x54, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1748                 "andps {$src2, $dst|$dst, $src2}", []>, TB;
1749 def ANDPDrr : I<0x54, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1750                 "andpd {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
1751 def MULSSrr : I<0x59, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1752                 "mulss {$src2, $dst|$dst, $src2}",
1753                 [(set V4F4:$dst, (fmul V4F4:$src1, V4F4:$src2))]>, XS;
1754 def MULSDrr : I<0x59, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1755                 "mulsd {$src2, $dst|$dst, $src2}",
1756                 [(set V2F8:$dst, (fmul V2F8:$src1, V2F8:$src2))]>, XD;
1757 def ORPSrr : I<0x56, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1758                 "orps {$src2, $dst|$dst, $src2}", []>, TB;
1759 def ORPDrr : I<0x56, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1760                 "orpd {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
1761 def XORPSrr : I<0x57, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1762                 "xorps {$src2, $dst|$dst, $src2}", []>, TB;
1763 def XORPDrr : I<0x57, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1764                 "xorpd {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
1765 }
1766 def ANDNPSrr : I<0x55, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1767                 "andnps {$src2, $dst|$dst, $src2}", []>, TB;
1768 def ANDNPDrr : I<0x55, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1769                 "andnpd {$src2, $dst|$dst, $src2}", []>, TB, OpSize;
1770 def ADDSSrm : I<0x58, MRMSrcMem, (ops V4F4:$dst, V4F4:$src1, f32mem:$src2),
1771                 "addss {$src2, $dst|$dst, $src2}", []>, XS;
1772 def ADDSDrm : I<0x58, MRMSrcMem, (ops V2F8:$dst, V2F8:$src1, f64mem:$src2),
1773                 "addsd {$src2, $dst|$dst, $src2}", []>, XD;
1774 def MULSSrm : I<0x59, MRMSrcMem, (ops V4F4:$dst, V4F4:$src1, f32mem:$src2),
1775                 "mulss {$src2, $dst|$dst, $src2}", []>, XS;
1776 def MULSDrm : I<0x59, MRMSrcMem, (ops V2F8:$dst, V2F8:$src1, f64mem:$src2),
1777                 "mulsd {$src2, $dst|$dst, $src2}", []>, XD;
1778
1779 def DIVSSrm : I<0x5E, MRMSrcMem, (ops V4F4:$dst, V4F4:$src1, f32mem:$src2),
1780                 "divss {$src2, $dst|$dst, $src2}", []>, XS;
1781 def DIVSSrr : I<0x5E, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1782                 "divss {$src2, $dst|$dst, $src2}",
1783                 [(set V4F4:$dst, (fdiv V4F4:$src1, V4F4:$src2))]>, XS;
1784 def DIVSDrm : I<0x5E, MRMSrcMem, (ops V2F8:$dst, V2F8:$src1, f64mem:$src2),
1785                 "divsd {$src2, $dst|$dst, $src2}", []>, XD;
1786 def DIVSDrr : I<0x5E, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1787                 "divsd {$src2, $dst|$dst, $src2}",
1788                 [(set V2F8:$dst, (fdiv V2F8:$src1, V2F8:$src2))]>, XD;
1789
1790 def SUBSSrm : I<0x5C, MRMSrcMem, (ops V4F4:$dst, V4F4:$src1, f32mem:$src2),
1791                 "subss {$src2, $dst|$dst, $src2}", []>, XS;
1792 def SUBSSrr : I<0x5C, MRMSrcReg, (ops V4F4:$dst, V4F4:$src1, V4F4:$src2),
1793                 "subss {$src2, $dst|$dst, $src2}",
1794                 [(set V4F4:$dst, (fsub V4F4:$src1, V4F4:$src2))]>, XS;
1795 def SUBSDrm : I<0x5C, MRMSrcMem, (ops V2F8:$dst, V2F8:$src1, f64mem:$src2),
1796                 "subsd {$src2, $dst|$dst, $src2}", []>, XD;
1797 def SUBSDrr : I<0x5C, MRMSrcReg, (ops V2F8:$dst, V2F8:$src1, V2F8:$src2),
1798                 "subsd {$src2, $dst|$dst, $src2}",
1799                 [(set V2F8:$dst, (fsub V2F8:$src1, V2F8:$src2))]>, XD;
1800
1801 def CMPSSrr : I<0xC2, MRMSrcReg, 
1802                 (ops V4F4:$dst, V4F4:$src1, V4F4:$src, SSECC:$cc),
1803                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>, XS;
1804 def CMPSSrm : I<0xC2, MRMSrcMem, 
1805                 (ops V4F4:$dst, V4F4:$src1, f32mem:$src, SSECC:$cc),
1806                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>, XS;
1807 def CMPSDrr : I<0xC2, MRMSrcReg, 
1808                 (ops V2F8:$dst, V2F8:$src1, V2F8:$src, SSECC:$cc),
1809                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>, XD;
1810 def CMPSDrm : I<0xC2, MRMSrcMem, 
1811                 (ops V2F8:$dst, V2F8:$src1, f64mem:$src, SSECC:$cc),
1812                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>, XD;
1813 }
1814
1815 //===----------------------------------------------------------------------===//
1816 // Miscellaneous Instructions
1817 //===----------------------------------------------------------------------===//
1818
1819 def RDTSC : I<0x31, RawFrm, (ops), "rdtsc", []>, TB, Imp<[],[EAX,EDX]>;
1820
1821
1822 //===----------------------------------------------------------------------===//
1823 // Stack-based Floating point support
1824 //===----------------------------------------------------------------------===//
1825
1826 // FIXME: These need to indicate mod/ref sets for FP regs... & FP 'TOP'
1827
1828 // Floating point instruction template
1829 class FPI<bits<8> o, Format F, FPFormat fp, dag ops, string asm>
1830   : X86Inst<o, F, NoImm, ops, asm> {
1831   let FPForm = fp; let FPFormBits = FPForm.Value;
1832 }
1833
1834 // Pseudo instructions for floating point.  We use these pseudo instructions
1835 // because they can be expanded by the fp spackifier into one of many different
1836 // forms of instructions for doing these operations.  Until the stackifier runs,
1837 // we prefer to be abstract.
1838 def FpMOV : FPI<0, Pseudo, SpecialFP,
1839                 (ops RFP:$dst, RFP:$src), "">;   // f1 = fmov f2
1840 def FpADD : FPI<0, Pseudo, TwoArgFP ,
1841                 (ops RFP:$dst, RFP:$src1, RFP:$src2), "">; // f1 = fadd f2, f3
1842 def FpSUB : FPI<0, Pseudo, TwoArgFP ,
1843                 (ops RFP:$dst, RFP:$src1, RFP:$src2), "">;    // f1 = fsub f2, f3
1844 def FpMUL : FPI<0, Pseudo, TwoArgFP ,
1845                 (ops RFP:$dst, RFP:$src1, RFP:$src2), "">;    // f1 = fmul f2, f3
1846 def FpDIV : FPI<0, Pseudo, TwoArgFP ,
1847                 (ops RFP:$dst, RFP:$src1, RFP:$src2), "">;    // f1 = fdiv f2, f3
1848
1849 def FpGETRESULT : FPI<0, Pseudo, SpecialFP, (ops RFP:$dst), "">,
1850                   Imp<[ST0], []>;  // FPR = ST(0)
1851
1852 def FpSETRESULT : FPI<0, Pseudo, SpecialFP, (ops RFP:$src), "">,
1853                   Imp<[], [ST0]>;  // ST(0) = FPR
1854
1855 // FADD reg, mem: Before stackification, these are represented by:
1856 // R1 = FADD* R2, [mem]
1857 def FADD32m  : FPI<0xD8, MRM0m, OneArgFPRW,    // ST(0) = ST(0) + [mem32real]
1858                    (ops f32mem:$src, variable_ops),
1859                    "fadd{s} $src">;
1860 def FADD64m  : FPI<0xDC, MRM0m, OneArgFPRW,    // ST(0) = ST(0) + [mem64real]
1861                    (ops f64mem:$src, variable_ops),
1862                    "fadd{l} $src">;
1863 //def FIADD16m : FPI<0xDE, MRM0m, OneArgFPRW>;    // ST(0) = ST(0) + [mem16int]
1864 //def FIADD32m : FPI<0xDA, MRM0m, OneArgFPRW>;    // ST(0) = ST(0) + [mem32int]
1865
1866 // FMUL reg, mem: Before stackification, these are represented by:
1867 // R1 = FMUL* R2, [mem]
1868 def FMUL32m  : FPI<0xD8, MRM1m, OneArgFPRW,    // ST(0) = ST(0) * [mem32real]
1869                    (ops f32mem:$src, variable_ops),
1870                    "fmul{s} $src">;
1871 def FMUL64m  : FPI<0xDC, MRM1m, OneArgFPRW,    // ST(0) = ST(0) * [mem64real]
1872                    (ops f64mem:$src, variable_ops),
1873                    "fmul{l} $src">;
1874 // ST(0) = ST(0) * [mem16int]
1875 //def FIMUL16m : FPI16m<"fimul", 0xDE, MRM1m, OneArgFPRW>;
1876 // ST(0) = ST(0) * [mem32int]
1877 //def FIMUL32m : FPI32m<"fimul", 0xDA, MRM1m, OneArgFPRW>;
1878
1879 // FSUB reg, mem: Before stackification, these are represented by:
1880 // R1 = FSUB* R2, [mem]
1881 def FSUB32m  : FPI<0xD8, MRM4m, OneArgFPRW,    // ST(0) = ST(0) - [mem32real]
1882                    (ops f32mem:$src, variable_ops),
1883                    "fsub{s} $src">;
1884 def FSUB64m  : FPI<0xDC, MRM4m, OneArgFPRW,    // ST(0) = ST(0) - [mem64real]
1885                    (ops f64mem:$src, variable_ops),
1886                    "fsub{l} $src">;
1887 // ST(0) = ST(0) - [mem16int]
1888 //def FISUB16m : FPI16m<"fisub", 0xDE, MRM4m, OneArgFPRW>;
1889 // ST(0) = ST(0) - [mem32int]
1890 //def FISUB32m : FPI32m<"fisub", 0xDA, MRM4m, OneArgFPRW>;
1891
1892 // FSUBR reg, mem: Before stackification, these are represented by:
1893 // R1 = FSUBR* R2, [mem]
1894
1895 // Note that the order of operands does not reflect the operation being
1896 // performed.
1897 def FSUBR32m  : FPI<0xD8, MRM5m, OneArgFPRW,  // ST(0) = [mem32real] - ST(0)
1898                     (ops f32mem:$src, variable_ops),
1899                     "fsubr{s} $src">;
1900 def FSUBR64m  : FPI<0xDC, MRM5m, OneArgFPRW,  // ST(0) = [mem64real] - ST(0)
1901                     (ops f64mem:$src, variable_ops),
1902                     "fsubr{l} $src">;
1903 // ST(0) = [mem16int] - ST(0)
1904 //def FISUBR16m : FPI16m<"fisubr", 0xDE, MRM5m, OneArgFPRW>;
1905 // ST(0) = [mem32int] - ST(0)
1906 //def FISUBR32m : FPI32m<"fisubr", 0xDA, MRM5m, OneArgFPRW>;
1907
1908 // FDIV reg, mem: Before stackification, these are represented by:
1909 // R1 = FDIV* R2, [mem]
1910 def FDIV32m  : FPI<0xD8, MRM6m, OneArgFPRW,    // ST(0) = ST(0) / [mem32real]
1911                    (ops f32mem:$src, variable_ops),
1912                    "fdiv{s} $src">;
1913 def FDIV64m  : FPI<0xDC, MRM6m, OneArgFPRW,    // ST(0) = ST(0) / [mem64real]
1914                    (ops f64mem:$src, variable_ops),
1915                    "fdiv{l} $src">;
1916 // ST(0) = ST(0) / [mem16int]
1917 //def FIDIV16m : FPI16m<"fidiv", 0xDE, MRM6m, OneArgFPRW>;
1918 // ST(0) = ST(0) / [mem32int]
1919 //def FIDIV32m : FPI32m<"fidiv", 0xDA, MRM6m, OneArgFPRW>;
1920
1921 // FDIVR reg, mem: Before stackification, these are represented by:
1922 // R1 = FDIVR* R2, [mem]
1923 // Note that the order of operands does not reflect the operation being
1924 // performed.
1925 def FDIVR32m  : FPI<0xD8, MRM7m, OneArgFPRW,  // ST(0) = [mem32real] / ST(0)
1926                     (ops f32mem:$src, variable_ops),
1927                     "fdivr{s} $src">;
1928 def FDIVR64m  : FPI<0xDC, MRM7m, OneArgFPRW,  // ST(0) = [mem64real] / ST(0)
1929                     (ops f64mem:$src, variable_ops),
1930                     "fdivr{l} $src">;
1931 // ST(0) = [mem16int] / ST(0)
1932 //def FIDIVR16m : FPI16m<"fidivr", 0xDE, MRM7m, OneArgFPRW>;
1933 // ST(0) = [mem32int] / ST(0)
1934 //def FIDIVR32m : FPI32m<"fidivr", 0xDA, MRM7m, OneArgFPRW>;
1935
1936
1937 // Floating point cmovs...
1938 let isTwoAddress = 1, Uses = [ST0], Defs = [ST0] in {
1939   def FCMOVB  : FPI<0xC0, AddRegFrm, CondMovFP,
1940                     (ops RST:$op, variable_ops),
1941                     "fcmovb {$op, %ST(0)|%ST(0), $op}">, DA;
1942   def FCMOVBE : FPI<0xD0, AddRegFrm, CondMovFP,
1943                     (ops RST:$op, variable_ops),
1944                     "fcmovbe {$op, %ST(0)|%ST(0), $op}">, DA;
1945   def FCMOVE  : FPI<0xC8, AddRegFrm, CondMovFP,
1946                     (ops RST:$op, variable_ops),
1947                     "fcmove {$op, %ST(0)|%ST(0), $op}">, DA;
1948   def FCMOVP  : FPI<0xD8, AddRegFrm, CondMovFP,
1949                     (ops RST:$op, variable_ops),
1950                     "fcmovu  {$op, %ST(0)|%ST(0), $op}">, DA;
1951   def FCMOVAE : FPI<0xC0, AddRegFrm, CondMovFP,
1952                     (ops RST:$op, variable_ops),
1953                     "fcmovae {$op, %ST(0)|%ST(0), $op}">, DB;
1954   def FCMOVA  : FPI<0xD0, AddRegFrm, CondMovFP,
1955                     (ops RST:$op, variable_ops),
1956                     "fcmova {$op, %ST(0)|%ST(0), $op}">, DB;
1957   def FCMOVNE : FPI<0xC8, AddRegFrm, CondMovFP,
1958                     (ops RST:$op, variable_ops),
1959                     "fcmovne {$op, %ST(0)|%ST(0), $op}">, DB;
1960   def FCMOVNP : FPI<0xD8, AddRegFrm, CondMovFP,
1961                     (ops RST:$op, variable_ops),
1962                     "fcmovnu {$op, %ST(0)|%ST(0), $op}">, DB;
1963 }
1964
1965 // Floating point loads & stores...
1966 // FIXME: these are all marked variable_ops because they have an implicit 
1967 // destination.  Instructions like FILD* that are generated by the instruction
1968 //  selector (not the fp stackifier) need more accurate operand accounting.
1969 def FLDrr   : FPI<0xC0, AddRegFrm, NotFP,
1970                   (ops RST:$src, variable_ops),
1971                   "fld $src">, D9;
1972 def FLD32m  : FPI<0xD9, MRM0m, ZeroArgFP,
1973                   (ops f32mem:$src, variable_ops),
1974                   "fld{s} $src">;
1975 def FLD64m  : FPI<0xDD, MRM0m, ZeroArgFP,
1976                   (ops f64mem:$src, variable_ops),
1977                   "fld{l} $src">;
1978 def FLD80m  : FPI<0xDB, MRM5m, ZeroArgFP,
1979                   (ops f80mem:$src, variable_ops),
1980                   "fld{t} $src">;
1981 def FILD16m : FPI<0xDF, MRM0m, ZeroArgFP,
1982                   (ops i16mem:$src, variable_ops),
1983                   "fild{s} $src">;
1984 def FILD32m : FPI<0xDB, MRM0m, ZeroArgFP,
1985                   (ops i32mem:$src, variable_ops),
1986                   "fild{l} $src">;
1987 def FILD64m : FPI<0xDF, MRM5m, ZeroArgFP,
1988                   (ops i64mem:$src, variable_ops),
1989                   "fild{ll} $src">;
1990
1991 def FSTrr    : FPI<0xD0, AddRegFrm, NotFP,
1992                    (ops RST:$op, variable_ops),
1993                    "fst $op">, DD;
1994 def FSTPrr   : FPI<0xD8, AddRegFrm, NotFP,
1995                    (ops RST:$op, variable_ops),
1996                    "fstp $op">, DD;
1997 def FST32m   : FPI<0xD9, MRM2m, OneArgFP,
1998                    (ops f32mem:$op, variable_ops),
1999                    "fst{s} $op">;
2000 def FST64m   : FPI<0xDD, MRM2m, OneArgFP,
2001                    (ops f64mem:$op, variable_ops),
2002                    "fst{l} $op">;
2003 def FSTP32m  : FPI<0xD9, MRM3m, OneArgFP,
2004                    (ops f32mem:$op, variable_ops),
2005                    "fstp{s} $op">;
2006 def FSTP64m  : FPI<0xDD, MRM3m, OneArgFP,
2007                    (ops f64mem:$op, variable_ops),
2008                    "fstp{l} $op">;
2009 def FSTP80m  : FPI<0xDB, MRM7m, OneArgFP,
2010                    (ops f80mem:$op, variable_ops),
2011                    "fstp{t} $op">;
2012
2013 def FIST16m  : FPI<0xDF, MRM2m , OneArgFP,
2014                    (ops i16mem:$op, variable_ops),
2015                    "fist{s} $op">;
2016 def FIST32m  : FPI<0xDB, MRM2m , OneArgFP,
2017                    (ops i32mem:$op, variable_ops),
2018                    "fist{l} $op">;
2019 def FISTP16m : FPI<0xDF, MRM3m , NotFP   ,
2020                    (ops i16mem:$op, variable_ops),
2021                    "fistp{s} $op">;
2022 def FISTP32m : FPI<0xDB, MRM3m , NotFP   ,
2023                    (ops i32mem:$op, variable_ops),
2024                    "fistp{l} $op">;
2025 def FISTP64m : FPI<0xDF, MRM7m , OneArgFP,
2026                    (ops i64mem:$op, variable_ops),
2027                    "fistp{ll} $op">;
2028
2029 def FXCH     : FPI<0xC8, AddRegFrm, NotFP,
2030                    (ops RST:$op), "fxch $op">, D9;      // fxch ST(i), ST(0)
2031
2032 // Floating point constant loads...
2033 def FLD0 : FPI<0xEE, RawFrm, ZeroArgFP, (ops variable_ops), "fldz">, D9;
2034 def FLD1 : FPI<0xE8, RawFrm, ZeroArgFP, (ops variable_ops), "fld1">, D9;
2035
2036
2037 // Unary operations...
2038 def FCHS  : FPI<0xE0, RawFrm, OneArgFPRW,   // f1 = fchs f2
2039                 (ops variable_ops),
2040                 "fchs">, D9;
2041 def FABS  : FPI<0xE1, RawFrm, OneArgFPRW,   // f1 = fabs f2
2042                 (ops variable_ops),
2043                 "fabs">, D9;
2044 def FSQRT : FPI<0xFA, RawFrm, OneArgFPRW,   // fsqrt ST(0)
2045                 (ops variable_ops),
2046                 "fsqrt">, D9;
2047 def FSIN  : FPI<0xFE, RawFrm, OneArgFPRW,   // fsin  ST(0)
2048                 (ops variable_ops),
2049                 "fsin">, D9;
2050 def FCOS  : FPI<0xFF, RawFrm, OneArgFPRW,   // fcos  ST(0)
2051                 (ops variable_ops),
2052                 "fcos">, D9;
2053 def FTST  : FPI<0xE4, RawFrm, OneArgFP  ,   // ftst ST(0)
2054                 (ops variable_ops),
2055                 "ftst">, D9;
2056
2057 // Binary arithmetic operations...
2058 class FPST0rInst<bits<8> o, dag ops, string asm>
2059   : I<o, AddRegFrm, ops, asm, []>, D8 {
2060   list<Register> Uses = [ST0];
2061   list<Register> Defs = [ST0];
2062 }
2063 class FPrST0Inst<bits<8> o, dag ops, string asm>
2064   : I<o, AddRegFrm, ops, asm, []>, DC {
2065   list<Register> Uses = [ST0];
2066 }
2067 class FPrST0PInst<bits<8> o, dag ops, string asm>
2068   : I<o, AddRegFrm, ops, asm, []>, DE {
2069   list<Register> Uses = [ST0];
2070 }
2071
2072 def FADDST0r   : FPST0rInst <0xC0, (ops RST:$op),
2073                              "fadd $op">;
2074 def FADDrST0   : FPrST0Inst <0xC0, (ops RST:$op),
2075                              "fadd {%ST(0), $op|$op, %ST(0)}">;
2076 def FADDPrST0  : FPrST0PInst<0xC0, (ops RST:$op),
2077                              "faddp $op">;
2078
2079 // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
2080 // of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
2081 // we have to put some 'r's in and take them out of weird places.
2082 def FSUBRST0r  : FPST0rInst <0xE8, (ops RST:$op),
2083                              "fsubr $op">;
2084 def FSUBrST0   : FPrST0Inst <0xE8, (ops RST:$op),
2085                              "fsub{r} {%ST(0), $op|$op, %ST(0)}">;
2086 def FSUBPrST0  : FPrST0PInst<0xE8, (ops RST:$op),
2087                              "fsub{r}p $op">;
2088
2089 def FSUBST0r   : FPST0rInst <0xE0, (ops RST:$op),
2090                              "fsub $op">;
2091 def FSUBRrST0  : FPrST0Inst <0xE0, (ops RST:$op),
2092                              "fsub{|r} {%ST(0), $op|$op, %ST(0)}">;
2093 def FSUBRPrST0 : FPrST0PInst<0xE0, (ops RST:$op),
2094                              "fsub{|r}p $op">;
2095
2096 def FMULST0r   : FPST0rInst <0xC8, (ops RST:$op),
2097                              "fmul $op">;
2098 def FMULrST0   : FPrST0Inst <0xC8, (ops RST:$op),
2099                              "fmul {%ST(0), $op|$op, %ST(0)}">;
2100 def FMULPrST0  : FPrST0PInst<0xC8, (ops RST:$op),
2101                              "fmulp $op">;
2102
2103 def FDIVRST0r  : FPST0rInst <0xF8, (ops RST:$op),
2104                              "fdivr $op">;
2105 def FDIVrST0   : FPrST0Inst <0xF8, (ops RST:$op),
2106                              "fdiv{r} {%ST(0), $op|$op, %ST(0)}">;
2107 def FDIVPrST0  : FPrST0PInst<0xF8, (ops RST:$op),
2108                              "fdiv{r}p $op">;
2109
2110 def FDIVST0r   : FPST0rInst <0xF0, (ops RST:$op),  // ST(0) = ST(0) / ST(i)
2111                              "fdiv $op">;
2112 def FDIVRrST0  : FPrST0Inst <0xF0, (ops RST:$op),  // ST(i) = ST(0) / ST(i)
2113                              "fdiv{|r} {%ST(0), $op|$op, %ST(0)}">;
2114 def FDIVRPrST0 : FPrST0PInst<0xF0, (ops RST:$op),  // ST(i) = ST(0) / ST(i), pop
2115                              "fdiv{|r}p $op">;
2116
2117 // Floating point compares
2118 def FUCOMr    : FPI<0xE0, AddRegFrm, CompareFP,   // FPSW = cmp ST(0) with ST(i)
2119                     (ops RST:$reg, variable_ops),
2120                     "fucom $reg">, DD, Imp<[ST0],[]>;
2121 def FUCOMPr   : I<0xE8, AddRegFrm,           // FPSW = cmp ST(0) with ST(i), pop
2122                   (ops RST:$reg, variable_ops),
2123                   "fucomp $reg", []>, DD, Imp<[ST0],[]>;
2124 def FUCOMPPr  : I<0xE9, RawFrm,                // cmp ST(0) with ST(1), pop, pop
2125                   (ops variable_ops),
2126                   "fucompp", []>, DA, Imp<[ST0],[]>;
2127
2128 def FUCOMIr  : FPI<0xE8, AddRegFrm, CompareFP,  // CC = cmp ST(0) with ST(i)
2129                    (ops RST:$reg, variable_ops),
2130                    "fucomi {$reg, %ST(0)|%ST(0), $reg}">, DB, Imp<[ST0],[]>;
2131 def FUCOMIPr : I<0xE8, AddRegFrm,              // CC = cmp ST(0) with ST(i), pop
2132                  (ops RST:$reg, variable_ops),
2133                  "fucomip {$reg, %ST(0)|%ST(0), $reg}", []>, DF, Imp<[ST0],[]>;
2134
2135
2136 // Floating point flag ops
2137 def FNSTSW8r  : I<0xE0, RawFrm,                  // AX = fp flags
2138                   (ops), "fnstsw", []>, DF, Imp<[],[AX]>;
2139
2140 def FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
2141                   (ops i16mem:$dst), "fnstcw $dst", []>;
2142 def FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
2143                   (ops i16mem:$dst), "fldcw $dst", []>;