blob: 16930b42519617a083e53127881b9937bed68db1 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//====- X86InstrX86-64.td - Describe the X86 Instruction Set ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the Evan Cheng 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-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
17// Operand Definitions...
18//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
22// 64-bits but only 8 bits are significant.
23def i64i8imm : Operand<i64>;
24
25def lea64mem : Operand<i64> {
26 let PrintMethod = "printi64mem";
27 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
28}
29
30def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
33}
34
35//===----------------------------------------------------------------------===//
36// Complex Pattern Definitions...
37//
38def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
39 [add, mul, shl, or, frameindex, X86Wrapper],
40 []>;
41
42//===----------------------------------------------------------------------===//
43// Instruction templates...
44//
45
Evan Chengb783fa32007-07-19 01:14:50 +000046class RI<bits<8> o, Format F, dag outs, dag ins, string asm, list<dag> pattern>
47 : I<o, F, outs, ins, asm, pattern>, REX_W;
48class RIi8 <bits<8> o, Format F, dag outs, dag ins, string asm,
49 list<dag> pattern>
50 : Ii8<o, F, outs, ins, asm, pattern>, REX_W;
51class RIi32 <bits<8> o, Format F, dag outs, dag ins, string asm,
52 list<dag> pattern>
53 : Ii32<o, F, outs, ins, asm, pattern>, REX_W;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Evan Chengb783fa32007-07-19 01:14:50 +000055class RIi64<bits<8> o, Format f, dag outs, dag ins, string asm,
56 list<dag> pattern>
57 : X86Inst<o, f, Imm64, outs, ins, asm>, REX_W {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 let Pattern = pattern;
59 let CodeSize = 3;
60}
61
Evan Chengb783fa32007-07-19 01:14:50 +000062class RSSI<bits<8> o, Format F, dag outs, dag ins, string asm,
63 list<dag> pattern>
64 : SSI<o, F, outs, ins, asm, pattern>, REX_W;
65class RSDI<bits<8> o, Format F, dag outs, dag ins, string asm,
66 list<dag> pattern>
67 : SDI<o, F, outs, ins, asm, pattern>, REX_W;
68class RPDI<bits<8> o, Format F, dag outs, dag ins, string asm,
69 list<dag> pattern>
70 : PDI<o, F, outs, ins, asm, pattern>, REX_W;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071
72//===----------------------------------------------------------------------===//
73// Pattern fragments...
74//
75
76def i64immSExt32 : PatLeaf<(i64 imm), [{
77 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
78 // sign extended field.
79 return (int64_t)N->getValue() == (int32_t)N->getValue();
80}]>;
81
82def i64immZExt32 : PatLeaf<(i64 imm), [{
83 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
84 // unsignedsign extended field.
85 return (uint64_t)N->getValue() == (uint32_t)N->getValue();
86}]>;
87
88def i64immSExt8 : PatLeaf<(i64 imm), [{
89 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
90 // sign extended field.
91 return (int64_t)N->getValue() == (int8_t)N->getValue();
92}]>;
93
94def sextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (sextloadi1 node:$ptr))>;
95def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
96def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
97def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
98
99def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
100def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
101def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
102def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
103
104def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
105def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
106def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
107def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
108
109//===----------------------------------------------------------------------===//
110// Instruction list...
111//
112
Evan Chengb783fa32007-07-19 01:14:50 +0000113def IMPLICIT_DEF_GR64 : I<0, Pseudo, (outs GR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114 "#IMPLICIT_DEF $dst",
115 [(set GR64:$dst, (undef))]>;
116
117//===----------------------------------------------------------------------===//
118// Call Instructions...
119//
Evan Cheng37e7c752007-07-21 00:34:19 +0000120let isCall = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000121 // All calls clobber the non-callee saved registers...
122 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
123 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
124 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
125 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
126 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000127 def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000128 "call ${dst:call}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000129 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000130 "call {*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000131 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132 "call {*}$dst", []>;
133 }
134
135// Branches
Evan Cheng37e7c752007-07-21 00:34:19 +0000136let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000137 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q} {*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000138 [(brind GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000139 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q} {*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 [(brind (loadi64 addr:$dst))]>;
141}
142
143//===----------------------------------------------------------------------===//
144// Miscellaneous Instructions...
145//
146def LEAVE64 : I<0xC9, RawFrm,
Evan Chengb783fa32007-07-19 01:14:50 +0000147 (outs), (ins), "leave", []>, Imp<[RBP,RSP],[RBP,RSP]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148def POP64r : I<0x58, AddRegFrm,
Evan Chengb783fa32007-07-19 01:14:50 +0000149 (outs GR64:$reg), (ins), "pop{q} $reg", []>, Imp<[RSP],[RSP]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150def PUSH64r : I<0x50, AddRegFrm,
Evan Chengb783fa32007-07-19 01:14:50 +0000151 (outs), (ins GR64:$reg), "push{q} $reg", []>, Imp<[RSP],[RSP]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000152
153def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000154 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 "lea{l} {$src|$dst}, {$dst|$src}",
156 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
157
Evan Chengb783fa32007-07-19 01:14:50 +0000158def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159 "lea{q} {$src|$dst}, {$dst|$src}",
160 [(set GR64:$dst, lea64addr:$src)]>;
161
162let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000163def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164 "bswap{q} $dst",
165 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
166// Exchange
Evan Chengb783fa32007-07-19 01:14:50 +0000167def XCHG64rr : RI<0x87, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168 "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000169def XCHG64mr : RI<0x87, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170 "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000171def XCHG64rm : RI<0x87, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172 "xchg{q} {$src2|$src1}, {$src1|$src2}", []>;
173
174// Repeat string ops
Evan Chengb783fa32007-07-19 01:14:50 +0000175def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 [(X86rep_movs i64)]>,
177 Imp<[RCX,RDI,RSI], [RCX,RDI,RSI]>, REP;
Evan Chengb783fa32007-07-19 01:14:50 +0000178def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 [(X86rep_stos i64)]>,
180 Imp<[RAX,RCX,RDI], [RCX,RDI]>, REP;
181
182//===----------------------------------------------------------------------===//
183// Move Instructions...
184//
185
Evan Chengb783fa32007-07-19 01:14:50 +0000186def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 "mov{q} {$src, $dst|$dst, $src}", []>;
188
Evan Chengb783fa32007-07-19 01:14:50 +0000189def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190 "movabs{q} {$src, $dst|$dst, $src}",
191 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000192def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 "mov{q} {$src, $dst|$dst, $src}",
194 [(set GR64:$dst, i64immSExt32:$src)]>;
195
Evan Chengb783fa32007-07-19 01:14:50 +0000196def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197 "mov{q} {$src, $dst|$dst, $src}",
198 [(set GR64:$dst, (load addr:$src))]>;
199
Evan Chengb783fa32007-07-19 01:14:50 +0000200def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 "mov{q} {$src, $dst|$dst, $src}",
202 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000203def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204 "mov{q} {$src, $dst|$dst, $src}",
205 [(store i64immSExt32:$src, addr:$dst)]>;
206
207// Sign/Zero extenders
208
Evan Chengb783fa32007-07-19 01:14:50 +0000209def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210 "movs{bq|x} {$src, $dst|$dst, $src}",
211 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000212def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 "movs{bq|x} {$src, $dst|$dst, $src}",
214 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000215def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 "movs{wq|x} {$src, $dst|$dst, $src}",
217 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000218def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219 "movs{wq|x} {$src, $dst|$dst, $src}",
220 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000221def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222 "movs{lq|xd} {$src, $dst|$dst, $src}",
223 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000224def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225 "movs{lq|xd} {$src, $dst|$dst, $src}",
226 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
227
Evan Chengb783fa32007-07-19 01:14:50 +0000228def MOVZX64rr8 : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 "movz{bq|x} {$src, $dst|$dst, $src}",
230 [(set GR64:$dst, (zext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000231def MOVZX64rm8 : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 "movz{bq|x} {$src, $dst|$dst, $src}",
233 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000234def MOVZX64rr16: RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235 "movz{wq|x} {$src, $dst|$dst, $src}",
236 [(set GR64:$dst, (zext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000237def MOVZX64rm16: RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 "movz{wq|x} {$src, $dst|$dst, $src}",
239 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
240
Evan Chengb783fa32007-07-19 01:14:50 +0000241def CDQE : RI<0x98, RawFrm, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 "{cltq|cdqe}", []>, Imp<[EAX],[RAX]>; // RAX = signext(EAX)
243
Evan Chengb783fa32007-07-19 01:14:50 +0000244def CQO : RI<0x99, RawFrm, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 "{cqto|cqo}", []>, Imp<[RAX],[RAX,RDX]>; // RDX:RAX = signext(RAX)
246
247//===----------------------------------------------------------------------===//
248// Arithmetic Instructions...
249//
250
251let isTwoAddress = 1 in {
252let isConvertibleToThreeAddress = 1 in {
253let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000254def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255 "add{q} {$src2, $dst|$dst, $src2}",
256 [(set GR64:$dst, (add GR64:$src1, GR64:$src2))]>;
257
Evan Chengb783fa32007-07-19 01:14:50 +0000258def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 "add{q} {$src2, $dst|$dst, $src2}",
260 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 "add{q} {$src2, $dst|$dst, $src2}",
263 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2))]>;
264} // isConvertibleToThreeAddress
265
Evan Chengb783fa32007-07-19 01:14:50 +0000266def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 "add{q} {$src2, $dst|$dst, $src2}",
268 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2)))]>;
269} // isTwoAddress
270
Evan Chengb783fa32007-07-19 01:14:50 +0000271def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272 "add{q} {$src2, $dst|$dst, $src2}",
273 [(store (add (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000274def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 "add{q} {$src2, $dst|$dst, $src2}",
276 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000277def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278 "add{q} {$src2, $dst|$dst, $src2}",
279 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
280
281let isTwoAddress = 1 in {
282let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000283def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 "adc{q} {$src2, $dst|$dst, $src2}",
285 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
286
Evan Chengb783fa32007-07-19 01:14:50 +0000287def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 "adc{q} {$src2, $dst|$dst, $src2}",
289 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
290
Evan Chengb783fa32007-07-19 01:14:50 +0000291def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "adc{q} {$src2, $dst|$dst, $src2}",
293 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000294def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295 "adc{q} {$src2, $dst|$dst, $src2}",
296 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
297} // isTwoAddress
298
Evan Chengb783fa32007-07-19 01:14:50 +0000299def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 "adc{q} {$src2, $dst|$dst, $src2}",
301 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000302def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 "adc{q} {$src2, $dst|$dst, $src2}",
304 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000305def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 "adc{q} {$src2, $dst|$dst, $src2}",
307 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
308
309let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000310def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 "sub{q} {$src2, $dst|$dst, $src2}",
312 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2))]>;
313
Evan Chengb783fa32007-07-19 01:14:50 +0000314def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 "sub{q} {$src2, $dst|$dst, $src2}",
316 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2)))]>;
317
Evan Chengb783fa32007-07-19 01:14:50 +0000318def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319 "sub{q} {$src2, $dst|$dst, $src2}",
320 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000321def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 "sub{q} {$src2, $dst|$dst, $src2}",
323 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2))]>;
324} // isTwoAddress
325
Evan Chengb783fa32007-07-19 01:14:50 +0000326def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327 "sub{q} {$src2, $dst|$dst, $src2}",
328 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 "sub{q} {$src2, $dst|$dst, $src2}",
331 [(store (sub (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000332def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333 "sub{q} {$src2, $dst|$dst, $src2}",
334 [(store (sub (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
335
336let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000337def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 "sbb{q} {$src2, $dst|$dst, $src2}",
339 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
340
Evan Chengb783fa32007-07-19 01:14:50 +0000341def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 "sbb{q} {$src2, $dst|$dst, $src2}",
343 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
344
Evan Chengb783fa32007-07-19 01:14:50 +0000345def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 "sbb{q} {$src2, $dst|$dst, $src2}",
347 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000348def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 "sbb{q} {$src2, $dst|$dst, $src2}",
350 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
351} // isTwoAddress
352
Evan Chengb783fa32007-07-19 01:14:50 +0000353def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 "sbb{q} {$src2, $dst|$dst, $src2}",
355 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000356def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 "sbb{q} {$src2, $dst|$dst, $src2}",
358 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000359def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 "sbb{q} {$src2, $dst|$dst, $src2}",
361 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
362
363// Unsigned multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000364def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000365 "mul{q} $src", []>,
366 Imp<[RAX],[RAX,RDX]>; // RAX,RDX = RAX*GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000367def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368 "mul{q} $src", []>,
369 Imp<[RAX],[RAX,RDX]>; // RAX,RDX = RAX*[mem64]
370
371// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000372def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373 "imul{q} $src", []>,
374 Imp<[RAX],[RAX,RDX]>; // RAX,RDX = RAX*GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000375def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376 "imul{q} $src", []>,
377 Imp<[RAX],[RAX,RDX]>; // RAX,RDX = RAX*[mem64]
378
379let isTwoAddress = 1 in {
380let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000381def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 "imul{q} {$src2, $dst|$dst, $src2}",
383 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2))]>, TB;
384
Evan Chengb783fa32007-07-19 01:14:50 +0000385def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386 "imul{q} {$src2, $dst|$dst, $src2}",
387 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2)))]>, TB;
388} // isTwoAddress
389
390// Suprisingly enough, these are not two address instructions!
391def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000392 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
394 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2))]>;
395def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000396 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
398 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2))]>;
399def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000400 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
402 [(set GR64:$dst, (mul (load addr:$src1), i64immSExt32:$src2))]>;
403def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000404 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405 "imul{q} {$src2, $src1, $dst|$dst, $src1, $src2}",
406 [(set GR64:$dst, (mul (load addr:$src1), i64immSExt8:$src2))]>;
407
408// Unsigned division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000409def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 "div{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000411def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000412 "div{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
413
414// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000415def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 "idiv{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000417def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418 "idiv{q} $src", []>, Imp<[RAX,RDX],[RAX,RDX]>;
419
420// Unary instructions
421let CodeSize = 2 in {
422let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000423def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000424 [(set GR64:$dst, (ineg GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000425def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
427
428let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000429def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000430 [(set GR64:$dst, (add GR64:$src, 1))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000431def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
433
434let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000435def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436 [(set GR64:$dst, (add GR64:$src, -1))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000437def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
439
440// In 64-bit mode, single byte INC and DEC cannot be encoded.
441let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
442// Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000443def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 [(set GR16:$dst, (add GR16:$src, 1))]>,
445 OpSize, Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000446def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 [(set GR32:$dst, (add GR32:$src, 1))]>,
448 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000449def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450 [(set GR16:$dst, (add GR16:$src, -1))]>,
451 OpSize, Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000452def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453 [(set GR32:$dst, (add GR32:$src, -1))]>,
454 Requires<[In64BitMode]>;
455} // isConvertibleToThreeAddress
456} // CodeSize
457
458
459// Shift instructions
460let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000461def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462 "shl{q} {%cl, $dst|$dst, %CL}",
463 [(set GR64:$dst, (shl GR64:$src, CL))]>,
464 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000465def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466 "shl{q} {$src2, $dst|$dst, $src2}",
467 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000468def SHL64r1 : RI<0xD1, MRM4r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469 "shl{q} $dst", []>;
470} // isTwoAddress
471
Evan Chengb783fa32007-07-19 01:14:50 +0000472def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 "shl{q} {%cl, $dst|$dst, %CL}",
474 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>,
475 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000476def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 "shl{q} {$src, $dst|$dst, $src}",
478 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000479def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480 "shl{q} $dst",
481 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
482
483let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000484def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485 "shr{q} {%cl, $dst|$dst, %CL}",
486 [(set GR64:$dst, (srl GR64:$src, CL))]>,
487 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000488def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489 "shr{q} {$src2, $dst|$dst, $src2}",
490 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000491def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492 "shr{q} $dst",
493 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
494} // isTwoAddress
495
Evan Chengb783fa32007-07-19 01:14:50 +0000496def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497 "shr{q} {%cl, $dst|$dst, %CL}",
498 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>,
499 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000500def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000501 "shr{q} {$src, $dst|$dst, $src}",
502 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000503def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 "shr{q} $dst",
505 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
506
507let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000508def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509 "sar{q} {%cl, $dst|$dst, %CL}",
510 [(set GR64:$dst, (sra GR64:$src, CL))]>, Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000511def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 "sar{q} {$src2, $dst|$dst, $src2}",
513 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000514def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515 "sar{q} $dst",
516 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
517} // isTwoAddress
518
Evan Chengb783fa32007-07-19 01:14:50 +0000519def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520 "sar{q} {%cl, $dst|$dst, %CL}",
521 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>,
522 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000523def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524 "sar{q} {$src, $dst|$dst, $src}",
525 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000526def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 "sar{q} $dst",
528 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
529
530// Rotate instructions
531let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000532def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533 "rol{q} {%cl, $dst|$dst, %CL}",
534 [(set GR64:$dst, (rotl GR64:$src, CL))]>, Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000535def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536 "rol{q} {$src2, $dst|$dst, $src2}",
537 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000538def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539 "rol{q} $dst",
540 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
541} // isTwoAddress
542
Evan Chengb783fa32007-07-19 01:14:50 +0000543def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 "rol{q} {%cl, $dst|$dst, %CL}",
545 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>,
546 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000547def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548 "rol{q} {$src, $dst|$dst, $src}",
549 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000550def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 "rol{q} $dst",
552 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
553
554let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000555def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556 "ror{q} {%cl, $dst|$dst, %CL}",
557 [(set GR64:$dst, (rotr GR64:$src, CL))]>, Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000558def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 "ror{q} {$src2, $dst|$dst, $src2}",
560 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000561def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 "ror{q} $dst",
563 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
564} // isTwoAddress
565
Evan Chengb783fa32007-07-19 01:14:50 +0000566def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567 "ror{q} {%cl, $dst|$dst, %CL}",
568 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>,
569 Imp<[CL],[]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000570def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571 "ror{q} {$src, $dst|$dst, $src}",
572 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000573def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574 "ror{q} $dst",
575 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
576
577// Double shift instructions (generalizations of rotate)
578let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000579def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580 "shld{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
581 Imp<[CL],[]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000582def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583 "shrd{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
584 Imp<[CL],[]>, TB;
585
586let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
587def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000588 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589 "shld{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
590 TB;
591def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000592 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593 "shrd{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
594 TB;
595} // isCommutable
596} // isTwoAddress
597
598// Temporary hack: there is no patterns associated with these instructions
599// so we have to tell tblgen that these do not produce results.
Evan Chengb783fa32007-07-19 01:14:50 +0000600def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 "shld{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
602 Imp<[CL],[]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000603def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604 "shrd{q} {%cl, $src2, $dst|$dst, $src2, %CL}", []>,
605 Imp<[CL],[]>, TB;
606def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000607 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608 "shld{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
609 TB;
610def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000611 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 "shrd{q} {$src3, $src2, $dst|$dst, $src2, $src3}", []>,
613 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614
615//===----------------------------------------------------------------------===//
616// Logical Instructions...
617//
618
619let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000620def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621 [(set GR64:$dst, (not GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000622def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q} $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
624
625let isTwoAddress = 1 in {
626let isCommutable = 1 in
627def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000628 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 "and{q} {$src2, $dst|$dst, $src2}",
630 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
631def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000632 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633 "and{q} {$src2, $dst|$dst, $src2}",
634 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
635def AND64ri32 : RIi32<0x81, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000636 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000637 "and{q} {$src2, $dst|$dst, $src2}",
638 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
639def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000640 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641 "and{q} {$src2, $dst|$dst, $src2}",
642 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
643} // isTwoAddress
644
645def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000646 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 "and{q} {$src, $dst|$dst, $src}",
648 [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
649def AND64mi32 : RIi32<0x81, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000650 (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 "and{q} {$src, $dst|$dst, $src}",
652 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
653def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000654 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655 "and{q} {$src, $dst|$dst, $src}",
656 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
657
658let isTwoAddress = 1 in {
659let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000660def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661 "or{q} {$src2, $dst|$dst, $src2}",
662 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000663def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664 "or{q} {$src2, $dst|$dst, $src2}",
665 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000666def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 "or{q} {$src2, $dst|$dst, $src2}",
668 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000669def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670 "or{q} {$src2, $dst|$dst, $src2}",
671 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
672} // isTwoAddress
673
Evan Chengb783fa32007-07-19 01:14:50 +0000674def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000675 "or{q} {$src, $dst|$dst, $src}",
676 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000677def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 "or{q} {$src, $dst|$dst, $src}",
679 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000680def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681 "or{q} {$src, $dst|$dst, $src}",
682 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
683
684let isTwoAddress = 1 in {
685let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000686def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000687 "xor{q} {$src2, $dst|$dst, $src2}",
688 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000689def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 "xor{q} {$src2, $dst|$dst, $src2}",
691 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
692def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000693 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 "xor{q} {$src2, $dst|$dst, $src2}",
695 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000696def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697 "xor{q} {$src2, $dst|$dst, $src2}",
698 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
699} // isTwoAddress
700
Evan Chengb783fa32007-07-19 01:14:50 +0000701def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 "xor{q} {$src, $dst|$dst, $src}",
703 [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000704def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000705 "xor{q} {$src, $dst|$dst, $src}",
706 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000707def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708 "xor{q} {$src, $dst|$dst, $src}",
709 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
710
711//===----------------------------------------------------------------------===//
712// Comparison Instructions...
713//
714
715// Integer comparison
716let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000717def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718 "test{q} {$src2, $src1|$src1, $src2}",
719 [(X86cmp (and GR64:$src1, GR64:$src2), 0)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000720def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721 "test{q} {$src2, $src1|$src1, $src2}",
722 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000723def TEST64ri32 : RIi32<0xF7, MRM0r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 "test{q} {$src2, $src1|$src1, $src2}",
725 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000726def TEST64mi32 : RIi32<0xF7, MRM0m, (outs), (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 "test{q} {$src2, $src1|$src1, $src2}",
728 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0)]>;
729
Evan Chengb783fa32007-07-19 01:14:50 +0000730def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000731 "cmp{q} {$src2, $src1|$src1, $src2}",
732 [(X86cmp GR64:$src1, GR64:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000733def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 "cmp{q} {$src2, $src1|$src1, $src2}",
735 [(X86cmp (loadi64 addr:$src1), GR64:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000736def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 "cmp{q} {$src2, $src1|$src1, $src2}",
738 [(X86cmp GR64:$src1, (loadi64 addr:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000739def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000740 "cmp{q} {$src2, $src1|$src1, $src2}",
741 [(X86cmp GR64:$src1, i64immSExt32:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000742def CMP64mi32 : RIi32<0x81, MRM7m, (outs), (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000743 "cmp{q} {$src2, $src1|$src1, $src2}",
744 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000745def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 "cmp{q} {$src2, $src1|$src1, $src2}",
747 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000748def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 "cmp{q} {$src2, $src1|$src1, $src2}",
750 [(X86cmp GR64:$src1, i64immSExt8:$src2)]>;
751
752// Conditional moves
753let isTwoAddress = 1 in {
754def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000755 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 "cmovb {$src2, $dst|$dst, $src2}",
757 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
758 X86_COND_B))]>, TB;
759def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000760 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 "cmovb {$src2, $dst|$dst, $src2}",
762 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
763 X86_COND_B))]>, TB;
764def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000765 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000766 "cmovae {$src2, $dst|$dst, $src2}",
767 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
768 X86_COND_AE))]>, TB;
769def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000770 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 "cmovae {$src2, $dst|$dst, $src2}",
772 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
773 X86_COND_AE))]>, TB;
774def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000775 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776 "cmove {$src2, $dst|$dst, $src2}",
777 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
778 X86_COND_E))]>, TB;
779def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000780 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 "cmove {$src2, $dst|$dst, $src2}",
782 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
783 X86_COND_E))]>, TB;
784def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000785 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786 "cmovne {$src2, $dst|$dst, $src2}",
787 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
788 X86_COND_NE))]>, TB;
789def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000790 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 "cmovne {$src2, $dst|$dst, $src2}",
792 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
793 X86_COND_NE))]>, TB;
794def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000795 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 "cmovbe {$src2, $dst|$dst, $src2}",
797 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
798 X86_COND_BE))]>, TB;
799def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000800 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 "cmovbe {$src2, $dst|$dst, $src2}",
802 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
803 X86_COND_BE))]>, TB;
804def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000805 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 "cmova {$src2, $dst|$dst, $src2}",
807 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
808 X86_COND_A))]>, TB;
809def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000810 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 "cmova {$src2, $dst|$dst, $src2}",
812 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
813 X86_COND_A))]>, TB;
814def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000815 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 "cmovl {$src2, $dst|$dst, $src2}",
817 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
818 X86_COND_L))]>, TB;
819def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000820 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 "cmovl {$src2, $dst|$dst, $src2}",
822 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
823 X86_COND_L))]>, TB;
824def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000825 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826 "cmovge {$src2, $dst|$dst, $src2}",
827 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
828 X86_COND_GE))]>, TB;
829def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000830 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000831 "cmovge {$src2, $dst|$dst, $src2}",
832 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
833 X86_COND_GE))]>, TB;
834def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000835 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836 "cmovle {$src2, $dst|$dst, $src2}",
837 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
838 X86_COND_LE))]>, TB;
839def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000840 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000841 "cmovle {$src2, $dst|$dst, $src2}",
842 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
843 X86_COND_LE))]>, TB;
844def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000845 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846 "cmovg {$src2, $dst|$dst, $src2}",
847 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
848 X86_COND_G))]>, TB;
849def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000850 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851 "cmovg {$src2, $dst|$dst, $src2}",
852 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
853 X86_COND_G))]>, TB;
854def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000855 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856 "cmovs {$src2, $dst|$dst, $src2}",
857 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
858 X86_COND_S))]>, TB;
859def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000860 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 "cmovs {$src2, $dst|$dst, $src2}",
862 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
863 X86_COND_S))]>, TB;
864def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000865 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000866 "cmovns {$src2, $dst|$dst, $src2}",
867 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
868 X86_COND_NS))]>, TB;
869def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000870 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000871 "cmovns {$src2, $dst|$dst, $src2}",
872 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
873 X86_COND_NS))]>, TB;
874def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000875 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000876 "cmovp {$src2, $dst|$dst, $src2}",
877 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
878 X86_COND_P))]>, TB;
879def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000880 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881 "cmovp {$src2, $dst|$dst, $src2}",
882 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
883 X86_COND_P))]>, TB;
884def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000885 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886 "cmovnp {$src2, $dst|$dst, $src2}",
887 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
888 X86_COND_NP))]>, TB;
889def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +0000890 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891 "cmovnp {$src2, $dst|$dst, $src2}",
892 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
893 X86_COND_NP))]>, TB;
894} // isTwoAddress
895
896//===----------------------------------------------------------------------===//
897// Conversion Instructions...
898//
899
900// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +0000901def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902 "cvtsd2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000903 [(set GR64:$dst,
904 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000905def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906 "cvtsd2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000907 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
908 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000909def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000910 "cvttsd2si{q} {$src, $dst|$dst, $src}",
911 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000912def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913 "cvttsd2si{q} {$src, $dst|$dst, $src}",
914 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000915def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000916 "cvttsd2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000917 [(set GR64:$dst,
918 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000919def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920 "cvttsd2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000921 [(set GR64:$dst,
922 (int_x86_sse2_cvttsd2si64
923 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924
925// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +0000926def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000927 "cvtsi2sd{q} {$src, $dst|$dst, $src}",
928 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000929def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 "cvtsi2sd{q} {$src, $dst|$dst, $src}",
931 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
932let isTwoAddress = 1 in {
933def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000934 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000935 "cvtsi2sd{q} {$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +0000936 [(set VR128:$dst,
937 (int_x86_sse2_cvtsi642sd VR128:$src1,
938 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000939def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000940 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 "cvtsi2sd{q} {$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +0000942 [(set VR128:$dst,
943 (int_x86_sse2_cvtsi642sd VR128:$src1,
944 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945} // isTwoAddress
946
947// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +0000948def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949 "cvtsi2ss{q} {$src, $dst|$dst, $src}",
950 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000951def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952 "cvtsi2ss{q} {$src, $dst|$dst, $src}",
953 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
954let isTwoAddress = 1 in {
955def Int_CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000956 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957 "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
958 []>; // TODO: add intrinsic
959def Int_CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000960 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961 "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
962 []>; // TODO: add intrinsic
963} // isTwoAddress
964
965// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +0000966def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967 "cvtss2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000968 [(set GR64:$dst,
969 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000970def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971 "cvtss2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000972 [(set GR64:$dst, (int_x86_sse_cvtss2si64
973 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000974def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 "cvttss2si{q} {$src, $dst|$dst, $src}",
976 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000977def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978 "cvttss2si{q} {$src, $dst|$dst, $src}",
979 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000980def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000981 "cvttss2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000982 [(set GR64:$dst,
983 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000984def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 "cvttss2si{q} {$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +0000986 [(set GR64:$dst,
987 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
988
989let isTwoAddress = 1 in {
990 def Int_CVTSI642SSrr : RSSI<0x2A, MRMSrcReg,
991 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
992 "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
993 [(set VR128:$dst,
994 (int_x86_sse_cvtsi642ss VR128:$src1,
995 GR64:$src2))]>;
996 def Int_CVTSI642SSrm : RSSI<0x2A, MRMSrcMem,
997 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
998 "cvtsi2ss{q} {$src2, $dst|$dst, $src2}",
999 [(set VR128:$dst,
1000 (int_x86_sse_cvtsi642ss VR128:$src1,
1001 (loadi64 addr:$src2)))]>;
1002}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003
1004//===----------------------------------------------------------------------===//
1005// Alias Instructions
1006//===----------------------------------------------------------------------===//
1007
1008// Truncate
1009// In 64-mode, each 64-bit and 32-bit registers has a low 8-bit sub-register.
Evan Chengb783fa32007-07-19 01:14:50 +00001010def TRUNC_64to8 : I<0x88, MRMDestReg, (outs GR8:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001011 "mov{b} {${src:subreg8}, $dst|$dst, ${src:subreg8}",
1012 [(set GR8:$dst, (trunc GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001013def TRUNC_32to8 : I<0x88, MRMDestReg, (outs GR8:$dst), (ins GR32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001014 "mov{b} {${src:subreg8}, $dst|$dst, ${src:subreg8}",
1015 [(set GR8:$dst, (trunc GR32:$src))]>,
1016 Requires<[In64BitMode]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001017def TRUNC_16to8 : I<0x88, MRMDestReg, (outs GR8:$dst), (ins GR16:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018 "mov{b} {${src:subreg8}, $dst|$dst, ${src:subreg8}}",
1019 [(set GR8:$dst, (trunc GR16:$src))]>,
1020 Requires<[In64BitMode]>;
1021
Evan Chengb783fa32007-07-19 01:14:50 +00001022def TRUNC_64to16 : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 "mov{w} {${src:subreg16}, $dst|$dst, ${src:subreg16}}",
1024 [(set GR16:$dst, (trunc GR64:$src))]>;
1025
Evan Chengb783fa32007-07-19 01:14:50 +00001026def TRUNC_64to32 : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001027 "mov{l} {${src:subreg32}, $dst|$dst, ${src:subreg32}}",
1028 [(set GR32:$dst, (trunc GR64:$src))]>;
1029
1030// Zero-extension
1031// TODO: Remove this after proper i32 -> i64 zext support.
Evan Chengb783fa32007-07-19 01:14:50 +00001032def PsMOVZX64rr32: I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033 "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1034 [(set GR64:$dst, (zext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001035def PsMOVZX64rm32: I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036 "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1037 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
1038
1039
1040// Alias instructions that map movr0 to xor.
1041// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1042// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1043// when we have a better way to specify isel priority.
1044let AddedComplexity = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001045def MOV64r0 : RI<0x31, MRMInitReg, (outs GR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046 "xor{q} $dst, $dst",
1047 [(set GR64:$dst, 0)]>;
1048
1049// Materialize i64 constant where top 32-bits are zero.
1050let AddedComplexity = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001051def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052 "mov{l} {$src, ${dst:subreg32}|${dst:subreg32}, $src}",
1053 [(set GR64:$dst, i64immZExt32:$src)]>;
1054
1055//===----------------------------------------------------------------------===//
1056// Non-Instruction Patterns
1057//===----------------------------------------------------------------------===//
1058
1059// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
1060def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1061 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1062def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1063 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1064def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1065 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1066def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1067 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1068
1069def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1070 (MOV64mi32 addr:$dst, tconstpool:$src)>,
1071 Requires<[SmallCode, IsStatic]>;
1072def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1073 (MOV64mi32 addr:$dst, tjumptable:$src)>,
1074 Requires<[SmallCode, IsStatic]>;
1075def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1076 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
1077 Requires<[SmallCode, IsStatic]>;
1078def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1079 (MOV64mi32 addr:$dst, texternalsym:$src)>,
1080 Requires<[SmallCode, IsStatic]>;
1081
1082// Calls
1083// Direct PC relative function call for small code model. 32-bit displacement
1084// sign extended to 64-bit.
1085def : Pat<(X86call (i64 tglobaladdr:$dst)),
1086 (CALL64pcrel32 tglobaladdr:$dst)>;
1087def : Pat<(X86call (i64 texternalsym:$dst)),
1088 (CALL64pcrel32 texternalsym:$dst)>;
1089
1090def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1091 (CALL64pcrel32 tglobaladdr:$dst)>;
1092def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1093 (CALL64pcrel32 texternalsym:$dst)>;
1094
1095def : Pat<(X86tailcall GR64:$dst),
1096 (CALL64r GR64:$dst)>;
1097
1098// {s|z}extload bool -> {s|z}extload byte
1099def : Pat<(sextloadi64i1 addr:$src), (MOVSX64rm8 addr:$src)>;
1100def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1101
1102// extload
1103def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1104def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1105def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1106def : Pat<(extloadi64i32 addr:$src), (PsMOVZX64rm32 addr:$src)>;
1107
1108// anyext -> zext
1109def : Pat<(i64 (anyext GR8 :$src)), (MOVZX64rr8 GR8 :$src)>;
1110def : Pat<(i64 (anyext GR16:$src)), (MOVZX64rr16 GR16:$src)>;
1111def : Pat<(i64 (anyext GR32:$src)), (PsMOVZX64rr32 GR32:$src)>;
1112def : Pat<(i64 (anyext (loadi8 addr:$src))), (MOVZX64rm8 addr:$src)>;
1113def : Pat<(i64 (anyext (loadi16 addr:$src))), (MOVZX64rm16 addr:$src)>;
1114def : Pat<(i64 (anyext (loadi32 addr:$src))), (PsMOVZX64rm32 addr:$src)>;
1115
1116//===----------------------------------------------------------------------===//
1117// Some peepholes
1118//===----------------------------------------------------------------------===//
1119
1120// (shl x, 1) ==> (add x, x)
1121def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1122
1123// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1124def : Pat<(or (srl GR64:$src1, CL:$amt),
1125 (shl GR64:$src2, (sub 64, CL:$amt))),
1126 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1127
1128def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1129 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1130 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1131
1132// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1133def : Pat<(or (shl GR64:$src1, CL:$amt),
1134 (srl GR64:$src2, (sub 64, CL:$amt))),
1135 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1136
1137def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1138 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1139 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1140
1141// X86 specific add which produces a flag.
1142def : Pat<(addc GR64:$src1, GR64:$src2),
1143 (ADD64rr GR64:$src1, GR64:$src2)>;
1144def : Pat<(addc GR64:$src1, (load addr:$src2)),
1145 (ADD64rm GR64:$src1, addr:$src2)>;
1146def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1147 (ADD64ri32 GR64:$src1, imm:$src2)>;
1148def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1149 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1150
1151def : Pat<(subc GR64:$src1, GR64:$src2),
1152 (SUB64rr GR64:$src1, GR64:$src2)>;
1153def : Pat<(subc GR64:$src1, (load addr:$src2)),
1154 (SUB64rm GR64:$src1, addr:$src2)>;
1155def : Pat<(subc GR64:$src1, imm:$src2),
1156 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1157def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1158 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1159
1160
1161//===----------------------------------------------------------------------===//
1162// X86-64 SSE Instructions
1163//===----------------------------------------------------------------------===//
1164
1165// Move instructions...
1166
Evan Chengb783fa32007-07-19 01:14:50 +00001167def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001168 "mov{d|q} {$src, $dst|$dst, $src}",
1169 [(set VR128:$dst,
1170 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001171def MOV64toPQIrm : RPDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001172 "mov{d|q} {$src, $dst|$dst, $src}",
1173 [(set VR128:$dst,
1174 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>;
1175
Evan Chengb783fa32007-07-19 01:14:50 +00001176def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 "mov{d|q} {$src, $dst|$dst, $src}",
1178 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1179 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001180def MOVPQIto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181 "mov{d|q} {$src, $dst|$dst, $src}",
1182 [(store (i64 (vector_extract (v2i64 VR128:$src),
1183 (iPTR 0))), addr:$dst)]>;
1184
Evan Chengb783fa32007-07-19 01:14:50 +00001185def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186 "mov{d|q} {$src, $dst|$dst, $src}",
1187 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001188def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001189 "mov{d|q} {$src, $dst|$dst, $src}",
1190 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1191
Evan Chengb783fa32007-07-19 01:14:50 +00001192def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001193 "mov{d|q} {$src, $dst|$dst, $src}",
1194 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001195def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001196 "mov{d|q} {$src, $dst|$dst, $src}",
1197 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;