blob: 6e284a63194ca2e4f7d349a38922131112033eec [file] [log] [blame]
Chris Lattner2de8d2b2008-01-10 05:50:42 +00001//====- X86Instr64bit.td - Describe X86-64 Instructions ----*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86-64 instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000017// Operand Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018//
19
20// 64-bits but only 32 bits are significant.
21def i64i32imm : Operand<i64>;
22// 64-bits but only 8 bits are significant.
23def i64i8imm : Operand<i64>;
24
25def lea64mem : Operand<i64> {
26 let PrintMethod = "printi64mem";
27 let MIOperandInfo = (ops GR64, i8imm, GR64, i32imm);
28}
29
30def lea64_32mem : Operand<i32> {
31 let PrintMethod = "printlea64_32mem";
32 let MIOperandInfo = (ops GR32, i8imm, GR32, i32imm);
33}
34
35//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000036// Complex Pattern Definitions.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037//
38def lea64addr : ComplexPattern<i64, 4, "SelectLEAAddr",
39 [add, mul, shl, or, frameindex, X86Wrapper],
40 []>;
41
42//===----------------------------------------------------------------------===//
Chris Lattner2de8d2b2008-01-10 05:50:42 +000043// Pattern fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044//
45
Dan Gohmand16fdc02008-12-19 18:25:21 +000046def i64immSExt8 : PatLeaf<(i64 imm), [{
47 // i64immSExt8 predicate - True if the 64-bit immediate fits in a 8-bit
48 // sign extended field.
49 return (int64_t)N->getZExtValue() == (int8_t)N->getZExtValue();
50}]>;
51
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052def i64immSExt32 : PatLeaf<(i64 imm), [{
53 // i64immSExt32 predicate - True if the 64-bit immediate fits in a 32-bit
54 // sign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000055 return (int64_t)N->getZExtValue() == (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}]>;
57
58def i64immZExt32 : PatLeaf<(i64 imm), [{
59 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
60 // unsignedsign extended field.
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000061 return (uint64_t)N->getZExtValue() == (uint32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062}]>;
63
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
65def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
66def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
67
68def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
69def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
70def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
71def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
72
73def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
74def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
75def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
76def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
77
78//===----------------------------------------------------------------------===//
79// Instruction list...
80//
81
Dan Gohman01c9f772008-10-01 18:28:06 +000082// ADJCALLSTACKDOWN/UP implicitly use/def RSP because they may be expanded into
83// a stack adjustment and the codegen must know that they may modify the stack
84// pointer before prolog-epilog rewriting occurs.
85// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
86// sub / add which can clobber EFLAGS.
87let Defs = [RSP, EFLAGS], Uses = [RSP] in {
88def ADJCALLSTACKDOWN64 : I<0, Pseudo, (outs), (ins i32imm:$amt),
89 "#ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000090 [(X86callseq_start timm:$amt)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000091 Requires<[In64BitMode]>;
92def ADJCALLSTACKUP64 : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
93 "#ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000094 [(X86callseq_end timm:$amt1, timm:$amt2)]>,
Dan Gohman01c9f772008-10-01 18:28:06 +000095 Requires<[In64BitMode]>;
96}
97
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098//===----------------------------------------------------------------------===//
99// Call Instructions...
100//
Evan Cheng37e7c752007-07-21 00:34:19 +0000101let isCall = 1 in
Dan Gohman01c9f772008-10-01 18:28:06 +0000102 // All calls clobber the non-callee saved registers. RSP is marked as
103 // a use to prevent stack-pointer assignments that appear immediately
104 // before calls from potentially appearing dead. Uses for argument
105 // registers are added manually.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
Evan Cheng931a8f42008-01-29 19:34:22 +0000107 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
109 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
Dan Gohman9499cfe2008-10-01 04:14:30 +0000110 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
111 Uses = [RSP] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000112 def CALL64pcrel32 : I<0xE8, RawFrm, (outs), (ins i64imm:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000113 "call\t${dst:call}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000114 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
Dan Gohman91888f02007-07-31 20:11:57 +0000115 "call\t{*}$dst", [(X86call GR64:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000116 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
Dan Gohmanea4faba2008-05-29 21:50:34 +0000117 "call\t{*}$dst", [(X86call (loadi64 addr:$dst))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 }
119
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000120
121
122let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
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
Bill Wendlingae034ed2008-12-12 00:56:36 +0000322def ADD64ri8 : RIi8<0x83, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
323 "add{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000324 [(set GR64:$dst, (add GR64:$src1, i64immSExt8:$src2)),
325 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000326def ADD64ri32 : RIi32<0x81, MRM0r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
327 "add{q}\t{$src2, $dst|$dst, $src2}",
328 [(set GR64:$dst, (add GR64:$src1, i64immSExt32:$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 ADD64mi8 : RIi8<0x83, MRM0m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2), addr:$dst),
347 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000348def ADD64mi32 : RIi32<0x81, MRM0m, (outs), (ins i64mem:$dst, i64i32imm :$src2),
349 "add{q}\t{$src2, $dst|$dst, $src2}",
350 [(store (add (load addr:$dst), i64immSExt32:$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 ADC64ri8 : RIi8<0x83, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$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, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000367def ADC64ri32 : RIi32<0x81, MRM2r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
368 "adc{q}\t{$src2, $dst|$dst, $src2}",
369 [(set GR64:$dst, (adde GR64:$src1, i64immSExt32:$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 ADC64mi8 : RIi8<0x83, MRM2m, (outs), (ins i64mem:$dst, i64i8imm :$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)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000378def ADC64mi32 : RIi32<0x81, MRM2m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
379 "adc{q}\t{$src2, $dst|$dst, $src2}",
380 [(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
Bill Wendlingae034ed2008-12-12 00:56:36 +0000397def SUB64ri8 : RIi8<0x83, MRM5r, (outs GR64:$dst),
398 (ins GR64:$src1, i64i8imm:$src2),
399 "sub{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendlingf5399032008-12-12 21:15:41 +0000400 [(set GR64:$dst, (sub GR64:$src1, i64immSExt8:$src2)),
401 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000402def SUB64ri32 : RIi32<0x81, MRM5r, (outs GR64:$dst),
403 (ins GR64:$src1, i64i32imm:$src2),
404 "sub{q}\t{$src2, $dst|$dst, $src2}",
405 [(set GR64:$dst, (sub GR64:$src1, i64immSExt32:$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
Evan Chengb783fa32007-07-19 01:14:50 +0000416def SUB64mi8 : RIi8<0x83, MRM5m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2),
Bill Wendlingf5399032008-12-12 21:15:41 +0000419 addr:$dst),
420 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000421def SUB64mi32 : RIi32<0x81, MRM5m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
422 "sub{q}\t{$src2, $dst|$dst, $src2}",
423 [(store (sub (load addr:$dst), i64immSExt32:$src2),
424 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 SBB64ri8 : RIi8<0x83, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$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, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000440def SBB64ri32 : RIi32<0x81, MRM3r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
441 "sbb{q}\t{$src2, $dst|$dst, $src2}",
442 [(set GR64:$dst, (sube GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000443} // 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 SBB64mi8 : RIi8<0x83, MRM3m, (outs), (ins i64mem:$dst, i64i8imm :$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), i64immSExt8:$src2), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000451def SBB64mi32 : RIi32<0x81, MRM3m, (outs), (ins i64mem:$dst, i64i32imm:$src2),
452 "sbb{q}\t{$src2, $dst|$dst, $src2}",
453 [(store (sube (load addr:$dst), i64immSExt32:$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 IMUL64rri8 : RIi8<0x6B, MRMSrcReg, // GR64 = GR64*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000495 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$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, i64immSExt8:$src2)),
498 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000499def IMUL64rri32 : RIi32<0x69, MRMSrcReg, // GR64 = GR64*I32
500 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
501 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
502 [(set GR64:$dst, (mul GR64:$src1, i64immSExt32:$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 IMUL64rmi8 : RIi8<0x6B, MRMSrcMem, // GR64 = [mem64]*I8
Evan Chengb783fa32007-07-19 01:14:50 +0000507 (outs GR64:$dst), (ins i64mem:$src1, i64i8imm: $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 i64immSExt8:$src2)),
511 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000512def IMUL64rmi32 : RIi32<0x69, MRMSrcMem, // GR64 = [mem64]*I32
513 (outs GR64:$dst), (ins i64mem:$src1, i64i32imm:$src2),
514 "imul{q}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
515 [(set GR64:$dst, (mul (load addr:$src1),
516 i64immSExt32:$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)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786def AND64ri8 : RIi8<0x83, MRM4r,
Evan Chengb783fa32007-07-19 01:14:50 +0000787 (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$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, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000790def AND64ri32 : RIi32<0x81, MRM4r,
791 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
792 "and{q}\t{$src2, $dst|$dst, $src2}",
793 [(set GR64:$dst, (and GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794} // 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)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800def AND64mi8 : RIi8<0x83, MRM4m,
Evan Chengb783fa32007-07-19 01:14:50 +0000801 (outs), (ins i64mem:$dst, i64i8imm :$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 (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000804def AND64mi32 : RIi32<0x81, MRM4m,
805 (outs), (ins i64mem:$dst, i64i32imm:$src),
806 "and{q}\t{$src, $dst|$dst, $src}",
807 [(store (and (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808
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 OR64ri8 : RIi8<0x83, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$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, i64immSExt8:$src2))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000820def OR64ri32 : RIi32<0x81, MRM1r, (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$src2),
821 "or{q}\t{$src2, $dst|$dst, $src2}",
822 [(set GR64:$dst, (or GR64:$src1, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823} // 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 OR64mi8 : RIi8<0x83, MRM1m, (outs), (ins i64mem:$dst, i64i8imm:$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 (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000831def OR64mi32 : RIi32<0x81, MRM1m, (outs), (ins i64mem:$dst, i64i32imm:$src),
832 "or{q}\t{$src, $dst|$dst, $src}",
833 [(store (or (loadi64 addr:$dst), i64immSExt32:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834
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)))]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000843def XOR64ri8 : RIi8<0x83, MRM6r, (outs GR64:$dst), (ins GR64:$src1, i64i8imm:$src2),
844 "xor{q}\t{$src2, $dst|$dst, $src2}",
845 [(set GR64:$dst, (xor GR64:$src1, i64immSExt8:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846def XOR64ri32 : RIi32<0x81, MRM6r,
Evan Chengb783fa32007-07-19 01:14:50 +0000847 (outs GR64:$dst), (ins GR64:$src1, i64i32imm:$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, i64immSExt32:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850} // 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 XOR64mi8 : RIi8<0x83, MRM6m, (outs), (ins i64mem:$dst, i64i8imm :$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 (load addr:$dst), i64immSExt8:$src), addr:$dst)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000858def XOR64mi32 : RIi32<0x81, MRM6m, (outs), (ins i64mem:$dst, i64i32imm:$src),
859 "xor{q}\t{$src, $dst|$dst, $src}",
860 [(store (xor (loadi64 addr:$dst), i64immSExt32:$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)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000901def CMP64ri8 : RIi8<0x83, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
902 "cmp{q}\t{$src2, $src1|$src1, $src2}",
903 [(X86cmp GR64:$src1, i64immSExt8:$src2),
904 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000905def CMP64ri32 : RIi32<0x81, MRM7r, (outs), (ins GR64:$src1, i64i32imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000906 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000907 [(X86cmp GR64:$src1, i64immSExt32:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000908 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000909def CMP64mi8 : RIi8<0x83, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000910 "cmp{q}\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000911 [(X86cmp (loadi64 addr:$src1), i64immSExt8:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000912 (implicit EFLAGS)]>;
Dan Gohmand16fdc02008-12-19 18:25:21 +0000913def CMP64mi32 : RIi32<0x81, MRM7m, (outs),
914 (ins i64mem:$src1, i64i32imm:$src2),
915 "cmp{q}\t{$src2, $src1|$src1, $src2}",
916 [(X86cmp (loadi64 addr:$src1), i64immSExt32:$src2),
917 (implicit EFLAGS)]>;
Evan Cheng950aac02007-09-25 01:57:46 +0000918} // Defs = [EFLAGS]
919
Dan Gohman7fe9b7f2008-12-23 22:45:23 +0000920// Bit tests.
921// TODO: BT with immediate operands.
922// TODO: BTC, BTR, and BTS
923let Defs = [EFLAGS] in {
924def BT64rr : RI<0xA3, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
925 "bt{q}\t{$src2, $src1|$src1, $src2}",
926 [(X86bt GR64:$src1, GR64:$src2),
927 (implicit EFLAGS)]>;
928def BT64mr : RI<0xA3, MRMSrcMem, (outs), (ins i64mem:$src1, GR64:$src2),
929 "bt{q}\t{$src2, $src1|$src1, $src2}",
930 [(X86bt addr:$src1, GR64:$src2),
931 (implicit EFLAGS)]>;
932} // Defs = [EFLAGS]
933
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934// Conditional moves
Evan Cheng950aac02007-09-25 01:57:46 +0000935let Uses = [EFLAGS], isTwoAddress = 1 in {
Evan Cheng926658c2007-10-05 23:13:21 +0000936let isCommutable = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937def CMOVB64rr : RI<0x42, MRMSrcReg, // if <u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000938 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000939 "cmovb\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000940 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000941 X86_COND_B, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000942def CMOVAE64rr: RI<0x43, MRMSrcReg, // if >=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000943 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000944 "cmovae\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000946 X86_COND_AE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000947def CMOVE64rr : RI<0x44, MRMSrcReg, // if ==, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000948 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "cmove\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000950 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000951 X86_COND_E, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952def CMOVNE64rr: RI<0x45, MRMSrcReg, // if !=, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000953 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "cmovne\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000956 X86_COND_NE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957def CMOVBE64rr: RI<0x46, MRMSrcReg, // if <=u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000958 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "cmovbe\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000961 X86_COND_BE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962def CMOVA64rr : RI<0x47, MRMSrcReg, // if >u, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000963 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "cmova\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000966 X86_COND_A, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967def CMOVL64rr : RI<0x4C, MRMSrcReg, // if <s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000968 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000969 "cmovl\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000970 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000971 X86_COND_L, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972def CMOVGE64rr: RI<0x4D, MRMSrcReg, // if >=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000973 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000974 "cmovge\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000976 X86_COND_GE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977def CMOVLE64rr: RI<0x4E, MRMSrcReg, // if <=s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000978 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000979 "cmovle\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000981 X86_COND_LE, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000982def CMOVG64rr : RI<0x4F, MRMSrcReg, // if >s, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000983 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000984 "cmovg\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000986 X86_COND_G, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000987def CMOVS64rr : RI<0x48, MRMSrcReg, // if signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000988 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "cmovs\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000991 X86_COND_S, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000992def CMOVNS64rr: RI<0x49, MRMSrcReg, // if !signed, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000993 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000994 "cmovns\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +0000996 X86_COND_NS, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000997def CMOVP64rr : RI<0x4A, MRMSrcReg, // if parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +0000998 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000999 "cmovp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001001 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001002def CMOVNP64rr : RI<0x4B, MRMSrcReg, // if !parity, GR64 = GR64
Evan Chengb783fa32007-07-19 01:14:50 +00001003 (outs GR64:$dst), (ins GR64:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001004 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001005 [(set GR64:$dst, (X86cmov GR64:$src1, GR64:$src2,
Evan Cheng621216e2007-09-29 00:00:36 +00001006 X86_COND_NP, EFLAGS))]>, TB;
Evan Cheng926658c2007-10-05 23:13:21 +00001007} // isCommutable = 1
1008
1009def CMOVB64rm : RI<0x42, MRMSrcMem, // if <u, GR64 = [mem64]
1010 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1011 "cmovb\t{$src2, $dst|$dst, $src2}",
1012 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1013 X86_COND_B, EFLAGS))]>, TB;
1014def CMOVAE64rm: RI<0x43, MRMSrcMem, // if >=u, GR64 = [mem64]
1015 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1016 "cmovae\t{$src2, $dst|$dst, $src2}",
1017 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1018 X86_COND_AE, EFLAGS))]>, TB;
1019def CMOVE64rm : RI<0x44, MRMSrcMem, // if ==, GR64 = [mem64]
1020 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1021 "cmove\t{$src2, $dst|$dst, $src2}",
1022 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1023 X86_COND_E, EFLAGS))]>, TB;
1024def CMOVNE64rm: RI<0x45, MRMSrcMem, // if !=, GR64 = [mem64]
1025 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1026 "cmovne\t{$src2, $dst|$dst, $src2}",
1027 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1028 X86_COND_NE, EFLAGS))]>, TB;
1029def CMOVBE64rm: RI<0x46, MRMSrcMem, // if <=u, GR64 = [mem64]
1030 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1031 "cmovbe\t{$src2, $dst|$dst, $src2}",
1032 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1033 X86_COND_BE, EFLAGS))]>, TB;
1034def CMOVA64rm : RI<0x47, MRMSrcMem, // if >u, GR64 = [mem64]
1035 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1036 "cmova\t{$src2, $dst|$dst, $src2}",
1037 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1038 X86_COND_A, EFLAGS))]>, TB;
1039def CMOVL64rm : RI<0x4C, MRMSrcMem, // if <s, GR64 = [mem64]
1040 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1041 "cmovl\t{$src2, $dst|$dst, $src2}",
1042 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1043 X86_COND_L, EFLAGS))]>, TB;
1044def CMOVGE64rm: RI<0x4D, MRMSrcMem, // if >=s, GR64 = [mem64]
1045 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1046 "cmovge\t{$src2, $dst|$dst, $src2}",
1047 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1048 X86_COND_GE, EFLAGS))]>, TB;
1049def CMOVLE64rm: RI<0x4E, MRMSrcMem, // if <=s, GR64 = [mem64]
1050 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1051 "cmovle\t{$src2, $dst|$dst, $src2}",
1052 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1053 X86_COND_LE, EFLAGS))]>, TB;
1054def CMOVG64rm : RI<0x4F, MRMSrcMem, // if >s, GR64 = [mem64]
1055 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1056 "cmovg\t{$src2, $dst|$dst, $src2}",
1057 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1058 X86_COND_G, EFLAGS))]>, TB;
1059def CMOVS64rm : RI<0x48, MRMSrcMem, // if signed, GR64 = [mem64]
1060 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1061 "cmovs\t{$src2, $dst|$dst, $src2}",
1062 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1063 X86_COND_S, EFLAGS))]>, TB;
1064def CMOVNS64rm: RI<0x49, MRMSrcMem, // if !signed, GR64 = [mem64]
1065 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1066 "cmovns\t{$src2, $dst|$dst, $src2}",
1067 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1068 X86_COND_NS, EFLAGS))]>, TB;
1069def CMOVP64rm : RI<0x4A, MRMSrcMem, // if parity, GR64 = [mem64]
1070 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
1071 "cmovp\t{$src2, $dst|$dst, $src2}",
1072 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
1073 X86_COND_P, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074def CMOVNP64rm : RI<0x4B, MRMSrcMem, // if !parity, GR64 = [mem64]
Evan Chengb783fa32007-07-19 01:14:50 +00001075 (outs GR64:$dst), (ins GR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001076 "cmovnp\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001077 [(set GR64:$dst, (X86cmov GR64:$src1, (loadi64 addr:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +00001078 X86_COND_NP, EFLAGS))]>, TB;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079} // isTwoAddress
1080
1081//===----------------------------------------------------------------------===//
1082// Conversion Instructions...
1083//
1084
1085// f64 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001086def Int_CVTSD2SI64rr: RSDI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001087 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001088 [(set GR64:$dst,
1089 (int_x86_sse2_cvtsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001090def Int_CVTSD2SI64rm: RSDI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "cvtsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001092 [(set GR64:$dst, (int_x86_sse2_cvtsd2si64
1093 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001094def CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 [(set GR64:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001097def CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099 [(set GR64:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001100def Int_CVTTSD2SI64rr: RSDI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001102 [(set GR64:$dst,
1103 (int_x86_sse2_cvttsd2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001104def Int_CVTTSD2SI64rm: RSDI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001105 "cvttsd2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001106 [(set GR64:$dst,
1107 (int_x86_sse2_cvttsd2si64
1108 (load addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001109
1110// Signed i64 -> f64
Evan Chengb783fa32007-07-19 01:14:50 +00001111def CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001112 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113 [(set FR64:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001114def CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001115 "cvtsi2sd{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116 [(set FR64:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001117
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118let isTwoAddress = 1 in {
1119def Int_CVTSI2SD64rr: RSDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001120 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001121 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001122 [(set VR128:$dst,
1123 (int_x86_sse2_cvtsi642sd VR128:$src1,
1124 GR64:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125def Int_CVTSI2SD64rm: RSDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001126 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001127 "cvtsi2sd{q}\t{$src2, $dst|$dst, $src2}",
Bill Wendling6227d462007-07-23 03:07:27 +00001128 [(set VR128:$dst,
1129 (int_x86_sse2_cvtsi642sd VR128:$src1,
1130 (loadi64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131} // isTwoAddress
1132
1133// Signed i64 -> f32
Evan Chengb783fa32007-07-19 01:14:50 +00001134def CVTSI2SS64rr: RSSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 [(set FR32:$dst, (sint_to_fp GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001137def CVTSI2SS64rm: RSSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001138 "cvtsi2ss{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139 [(set FR32:$dst, (sint_to_fp (loadi64 addr:$src)))]>;
Evan Cheng1d5832e2008-01-11 07:37:44 +00001140
1141let isTwoAddress = 1 in {
1142 def Int_CVTSI2SS64rr : RSSI<0x2A, MRMSrcReg,
1143 (outs VR128:$dst), (ins VR128:$src1, GR64:$src2),
1144 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1145 [(set VR128:$dst,
1146 (int_x86_sse_cvtsi642ss VR128:$src1,
1147 GR64:$src2))]>;
1148 def Int_CVTSI2SS64rm : RSSI<0x2A, MRMSrcMem,
1149 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
1150 "cvtsi2ss{q}\t{$src2, $dst|$dst, $src2}",
1151 [(set VR128:$dst,
1152 (int_x86_sse_cvtsi642ss VR128:$src1,
1153 (loadi64 addr:$src2)))]>;
1154}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001155
1156// f32 -> signed i64
Evan Chengb783fa32007-07-19 01:14:50 +00001157def Int_CVTSS2SI64rr: RSSI<0x2D, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001158 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001159 [(set GR64:$dst,
1160 (int_x86_sse_cvtss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001161def Int_CVTSS2SI64rm: RSSI<0x2D, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "cvtss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001163 [(set GR64:$dst, (int_x86_sse_cvtss2si64
1164 (load addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001165def CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001166 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001167 [(set GR64:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001168def CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001169 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001170 [(set GR64:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001171def Int_CVTTSS2SI64rr: RSSI<0x2C, MRMSrcReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001172 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001173 [(set GR64:$dst,
1174 (int_x86_sse_cvttss2si64 VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001175def Int_CVTTSS2SI64rm: RSSI<0x2C, MRMSrcMem, (outs GR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001176 "cvttss2si{q}\t{$src, $dst|$dst, $src}",
Bill Wendling6227d462007-07-23 03:07:27 +00001177 [(set GR64:$dst,
1178 (int_x86_sse_cvttss2si64 (load addr:$src)))]>;
1179
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001180//===----------------------------------------------------------------------===//
1181// Alias Instructions
1182//===----------------------------------------------------------------------===//
1183
Dan Gohman027cd112007-09-17 14:55:08 +00001184// Alias instructions that map movr0 to xor. Use xorl instead of xorq; it's
1185// equivalent due to implicit zero-extending, and it sometimes has a smaller
1186// encoding.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
1188// FIXME: AddedComplexity gives MOV64r0 a higher priority than MOV64ri32. Remove
1189// when we have a better way to specify isel priority.
Bill Wendling12e97212008-05-30 06:47:04 +00001190let Defs = [EFLAGS], AddedComplexity = 1,
1191 isReMaterializable = 1, isAsCheapAsAMove = 1 in
Dan Gohman9203ab42008-07-30 18:09:17 +00001192def MOV64r0 : I<0x31, MRMInitReg, (outs GR64:$dst), (ins),
1193 "xor{l}\t${dst:subreg32}, ${dst:subreg32}",
1194 [(set GR64:$dst, 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195
1196// Materialize i64 constant where top 32-bits are zero.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001197let AddedComplexity = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001198def MOV64ri64i32 : Ii32<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64i32imm:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001199 "mov{l}\t{$src, ${dst:subreg32}|${dst:subreg32}, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200 [(set GR64:$dst, i64immZExt32:$src)]>;
1201
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001202//===----------------------------------------------------------------------===//
1203// Thread Local Storage Instructions
1204//===----------------------------------------------------------------------===//
1205
1206def TLS_addr64 : I<0, Pseudo, (outs GR64:$dst), (ins i64imm:$sym),
Anton Korobeynikov5577e2e2008-05-05 17:08:59 +00001207 ".byte\t0x66; leaq\t${sym:mem}(%rip), $dst; .word\t0x6666; rex64",
Anton Korobeynikov4fbf00b2008-05-04 21:36:32 +00001208 [(set GR64:$dst, (X86tlsaddr tglobaltlsaddr:$sym))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001209
1210//===----------------------------------------------------------------------===//
1211// Atomic Instructions
1212//===----------------------------------------------------------------------===//
1213
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001214let Defs = [RAX, EFLAGS], Uses = [RAX] in {
Evan Chengd49dbb82008-04-18 20:55:36 +00001215def LCMPXCHG64 : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$ptr, GR64:$swap),
Bill Wendling6f189e22008-08-19 23:09:18 +00001216 "lock\n\tcmpxchgq\t$swap,$ptr",
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001217 [(X86cas addr:$ptr, GR64:$swap, 8)]>, TB, LOCK;
1218}
1219
Dan Gohmana41a1c092008-08-06 15:52:50 +00001220let Constraints = "$val = $dst" in {
1221let Defs = [EFLAGS] in
Evan Chengd49dbb82008-04-18 20:55:36 +00001222def LXADD64 : RI<0xC1, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001223 "lock\n\txadd\t$val, $ptr",
Mon P Wang6bde9ec2008-06-25 08:15:39 +00001224 [(set GR64:$dst, (atomic_load_add_64 addr:$ptr, GR64:$val))]>,
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001225 TB, LOCK;
Evan Chenga1e80602008-04-19 02:05:42 +00001226def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$ptr,GR64:$val),
Bill Wendling6f189e22008-08-19 23:09:18 +00001227 "xchg\t$val, $ptr",
Evan Chenga1e80602008-04-19 02:05:42 +00001228 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))]>;
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001229}
1230
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001231// Atomic exchange, and, or, xor
1232let Constraints = "$val = $dst", Defs = [EFLAGS],
1233 usesCustomDAGSchedInserter = 1 in {
1234def ATOMAND64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001235 "#ATOMAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001236 [(set GR64:$dst, (atomic_load_and_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001237def ATOMOR64 : I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001238 "#ATOMOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001239 [(set GR64:$dst, (atomic_load_or_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001240def ATOMXOR64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001241 "#ATOMXOR64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001242 [(set GR64:$dst, (atomic_load_xor_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001243def ATOMNAND64 : I<0, Pseudo,(outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001244 "#ATOMNAND64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001245 [(set GR64:$dst, (atomic_load_nand_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001246def ATOMMIN64: I<0, Pseudo, (outs GR64:$dst), (ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001247 "#ATOMMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001248 [(set GR64:$dst, (atomic_load_min_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001249def ATOMMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001250 "#ATOMMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001251 [(set GR64:$dst, (atomic_load_max_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001252def ATOMUMIN64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001253 "#ATOMUMIN64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001254 [(set GR64:$dst, (atomic_load_umin_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001255def ATOMUMAX64: I<0, Pseudo, (outs GR64:$dst),(ins i64mem:$ptr, GR64:$val),
Nick Lewyckybfb9fd22008-12-07 03:49:52 +00001256 "#ATOMUMAX64 PSEUDO!",
Dale Johannesenbc187662008-08-28 02:44:49 +00001257 [(set GR64:$dst, (atomic_load_umax_64 addr:$ptr, GR64:$val))]>;
Dale Johannesen6b60eca2008-08-20 00:48:50 +00001258}
Andrew Lenharthbd7d3262008-03-04 21:13:33 +00001259
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260//===----------------------------------------------------------------------===//
1261// Non-Instruction Patterns
1262//===----------------------------------------------------------------------===//
1263
Bill Wendlingfef06052008-09-16 21:48:12 +00001264// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
1266 (MOV64ri tconstpool :$dst)>, Requires<[NotSmallCode]>;
1267def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
1268 (MOV64ri tjumptable :$dst)>, Requires<[NotSmallCode]>;
1269def : Pat<(i64 (X86Wrapper tglobaladdr :$dst)),
1270 (MOV64ri tglobaladdr :$dst)>, Requires<[NotSmallCode]>;
1271def : Pat<(i64 (X86Wrapper texternalsym:$dst)),
1272 (MOV64ri texternalsym:$dst)>, Requires<[NotSmallCode]>;
1273
1274def : Pat<(store (i64 (X86Wrapper tconstpool:$src)), addr:$dst),
1275 (MOV64mi32 addr:$dst, tconstpool:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001276 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001277def : Pat<(store (i64 (X86Wrapper tjumptable:$src)), addr:$dst),
1278 (MOV64mi32 addr:$dst, tjumptable:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001279 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001280def : Pat<(store (i64 (X86Wrapper tglobaladdr:$src)), addr:$dst),
1281 (MOV64mi32 addr:$dst, tglobaladdr:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001282 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283def : Pat<(store (i64 (X86Wrapper texternalsym:$src)), addr:$dst),
1284 (MOV64mi32 addr:$dst, texternalsym:$src)>,
Evan Cheng3b5a1272008-02-07 08:53:49 +00001285 Requires<[SmallCode, IsStatic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286
1287// Calls
1288// Direct PC relative function call for small code model. 32-bit displacement
1289// sign extended to 64-bit.
1290def : Pat<(X86call (i64 tglobaladdr:$dst)),
1291 (CALL64pcrel32 tglobaladdr:$dst)>;
1292def : Pat<(X86call (i64 texternalsym:$dst)),
1293 (CALL64pcrel32 texternalsym:$dst)>;
1294
1295def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1296 (CALL64pcrel32 tglobaladdr:$dst)>;
1297def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1298 (CALL64pcrel32 texternalsym:$dst)>;
1299
1300def : Pat<(X86tailcall GR64:$dst),
1301 (CALL64r GR64:$dst)>;
1302
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +00001303
1304// tailcall stuff
1305def : Pat<(X86tailcall GR32:$dst),
1306 (TAILCALL)>;
1307def : Pat<(X86tailcall (i64 tglobaladdr:$dst)),
1308 (TAILCALL)>;
1309def : Pat<(X86tailcall (i64 texternalsym:$dst)),
1310 (TAILCALL)>;
1311
1312def : Pat<(X86tcret GR64:$dst, imm:$off),
1313 (TCRETURNri64 GR64:$dst, imm:$off)>;
1314
1315def : Pat<(X86tcret (i64 tglobaladdr:$dst), imm:$off),
1316 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1317
1318def : Pat<(X86tcret (i64 texternalsym:$dst), imm:$off),
1319 (TCRETURNdi64 texternalsym:$dst, imm:$off)>;
1320
Dan Gohmanec596042007-09-17 14:35:24 +00001321// Comparisons.
1322
1323// TEST R,R is smaller than CMP R,0
Evan Cheng621216e2007-09-29 00:00:36 +00001324def : Pat<(parallel (X86cmp GR64:$src1, 0), (implicit EFLAGS)),
Dan Gohmanec596042007-09-17 14:35:24 +00001325 (TEST64rr GR64:$src1, GR64:$src1)>;
1326
Christopher Lambb371e032008-03-13 05:47:01 +00001327
1328
1329// Zero-extension
Christopher Lamb76d72da2008-03-16 03:12:01 +00001330def : Pat<(i64 (zext GR32:$src)),
1331 (SUBREG_TO_REG (i64 0), GR32:$src, x86_subreg_32bit)>;
Christopher Lambb371e032008-03-13 05:47:01 +00001332
Duncan Sands082524c2008-01-23 20:39:46 +00001333// zextload bool -> zextload byte
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001334def : Pat<(zextloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1335
1336// extload
Dan Gohmanab460da2008-08-27 17:33:15 +00001337// When extloading from 16-bit and smaller memory locations into 64-bit registers,
1338// use zero-extending loads so that the entire 64-bit register is defined, avoiding
1339// partial-register updates.
1340def : Pat<(extloadi64i1 addr:$src), (MOVZX64rm8 addr:$src)>;
1341def : Pat<(extloadi64i8 addr:$src), (MOVZX64rm8 addr:$src)>;
1342def : Pat<(extloadi64i16 addr:$src), (MOVZX64rm16 addr:$src)>;
1343// For other extloads, use subregs, since the high contents of the register are
1344// defined after an extload.
Dan Gohmandd612bb2008-08-20 21:27:32 +00001345def : Pat<(extloadi64i32 addr:$src),
1346 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), (MOV32rm addr:$src),
1347 x86_subreg_32bit)>;
1348def : Pat<(extloadi16i1 addr:$src),
1349 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1350 x86_subreg_8bit)>,
1351 Requires<[In64BitMode]>;
1352def : Pat<(extloadi16i8 addr:$src),
1353 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), (MOV8rm addr:$src),
1354 x86_subreg_8bit)>,
1355 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001356
Dan Gohmandd612bb2008-08-20 21:27:32 +00001357// anyext
1358def : Pat<(i64 (anyext GR8:$src)),
1359 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>;
1360def : Pat<(i64 (anyext GR16:$src)),
1361 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR16:$src, x86_subreg_16bit)>;
Christopher Lamb76d72da2008-03-16 03:12:01 +00001362def : Pat<(i64 (anyext GR32:$src)),
1363 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GR32:$src, x86_subreg_32bit)>;
Dan Gohmandd612bb2008-08-20 21:27:32 +00001364def : Pat<(i16 (anyext GR8:$src)),
1365 (INSERT_SUBREG (i16 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1366 Requires<[In64BitMode]>;
1367def : Pat<(i32 (anyext GR8:$src)),
1368 (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR8:$src, x86_subreg_8bit)>,
1369 Requires<[In64BitMode]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001370
1371//===----------------------------------------------------------------------===//
1372// Some peepholes
1373//===----------------------------------------------------------------------===//
1374
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001375// Odd encoding trick: -128 fits into an 8-bit immediate field while
1376// +128 doesn't, so in this special case use a sub instead of an add.
1377def : Pat<(add GR64:$src1, 128),
1378 (SUB64ri8 GR64:$src1, -128)>;
1379def : Pat<(store (add (loadi64 addr:$dst), 128), addr:$dst),
1380 (SUB64mi8 addr:$dst, -128)>;
1381
1382// The same trick applies for 32-bit immediate fields in 64-bit
1383// instructions.
1384def : Pat<(add GR64:$src1, 0x0000000080000000),
1385 (SUB64ri32 GR64:$src1, 0xffffffff80000000)>;
1386def : Pat<(store (add (loadi64 addr:$dst), 0x00000000800000000), addr:$dst),
1387 (SUB64mi32 addr:$dst, 0xffffffff80000000)>;
1388
Dan Gohman47a419d2008-08-07 02:54:50 +00001389// r & (2^32-1) ==> movz
Dan Gohman5a5e6e92008-10-17 01:33:43 +00001390def : Pat<(and GR64:$src, 0x00000000FFFFFFFF),
Dan Gohman47a419d2008-08-07 02:54:50 +00001391 (MOVZX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001392// r & (2^16-1) ==> movz
1393def : Pat<(and GR64:$src, 0xffff),
1394 (MOVZX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1395// r & (2^8-1) ==> movz
1396def : Pat<(and GR64:$src, 0xff),
1397 (MOVZX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
Dan Gohman9203ab42008-07-30 18:09:17 +00001398// r & (2^8-1) ==> movz
1399def : Pat<(and GR32:$src1, 0xff),
1400 (MOVZX32rr8 (i8 (EXTRACT_SUBREG GR32:$src1, x86_subreg_8bit)))>,
1401 Requires<[In64BitMode]>;
1402// r & (2^8-1) ==> movz
1403def : Pat<(and GR16:$src1, 0xff),
1404 (MOVZX16rr8 (i8 (EXTRACT_SUBREG GR16:$src1, x86_subreg_8bit)))>,
1405 Requires<[In64BitMode]>;
Christopher Lambb371e032008-03-13 05:47:01 +00001406
Dan Gohmandd612bb2008-08-20 21:27:32 +00001407// sext_inreg patterns
1408def : Pat<(sext_inreg GR64:$src, i32),
1409 (MOVSX64rr32 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit)))>;
1410def : Pat<(sext_inreg GR64:$src, i16),
1411 (MOVSX64rr16 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit)))>;
1412def : Pat<(sext_inreg GR64:$src, i8),
1413 (MOVSX64rr8 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit)))>;
1414def : Pat<(sext_inreg GR32:$src, i8),
1415 (MOVSX32rr8 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit)))>,
1416 Requires<[In64BitMode]>;
1417def : Pat<(sext_inreg GR16:$src, i8),
1418 (MOVSX16rr8 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit)))>,
1419 Requires<[In64BitMode]>;
1420
1421// trunc patterns
1422def : Pat<(i32 (trunc GR64:$src)),
1423 (i32 (EXTRACT_SUBREG GR64:$src, x86_subreg_32bit))>;
1424def : Pat<(i16 (trunc GR64:$src)),
1425 (i16 (EXTRACT_SUBREG GR64:$src, x86_subreg_16bit))>;
1426def : Pat<(i8 (trunc GR64:$src)),
1427 (i8 (EXTRACT_SUBREG GR64:$src, x86_subreg_8bit))>;
1428def : Pat<(i8 (trunc GR32:$src)),
1429 (i8 (EXTRACT_SUBREG GR32:$src, x86_subreg_8bit))>,
1430 Requires<[In64BitMode]>;
1431def : Pat<(i8 (trunc GR16:$src)),
1432 (i8 (EXTRACT_SUBREG GR16:$src, x86_subreg_8bit))>,
1433 Requires<[In64BitMode]>;
1434
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001435// (shl x, 1) ==> (add x, x)
1436def : Pat<(shl GR64:$src1, (i8 1)), (ADD64rr GR64:$src1, GR64:$src1)>;
1437
Evan Cheng76a64c72008-08-30 02:03:58 +00001438// (shl x (and y, 63)) ==> (shl x, y)
1439def : Pat<(shl GR64:$src1, (and CL:$amt, 63)),
1440 (SHL64rCL GR64:$src1)>;
1441def : Pat<(store (shl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1442 (SHL64mCL addr:$dst)>;
1443
1444def : Pat<(srl GR64:$src1, (and CL:$amt, 63)),
1445 (SHR64rCL GR64:$src1)>;
1446def : Pat<(store (srl (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1447 (SHR64mCL addr:$dst)>;
1448
1449def : Pat<(sra GR64:$src1, (and CL:$amt, 63)),
1450 (SAR64rCL GR64:$src1)>;
1451def : Pat<(store (sra (loadi64 addr:$dst), (and CL:$amt, 63)), addr:$dst),
1452 (SAR64mCL addr:$dst)>;
1453
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454// (or (x >> c) | (y << (64 - c))) ==> (shrd64 x, y, c)
1455def : Pat<(or (srl GR64:$src1, CL:$amt),
1456 (shl GR64:$src2, (sub 64, CL:$amt))),
1457 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1458
1459def : Pat<(store (or (srl (loadi64 addr:$dst), CL:$amt),
1460 (shl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1461 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1462
Dan Gohman921581d2008-10-17 01:23:35 +00001463def : Pat<(or (srl GR64:$src1, (i8 (trunc RCX:$amt))),
1464 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1465 (SHRD64rrCL GR64:$src1, GR64:$src2)>;
1466
1467def : Pat<(store (or (srl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1468 (shl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1469 addr:$dst),
1470 (SHRD64mrCL addr:$dst, GR64:$src2)>;
1471
1472def : Pat<(shrd GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1473 (SHRD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1474
1475def : Pat<(store (shrd (loadi64 addr:$dst), (i8 imm:$amt1),
1476 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1477 (SHRD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1478
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001479// (or (x << c) | (y >> (64 - c))) ==> (shld64 x, y, c)
1480def : Pat<(or (shl GR64:$src1, CL:$amt),
1481 (srl GR64:$src2, (sub 64, CL:$amt))),
1482 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1483
1484def : Pat<(store (or (shl (loadi64 addr:$dst), CL:$amt),
1485 (srl GR64:$src2, (sub 64, CL:$amt))), addr:$dst),
1486 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1487
Dan Gohman921581d2008-10-17 01:23:35 +00001488def : Pat<(or (shl GR64:$src1, (i8 (trunc RCX:$amt))),
1489 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1490 (SHLD64rrCL GR64:$src1, GR64:$src2)>;
1491
1492def : Pat<(store (or (shl (loadi64 addr:$dst), (i8 (trunc RCX:$amt))),
1493 (srl GR64:$src2, (i8 (trunc (sub 64, RCX:$amt))))),
1494 addr:$dst),
1495 (SHLD64mrCL addr:$dst, GR64:$src2)>;
1496
1497def : Pat<(shld GR64:$src1, (i8 imm:$amt1), GR64:$src2, (i8 imm:$amt2)),
1498 (SHLD64rri8 GR64:$src1, GR64:$src2, (i8 imm:$amt1))>;
1499
1500def : Pat<(store (shld (loadi64 addr:$dst), (i8 imm:$amt1),
1501 GR64:$src2, (i8 imm:$amt2)), addr:$dst),
1502 (SHLD64mri8 addr:$dst, GR64:$src2, (i8 imm:$amt1))>;
1503
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001504// X86 specific add which produces a flag.
1505def : Pat<(addc GR64:$src1, GR64:$src2),
1506 (ADD64rr GR64:$src1, GR64:$src2)>;
1507def : Pat<(addc GR64:$src1, (load addr:$src2)),
1508 (ADD64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001509def : Pat<(addc GR64:$src1, i64immSExt8:$src2),
1510 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001511def : Pat<(addc GR64:$src1, i64immSExt32:$src2),
1512 (ADD64ri32 GR64:$src1, imm:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001513
1514def : Pat<(subc GR64:$src1, GR64:$src2),
1515 (SUB64rr GR64:$src1, GR64:$src2)>;
1516def : Pat<(subc GR64:$src1, (load addr:$src2)),
1517 (SUB64rm GR64:$src1, addr:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518def : Pat<(subc GR64:$src1, i64immSExt8:$src2),
1519 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001520def : Pat<(subc GR64:$src1, imm:$src2),
1521 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522
Bill Wendlingf5399032008-12-12 21:15:41 +00001523//===----------------------------------------------------------------------===//
1524// Overflow Patterns
1525//===----------------------------------------------------------------------===//
1526
1527// Register-Register Addition with Overflow
1528def : Pat<(parallel (X86add_ovf GR64:$src1, GR64:$src2),
1529 (implicit EFLAGS)),
1530 (ADD64rr GR64:$src1, GR64:$src2)>;
1531
1532// Register-Integer Addition with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001533def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt8:$src2),
1534 (implicit EFLAGS)),
1535 (ADD64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001536def : Pat<(parallel (X86add_ovf GR64:$src1, i64immSExt32:$src2),
1537 (implicit EFLAGS)),
1538 (ADD64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001539
1540// Register-Memory Addition with Overflow
1541def : Pat<(parallel (X86add_ovf GR64:$src1, (load addr:$src2)),
1542 (implicit EFLAGS)),
1543 (ADD64rm GR64:$src1, addr:$src2)>;
1544
1545// Memory-Register Addition with Overflow
1546def : Pat<(parallel (store (X86add_ovf (load addr:$dst), GR64:$src2),
1547 addr:$dst),
1548 (implicit EFLAGS)),
1549 (ADD64mr addr:$dst, GR64:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001550def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt8:$src2),
1551 addr:$dst),
1552 (implicit EFLAGS)),
1553 (ADD64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001554def : Pat<(parallel (store (X86add_ovf (load addr:$dst), i64immSExt32:$src2),
1555 addr:$dst),
1556 (implicit EFLAGS)),
1557 (ADD64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001558
1559// Register-Register Subtraction with Overflow
1560def : Pat<(parallel (X86sub_ovf GR64:$src1, GR64:$src2),
1561 (implicit EFLAGS)),
1562 (SUB64rr GR64:$src1, GR64:$src2)>;
1563
1564// Register-Memory Subtraction with Overflow
1565def : Pat<(parallel (X86sub_ovf GR64:$src1, (load addr:$src2)),
1566 (implicit EFLAGS)),
1567 (SUB64rm GR64:$src1, addr:$src2)>;
1568
1569// Register-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001570def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt8:$src2),
1571 (implicit EFLAGS)),
1572 (SUB64ri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001573def : Pat<(parallel (X86sub_ovf GR64:$src1, i64immSExt32:$src2),
1574 (implicit EFLAGS)),
1575 (SUB64ri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001576
1577// Memory-Register Subtraction with Overflow
1578def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), GR64:$src2),
1579 addr:$dst),
1580 (implicit EFLAGS)),
1581 (SUB64mr addr:$dst, GR64:$src2)>;
1582
1583// Memory-Integer Subtraction with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001584def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt8:$src2),
1585 addr:$dst),
1586 (implicit EFLAGS)),
1587 (SUB64mi8 addr:$dst, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001588def : Pat<(parallel (store (X86sub_ovf (load addr:$dst), i64immSExt32:$src2),
1589 addr:$dst),
1590 (implicit EFLAGS)),
1591 (SUB64mi32 addr:$dst, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001592
1593// Register-Register Signed Integer Multiplication with Overflow
1594def : Pat<(parallel (X86smul_ovf GR64:$src1, GR64:$src2),
1595 (implicit EFLAGS)),
1596 (IMUL64rr GR64:$src1, GR64:$src2)>;
1597
1598// Register-Memory Signed Integer Multiplication with Overflow
1599def : Pat<(parallel (X86smul_ovf GR64:$src1, (load addr:$src2)),
1600 (implicit EFLAGS)),
1601 (IMUL64rm GR64:$src1, addr:$src2)>;
1602
1603// Register-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001604def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt8:$src2),
1605 (implicit EFLAGS)),
1606 (IMUL64rri8 GR64:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001607def : Pat<(parallel (X86smul_ovf GR64:$src1, i64immSExt32:$src2),
1608 (implicit EFLAGS)),
1609 (IMUL64rri32 GR64:$src1, i64immSExt32:$src2)>;
Bill Wendlingf5399032008-12-12 21:15:41 +00001610
1611// Memory-Integer Signed Integer Multiplication with Overflow
Bill Wendlingf5399032008-12-12 21:15:41 +00001612def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt8:$src2),
1613 (implicit EFLAGS)),
1614 (IMUL64rmi8 addr:$src1, i64immSExt8:$src2)>;
Dan Gohmand16fdc02008-12-19 18:25:21 +00001615def : Pat<(parallel (X86smul_ovf (load addr:$src1), i64immSExt32:$src2),
1616 (implicit EFLAGS)),
1617 (IMUL64rmi32 addr:$src1, i64immSExt32:$src2)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001618
1619//===----------------------------------------------------------------------===//
1620// X86-64 SSE Instructions
1621//===----------------------------------------------------------------------===//
1622
1623// Move instructions...
1624
Evan Chengb783fa32007-07-19 01:14:50 +00001625def MOV64toPQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001626 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001627 [(set VR128:$dst,
1628 (v2i64 (scalar_to_vector GR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001629def MOVPQIto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001630 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001631 [(set GR64:$dst, (vector_extract (v2i64 VR128:$src),
1632 (iPTR 0)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001633
Evan Chengb783fa32007-07-19 01:14:50 +00001634def MOV64toSDrr : RPDI<0x6E, MRMSrcReg, (outs FR64:$dst), (ins GR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001635 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001636 [(set FR64:$dst, (bitconvert GR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001637def MOV64toSDrm : RPDI<0x6E, MRMSrcMem, (outs FR64:$dst), (ins i64mem:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001638 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001639 [(set FR64:$dst, (bitconvert (loadi64 addr:$src)))]>;
1640
Evan Chengb783fa32007-07-19 01:14:50 +00001641def MOVSDto64rr : RPDI<0x7E, MRMDestReg, (outs GR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001642 "mov{d|q}\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001643 [(set GR64:$dst, (bitconvert FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001644def MOVSDto64mr : RPDI<0x7E, MRMDestMem, (outs), (ins i64mem:$dst, FR64:$src),
Evan Cheng69ca4da2008-08-25 04:11:42 +00001645 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001646 [(store (i64 (bitconvert FR64:$src)), addr:$dst)]>;
Nate Begemanb2975562008-02-03 07:18:54 +00001647
1648//===----------------------------------------------------------------------===//
1649// X86-64 SSE4.1 Instructions
1650//===----------------------------------------------------------------------===//
1651
Nate Begeman4294c1f2008-02-12 22:51:28 +00001652/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
1653multiclass SS41I_extract64<bits<8> opc, string OpcodeStr> {
Nate Begeman0050ab52008-10-29 23:07:17 +00001654 def rr : SS4AIi8<opc, MRMDestReg, (outs GR64:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001655 (ins VR128:$src1, i32i8imm:$src2),
1656 !strconcat(OpcodeStr,
1657 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1658 [(set GR64:$dst,
1659 (extractelt (v2i64 VR128:$src1), imm:$src2))]>, OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001660 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001661 (ins i64mem:$dst, VR128:$src1, i32i8imm:$src2),
1662 !strconcat(OpcodeStr,
1663 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
1664 [(store (extractelt (v2i64 VR128:$src1), imm:$src2),
1665 addr:$dst)]>, OpSize, REX_W;
1666}
1667
1668defm PEXTRQ : SS41I_extract64<0x16, "pextrq">;
1669
1670let isTwoAddress = 1 in {
1671 multiclass SS41I_insert64<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00001672 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001673 (ins VR128:$src1, GR64:$src2, i32i8imm:$src3),
1674 !strconcat(OpcodeStr,
1675 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1676 [(set VR128:$dst,
1677 (v2i64 (insertelt VR128:$src1, GR64:$src2, imm:$src3)))]>,
1678 OpSize, REX_W;
Evan Cheng78d00612008-03-14 07:39:27 +00001679 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman4294c1f2008-02-12 22:51:28 +00001680 (ins VR128:$src1, i64mem:$src2, i32i8imm:$src3),
1681 !strconcat(OpcodeStr,
1682 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
1683 [(set VR128:$dst,
1684 (v2i64 (insertelt VR128:$src1, (loadi64 addr:$src2),
1685 imm:$src3)))]>, OpSize, REX_W;
1686 }
1687}
1688
1689defm PINSRQ : SS41I_insert64<0x22, "pinsrq">;