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