blob: 38a16135cdfba65beec8c86bdc2537c267b4565c [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
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//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000036// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037//
38def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
39 [add, mul, shl, or, frameindex, X86Wrapper],
40 []>;
41
42//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000043// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044//
45
Dan Gohmand16fdc02008-12-19 18:25:21 +000046def i64immSExt8 : PatLeaf<(i64 imm), [{
47 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
48 // sign extended field.
49 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
50}]>;
51
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052def i64immSExt32 : PatLeaf<(i64 imm), [{
53 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immZExt32 : PatLeaf<(i64 imm), [{
59 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
60 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
67
68def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
72
73def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
77
78//===----------------------------------------------------------------------===//
79// Instruction list...
80//
81
Dan Gohman01c9f772008-10-01 18:28:06 +000082// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83// a stack adjustment and the codegen must know that they may modify the stack
84// pointer before prolog-epilog rewriting occurs.
85// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86// sub / add which can clobber EFLAGS.
87let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
89 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000090 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000091 Requires<[In64BitMode]>;
92def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
93 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000094 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000095 Requires<[In64BitMode]>;
96}
97
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098//===----------------------------------------------------------------------===//
99// Call Instructions...
100//
Evan Cheng37e7c752007-07-21 00:34:19 +0000101let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000102 // All calls clobber the non-callee saved registers. RSP is marked as
103 // a use to prevent stack-pointer assignments that appear immediately
104 // before calls from potentially appearing dead. Uses for argument
105 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000107 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000110 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
111 Uses = [RSP] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000112 def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000113 "call\t${dst:call}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000114 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000115 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000116 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000117 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 }
119
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000120
121
122let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000123def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset,
124 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000125 "#TC_RETURN $dst $offset",
126 []>;
127
128let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000129def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset,
130 variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000131 "#TC_RETURN $dst $offset",
132 []>;
133
134
135let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Evan Chengbd780d22009-02-10 21:39:44 +0000136 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
137 "jmp{q}\t{*}$dst # TAILCALL",
138 []>;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000139
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000141let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000142 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000143 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000144 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 [(brind (loadi64 addr:$dst))]>;
146}
147
148//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000149// EH Pseudo Instructions
150//
151let isTerminator = 1, isReturn = 1, isBarrier = 1,
152 hasCtrlDep = 1 in {
153def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
154 "ret\t#eh_return, addr: $addr",
155 [(X86ehret GR64:$addr)]>;
156
157}
158
159//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160// Miscellaneous Instructions...
161//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000162let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000164 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000165let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
166let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000168 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000169let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000171 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
172}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000174let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000175def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000176let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000177def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000178
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000180 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000181 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
183
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000184let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000185def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000186 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 [(set GR64:$dst, lea64addr:$src)]>;
188
189let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000190def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000191 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193
Evan Cheng48679f42007-12-14 02:13:44 +0000194// Bit scan instructions.
195let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000196def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000197 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000198 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000199def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000200 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000201 [(set GR64:$dst, (X86bsf (loadi64 addr:$src))),
202 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000203
Evan Cheng4e33de92007-12-14 18:49:43 +0000204def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000205 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000206 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000207def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000208 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000209 [(set GR64:$dst, (X86bsr (loadi64 addr:$src))),
210 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000211} // Defs = [EFLAGS]
212
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000214let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000215def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000216 [(X86rep_movs i64)]>, REP;
217let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000218def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000219 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220
221//===----------------------------------------------------------------------===//
222// Move Instructions...
223//
224
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000225let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000226def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000227 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228
Evan Chengd2b9d302008-06-25 01:16:38 +0000229let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000230def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000231 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000233def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000234 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000236}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237
Dan Gohman5574cc72008-12-03 18:15:48 +0000238let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000239def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000240 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241 [(set GR64:$dst, (load addr:$src))]>;
242
Evan Chengb783fa32007-07-19 01:14:50 +0000243def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000244 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000246def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000247 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 [(store i64immSExt32:$src, addr:$dst)]>;
249
250// Sign/Zero extenders
251
Evan Chengb783fa32007-07-19 01:14:50 +0000252def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000253 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000255def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000256 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000259 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000264def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000265 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000267def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000268 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
270
Dan Gohman9203ab42008-07-30 18:09:17 +0000271// Use movzbl instead of movzbq when the destination is a register; it's
272// equivalent due to implicit zero-extending, and it has a smaller encoding.
273def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
274 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
275 [(set GR64:$dst, (zext GR8:$src))]>, TB;
276def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
277 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
278 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
279// Use movzwl instead of movzwq when the destination is a register; it's
280// equivalent due to implicit zero-extending, and it has a smaller encoding.
281def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
282 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
283 [(set GR64:$dst, (zext GR16:$src))]>, TB;
284def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
285 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
286 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287
Dan Gohman47a419d2008-08-07 02:54:50 +0000288// There's no movzlq instruction, but movl can be used for this purpose, using
289// implicit zero-extension. We need this because the seeming alternative for
290// implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
291// safe because both instructions could be optimized away in the
292// register-to-register case, leaving nothing behind to do the zero extension.
293def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
294 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zext GR32:$src))]>;
296def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
297 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
298 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
299
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000300let neverHasSideEffects = 1 in {
301 let Defs = [RAX], Uses = [EAX] in
302 def CDQE : RI<0x98, RawFrm, (outs), (ins),
303 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000305 let Defs = [RAX,RDX], Uses = [RAX] in
306 def CQO : RI<0x99, RawFrm, (outs), (ins),
307 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
308}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309
310//===----------------------------------------------------------------------===//
311// Arithmetic Instructions...
312//
313
Evan Cheng55687072007-09-14 21:48:26 +0000314let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315let isTwoAddress = 1 in {
316let isConvertibleToThreeAddress = 1 in {
317let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000318// Register-Register Addition
319def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
320 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000321 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000322 (implicit EFLAGS)]>;
323
324// Register-Integer Addition
Bill Wendlingae034ed2008-12-12 00:56:36 +0000325def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
326 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000327 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
328 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000329def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
330 "add{q}\t{$src2, $dst|$dst, $src2}",
331 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
332 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333} // isConvertibleToThreeAddress
334
Bill Wendlingae034ed2008-12-12 00:56:36 +0000335// Register-Memory Addition
336def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
337 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000338 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000339 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340} // isTwoAddress
341
Bill Wendlingae034ed2008-12-12 00:56:36 +0000342// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000343def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000345 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
346 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000347def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000348 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000349 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
350 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000351def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
352 "add{q}\t{$src2, $dst|$dst, $src2}",
353 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
354 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355
Evan Cheng259471d2007-10-05 17:59:57 +0000356let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357let isTwoAddress = 1 in {
358let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000359def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000360 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000361 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362
Evan Chengb783fa32007-07-19 01:14:50 +0000363def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000364 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000365 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366
Evan Chengb783fa32007-07-19 01:14:50 +0000367def ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000368 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000369 [(set GR64:$dst, (adde GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000370def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
371 "adc{q}\t{$src2, $dst|$dst, $src2}",
372 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373} // isTwoAddress
374
Evan Chengb783fa32007-07-19 01:14:50 +0000375def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000376 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000377 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000378def ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000379 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000380 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000381def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
382 "adc{q}\t{$src2, $dst|$dst, $src2}",
383 [(store (adde (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000384} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
386let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000387// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000388def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000389 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000390 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
391 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000392
393// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000394def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000395 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000396 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
397 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000398
399// Register-Integer Subtraction
Bill Wendlingae034ed2008-12-12 00:56:36 +0000400def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
401 (ins GR64:$src1, i64i8imm:$src2),
402 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000403 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
404 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000405def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
406 (ins GR64:$src1, i64i32imm:$src2),
407 "sub{q}\t{$src2, $dst|$dst, $src2}",
408 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
409 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410} // isTwoAddress
411
Bill Wendlingae034ed2008-12-12 00:56:36 +0000412// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000413def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000414 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000415 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
416 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000417
418// Memory-Integer Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000419def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000420 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000421 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000422 addr:$dst),
423 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000424def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
425 "sub{q}\t{$src2, $dst|$dst, $src2}",
426 [(store (sub (load addr:$dst), i64immSExt32:$src2),
427 addr:$dst),
428 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429
Evan Cheng259471d2007-10-05 17:59:57 +0000430let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000432def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000433 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
435
Evan Chengb783fa32007-07-19 01:14:50 +0000436def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000437 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
439
Evan Chengb783fa32007-07-19 01:14:50 +0000440def SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000441 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442 [(set GR64:$dst, (sube GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000443def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
444 "sbb{q}\t{$src2, $dst|$dst, $src2}",
445 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446} // isTwoAddress
447
Evan Chengb783fa32007-07-19 01:14:50 +0000448def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000451def SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000452 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453 [(store (sube (load addr:$dst), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000454def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
455 "sbb{q}\t{$src2, $dst|$dst, $src2}",
456 [(store (sube (load addr:$dst), i64immSExt32:$src2), addr:$dst)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000457} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000458} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459
460// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000461let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000462def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000463 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000464let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000465def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000466 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467
468// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000469def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000470 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000471let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000472def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000473 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
474}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475
Evan Cheng55687072007-09-14 21:48:26 +0000476let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477let isTwoAddress = 1 in {
478let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000479// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000480def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
481 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000482 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000483 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
484 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485
Bill Wendlingf5399032008-12-12 21:15:41 +0000486// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000487def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
488 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000490 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
491 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492} // isTwoAddress
493
494// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000495
Bill Wendlingf5399032008-12-12 21:15:41 +0000496// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000498 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000499 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000500 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
501 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000502def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
503 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
504 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
505 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
506 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000507
Bill Wendlingf5399032008-12-12 21:15:41 +0000508// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000510 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000511 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000512 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000513 i64immSExt8:$src2)),
514 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000515def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
516 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
517 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
518 [(set GR64:$dst, (mul (load addr:$src1),
519 i64immSExt32:$src2)),
520 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000521} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522
523// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000524let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000525def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000526 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000528def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000529 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000530let mayLoad = 1 in {
531def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
532 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000533def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000534 "idiv{q}\t$src", []>;
535}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000536}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537
538// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000539let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000541def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000542 [(set GR64:$dst, (ineg GR64:$src)),
543 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000544def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000545 [(store (ineg (loadi64 addr:$dst)), addr:$dst),
546 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
548let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000549def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000550 [(set GR64:$dst, (add GR64:$src, 1)),
551 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000552def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000553 [(store (add (loadi64 addr:$dst), 1), addr:$dst),
554 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555
556let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000557def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000558 [(set GR64:$dst, (add GR64:$src, -1)),
559 (implicit EFLAGS)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000560def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000561 [(store (add (loadi64 addr:$dst), -1), addr:$dst),
562 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563
564// In 64-bit mode, single byte INC and DEC cannot be encoded.
565let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
566// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000567def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000568 [(set GR16:$dst, (add GR16:$src, 1)),
569 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000571def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000572 [(set GR32:$dst, (add GR32:$src, 1)),
573 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000575def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000576 [(set GR16:$dst, (add GR16:$src, -1)),
577 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000579def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000580 [(set GR32:$dst, (add GR32:$src, -1)),
581 (implicit EFLAGS)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582 Requires<[In64BitMode]>;
583} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000584
585// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
586// how to unfold them.
587let isTwoAddress = 0, CodeSize = 2 in {
588 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000589 [(store (add (loadi16 addr:$dst), 1), addr:$dst),
590 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000591 OpSize, Requires<[In64BitMode]>;
592 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000593 [(store (add (loadi32 addr:$dst), 1), addr:$dst),
594 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000595 Requires<[In64BitMode]>;
596 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000597 [(store (add (loadi16 addr:$dst), -1), addr:$dst),
598 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000599 OpSize, Requires<[In64BitMode]>;
600 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000601 [(store (add (loadi32 addr:$dst), -1), addr:$dst),
602 (implicit EFLAGS)]>,
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000603 Requires<[In64BitMode]>;
604}
Evan Cheng55687072007-09-14 21:48:26 +0000605} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606
607
Evan Cheng55687072007-09-14 21:48:26 +0000608let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609// Shift instructions
610let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000611let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000612def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000613 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000614 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000615let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000616def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000617 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000619// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
620// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621} // isTwoAddress
622
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000623let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000624def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000625 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000626 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000627def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000628 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000630def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000631 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
633
634let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000635let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000636def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000637 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000638 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000639def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000640 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000642def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000643 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000644 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
645} // isTwoAddress
646
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000647let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000648def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000649 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000650 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000651def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000652 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000654def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000655 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
657
658let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000659let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000660def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000661 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000662 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000663def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000664 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000666def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000667 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
669} // isTwoAddress
670
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000671let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000672def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000673 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000674 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000675def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000676 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000678def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
681
682// Rotate instructions
683let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000684let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000685def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000687 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000688def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000689 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000691def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000692 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
694} // isTwoAddress
695
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000696let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000697def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000699 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000700def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000703def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000704 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000705 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
706
707let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000708let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000709def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000710 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000711 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000712def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000713 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000715def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000716 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000717 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
718} // isTwoAddress
719
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000720let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000721def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000722 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000724def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000725 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000727def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000728 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
730
731// Double shift instructions (generalizations of rotate)
732let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000733let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000734def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000735 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
736 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000737def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000738 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
739 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000740}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741
742let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
743def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000744 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000745 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
746 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
747 (i8 imm:$src3)))]>,
748 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000750 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000751 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
752 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
753 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 TB;
755} // isCommutable
756} // isTwoAddress
757
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000758let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000759def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000760 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
761 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
762 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000763def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000764 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
765 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
766 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000767}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000769 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000770 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
771 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
772 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 TB;
774def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000775 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000776 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
777 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
778 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000780} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781
782//===----------------------------------------------------------------------===//
783// Logical Instructions...
784//
785
Evan Cheng5b51c242009-01-21 19:45:31 +0000786let isTwoAddress = 1 , AddedComplexity = 15 in
Dan Gohman91888f02007-07-31 20:11:57 +0000787def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000788 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000789def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
791
Evan Cheng55687072007-09-14 21:48:26 +0000792let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793let isTwoAddress = 1 in {
794let isCommutable = 1 in
795def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000796 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000797 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000798 [(set GR64:$dst, (and GR64:$src1, GR64:$src2)),
799 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000801 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000803 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2))),
804 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000805def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000806 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000807 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000808 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2)),
809 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000810def AND64ri32 : RIi32<0x81, MRM4r,
811 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
812 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000813 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2)),
814 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000815} // isTwoAddress
816
817def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000818 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000819 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000820 [(store (and (load addr:$dst), GR64:$src), addr:$dst),
821 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000822def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000823 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000824 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000825 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst),
826 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000827def AND64mi32 : RIi32<0x81, MRM4m,
828 (outs), (ins i64mem:$dst, i64i32imm:$src),
829 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000830 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
831 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832
833let isTwoAddress = 1 in {
834let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000835def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000836 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000837 [(set GR64:$dst, (or GR64:$src1, GR64:$src2)),
838 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000839def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000840 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000841 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2))),
842 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000843def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000844 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000845 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2)),
846 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000847def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
848 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000849 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2)),
850 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851} // isTwoAddress
852
Evan Chengb783fa32007-07-19 01:14:50 +0000853def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000854 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000855 [(store (or (load addr:$dst), GR64:$src), addr:$dst),
856 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000857def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000858 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000859 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst),
860 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000861def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
862 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000863 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
864 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865
866let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000867let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000868def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000869 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000870 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2)),
871 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000872def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000873 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000874 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2))),
875 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000876def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
877 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000878 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2)),
879 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000881 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000882 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000883 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2)),
884 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885} // isTwoAddress
886
Evan Chengb783fa32007-07-19 01:14:50 +0000887def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000889 [(store (xor (load addr:$dst), GR64:$src), addr:$dst),
890 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000891def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000892 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000893 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst),
894 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000895def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
896 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohman7b93f1c2009-03-03 19:53:46 +0000897 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst),
898 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000899} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000900
901//===----------------------------------------------------------------------===//
902// Comparison Instructions...
903//
904
905// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000906let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000907let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000908def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000909 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000910 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
911 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000912def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000913 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000914 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
915 (implicit EFLAGS)]>;
916def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
917 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000919 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
920 (implicit EFLAGS)]>;
921def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
922 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000923 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000924 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
925 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000926
Evan Chengb783fa32007-07-19 01:14:50 +0000927def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000929 [(X86cmp GR64:$src1, GR64:$src2),
930 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000931def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000932 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000933 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
934 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000935def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000937 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
938 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000939def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
940 "cmp{q}\t{$src2, $src1|$src1, $src2}",
941 [(X86cmp GR64:$src1, i64immSExt8:$src2),
942 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000943def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000944 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000945 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000946 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000947def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000948 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000949 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000950 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000951def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
952 (ins i64mem:$src1, i64i32imm:$src2),
953 "cmp{q}\t{$src2, $src1|$src1, $src2}",
954 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
955 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000956} // Defs = [EFLAGS]
957
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000958// Bit tests.
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000959// TODO: BTC, BTR, and BTS
960let Defs = [EFLAGS] in {
Chris Lattner5a95cde2008-12-25 01:32:49 +0000961def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000962 "bt{q}\t{$src2, $src1|$src1, $src2}",
963 [(X86bt GR64:$src1, GR64:$src2),
Chris Lattner5a95cde2008-12-25 01:32:49 +0000964 (implicit EFLAGS)]>, TB;
Dan Gohman85a228c2009-01-13 23:23:30 +0000965
966// Unlike with the register+register form, the memory+register form of the
967// bt instruction does not ignore the high bits of the index. From ISel's
968// perspective, this is pretty bizarre. Disable these instructions for now.
969//def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
970// "bt{q}\t{$src2, $src1|$src1, $src2}",
971// [(X86bt (loadi64 addr:$src1), GR64:$src2),
972// (implicit EFLAGS)]>, TB;
Dan Gohman46fb1cf2009-01-13 20:33:23 +0000973
974def BT64ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
975 "bt{q}\t{$src2, $src1|$src1, $src2}",
976 [(X86bt GR64:$src1, i64immSExt8:$src2),
977 (implicit EFLAGS)]>, TB;
978// Note that these instructions don't need FastBTMem because that
979// only applies when the other operand is in a register. When it's
980// an immediate, bt is still fast.
981def BT64mi8 : Ii8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
982 "bt{q}\t{$src2, $src1|$src1, $src2}",
983 [(X86bt (loadi64 addr:$src1), i64immSExt8:$src2),
984 (implicit EFLAGS)]>, TB;
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000985} // Defs = [EFLAGS]
986
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000987// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +0000988let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +0000989let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000991 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000992 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000993 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000994 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000996 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000997 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000998 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000999 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001001 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001002 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001004 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001005def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001006 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001007 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001008 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001009 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001010def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001011 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001014 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001015def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001016 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001017 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001019 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001021 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001022 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001024 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001025def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001026 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001027 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001029 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001031 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001032 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001034 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001036 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001037 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001039 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001041 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001042 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001044 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001046 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001047 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001049 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001051 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001052 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001054 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001056 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001057 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001059 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001060def CMOVO64rr : RI<0x40, MRMSrcReg, // if overflow, GR64 = GR64
1061 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1062 "cmovo\t{$src2, $dst|$dst, $src2}",
1063 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1064 X86_COND_O, EFLAGS))]>, TB;
1065def CMOVNO64rr : RI<0x41, MRMSrcReg, // if !overflow, GR64 = GR64
1066 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
1067 "cmovno\t{$src2, $dst|$dst, $src2}",
1068 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
1069 X86_COND_NO, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001070} // isCommutable = 1
1071
1072def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1073 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1074 "cmovb\t{$src2, $dst|$dst, $src2}",
1075 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1076 X86_COND_B, EFLAGS))]>, TB;
1077def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1078 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1079 "cmovae\t{$src2, $dst|$dst, $src2}",
1080 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1081 X86_COND_AE, EFLAGS))]>, TB;
1082def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1083 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1084 "cmove\t{$src2, $dst|$dst, $src2}",
1085 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1086 X86_COND_E, EFLAGS))]>, TB;
1087def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1088 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1089 "cmovne\t{$src2, $dst|$dst, $src2}",
1090 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1091 X86_COND_NE, EFLAGS))]>, TB;
1092def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1093 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1094 "cmovbe\t{$src2, $dst|$dst, $src2}",
1095 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1096 X86_COND_BE, EFLAGS))]>, TB;
1097def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1098 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1099 "cmova\t{$src2, $dst|$dst, $src2}",
1100 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1101 X86_COND_A, EFLAGS))]>, TB;
1102def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1103 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1104 "cmovl\t{$src2, $dst|$dst, $src2}",
1105 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1106 X86_COND_L, EFLAGS))]>, TB;
1107def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1108 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1109 "cmovge\t{$src2, $dst|$dst, $src2}",
1110 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1111 X86_COND_GE, EFLAGS))]>, TB;
1112def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1113 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1114 "cmovle\t{$src2, $dst|$dst, $src2}",
1115 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1116 X86_COND_LE, EFLAGS))]>, TB;
1117def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1118 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1119 "cmovg\t{$src2, $dst|$dst, $src2}",
1120 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1121 X86_COND_G, EFLAGS))]>, TB;
1122def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1123 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1124 "cmovs\t{$src2, $dst|$dst, $src2}",
1125 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1126 X86_COND_S, EFLAGS))]>, TB;
1127def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1128 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1129 "cmovns\t{$src2, $dst|$dst, $src2}",
1130 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1131 X86_COND_NS, EFLAGS))]>, TB;
1132def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1133 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1134 "cmovp\t{$src2, $dst|$dst, $src2}",
1135 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1136 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001137def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001138 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001139 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001141 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohman12fd4d72009-01-07 00:35:10 +00001142def CMOVO64rm : RI<0x40, MRMSrcMem, // if overflow, GR64 = [mem64]
1143 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1144 "cmovo\t{$src2, $dst|$dst, $src2}",
1145 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1146 X86_COND_O, EFLAGS))]>, TB;
1147def CMOVNO64rm : RI<0x41, MRMSrcMem, // if !overflow, GR64 = [mem64]
1148 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1149 "cmovno\t{$src2, $dst|$dst, $src2}",
1150 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1151 X86_COND_NO, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001152} // isTwoAddress
1153
1154//===----------------------------------------------------------------------===//
1155// Conversion Instructions...
1156//
1157
1158// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001159def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001160 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001161 [(set GR64:$dst,
1162 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001163def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001164 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001165 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1166 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001167def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001168 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001169 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001170def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001171 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001172 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001173def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001174 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001175 [(set GR64:$dst,
1176 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001177def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001178 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001179 [(set GR64:$dst,
1180 (int_x86_sse2_cvttsd2si64
1181 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182
1183// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001184def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001185 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001187def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001188 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001189 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001190
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001191let isTwoAddress = 1 in {
1192def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001193 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001194 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001195 [(set VR128:$dst,
1196 (int_x86_sse2_cvtsi642sd VR128:$src1,
1197 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001198def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001199 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001200 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001201 [(set VR128:$dst,
1202 (int_x86_sse2_cvtsi642sd VR128:$src1,
1203 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001204} // isTwoAddress
1205
1206// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001207def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001208 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001210def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001213
1214let isTwoAddress = 1 in {
1215 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1216 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1217 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1218 [(set VR128:$dst,
1219 (int_x86_sse_cvtsi642ss VR128:$src1,
1220 GR64:$src2))]>;
1221 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1222 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1223 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1224 [(set VR128:$dst,
1225 (int_x86_sse_cvtsi642ss VR128:$src1,
1226 (loadi64 addr:$src2)))]>;
1227}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001228
1229// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001230def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001231 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001232 [(set GR64:$dst,
1233 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001234def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001235 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001236 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1237 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001238def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001239 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001241def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001242 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001244def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001245 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001246 [(set GR64:$dst,
1247 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001248def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001249 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001250 [(set GR64:$dst,
1251 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1252
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253//===----------------------------------------------------------------------===//
1254// Alias Instructions
1255//===----------------------------------------------------------------------===//
1256
Dan Gohman027cd112007-09-17 14:55:08 +00001257// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1258// equivalent due to implicit zero-extending, and it sometimes has a smaller
1259// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1261// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1262// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001263let Defs = [EFLAGS], AddedComplexity = 1,
1264 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001265def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1266 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1267 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001268
1269// Materialize i64 constant where top 32-bits are zero.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001270let AddedComplexity = 1, isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001271def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001272 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273 [(set GR64:$dst, i64immZExt32:$src)]>;
1274
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001275//===----------------------------------------------------------------------===//
1276// Thread Local Storage Instructions
1277//===----------------------------------------------------------------------===//
1278
1279def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001280 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001281 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001282
sampo9cc09a32009-01-26 01:24:32 +00001283let AddedComplexity = 5 in
1284def MOV64GSrm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1285 "movq\t%gs:$src, $dst",
1286 [(set GR64:$dst, (gsload addr:$src))]>, SegGS;
1287
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001288//===----------------------------------------------------------------------===//
1289// Atomic Instructions
1290//===----------------------------------------------------------------------===//
1291
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001292let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001293def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001294 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001295 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1296}
1297
Dan Gohmana41a1c092008-08-06 15:52:50 +00001298let Constraints = "$val = $dst" in {
1299let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001300def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001301 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001302 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001303 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001304def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001305 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001306 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001307}
1308
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001309// Atomic exchange, and, or, xor
1310let Constraints = "$val = $dst", Defs = [EFLAGS],
1311 usesCustomDAGSchedInserter = 1 in {
1312def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001313 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001314 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001315def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001316 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001317 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001318def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001319 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001320 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001321def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001322 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001323 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001324def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001325 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001326 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001327def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001328 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001329 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001330def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001331 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001332 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001333def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001334 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001335 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001336}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001337
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001338//===----------------------------------------------------------------------===//
1339// Non-Instruction Patterns
1340//===----------------------------------------------------------------------===//
1341
Bill Wendlingfef06052008-09-16 21:48:12 +00001342// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001343def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1344 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1345def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1346 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1347def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1348 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1349def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1350 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1351
1352def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1353 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001354 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001355def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1356 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001357 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001358def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1359 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001360 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001361def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1362 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001363 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364
1365// Calls
1366// Direct PC relative function call for small code model. 32-bit displacement
1367// sign extended to 64-bit.
1368def : Pat<(X86call (i64 tglobaladdr:$dst)),
1369 (CALL64pcrel32 tglobaladdr:$dst)>;
1370def : Pat<(X86call (i64 texternalsym:$dst)),
1371 (CALL64pcrel32 texternalsym:$dst)>;
1372
1373def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1374 (CALL64pcrel32 tglobaladdr:$dst)>;
1375def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1376 (CALL64pcrel32 texternalsym:$dst)>;
1377
1378def : Pat<(X86tailcall GR64:$dst),
1379 (CALL64r GR64:$dst)>;
1380
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001381
1382// tailcall stuff
1383def : Pat<(X86tailcall GR32:$dst),
1384 (TAILCALL)>;
1385def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1386 (TAILCALL)>;
1387def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1388 (TAILCALL)>;
1389
1390def : Pat<(X86tcret GR64:$dst, imm:$off),
1391 (TCRETURNri64 GR64:$dst, imm:$off)>;
1392
1393def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1394 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1395
1396def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1397 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1398
Dan Gohmanec596042007-09-17 14:35:24 +00001399// Comparisons.
1400
1401// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001402def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001403 (TEST64rr GR64:$src1, GR64:$src1)>;
1404
Dan Gohman0a3c5222009-01-07 01:00:24 +00001405// Conditional moves with folded loads with operands swapped and conditions
1406// inverted.
1407def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_B, EFLAGS),
1408 (CMOVAE64rm GR64:$src2, addr:$src1)>;
1409def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_AE, EFLAGS),
1410 (CMOVB64rm GR64:$src2, addr:$src1)>;
1411def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_E, EFLAGS),
1412 (CMOVNE64rm GR64:$src2, addr:$src1)>;
1413def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NE, EFLAGS),
1414 (CMOVE64rm GR64:$src2, addr:$src1)>;
1415def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_BE, EFLAGS),
1416 (CMOVA64rm GR64:$src2, addr:$src1)>;
1417def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_A, EFLAGS),
1418 (CMOVBE64rm GR64:$src2, addr:$src1)>;
1419def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_L, EFLAGS),
1420 (CMOVGE64rm GR64:$src2, addr:$src1)>;
1421def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_GE, EFLAGS),
1422 (CMOVL64rm GR64:$src2, addr:$src1)>;
1423def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_LE, EFLAGS),
1424 (CMOVG64rm GR64:$src2, addr:$src1)>;
1425def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_G, EFLAGS),
1426 (CMOVLE64rm GR64:$src2, addr:$src1)>;
1427def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_P, EFLAGS),
1428 (CMOVNP64rm GR64:$src2, addr:$src1)>;
1429def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NP, EFLAGS),
1430 (CMOVP64rm GR64:$src2, addr:$src1)>;
1431def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_S, EFLAGS),
1432 (CMOVNS64rm GR64:$src2, addr:$src1)>;
1433def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NS, EFLAGS),
1434 (CMOVS64rm GR64:$src2, addr:$src1)>;
1435def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_O, EFLAGS),
1436 (CMOVNO64rm GR64:$src2, addr:$src1)>;
1437def : Pat<(X86cmov (loadi64 addr:$src1), GR64:$src2, X86_COND_NO, EFLAGS),
1438 (CMOVO64rm GR64:$src2, addr:$src1)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001439
1440// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001441def : Pat<(i64 (zext GR32:$src)),
1442 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001443
Duncan Sands082524c2008-01-23 20:39:46 +00001444// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001445def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1446
1447// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001448// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1449// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1450// partial-register updates.
1451def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1452def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1453def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1454// For other extloads, use subregs, since the high contents of the register are
1455// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001456def : Pat<(extloadi64i32 addr:$src),
1457 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1458 x86_subreg_32bit)>;
1459def : Pat<(extloadi16i1 addr:$src),
1460 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1461 x86_subreg_8bit)>,
1462 Requires<[In64BitMode]>;
1463def : Pat<(extloadi16i8 addr:$src),
1464 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1465 x86_subreg_8bit)>,
1466 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001467
Dan Gohmandd612bb2008-08-20 21:27:32 +00001468// anyext
1469def : Pat<(i64 (anyext GR8:$src)),
1470 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1471def : Pat<(i64 (anyext GR16:$src)),
1472 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001473def : Pat<(i64 (anyext GR32:$src)),
1474 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001475def : Pat<(i16 (anyext GR8:$src)),
1476 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1477 Requires<[In64BitMode]>;
1478def : Pat<(i32 (anyext GR8:$src)),
1479 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1480 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001481
1482//===----------------------------------------------------------------------===//
1483// Some peepholes
1484//===----------------------------------------------------------------------===//
1485
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001486// Odd encoding trick: -128 fits into an 8-bit immediate field while
1487// +128 doesn't, so in this special case use a sub instead of an add.
1488def : Pat<(add GR64:$src1, 128),
1489 (SUB64ri8 GR64:$src1, -128)>;
1490def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1491 (SUB64mi8 addr:$dst, -128)>;
1492
1493// The same trick applies for 32-bit immediate fields in 64-bit
1494// instructions.
1495def : Pat<(add GR64:$src1, 0x0000000080000000),
1496 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1497def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1498 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1499
Dan Gohman47a419d2008-08-07 02:54:50 +00001500// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001501def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001502 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001503// r & (2^16-1) ==> movz
1504def : Pat<(and GR64:$src, 0xffff),
1505 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1506// r & (2^8-1) ==> movz
1507def : Pat<(and GR64:$src, 0xff),
1508 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001509// r & (2^8-1) ==> movz
1510def : Pat<(and GR32:$src1, 0xff),
1511 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1512 Requires<[In64BitMode]>;
1513// r & (2^8-1) ==> movz
1514def : Pat<(and GR16:$src1, 0xff),
1515 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1516 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001517
Dan Gohmandd612bb2008-08-20 21:27:32 +00001518// sext_inreg patterns
1519def : Pat<(sext_inreg GR64:$src, i32),
1520 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1521def : Pat<(sext_inreg GR64:$src, i16),
1522 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1523def : Pat<(sext_inreg GR64:$src, i8),
1524 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1525def : Pat<(sext_inreg GR32:$src, i8),
1526 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1527 Requires<[In64BitMode]>;
1528def : Pat<(sext_inreg GR16:$src, i8),
1529 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1530 Requires<[In64BitMode]>;
1531
1532// trunc patterns
1533def : Pat<(i32 (trunc GR64:$src)),
1534 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1535def : Pat<(i16 (trunc GR64:$src)),
1536 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1537def : Pat<(i8 (trunc GR64:$src)),
1538 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1539def : Pat<(i8 (trunc GR32:$src)),
1540 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1541 Requires<[In64BitMode]>;
1542def : Pat<(i8 (trunc GR16:$src)),
1543 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1544 Requires<[In64BitMode]>;
1545
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001546// (shl x, 1) ==> (add x, x)
1547def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1548
Evan Cheng76a64c72008-08-30 02:03:58 +00001549// (shl x (and y, 63)) ==> (shl x, y)
1550def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1551 (SHL64rCL GR64:$src1)>;
1552def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1553 (SHL64mCL addr:$dst)>;
1554
1555def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1556 (SHR64rCL GR64:$src1)>;
1557def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1558 (SHR64mCL addr:$dst)>;
1559
1560def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1561 (SAR64rCL GR64:$src1)>;
1562def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1563 (SAR64mCL addr:$dst)>;
1564
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001565// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1566def : Pat<(or (srl GR64:$src1, CL:$amt),
1567 (shl GR64:$src2, (sub 64, CL:$amt))),
1568 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1569
1570def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1571 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1572 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1573
Dan Gohman921581d2008-10-17 01:23:35 +00001574def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1575 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1576 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1577
1578def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1579 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1580 addr:$dst),
1581 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1582
1583def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1584 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1585
1586def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1587 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1588 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1589
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1591def : Pat<(or (shl GR64:$src1, CL:$amt),
1592 (srl GR64:$src2, (sub 64, CL:$amt))),
1593 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1594
1595def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1596 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1597 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1598
Dan Gohman921581d2008-10-17 01:23:35 +00001599def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1600 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1601 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1602
1603def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1604 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1605 addr:$dst),
1606 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1607
1608def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1609 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1610
1611def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1612 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1613 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1614
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001615// X86 specific add which produces a flag.
1616def : Pat<(addc GR64:$src1, GR64:$src2),
1617 (ADD64rr GR64:$src1, GR64:$src2)>;
1618def : Pat<(addc GR64:$src1, (load addr:$src2)),
1619 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001620def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1621 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001622def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1623 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001624
1625def : Pat<(subc GR64:$src1, GR64:$src2),
1626 (SUB64rr GR64:$src1, GR64:$src2)>;
1627def : Pat<(subc GR64:$src1, (load addr:$src2)),
1628 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001629def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1630 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001631def : Pat<(subc GR64:$src1, imm:$src2),
1632 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001633
Bill Wendlingf5399032008-12-12 21:15:41 +00001634//===----------------------------------------------------------------------===//
1635// Overflow Patterns
1636//===----------------------------------------------------------------------===//
1637
1638// Register-Register Addition with Overflow
1639def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1640 (implicit EFLAGS)),
1641 (ADD64rr GR64:$src1, GR64:$src2)>;
1642
1643// Register-Integer Addition with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001644def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1645 (implicit EFLAGS)),
1646 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001647def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1648 (implicit EFLAGS)),
1649 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001650
1651// Register-Memory Addition with Overflow
1652def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1653 (implicit EFLAGS)),
1654 (ADD64rm GR64:$src1, addr:$src2)>;
1655
1656// Memory-Register Addition with Overflow
1657def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1658 addr:$dst),
1659 (implicit EFLAGS)),
1660 (ADD64mr addr:$dst, GR64:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001661def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1662 addr:$dst),
1663 (implicit EFLAGS)),
1664 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001665def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1666 addr:$dst),
1667 (implicit EFLAGS)),
1668 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001669
1670// Register-Register Subtraction with Overflow
1671def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1672 (implicit EFLAGS)),
1673 (SUB64rr GR64:$src1, GR64:$src2)>;
1674
1675// Register-Memory Subtraction with Overflow
1676def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1677 (implicit EFLAGS)),
1678 (SUB64rm GR64:$src1, addr:$src2)>;
1679
1680// Register-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001681def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1682 (implicit EFLAGS)),
1683 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001684def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1685 (implicit EFLAGS)),
1686 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001687
1688// Memory-Register Subtraction with Overflow
1689def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1690 addr:$dst),
1691 (implicit EFLAGS)),
1692 (SUB64mr addr:$dst, GR64:$src2)>;
1693
1694// Memory-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001695def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1696 addr:$dst),
1697 (implicit EFLAGS)),
1698 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001699def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1700 addr:$dst),
1701 (implicit EFLAGS)),
1702 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001703
1704// Register-Register Signed Integer Multiplication with Overflow
1705def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1706 (implicit EFLAGS)),
1707 (IMUL64rr GR64:$src1, GR64:$src2)>;
1708
1709// Register-Memory Signed Integer Multiplication with Overflow
1710def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1711 (implicit EFLAGS)),
1712 (IMUL64rm GR64:$src1, addr:$src2)>;
1713
1714// Register-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001715def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1716 (implicit EFLAGS)),
1717 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001718def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1719 (implicit EFLAGS)),
1720 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001721
1722// Memory-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001723def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1724 (implicit EFLAGS)),
1725 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001726def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1727 (implicit EFLAGS)),
1728 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001729
1730//===----------------------------------------------------------------------===//
1731// X86-64 SSE Instructions
1732//===----------------------------------------------------------------------===//
1733
1734// Move instructions...
1735
Evan Chengb783fa32007-07-19 01:14:50 +00001736def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001737 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001738 [(set VR128:$dst,
1739 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001740def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001741 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001742 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1743 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001744
Evan Chengb783fa32007-07-19 01:14:50 +00001745def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001746 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001747 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001748def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001749 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1751
Evan Chengb783fa32007-07-19 01:14:50 +00001752def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001753 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001755def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001756 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001757 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001758
1759//===----------------------------------------------------------------------===//
1760// X86-64 SSE4.1 Instructions
1761//===----------------------------------------------------------------------===//
1762
Nate Begeman4294c1f2008-02-12 22:51:28 +00001763/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1764multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001765 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001766 (ins VR128:$src1, i32i8imm:$src2),
1767 !strconcat(OpcodeStr,
1768 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1769 [(set GR64:$dst,
1770 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001771 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001772 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1773 !strconcat(OpcodeStr,
1774 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1775 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1776 addr:$dst)]>, OpSize, REX_W;
1777}
1778
1779defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1780
1781let isTwoAddress = 1 in {
1782 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001783 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001784 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1785 !strconcat(OpcodeStr,
1786 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1787 [(set VR128:$dst,
1788 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1789 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001790 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001791 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1792 !strconcat(OpcodeStr,
1793 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1794 [(set VR128:$dst,
1795 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1796 imm:$src3)))]>, OpSize, REX_W;
1797 }
1798}
1799
1800defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;