blob: 7679a0bcfcdae9a53c6fa5e2bfa7c8c06cac55a7 [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
46def i64immSExt32 : PatLeaf<(i64 imm), [{
47 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
48 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000049 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050}]>;
51
52def i64immZExt32 : PatLeaf<(i64 imm), [{
53 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immSExt8 : PatLeaf<(i64 imm), [{
59 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
60 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (int64_t)N->getZExtValue() == (int8_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
Arnold Schwaighofer6fd37ac2008-03-19 16:39:45 +0000123def TCRETURNdi64 : I<0, Pseudo, (outs), (ins i64imm:$dst, i32imm:$offset, variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000124 "#TC_RETURN $dst $offset",
125 []>;
126
127let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
Arnold Schwaighofer6fd37ac2008-03-19 16:39:45 +0000128def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64:$dst, i32imm:$offset, variable_ops),
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000129 "#TC_RETURN $dst $offset",
130 []>;
131
132
133let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
134 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst # TAILCALL",
135 []>;
136
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137// Branches
Owen Andersonf8053082007-11-12 07:39:39 +0000138let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Dan Gohman91888f02007-07-31 20:11:57 +0000139 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 [(brind GR64:$dst)]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000141 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142 [(brind (loadi64 addr:$dst))]>;
143}
144
145//===----------------------------------------------------------------------===//
Anton Korobeynikov1ec04ee2008-09-08 21:12:47 +0000146// EH Pseudo Instructions
147//
148let isTerminator = 1, isReturn = 1, isBarrier = 1,
149 hasCtrlDep = 1 in {
150def EH_RETURN64 : I<0xC3, RawFrm, (outs), (ins GR64:$addr),
151 "ret\t#eh_return, addr: $addr",
152 [(X86ehret GR64:$addr)]>;
153
154}
155
156//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157// Miscellaneous Instructions...
158//
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000159let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160def LEAVE64 : I<0xC9, RawFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000161 (outs), (ins), "leave", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000162let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
163let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164def POP64r : I<0x58, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000165 (outs GR64:$reg), (ins), "pop{q}\t$reg", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000166let mayStore = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167def PUSH64r : I<0x50, AddRegFrm,
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000168 (outs), (ins GR64:$reg), "push{q}\t$reg", []>;
169}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000171let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000172def POPFQ : I<0x9D, RawFrm, (outs), (ins), "popf", []>, REX_W;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000173let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1 in
Evan Chengf1341312007-09-26 21:28:00 +0000174def PUSHFQ : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
Evan Chengd8434332007-09-26 01:29:06 +0000175
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176def LEA64_32r : I<0x8D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000177 (outs GR32:$dst), (ins lea64_32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000178 "lea{l}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 [(set GR32:$dst, lea32addr:$src)]>, Requires<[In64BitMode]>;
180
Evan Cheng1ea8e6b2008-03-27 01:41:09 +0000181let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000182def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000183 "lea{q}\t{$src|$dst}, {$dst|$src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 [(set GR64:$dst, lea64addr:$src)]>;
185
186let isTwoAddress = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000187def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000188 "bswap{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 [(set GR64:$dst, (bswap GR64:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190
Evan Cheng48679f42007-12-14 02:13:44 +0000191// Bit scan instructions.
192let Defs = [EFLAGS] in {
Evan Cheng4e33de92007-12-14 18:49:43 +0000193def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000194 "bsf{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000195 [(set GR64:$dst, (X86bsf GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000196def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$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 (loadi64 addr:$src))),
199 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000200
Evan Cheng4e33de92007-12-14 18:49:43 +0000201def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohmancdb54c62007-12-14 15:10:00 +0000202 "bsr{q}\t{$src, $dst|$dst, $src}",
Evan Cheng9a8ffd52007-12-14 18:25:34 +0000203 [(set GR64:$dst, (X86bsr GR64:$src)), (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000204def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$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 (loadi64 addr:$src))),
207 (implicit EFLAGS)]>, TB;
Evan Cheng48679f42007-12-14 02:13:44 +0000208} // Defs = [EFLAGS]
209
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210// Repeat string ops
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000211let Defs = [RCX,RDI,RSI], Uses = [RCX,RDI,RSI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000212def REP_MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "{rep;movsq|rep movsq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000213 [(X86rep_movs i64)]>, REP;
214let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI] in
Evan Chengb783fa32007-07-19 01:14:50 +0000215def REP_STOSQ : RI<0xAB, RawFrm, (outs), (ins), "{rep;stosq|rep stosq}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000216 [(X86rep_stos i64)]>, REP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
218//===----------------------------------------------------------------------===//
219// Move Instructions...
220//
221
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000222let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000223def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000224 "mov{q}\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225
Evan Chengd2b9d302008-06-25 01:16:38 +0000226let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000227def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000228 "movabs{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 [(set GR64:$dst, imm:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000230def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000231 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 [(set GR64:$dst, i64immSExt32:$src)]>;
Dan Gohman8aef09b2007-09-07 21:32:51 +0000233}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Dan Gohman5574cc72008-12-03 18:15:48 +0000235let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000236def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000237 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 [(set GR64:$dst, (load addr:$src))]>;
239
Evan Chengb783fa32007-07-19 01:14:50 +0000240def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000241 "mov{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 [(store GR64:$src, addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000243def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$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 i64immSExt32:$src, addr:$dst)]>;
246
247// Sign/Zero extenders
248
Evan Chengb783fa32007-07-19 01:14:50 +0000249def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000250 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 [(set GR64:$dst, (sext GR8:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000252def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$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, (sextloadi64i8 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000255def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000256 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 [(set GR64:$dst, (sext GR16:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000258def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$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, (sextloadi64i16 addr:$src))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000261def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000262 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 [(set GR64:$dst, (sext GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000264def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$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, (sextloadi64i32 addr:$src))]>;
267
Dan Gohman9203ab42008-07-30 18:09:17 +0000268// Use movzbl instead of movzbq when the destination is a register; it's
269// equivalent due to implicit zero-extending, and it has a smaller encoding.
270def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
271 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
272 [(set GR64:$dst, (zext GR8:$src))]>, TB;
273def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
274 "movz{bl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
275 [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
276// Use movzwl instead of movzwq when the destination is a register; it's
277// equivalent due to implicit zero-extending, and it has a smaller encoding.
278def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
279 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
280 [(set GR64:$dst, (zext GR16:$src))]>, TB;
281def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
282 "movz{wl|x}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
283 [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284
Dan Gohman47a419d2008-08-07 02:54:50 +0000285// There's no movzlq instruction, but movl can be used for this purpose, using
286// implicit zero-extension. We need this because the seeming alternative for
287// implementing zext from 32 to 64, an EXTRACT_SUBREG/SUBREG_TO_REG pair, isn't
288// safe because both instructions could be optimized away in the
289// register-to-register case, leaving nothing behind to do the zero extension.
290def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
291 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
292 [(set GR64:$dst, (zext GR32:$src))]>;
293def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
294 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
295 [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
296
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000297let neverHasSideEffects = 1 in {
298 let Defs = [RAX], Uses = [EAX] in
299 def CDQE : RI<0x98, RawFrm, (outs), (ins),
300 "{cltq|cdqe}", []>; // RAX = signext(EAX)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000302 let Defs = [RAX,RDX], Uses = [RAX] in
303 def CQO : RI<0x99, RawFrm, (outs), (ins),
304 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
305}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306
307//===----------------------------------------------------------------------===//
308// Arithmetic Instructions...
309//
310
Evan Cheng55687072007-09-14 21:48:26 +0000311let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312let isTwoAddress = 1 in {
313let isConvertibleToThreeAddress = 1 in {
314let isCommutable = 1 in
Bill Wendlingae034ed2008-12-12 00:56:36 +0000315// Register-Register Addition
316def ADD64rr : RI<0x01, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
317 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000318 [(set GR64:$dst, (add GR64:$src1, GR64:$src2)),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000319 (implicit EFLAGS)]>;
320
321// Register-Integer Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000322def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000323 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000324 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$src2)),
325 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000326def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
327 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000328 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
329 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330} // isConvertibleToThreeAddress
331
Bill Wendlingae034ed2008-12-12 00:56:36 +0000332// Register-Memory Addition
333def ADD64rm : RI<0x03, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
334 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000335 [(set GR64:$dst, (add GR64:$src1, (load addr:$src2))),
Bill Wendlingae034ed2008-12-12 00:56:36 +0000336 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337} // isTwoAddress
338
Bill Wendlingae034ed2008-12-12 00:56:36 +0000339// Memory-Register Addition
Evan Chengb783fa32007-07-19 01:14:50 +0000340def ADD64mr : RI<0x01, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000342 [(store (add (load addr:$dst), GR64:$src2), addr:$dst),
343 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000344def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000345 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000346 [(store (add (load addr:$dst), i64immSExt32:$src2), addr:$dst),
347 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000348def ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000349 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000350 [(store (add (load addr:$dst), i64immSExt8:$src2), addr:$dst),
351 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
Evan Cheng259471d2007-10-05 17:59:57 +0000353let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354let isTwoAddress = 1 in {
355let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000356def ADC64rr : RI<0x11, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000357 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000358 [(set GR64:$dst, (adde GR64:$src1, GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359
Evan Chengb783fa32007-07-19 01:14:50 +0000360def ADC64rm : RI<0x13, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000361 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000362 [(set GR64:$dst, (adde GR64:$src1, (load addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363
Evan Chengb783fa32007-07-19 01:14:50 +0000364def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000365 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000366 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$src2))]>;
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 Gohmanf17a25c2007-07-18 16:29:46 +0000370} // isTwoAddress
371
Evan Chengb783fa32007-07-19 01:14:50 +0000372def ADC64mr : RI<0x11, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000373 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingc0ca7f32008-12-01 23:44:08 +0000374 [(store (adde (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000375def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000376 "adc{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling0c52d0a2008-12-02 00:07:05 +0000377 [(store (adde (load addr:$dst), i64immSExt8:$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)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000381} // Uses = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382
383let isTwoAddress = 1 in {
Bill Wendlingae034ed2008-12-12 00:56:36 +0000384// Register-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000385def SUB64rr : RI<0x29, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000386 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000387 [(set GR64:$dst, (sub GR64:$src1, GR64:$src2)),
388 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000389
390// Register-Memory Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000391def SUB64rm : RI<0x2B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000392 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000393 [(set GR64:$dst, (sub GR64:$src1, (load addr:$src2))),
394 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000395
396// Register-Integer Subtraction
397def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
398 (ins GR64:$src1, i64i32imm:$src2),
399 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000400 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$src2)),
401 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000402def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
403 (ins GR64:$src1, i64i8imm:$src2),
404 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000405 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
406 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407} // isTwoAddress
408
Bill Wendlingae034ed2008-12-12 00:56:36 +0000409// Memory-Register Subtraction
Evan Chengb783fa32007-07-19 01:14:50 +0000410def SUB64mr : RI<0x29, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000411 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000412 [(store (sub (load addr:$dst), GR64:$src2), addr:$dst),
413 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000414
415// Memory-Integer Subtraction
416def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000417 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000418 [(store (sub (load addr:$dst), i64immSExt32:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000419 addr:$dst),
420 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000421def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000422 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000423 [(store (sub (load addr:$dst), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000424 addr:$dst),
425 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426
Evan Cheng259471d2007-10-05 17:59:57 +0000427let Uses = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428let isTwoAddress = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000429def SBB64rr : RI<0x19, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431 [(set GR64:$dst, (sube GR64:$src1, GR64:$src2))]>;
432
Evan Chengb783fa32007-07-19 01:14:50 +0000433def SBB64rm : RI<0x1B, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000434 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435 [(set GR64:$dst, (sube GR64:$src1, (load addr:$src2)))]>;
436
Evan Chengb783fa32007-07-19 01:14:50 +0000437def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000438 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
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))]>;
443} // isTwoAddress
444
Evan Chengb783fa32007-07-19 01:14:50 +0000445def SBB64mr : RI<0x19, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "sbb{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 [(store (sube (load addr:$dst), GR64:$src2), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000448def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$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), i64immSExt32:$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)]>;
Evan Cheng259471d2007-10-05 17:59:57 +0000454} // Uses = [EFLAGS]
Evan Cheng55687072007-09-14 21:48:26 +0000455} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456
457// Unsigned multiplication
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000458let Defs = [RAX,RDX,EFLAGS], Uses = [RAX], neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000459def MUL64r : RI<0xF7, MRM4r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000460 "mul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000461let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000462def MUL64m : RI<0xF7, MRM4m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000463 "mul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464
465// Signed multiplication
Evan Chengb783fa32007-07-19 01:14:50 +0000466def IMUL64r : RI<0xF7, MRM5r, (outs), (ins GR64:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000467 "imul{q}\t$src", []>; // RAX,RDX = RAX*GR64
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000468let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000469def IMUL64m : RI<0xF7, MRM5m, (outs), (ins i64mem:$src),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000470 "imul{q}\t$src", []>; // RAX,RDX = RAX*[mem64]
471}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
Evan Cheng55687072007-09-14 21:48:26 +0000473let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474let isTwoAddress = 1 in {
475let isCommutable = 1 in
Bill Wendlingf5399032008-12-12 21:15:41 +0000476// Register-Register Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000477def IMUL64rr : RI<0xAF, MRMSrcReg, (outs GR64:$dst),
478 (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000479 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000480 [(set GR64:$dst, (mul GR64:$src1, GR64:$src2)),
481 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482
Bill Wendlingf5399032008-12-12 21:15:41 +0000483// Register-Memory Signed Integer Multiplication
Bill Wendlingae034ed2008-12-12 00:56:36 +0000484def IMUL64rm : RI<0xAF, MRMSrcMem, (outs GR64:$dst),
485 (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "imul{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000487 [(set GR64:$dst, (mul GR64:$src1, (load addr:$src2))),
488 (implicit EFLAGS)]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489} // isTwoAddress
490
491// Suprisingly enough, these are not two address instructions!
Bill Wendlingae034ed2008-12-12 00:56:36 +0000492
Bill Wendlingf5399032008-12-12 21:15:41 +0000493// Register-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000495 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000496 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000497 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$src2)),
498 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499def IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000500 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000502 [(set GR64:$dst, (mul GR64:$src1, i64immSExt8:$src2)),
503 (implicit EFLAGS)]>;
Bill Wendlingae034ed2008-12-12 00:56:36 +0000504
Bill Wendlingf5399032008-12-12 21:15:41 +0000505// Memory-Integer Signed Integer Multiplication
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
Evan Chengb783fa32007-07-19 01:14:50 +0000507 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000508 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000509 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000510 i64immSExt32:$src2)),
511 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512def IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000513 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000514 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Bill Wendlingae034ed2008-12-12 00:56:36 +0000515 [(set GR64:$dst, (mul (load addr:$src1),
Bill Wendlingf5399032008-12-12 21:15:41 +0000516 i64immSExt8:$src2)),
517 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000518} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
520// Unsigned division / remainder
Evan Cheng55687072007-09-14 21:48:26 +0000521let Defs = [RAX,RDX,EFLAGS], Uses = [RAX,RDX] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000522def DIV64r : RI<0xF7, MRM6r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000523 "div{q}\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524// Signed division / remainder
Evan Chengb783fa32007-07-19 01:14:50 +0000525def IDIV64r: RI<0xF7, MRM7r, (outs), (ins GR64:$src), // RDX:RAX/r64 = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000526 "idiv{q}\t$src", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000527let mayLoad = 1 in {
528def DIV64m : RI<0xF7, MRM6m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
529 "div{q}\t$src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000530def IDIV64m: RI<0xF7, MRM7m, (outs), (ins i64mem:$src), // RDX:RAX/[mem64] = RAX,RDX
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000531 "idiv{q}\t$src", []>;
532}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000533}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
535// Unary instructions
Evan Cheng55687072007-09-14 21:48:26 +0000536let Defs = [EFLAGS], CodeSize = 2 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000538def NEG64r : RI<0xF7, MRM3r, (outs GR64:$dst), (ins GR64:$src), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539 [(set GR64:$dst, (ineg GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000540def NEG64m : RI<0xF7, MRM3m, (outs), (ins i64mem:$dst), "neg{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 [(store (ineg (loadi64 addr:$dst)), addr:$dst)]>;
542
543let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000544def INC64r : RI<0xFF, MRM0r, (outs GR64:$dst), (ins GR64:$src), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 [(set GR64:$dst, (add GR64:$src, 1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000546def INC64m : RI<0xFF, MRM0m, (outs), (ins i64mem:$dst), "inc{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 [(store (add (loadi64 addr:$dst), 1), addr:$dst)]>;
548
549let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000550def DEC64r : RI<0xFF, MRM1r, (outs GR64:$dst), (ins GR64:$src), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 [(set GR64:$dst, (add GR64:$src, -1))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000552def DEC64m : RI<0xFF, MRM1m, (outs), (ins i64mem:$dst), "dec{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553 [(store (add (loadi64 addr:$dst), -1), addr:$dst)]>;
554
555// In 64-bit mode, single byte INC and DEC cannot be encoded.
556let isTwoAddress = 1, isConvertibleToThreeAddress = 1 in {
557// Can transform into LEA.
Dan Gohman91888f02007-07-31 20:11:57 +0000558def INC64_16r : I<0xFF, MRM0r, (outs GR16:$dst), (ins GR16:$src), "inc{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 [(set GR16:$dst, (add GR16:$src, 1))]>,
560 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000561def INC64_32r : I<0xFF, MRM0r, (outs GR32:$dst), (ins GR32:$src), "inc{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 [(set GR32:$dst, (add GR32:$src, 1))]>,
563 Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000564def DEC64_16r : I<0xFF, MRM1r, (outs GR16:$dst), (ins GR16:$src), "dec{w}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565 [(set GR16:$dst, (add GR16:$src, -1))]>,
566 OpSize, Requires<[In64BitMode]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000567def DEC64_32r : I<0xFF, MRM1r, (outs GR32:$dst), (ins GR32:$src), "dec{l}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 [(set GR32:$dst, (add GR32:$src, -1))]>,
569 Requires<[In64BitMode]>;
570} // isConvertibleToThreeAddress
Evan Cheng4a7e72f2007-10-19 21:23:22 +0000571
572// These are duplicates of their 32-bit counterparts. Only needed so X86 knows
573// how to unfold them.
574let isTwoAddress = 0, CodeSize = 2 in {
575 def INC64_16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
576 [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>,
577 OpSize, Requires<[In64BitMode]>;
578 def INC64_32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
579 [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>,
580 Requires<[In64BitMode]>;
581 def DEC64_16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
582 [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>,
583 OpSize, Requires<[In64BitMode]>;
584 def DEC64_32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
585 [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>,
586 Requires<[In64BitMode]>;
587}
Evan Cheng55687072007-09-14 21:48:26 +0000588} // Defs = [EFLAGS], CodeSize
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589
590
Evan Cheng55687072007-09-14 21:48:26 +0000591let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592// Shift instructions
593let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000594let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000595def SHL64rCL : RI<0xD3, MRM4r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000596 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000597 [(set GR64:$dst, (shl GR64:$src, CL))]>;
Evan Chenga98f6272007-10-05 18:20:36 +0000598let isConvertibleToThreeAddress = 1 in // Can transform into LEA.
Evan Chengb783fa32007-07-19 01:14:50 +0000599def SHL64ri : RIi8<0xC1, MRM4r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 "shl{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 [(set GR64:$dst, (shl GR64:$src1, (i8 imm:$src2)))]>;
Chris Lattnerf4005a82008-01-11 18:00:50 +0000602// NOTE: We don't use shifts of a register by one, because 'add reg,reg' is
603// cheaper.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604} // isTwoAddress
605
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000606let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000607def SHL64mCL : RI<0xD3, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000608 "shl{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000609 [(store (shl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000610def SHL64mi : RIi8<0xC1, MRM4m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000611 "shl{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 [(store (shl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000613def SHL64m1 : RI<0xD1, MRM4m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000614 "shl{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615 [(store (shl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
616
617let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000618let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000619def SHR64rCL : RI<0xD3, MRM5r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000620 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000621 [(set GR64:$dst, (srl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000622def SHR64ri : RIi8<0xC1, MRM5r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000623 "shr{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 [(set GR64:$dst, (srl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000625def SHR64r1 : RI<0xD1, MRM5r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000626 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 [(set GR64:$dst, (srl GR64:$src1, (i8 1)))]>;
628} // isTwoAddress
629
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000630let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000631def SHR64mCL : RI<0xD3, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000632 "shr{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000633 [(store (srl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000634def SHR64mi : RIi8<0xC1, MRM5m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000635 "shr{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636 [(store (srl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000637def SHR64m1 : RI<0xD1, MRM5m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000638 "shr{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 [(store (srl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
640
641let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000642let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000643def SAR64rCL : RI<0xD3, MRM7r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000644 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000645 [(set GR64:$dst, (sra GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000646def SAR64ri : RIi8<0xC1, MRM7r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000647 "sar{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000648 [(set GR64:$dst, (sra GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000649def SAR64r1 : RI<0xD1, MRM7r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000650 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 [(set GR64:$dst, (sra GR64:$src1, (i8 1)))]>;
652} // isTwoAddress
653
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000654let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000655def SAR64mCL : RI<0xD3, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000656 "sar{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000657 [(store (sra (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000658def SAR64mi : RIi8<0xC1, MRM7m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000659 "sar{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 [(store (sra (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000661def SAR64m1 : RI<0xD1, MRM7m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000662 "sar{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663 [(store (sra (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
664
665// Rotate instructions
666let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000667let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000668def ROL64rCL : RI<0xD3, MRM0r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000669 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000670 [(set GR64:$dst, (rotl GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000671def ROL64ri : RIi8<0xC1, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000672 "rol{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 [(set GR64:$dst, (rotl GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000674def ROL64r1 : RI<0xD1, MRM0r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000675 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 [(set GR64:$dst, (rotl GR64:$src1, (i8 1)))]>;
677} // isTwoAddress
678
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000679let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000680def ROL64mCL : I<0xD3, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000681 "rol{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000682 [(store (rotl (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000683def ROL64mi : RIi8<0xC1, MRM0m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "rol{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 [(store (rotl (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000686def ROL64m1 : RI<0xD1, MRM0m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000687 "rol{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 [(store (rotl (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
689
690let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000691let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000692def ROR64rCL : RI<0xD3, MRM1r, (outs GR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000693 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000694 [(set GR64:$dst, (rotr GR64:$src, CL))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000695def ROR64ri : RIi8<0xC1, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 "ror{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697 [(set GR64:$dst, (rotr GR64:$src1, (i8 imm:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000698def ROR64r1 : RI<0xD1, MRM1r, (outs GR64:$dst), (ins GR64:$src1),
Dan Gohman91888f02007-07-31 20:11:57 +0000699 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 [(set GR64:$dst, (rotr GR64:$src1, (i8 1)))]>;
701} // isTwoAddress
702
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000703let Uses = [CL] in
Evan Chengb783fa32007-07-19 01:14:50 +0000704def ROR64mCL : RI<0xD3, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000705 "ror{q}\t{%cl, $dst|$dst, %CL}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000706 [(store (rotr (loadi64 addr:$dst), CL), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000707def ROR64mi : RIi8<0xC1, MRM1m, (outs), (ins i64mem:$dst, i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "ror{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(store (rotr (loadi64 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000710def ROR64m1 : RI<0xD1, MRM1m, (outs), (ins i64mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "ror{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 [(store (rotr (loadi64 addr:$dst), (i8 1)), addr:$dst)]>;
713
714// Double shift instructions (generalizations of rotate)
715let isTwoAddress = 1 in {
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000716let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000717def SHLD64rrCL : RI<0xA5, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000718 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
719 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000720def SHRD64rrCL : RI<0xAD, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000721 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
722 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2, CL))]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000723}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724
725let isCommutable = 1 in { // FIXME: Update X86InstrInfo::commuteInstruction
726def SHLD64rri8 : RIi8<0xA4, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000727 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000728 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
729 [(set GR64:$dst, (X86shld GR64:$src1, GR64:$src2,
730 (i8 imm:$src3)))]>,
731 TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000732def SHRD64rri8 : RIi8<0xAC, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000733 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000734 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
735 [(set GR64:$dst, (X86shrd GR64:$src1, GR64:$src2,
736 (i8 imm:$src3)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 TB;
738} // isCommutable
739} // isTwoAddress
740
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000741let Uses = [CL] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000742def SHLD64mrCL : RI<0xA5, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000743 "shld{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
744 [(store (X86shld (loadi64 addr:$dst), GR64:$src2, CL),
745 addr:$dst)]>, TB;
Evan Chengb783fa32007-07-19 01:14:50 +0000746def SHRD64mrCL : RI<0xAD, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src2),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000747 "shrd{q}\t{%cl, $src2, $dst|$dst, $src2, %CL}",
748 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2, CL),
749 addr:$dst)]>, TB;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000750}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751def SHLD64mri8 : RIi8<0xA4, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000752 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000753 "shld{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
754 [(store (X86shld (loadi64 addr:$dst), GR64:$src2,
755 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 TB;
757def SHRD64mri8 : RIi8<0xAC, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000758 (outs), (ins i64mem:$dst, GR64:$src2, i8imm:$src3),
Dan Gohman4d9fc4a2007-09-14 23:17:45 +0000759 "shrd{q}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
760 [(store (X86shrd (loadi64 addr:$dst), GR64:$src2,
761 (i8 imm:$src3)), addr:$dst)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 TB;
Evan Cheng55687072007-09-14 21:48:26 +0000763} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764
765//===----------------------------------------------------------------------===//
766// Logical Instructions...
767//
768
769let isTwoAddress = 1 in
Dan Gohman91888f02007-07-31 20:11:57 +0000770def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 [(set GR64:$dst, (not GR64:$src))]>;
Dan Gohman91888f02007-07-31 20:11:57 +0000772def NOT64m : RI<0xF7, MRM2m, (outs), (ins i64mem:$dst), "not{q}\t$dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(store (not (loadi64 addr:$dst)), addr:$dst)]>;
774
Evan Cheng55687072007-09-14 21:48:26 +0000775let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776let isTwoAddress = 1 in {
777let isCommutable = 1 in
778def AND64rr : RI<0x21, MRMDestReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000779 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set GR64:$dst, (and GR64:$src1, GR64:$src2))]>;
782def AND64rm : RI<0x23, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000783 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(set GR64:$dst, (and GR64:$src1, (load addr:$src2)))]>;
786def AND64ri32 : RIi32<0x81, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000787 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000788 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000789 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
790def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000791 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000792 "and{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 [(set GR64:$dst, (and GR64:$src1, i64immSExt8:$src2))]>;
794} // isTwoAddress
795
796def AND64mr : RI<0x21, MRMDestMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000797 (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000798 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 [(store (and (load addr:$dst), GR64:$src), addr:$dst)]>;
800def AND64mi32 : RIi32<0x81, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000801 (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
804def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000805 (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000806 "and{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000807 [(store (and (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
808
809let isTwoAddress = 1 in {
810let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000811def OR64rr : RI<0x09, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000812 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813 [(set GR64:$dst, (or GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000814def OR64rm : RI<0x0B, MRMSrcMem , (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000815 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 [(set GR64:$dst, (or GR64:$src1, (load addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000817def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000818 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000820def OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000821 "or{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000822 [(set GR64:$dst, (or GR64:$src1, i64immSExt8:$src2))]>;
823} // isTwoAddress
824
Evan Chengb783fa32007-07-19 01:14:50 +0000825def OR64mr : RI<0x09, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000826 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 [(store (or (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000828def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000829 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000831def OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000832 "or{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(store (or (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
834
835let isTwoAddress = 1 in {
Evan Cheng0685efa2008-08-30 08:54:22 +0000836let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000837def XOR64rr : RI<0x31, MRMDestReg, (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000838 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 [(set GR64:$dst, (xor GR64:$src1, GR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000840def XOR64rm : RI<0x33, MRMSrcMem, (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000841 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 [(set GR64:$dst, (xor GR64:$src1, (load addr:$src2)))]>;
843def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000844 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000845 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846 [(set GR64:$dst, (xor GR64:$src1, i64immSExt32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000847def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000848 "xor{q}\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
850} // isTwoAddress
851
Evan Chengb783fa32007-07-19 01:14:50 +0000852def XOR64mr : RI<0x31, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000853 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854 [(store (xor (load addr:$dst), GR64:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000855def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000856 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857 [(store (xor (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000858def XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000859 "xor{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860 [(store (xor (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000861} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862
863//===----------------------------------------------------------------------===//
864// Comparison Instructions...
865//
866
867// Integer comparison
Evan Cheng55687072007-09-14 21:48:26 +0000868let Defs = [EFLAGS] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869let isCommutable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000870def TEST64rr : RI<0x85, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000871 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000872 [(X86cmp (and GR64:$src1, GR64:$src2), 0),
873 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000874def TEST64rm : RI<0x85, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000875 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000876 [(X86cmp (and GR64:$src1, (loadi64 addr:$src2)), 0),
877 (implicit EFLAGS)]>;
878def TEST64ri32 : RIi32<0xF7, MRM0r, (outs),
879 (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000880 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000881 [(X86cmp (and GR64:$src1, i64immSExt32:$src2), 0),
882 (implicit EFLAGS)]>;
883def TEST64mi32 : RIi32<0xF7, MRM0m, (outs),
884 (ins i64mem:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "test{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000886 [(X86cmp (and (loadi64 addr:$src1), i64immSExt32:$src2), 0),
887 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888
Evan Chengb783fa32007-07-19 01:14:50 +0000889def CMP64rr : RI<0x39, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000890 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000891 [(X86cmp GR64:$src1, GR64:$src2),
892 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000893def CMP64mr : RI<0x39, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000894 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000895 [(X86cmp (loadi64 addr:$src1), GR64:$src2),
896 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000897def CMP64rm : RI<0x3B, MRMSrcMem, (outs), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000898 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000899 [(X86cmp GR64:$src1, (loadi64 addr:$src2)),
900 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000901def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000902 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000903 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000904 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000905def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000906 (ins i64mem:$src1, i64i32imm:$src2),
907 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000908 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000909 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000910def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000911 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000912 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000913 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000914def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000915 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000916 [(X86cmp GR64:$src1, i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000917 (implicit EFLAGS)]>;
918} // Defs = [EFLAGS]
919
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +0000921let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +0000922let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000924 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000925 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000926 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000927 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000928def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000929 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000930 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000931 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000932 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000933def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000934 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000935 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000936 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000937 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000939 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000942 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000944 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000945 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000947 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000949 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000950 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000951 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000952 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000954 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000955 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000956 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000957 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000958def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000959 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000960 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000962 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000964 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000967 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000969 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000970 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000972 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000974 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000975 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000977 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000979 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000981 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000982 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000983def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000984 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000985 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000987 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000988def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000989 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000990 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000992 X86_COND_NP, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +0000993} // isCommutable = 1
994
995def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
996 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
997 "cmovb\t{$src2, $dst|$dst, $src2}",
998 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
999 X86_COND_B, EFLAGS))]>, TB;
1000def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1001 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1002 "cmovae\t{$src2, $dst|$dst, $src2}",
1003 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1004 X86_COND_AE, EFLAGS))]>, TB;
1005def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1006 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1007 "cmove\t{$src2, $dst|$dst, $src2}",
1008 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1009 X86_COND_E, EFLAGS))]>, TB;
1010def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1011 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1012 "cmovne\t{$src2, $dst|$dst, $src2}",
1013 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1014 X86_COND_NE, EFLAGS))]>, TB;
1015def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1016 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1017 "cmovbe\t{$src2, $dst|$dst, $src2}",
1018 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1019 X86_COND_BE, EFLAGS))]>, TB;
1020def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1021 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1022 "cmova\t{$src2, $dst|$dst, $src2}",
1023 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1024 X86_COND_A, EFLAGS))]>, TB;
1025def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1026 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1027 "cmovl\t{$src2, $dst|$dst, $src2}",
1028 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1029 X86_COND_L, EFLAGS))]>, TB;
1030def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1031 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1032 "cmovge\t{$src2, $dst|$dst, $src2}",
1033 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1034 X86_COND_GE, EFLAGS))]>, TB;
1035def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1036 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1037 "cmovle\t{$src2, $dst|$dst, $src2}",
1038 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1039 X86_COND_LE, EFLAGS))]>, TB;
1040def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1041 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1042 "cmovg\t{$src2, $dst|$dst, $src2}",
1043 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1044 X86_COND_G, EFLAGS))]>, TB;
1045def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1046 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1047 "cmovs\t{$src2, $dst|$dst, $src2}",
1048 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1049 X86_COND_S, EFLAGS))]>, TB;
1050def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1051 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1052 "cmovns\t{$src2, $dst|$dst, $src2}",
1053 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1054 X86_COND_NS, EFLAGS))]>, TB;
1055def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1056 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1057 "cmovp\t{$src2, $dst|$dst, $src2}",
1058 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1059 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001061 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001062 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001064 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065} // isTwoAddress
1066
1067//===----------------------------------------------------------------------===//
1068// Conversion Instructions...
1069//
1070
1071// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001072def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001073 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001074 [(set GR64:$dst,
1075 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001076def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001078 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1079 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001080def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001081 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001083def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001084 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001086def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001087 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001088 [(set GR64:$dst,
1089 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001090def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001092 [(set GR64:$dst,
1093 (int_x86_sse2_cvttsd2si64
1094 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095
1096// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001097def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001100def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001103
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104let isTwoAddress = 1 in {
1105def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001106 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001107 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001108 [(set VR128:$dst,
1109 (int_x86_sse2_cvtsi642sd VR128:$src1,
1110 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001112 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001113 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001114 [(set VR128:$dst,
1115 (int_x86_sse2_cvtsi642sd VR128:$src1,
1116 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001117} // isTwoAddress
1118
1119// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001120def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001121 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001123def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001124 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001126
1127let isTwoAddress = 1 in {
1128 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1129 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1130 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1131 [(set VR128:$dst,
1132 (int_x86_sse_cvtsi642ss VR128:$src1,
1133 GR64:$src2))]>;
1134 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1135 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1136 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1137 [(set VR128:$dst,
1138 (int_x86_sse_cvtsi642ss VR128:$src1,
1139 (loadi64 addr:$src2)))]>;
1140}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141
1142// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001143def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001144 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001145 [(set GR64:$dst,
1146 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001147def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001148 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001149 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1150 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001151def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001152 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001154def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001155 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001156 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001157def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001158 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001159 [(set GR64:$dst,
1160 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001161def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001163 [(set GR64:$dst,
1164 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1165
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166//===----------------------------------------------------------------------===//
1167// Alias Instructions
1168//===----------------------------------------------------------------------===//
1169
Dan Gohman027cd112007-09-17 14:55:08 +00001170// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1171// equivalent due to implicit zero-extending, and it sometimes has a smaller
1172// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001173// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1174// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1175// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001176let Defs = [EFLAGS], AddedComplexity = 1,
1177 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001178def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1179 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1180 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181
1182// Materialize i64 constant where top 32-bits are zero.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001183let AddedComplexity = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001184def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001185 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186 [(set GR64:$dst, i64immZExt32:$src)]>;
1187
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001188//===----------------------------------------------------------------------===//
1189// Thread Local Storage Instructions
1190//===----------------------------------------------------------------------===//
1191
1192def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001193 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001194 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001195
1196//===----------------------------------------------------------------------===//
1197// Atomic Instructions
1198//===----------------------------------------------------------------------===//
1199
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001200let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001201def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001202 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001203 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1204}
1205
Dan Gohmana41a1c092008-08-06 15:52:50 +00001206let Constraints = "$val = $dst" in {
1207let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001208def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001209 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001210 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001211 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001212def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001213 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001214 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001215}
1216
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001217// Atomic exchange, and, or, xor
1218let Constraints = "$val = $dst", Defs = [EFLAGS],
1219 usesCustomDAGSchedInserter = 1 in {
1220def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001221 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001222 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001223def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001224 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001225 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001226def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001227 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001228 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001229def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001230 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001231 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001232def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001233 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001234 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001235def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001236 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001237 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001238def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001239 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001240 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001241def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001242 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001243 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001244}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001245
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001246//===----------------------------------------------------------------------===//
1247// Non-Instruction Patterns
1248//===----------------------------------------------------------------------===//
1249
Bill Wendlingfef06052008-09-16 21:48:12 +00001250// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001251def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1252 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1253def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1254 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1255def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1256 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1257def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1258 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1259
1260def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1261 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001262 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001263def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1264 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001265 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1267 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001268 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1270 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001271 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272
1273// Calls
1274// Direct PC relative function call for small code model. 32-bit displacement
1275// sign extended to 64-bit.
1276def : Pat<(X86call (i64 tglobaladdr:$dst)),
1277 (CALL64pcrel32 tglobaladdr:$dst)>;
1278def : Pat<(X86call (i64 texternalsym:$dst)),
1279 (CALL64pcrel32 texternalsym:$dst)>;
1280
1281def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1282 (CALL64pcrel32 tglobaladdr:$dst)>;
1283def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1284 (CALL64pcrel32 texternalsym:$dst)>;
1285
1286def : Pat<(X86tailcall GR64:$dst),
1287 (CALL64r GR64:$dst)>;
1288
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001289
1290// tailcall stuff
1291def : Pat<(X86tailcall GR32:$dst),
1292 (TAILCALL)>;
1293def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1294 (TAILCALL)>;
1295def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1296 (TAILCALL)>;
1297
1298def : Pat<(X86tcret GR64:$dst, imm:$off),
1299 (TCRETURNri64 GR64:$dst, imm:$off)>;
1300
1301def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1302 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1303
1304def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1305 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1306
Dan Gohmanec596042007-09-17 14:35:24 +00001307// Comparisons.
1308
1309// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001310def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001311 (TEST64rr GR64:$src1, GR64:$src1)>;
1312
Christopher Lambb371e032008-03-13 05:47:01 +00001313
1314
1315// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001316def : Pat<(i64 (zext GR32:$src)),
1317 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001318
Duncan Sands082524c2008-01-23 20:39:46 +00001319// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1321
1322// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001323// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1324// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1325// partial-register updates.
1326def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1327def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1328def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1329// For other extloads, use subregs, since the high contents of the register are
1330// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001331def : Pat<(extloadi64i32 addr:$src),
1332 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1333 x86_subreg_32bit)>;
1334def : Pat<(extloadi16i1 addr:$src),
1335 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1336 x86_subreg_8bit)>,
1337 Requires<[In64BitMode]>;
1338def : Pat<(extloadi16i8 addr:$src),
1339 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1340 x86_subreg_8bit)>,
1341 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342
Dan Gohmandd612bb2008-08-20 21:27:32 +00001343// anyext
1344def : Pat<(i64 (anyext GR8:$src)),
1345 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1346def : Pat<(i64 (anyext GR16:$src)),
1347 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001348def : Pat<(i64 (anyext GR32:$src)),
1349 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001350def : Pat<(i16 (anyext GR8:$src)),
1351 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1352 Requires<[In64BitMode]>;
1353def : Pat<(i32 (anyext GR8:$src)),
1354 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1355 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001356
1357//===----------------------------------------------------------------------===//
1358// Some peepholes
1359//===----------------------------------------------------------------------===//
1360
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001361// Odd encoding trick: -128 fits into an 8-bit immediate field while
1362// +128 doesn't, so in this special case use a sub instead of an add.
1363def : Pat<(add GR64:$src1, 128),
1364 (SUB64ri8 GR64:$src1, -128)>;
1365def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1366 (SUB64mi8 addr:$dst, -128)>;
1367
1368// The same trick applies for 32-bit immediate fields in 64-bit
1369// instructions.
1370def : Pat<(add GR64:$src1, 0x0000000080000000),
1371 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1372def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1373 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1374
Dan Gohman47a419d2008-08-07 02:54:50 +00001375// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001376def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001377 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001378// r & (2^16-1) ==> movz
1379def : Pat<(and GR64:$src, 0xffff),
1380 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1381// r & (2^8-1) ==> movz
1382def : Pat<(and GR64:$src, 0xff),
1383 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001384// r & (2^8-1) ==> movz
1385def : Pat<(and GR32:$src1, 0xff),
1386 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1387 Requires<[In64BitMode]>;
1388// r & (2^8-1) ==> movz
1389def : Pat<(and GR16:$src1, 0xff),
1390 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1391 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001392
Dan Gohmandd612bb2008-08-20 21:27:32 +00001393// sext_inreg patterns
1394def : Pat<(sext_inreg GR64:$src, i32),
1395 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1396def : Pat<(sext_inreg GR64:$src, i16),
1397 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1398def : Pat<(sext_inreg GR64:$src, i8),
1399 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1400def : Pat<(sext_inreg GR32:$src, i8),
1401 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1402 Requires<[In64BitMode]>;
1403def : Pat<(sext_inreg GR16:$src, i8),
1404 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1405 Requires<[In64BitMode]>;
1406
1407// trunc patterns
1408def : Pat<(i32 (trunc GR64:$src)),
1409 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1410def : Pat<(i16 (trunc GR64:$src)),
1411 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1412def : Pat<(i8 (trunc GR64:$src)),
1413 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1414def : Pat<(i8 (trunc GR32:$src)),
1415 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1416 Requires<[In64BitMode]>;
1417def : Pat<(i8 (trunc GR16:$src)),
1418 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1419 Requires<[In64BitMode]>;
1420
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001421// (shl x, 1) ==> (add x, x)
1422def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1423
Evan Cheng76a64c72008-08-30 02:03:58 +00001424// (shl x (and y, 63)) ==> (shl x, y)
1425def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1426 (SHL64rCL GR64:$src1)>;
1427def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1428 (SHL64mCL addr:$dst)>;
1429
1430def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1431 (SHR64rCL GR64:$src1)>;
1432def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1433 (SHR64mCL addr:$dst)>;
1434
1435def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1436 (SAR64rCL GR64:$src1)>;
1437def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1438 (SAR64mCL addr:$dst)>;
1439
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001440// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1441def : Pat<(or (srl GR64:$src1, CL:$amt),
1442 (shl GR64:$src2, (sub 64, CL:$amt))),
1443 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1444
1445def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1446 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1447 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1448
Dan Gohman921581d2008-10-17 01:23:35 +00001449def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1450 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1451 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1452
1453def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1454 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1455 addr:$dst),
1456 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1457
1458def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1459 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1460
1461def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1462 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1463 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1464
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001465// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1466def : Pat<(or (shl GR64:$src1, CL:$amt),
1467 (srl GR64:$src2, (sub 64, CL:$amt))),
1468 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1469
1470def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1471 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1472 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1473
Dan Gohman921581d2008-10-17 01:23:35 +00001474def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1475 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1476 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1477
1478def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1479 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1480 addr:$dst),
1481 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1482
1483def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1484 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1485
1486def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1487 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1488 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1489
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490// X86 specific add which produces a flag.
1491def : Pat<(addc GR64:$src1, GR64:$src2),
1492 (ADD64rr GR64:$src1, GR64:$src2)>;
1493def : Pat<(addc GR64:$src1, (load addr:$src2)),
1494 (ADD64rm GR64:$src1, addr:$src2)>;
1495def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1496 (ADD64ri32 GR64:$src1, imm:$src2)>;
1497def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1498 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1499
1500def : Pat<(subc GR64:$src1, GR64:$src2),
1501 (SUB64rr GR64:$src1, GR64:$src2)>;
1502def : Pat<(subc GR64:$src1, (load addr:$src2)),
1503 (SUB64rm GR64:$src1, addr:$src2)>;
1504def : Pat<(subc GR64:$src1, imm:$src2),
1505 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1506def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1507 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1508
Bill Wendlingf5399032008-12-12 21:15:41 +00001509//===----------------------------------------------------------------------===//
1510// Overflow Patterns
1511//===----------------------------------------------------------------------===//
1512
1513// Register-Register Addition with Overflow
1514def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1515 (implicit EFLAGS)),
1516 (ADD64rr GR64:$src1, GR64:$src2)>;
1517
1518// Register-Integer Addition with Overflow
1519def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1520 (implicit EFLAGS)),
1521 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
1522def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1523 (implicit EFLAGS)),
1524 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
1525
1526// Register-Memory Addition with Overflow
1527def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1528 (implicit EFLAGS)),
1529 (ADD64rm GR64:$src1, addr:$src2)>;
1530
1531// Memory-Register Addition with Overflow
1532def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1533 addr:$dst),
1534 (implicit EFLAGS)),
1535 (ADD64mr addr:$dst, GR64:$src2)>;
1536def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1537 addr:$dst),
1538 (implicit EFLAGS)),
1539 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
1540def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1541 addr:$dst),
1542 (implicit EFLAGS)),
1543 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
1544
1545// Register-Register Subtraction with Overflow
1546def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1547 (implicit EFLAGS)),
1548 (SUB64rr GR64:$src1, GR64:$src2)>;
1549
1550// Register-Memory Subtraction with Overflow
1551def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1552 (implicit EFLAGS)),
1553 (SUB64rm GR64:$src1, addr:$src2)>;
1554
1555// Register-Integer Subtraction with Overflow
1556def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1557 (implicit EFLAGS)),
1558 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
1559def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1560 (implicit EFLAGS)),
1561 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
1562
1563// Memory-Register Subtraction with Overflow
1564def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1565 addr:$dst),
1566 (implicit EFLAGS)),
1567 (SUB64mr addr:$dst, GR64:$src2)>;
1568
1569// Memory-Integer Subtraction with Overflow
1570def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1571 addr:$dst),
1572 (implicit EFLAGS)),
1573 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
1574def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1575 addr:$dst),
1576 (implicit EFLAGS)),
1577 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
1578
1579// Register-Register Signed Integer Multiplication with Overflow
1580def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1581 (implicit EFLAGS)),
1582 (IMUL64rr GR64:$src1, GR64:$src2)>;
1583
1584// Register-Memory Signed Integer Multiplication with Overflow
1585def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1586 (implicit EFLAGS)),
1587 (IMUL64rm GR64:$src1, addr:$src2)>;
1588
1589// Register-Integer Signed Integer Multiplication with Overflow
1590def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1591 (implicit EFLAGS)),
1592 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
1593def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1594 (implicit EFLAGS)),
1595 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
1596
1597// Memory-Integer Signed Integer Multiplication with Overflow
1598def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1599 (implicit EFLAGS)),
1600 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
1601def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1602 (implicit EFLAGS)),
1603 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001604
1605//===----------------------------------------------------------------------===//
1606// X86-64 SSE Instructions
1607//===----------------------------------------------------------------------===//
1608
1609// Move instructions...
1610
Evan Chengb783fa32007-07-19 01:14:50 +00001611def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001612 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001613 [(set VR128:$dst,
1614 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001615def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001616 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001617 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1618 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001619
Evan Chengb783fa32007-07-19 01:14:50 +00001620def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001621 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001622 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001623def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001624 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001625 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1626
Evan Chengb783fa32007-07-19 01:14:50 +00001627def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001628 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001629 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001630def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001631 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001633
1634//===----------------------------------------------------------------------===//
1635// X86-64 SSE4.1 Instructions
1636//===----------------------------------------------------------------------===//
1637
Nate Begeman4294c1f2008-02-12 22:51:28 +00001638/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1639multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001640 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001641 (ins VR128:$src1, i32i8imm:$src2),
1642 !strconcat(OpcodeStr,
1643 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1644 [(set GR64:$dst,
1645 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001646 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001647 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1648 !strconcat(OpcodeStr,
1649 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1650 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1651 addr:$dst)]>, OpSize, REX_W;
1652}
1653
1654defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1655
1656let isTwoAddress = 1 in {
1657 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001658 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001659 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1660 !strconcat(OpcodeStr,
1661 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1662 [(set VR128:$dst,
1663 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1664 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001665 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001666 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1667 !strconcat(OpcodeStr,
1668 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1669 [(set VR128:$dst,
1670 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1671 imm:$src3)))]>, OpSize, REX_W;
1672 }
1673}
1674
1675defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;