blob: 4547ad2c4823c9dbe0ea4293330c12a211eb1fce [file] [log] [blame]
Arnold Schwaighofer373e8652007-10-12 21:30:57 +00001//====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003// 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.
Eric Christopher7f2d4f42009-07-31 20:07:27 +00007//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00008//===----------------------------------------------------------------------===//
9//
10// This file describes the X86 SSE instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16
17//===----------------------------------------------------------------------===//
18// SSE specific DAG Nodes.
19//===----------------------------------------------------------------------===//
20
21def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
Nate Begeman03605a02008-07-17 16:51:19 +000023def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
28def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
33 [SDNPCommutative, SDNPAssociative]>;
34def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
36def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
Evan Chengf37bf452007-10-01 18:12:48 +000037def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
Evan Cheng621216e2007-09-29 00:00:36 +000038def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +000039def X86pshufb : SDNode<"X86ISD::PSHUFB",
Nate Begeman2c87c422009-02-23 08:49:38 +000040 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
41 SDTCisSameAs<0,2>]>>;
Nate Begemand77e59e2008-02-11 04:19:36 +000042def X86pextrb : SDNode<"X86ISD::PEXTRB",
43 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
44def X86pextrw : SDNode<"X86ISD::PEXTRW",
45 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +000046def X86pinsrb : SDNode<"X86ISD::PINSRB",
Nate Begemand77e59e2008-02-11 04:19:36 +000047 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +000049def X86pinsrw : SDNode<"X86ISD::PINSRW",
Nate Begemand77e59e2008-02-11 04:19:36 +000050 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +000052def X86insrtps : SDNode<"X86ISD::INSERTPS",
Nate Begemand77e59e2008-02-11 04:19:36 +000053 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
Eric Christopherefb657e2009-07-24 00:33:09 +000054 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
Evan Chenge9b9c672008-05-09 21:53:03 +000055def X86vzmovl : SDNode<"X86ISD::VZEXT_MOVL",
56 SDTypeProfile<1, 1, [SDTCisSameAs<0,1>]>>;
57def X86vzload : SDNode<"X86ISD::VZEXT_LOAD", SDTLoad,
58 [SDNPHasChain, SDNPMayLoad]>;
Evan Chengdea99362008-05-29 08:22:04 +000059def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
Nate Begeman03605a02008-07-17 16:51:19 +000061def X86cmpps : SDNode<"X86ISD::CMPPS", SDTX86VFCMP>;
62def X86cmppd : SDNode<"X86ISD::CMPPD", SDTX86VFCMP>;
63def X86pcmpeqb : SDNode<"X86ISD::PCMPEQB", SDTIntBinOp, [SDNPCommutative]>;
64def X86pcmpeqw : SDNode<"X86ISD::PCMPEQW", SDTIntBinOp, [SDNPCommutative]>;
65def X86pcmpeqd : SDNode<"X86ISD::PCMPEQD", SDTIntBinOp, [SDNPCommutative]>;
66def X86pcmpeqq : SDNode<"X86ISD::PCMPEQQ", SDTIntBinOp, [SDNPCommutative]>;
67def X86pcmpgtb : SDNode<"X86ISD::PCMPGTB", SDTIntBinOp>;
68def X86pcmpgtw : SDNode<"X86ISD::PCMPGTW", SDTIntBinOp>;
69def X86pcmpgtd : SDNode<"X86ISD::PCMPGTD", SDTIntBinOp>;
70def X86pcmpgtq : SDNode<"X86ISD::PCMPGTQ", SDTIntBinOp>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071
Eric Christopher85f187b2009-08-10 21:48:58 +000072def SDTX86CmpPTest : SDTypeProfile<0, 2, [SDTCisVT<0, v4f32>,
73 SDTCisVT<1, v4f32>]>;
Eric Christopher95d79262009-07-29 00:28:05 +000074def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
75
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077// SSE Complex Patterns
78//===----------------------------------------------------------------------===//
79
80// These are 'extloads' from a scalar to the low element of a vector, zeroing
81// the top elements. These are used for the SSE 'ss' and 'sd' instruction
82// forms.
Rafael Espindolabca99f72009-04-08 21:14:34 +000083def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000084 [SDNPHasChain, SDNPMayLoad]>;
Rafael Espindolabca99f72009-04-08 21:14:34 +000085def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000086 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087
88def ssmem : Operand<v4f32> {
89 let PrintMethod = "printf32mem";
Dan Gohmanfe606822009-07-30 01:56:29 +000090 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000091 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092}
93def sdmem : Operand<v2f64> {
94 let PrintMethod = "printf64mem";
Dan Gohmanfe606822009-07-30 01:56:29 +000095 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000096 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000097}
98
99//===----------------------------------------------------------------------===//
100// SSE pattern fragments
101//===----------------------------------------------------------------------===//
102
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000103def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
104def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
105def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
106def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
107
Dan Gohman11821702007-07-27 17:16:43 +0000108// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +0000109def alignedstore : PatFrag<(ops node:$val, node:$ptr),
Dan Gohman2a174122008-10-15 06:50:19 +0000110 (store node:$val, node:$ptr), [{
111 return cast<StoreSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000112}]>;
113
Dan Gohman11821702007-07-27 17:16:43 +0000114// Like 'load', but always requires vector alignment.
Dan Gohman2a174122008-10-15 06:50:19 +0000115def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
116 return cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000117}]>;
118
Dan Gohman11821702007-07-27 17:16:43 +0000119def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
120def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000121def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
122def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
123def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
124def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
125
126// Like 'load', but uses special alignment checks suitable for use in
127// memory operands in most SSE instructions, which are required to
128// be naturally aligned on some targets but not on others.
129// FIXME: Actually implement support for targets that don't require the
130// alignment. This probably wants a subtarget predicate.
Dan Gohman2a174122008-10-15 06:50:19 +0000131def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
132 return cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000133}]>;
134
Dan Gohman11821702007-07-27 17:16:43 +0000135def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
136def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000137def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
138def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
139def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
140def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000141def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000142
Bill Wendling3b15d722007-08-11 09:52:53 +0000143// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
144// 16-byte boundary.
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000145// FIXME: 8 byte alignment for mmx reads is not required
Dan Gohman61efc5a2008-10-16 00:03:00 +0000146def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
Dan Gohman2a174122008-10-15 06:50:19 +0000147 return cast<LoadSDNode>(N)->getAlignment() >= 8;
Bill Wendling3b15d722007-08-11 09:52:53 +0000148}]>;
149
150def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
Bill Wendling3b15d722007-08-11 09:52:53 +0000151def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
152def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
153def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
154
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
156def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
157def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
158def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
159def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
160def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
161
Evan Cheng56ec77b2008-09-24 23:27:55 +0000162def vzmovl_v2i64 : PatFrag<(ops node:$src),
163 (bitconvert (v2i64 (X86vzmovl
164 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
165def vzmovl_v4i32 : PatFrag<(ops node:$src),
166 (bitconvert (v4i32 (X86vzmovl
167 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
168
169def vzload_v2i64 : PatFrag<(ops node:$src),
170 (bitconvert (v2i64 (X86vzload node:$src)))>;
171
172
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173def fp32imm0 : PatLeaf<(f32 fpimm), [{
174 return N->isExactlyValue(+0.0);
175}]>;
176
177def PSxLDQ_imm : SDNodeXForm<imm, [{
178 // Transformation function: imm >> 3
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000179 return getI32Imm(N->getZExtValue() >> 3);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180}]>;
181
182// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
183// SHUFP* etc. imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000184def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185 return getI8Imm(X86::getShuffleSHUFImmediate(N));
186}]>;
187
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000188// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189// PSHUFHW imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000190def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
192}]>;
193
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000194// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195// PSHUFLW imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000196def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
198}]>;
199
Nate Begeman543d2142009-04-27 18:41:29 +0000200def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
201 (vector_shuffle node:$lhs, node:$rhs), [{
202 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
203 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
204}]>;
205
206def movddup : PatFrag<(ops node:$lhs, node:$rhs),
207 (vector_shuffle node:$lhs, node:$rhs), [{
208 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
209}]>;
210
211def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
212 (vector_shuffle node:$lhs, node:$rhs), [{
213 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
214}]>;
215
216def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
217 (vector_shuffle node:$lhs, node:$rhs), [{
218 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
219}]>;
220
221def movhp : PatFrag<(ops node:$lhs, node:$rhs),
222 (vector_shuffle node:$lhs, node:$rhs), [{
223 return X86::isMOVHPMask(cast<ShuffleVectorSDNode>(N));
224}]>;
225
226def movlp : PatFrag<(ops node:$lhs, node:$rhs),
227 (vector_shuffle node:$lhs, node:$rhs), [{
228 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
229}]>;
230
231def movl : PatFrag<(ops node:$lhs, node:$rhs),
232 (vector_shuffle node:$lhs, node:$rhs), [{
233 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
234}]>;
235
236def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
237 (vector_shuffle node:$lhs, node:$rhs), [{
238 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
239}]>;
240
241def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
242 (vector_shuffle node:$lhs, node:$rhs), [{
243 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
244}]>;
245
246def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
247 (vector_shuffle node:$lhs, node:$rhs), [{
248 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
249}]>;
250
251def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
252 (vector_shuffle node:$lhs, node:$rhs), [{
253 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
254}]>;
255
256def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
257 (vector_shuffle node:$lhs, node:$rhs), [{
258 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
259}]>;
260
261def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
262 (vector_shuffle node:$lhs, node:$rhs), [{
263 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
264}]>;
265
266def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
267 (vector_shuffle node:$lhs, node:$rhs), [{
268 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269}], SHUFFLE_get_shuf_imm>;
270
Nate Begeman543d2142009-04-27 18:41:29 +0000271def shufp : PatFrag<(ops node:$lhs, node:$rhs),
272 (vector_shuffle node:$lhs, node:$rhs), [{
273 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274}], SHUFFLE_get_shuf_imm>;
275
Nate Begeman543d2142009-04-27 18:41:29 +0000276def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
277 (vector_shuffle node:$lhs, node:$rhs), [{
278 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279}], SHUFFLE_get_pshufhw_imm>;
280
Nate Begeman543d2142009-04-27 18:41:29 +0000281def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
282 (vector_shuffle node:$lhs, node:$rhs), [{
283 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284}], SHUFFLE_get_pshuflw_imm>;
285
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286//===----------------------------------------------------------------------===//
287// SSE scalar FP Instructions
288//===----------------------------------------------------------------------===//
289
290// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
291// scheduler into a branch sequence.
Evan Cheng950aac02007-09-25 01:57:46 +0000292// These are expanded by the scheduler.
293let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000295 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 "#CMOV_FR32 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000297 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
298 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000300 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301 "#CMOV_FR64 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000302 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
303 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000305 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 "#CMOV_V4F32 PSEUDO!",
307 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000308 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
309 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000311 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 "#CMOV_V2F64 PSEUDO!",
313 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000314 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
315 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000317 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318 "#CMOV_V2I64 PSEUDO!",
319 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000320 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng950aac02007-09-25 01:57:46 +0000321 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322}
323
324//===----------------------------------------------------------------------===//
325// SSE1 Instructions
326//===----------------------------------------------------------------------===//
327
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000329let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000330def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000331 "movss\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000332let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000333def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000334 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000336def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000337 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 [(store FR32:$src, addr:$dst)]>;
339
340// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000341def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000342 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000344def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000345 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000347def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000348 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000350def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000351 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
353
354// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000355def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000356 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000358def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000359 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 [(set GR32:$dst, (int_x86_sse_cvtss2si
361 (load addr:$src)))]>;
362
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000363// Match intrinisics which expect MM and XMM operand(s).
364def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
365 "cvtps2pi\t{$src, $dst|$dst, $src}",
366 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
367def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
368 "cvtps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000369 [(set VR64:$dst, (int_x86_sse_cvtps2pi
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000370 (load addr:$src)))]>;
371def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
372 "cvttps2pi\t{$src, $dst|$dst, $src}",
373 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
374def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
375 "cvttps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000376 [(set VR64:$dst, (int_x86_sse_cvttps2pi
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000377 (load addr:$src)))]>;
Evan Cheng3ea4d672008-03-05 08:19:16 +0000378let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000379 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000380 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
381 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
382 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
383 VR64:$src2))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000384 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000385 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
386 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000387 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000388 (load addr:$src2)))]>;
389}
390
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000392def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 [(set GR32:$dst,
395 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000396def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000397 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398 [(set GR32:$dst,
399 (int_x86_sse_cvttss2si(load addr:$src)))]>;
400
Evan Cheng3ea4d672008-03-05 08:19:16 +0000401let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000403 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000404 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
406 GR32:$src2))]>;
407 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000408 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
411 (loadi32 addr:$src2)))]>;
412}
413
414// Comparison instructions
Dan Gohmanf221da12009-01-09 02:27:34 +0000415let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000416 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000417 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000418 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000419let mayLoad = 1 in
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000420 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000421 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000422 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423}
424
Evan Cheng55687072007-09-14 21:48:26 +0000425let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000426def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000427 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000428 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000429def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000431 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000432 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000433} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434
435// Aliases to match intrinsics which expect XMM operand(s).
Evan Cheng3ea4d672008-03-05 08:19:16 +0000436let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000437 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
438 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
439 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000440 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000442 VR128:$src, imm:$cc))]>;
443 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
444 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src,
445 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
448 (load addr:$src), imm:$cc))]>;
449}
450
Evan Cheng55687072007-09-14 21:48:26 +0000451let Defs = [EFLAGS] in {
Dan Gohmanf221da12009-01-09 02:27:34 +0000452def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000453 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000454 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000455 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000456def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000457 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000458 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000459 (implicit EFLAGS)]>;
460
Dan Gohmanf221da12009-01-09 02:27:34 +0000461def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000462 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000463 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000464 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000465def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000466 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000467 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000468 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000469} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000470
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000471// Aliases of packed SSE1 instructions for scalar use. These all have names
472// that start with 'Fs'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
474// Alias instructions that map fld0 to pxor for sse.
Evan Chengbf81b9b2008-08-28 07:52:25 +0000475let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000476def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000477 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478 Requires<[HasSSE1]>, TB, OpSize;
479
480// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
481// disregarded.
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000482let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000483def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000484 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485
486// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
487// disregarded.
Dan Gohman5574cc72008-12-03 18:15:48 +0000488let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000489def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000490 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000491 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
493// Alias bitwise logical operations using SSE logical ops on packed FP values.
Evan Cheng3ea4d672008-03-05 08:19:16 +0000494let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495let isCommutable = 1 in {
Dan Gohmanf221da12009-01-09 02:27:34 +0000496 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst),
497 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000498 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000500 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst),
501 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000502 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000504 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst),
505 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000506 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
508}
509
Dan Gohmanf221da12009-01-09 02:27:34 +0000510def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst),
511 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000512 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000514 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000515def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst),
516 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000517 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000519 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000520def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst),
521 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000522 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000524 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000525
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000526let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000528 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000529 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000530let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000532 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000533 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000535}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536
537/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
538///
539/// In addition, we also have a special variant of the scalar form here to
540/// represent the associated intrinsic operation. This form is unlike the
541/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng5d5dbbc2009-02-26 03:12:02 +0000542/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543///
544/// These three forms can each be reg+reg or reg+mem, so there are a total of
545/// six "instructions".
546///
Evan Cheng3ea4d672008-03-05 08:19:16 +0000547let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
549 SDNode OpNode, Intrinsic F32Int,
550 bit Commutable = 0> {
551 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000552 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000553 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
555 let isCommutable = Commutable;
556 }
557
558 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000559 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
560 (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000561 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000563
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000565 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
566 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000567 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
569 let isCommutable = Commutable;
570 }
571
572 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000573 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
574 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000575 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000576 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577
578 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000579 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
580 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000581 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Evan Cheng5d5dbbc2009-02-26 03:12:02 +0000582 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583
584 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000585 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
586 (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000587 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 [(set VR128:$dst, (F32Int VR128:$src1,
589 sse_load_f32:$src2))]>;
590}
591}
592
593// Arithmetic instructions
594defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
595defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
596defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
597defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
598
599/// sse1_fp_binop_rm - Other SSE1 binops
600///
601/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
602/// instructions for a full-vector intrinsic form. Operations that map
603/// onto C operators don't use this form since they just use the plain
604/// vector form instead of having a separate vector intrinsic form.
605///
606/// This provides a total of eight "instructions".
607///
Evan Cheng3ea4d672008-03-05 08:19:16 +0000608let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
610 SDNode OpNode,
611 Intrinsic F32Int,
612 Intrinsic V4F32Int,
613 bit Commutable = 0> {
614
615 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000616 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000617 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
619 let isCommutable = Commutable;
620 }
621
622 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000623 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
624 (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000625 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000627
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000629 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
630 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000631 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
633 let isCommutable = Commutable;
634 }
635
636 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000637 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
638 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000639 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000640 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641
642 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000643 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
644 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000645 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
647 let isCommutable = Commutable;
648 }
649
650 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000651 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
652 (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000653 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 [(set VR128:$dst, (F32Int VR128:$src1,
655 sse_load_f32:$src2))]>;
656
657 // Vector intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000658 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst),
659 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000660 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
662 let isCommutable = Commutable;
663 }
664
665 // Vector intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000666 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst),
667 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000668 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000669 [(set VR128:$dst, (V4F32Int VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670}
671}
672
673defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
674 int_x86_sse_max_ss, int_x86_sse_max_ps>;
675defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
676 int_x86_sse_min_ss, int_x86_sse_min_ps>;
677
678//===----------------------------------------------------------------------===//
679// SSE packed FP Instructions
680
681// Move Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000682let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000683def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000685let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000686def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000687 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000688 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689
Evan Chengb783fa32007-07-19 01:14:50 +0000690def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000692 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000694let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000695def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 "movups\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000697let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000698def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000699 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000700 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000701def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000702 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000703 [(store (v4f32 VR128:$src), addr:$dst)]>;
704
705// Intrinsic forms of MOVUPS load and store
Dan Gohman5574cc72008-12-03 18:15:48 +0000706let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000707def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000709 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000710def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000711 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000712 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000713
Evan Cheng3ea4d672008-03-05 08:19:16 +0000714let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715 let AddedComplexity = 20 in {
716 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000717 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000718 "movlps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000719 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000720 (movlp VR128:$src1,
721 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000723 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "movhps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000725 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000726 (movhp VR128:$src1,
727 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000729} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730
Evan Chengd743a5f2008-05-10 00:59:18 +0000731
Evan Chengb783fa32007-07-19 01:14:50 +0000732def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000733 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
735 (iPTR 0))), addr:$dst)]>;
736
737// v2f64 extract element 1 is always custom lowered to unpack high to low
738// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000739def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741 [(store (f64 (vector_extract
Nate Begeman543d2142009-04-27 18:41:29 +0000742 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
743 (undef)), (iPTR 0))), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744
Evan Cheng3ea4d672008-03-05 08:19:16 +0000745let Constraints = "$src1 = $dst" in {
Evan Cheng13559d62008-09-26 23:41:32 +0000746let AddedComplexity = 20 in {
Evan Cheng7581a822009-05-12 20:17:52 +0000747def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
748 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000751 (v4f32 (movhp VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752
Evan Cheng7581a822009-05-12 20:17:52 +0000753def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
754 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000755 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000756 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000757 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000758} // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000759} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760
Nate Begemanb44aad72009-04-29 22:47:44 +0000761let AddedComplexity = 20 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000762def : Pat<(v4f32 (movddup VR128:$src, (undef))),
Evan Chenga2497eb2008-09-25 20:50:48 +0000763 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begemanb44aad72009-04-29 22:47:44 +0000764def : Pat<(v2i64 (movddup VR128:$src, (undef))),
765 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
766}
Evan Chenga2497eb2008-09-25 20:50:48 +0000767
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768
769
770// Arithmetic
771
772/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
773///
774/// In addition, we also have a special variant of the scalar form here to
775/// represent the associated intrinsic operation. This form is unlike the
776/// plain scalar form, in that it takes an entire vector (instead of a
777/// scalar) and leaves the top elements undefined.
778///
779/// And, we have a special variant form for a full-vector intrinsic form.
780///
781/// These four forms can each have a reg or a mem operand, so there are a
782/// total of eight "instructions".
783///
784multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
785 SDNode OpNode,
786 Intrinsic F32Int,
787 Intrinsic V4F32Int,
788 bit Commutable = 0> {
789 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000790 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000791 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000792 [(set FR32:$dst, (OpNode FR32:$src))]> {
793 let isCommutable = Commutable;
794 }
795
796 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000797 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000798 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000800
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000802 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000803 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000804 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
805 let isCommutable = Commutable;
806 }
807
808 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000809 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000810 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000811 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812
813 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000814 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000815 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 [(set VR128:$dst, (F32Int VR128:$src))]> {
817 let isCommutable = Commutable;
818 }
819
820 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000821 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000822 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
824
825 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000826 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000827 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
829 let isCommutable = Commutable;
830 }
831
832 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000833 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000834 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000835 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836}
837
838// Square root.
839defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
840 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
841
842// Reciprocal approximations. Note that these typically require refinement
843// in order to obtain suitable precision.
844defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
845 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
846defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
847 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
848
849// Logical
Evan Cheng3ea4d672008-03-05 08:19:16 +0000850let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851 let isCommutable = 1 in {
852 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000853 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000854 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 [(set VR128:$dst, (v2i64
856 (and VR128:$src1, VR128:$src2)))]>;
857 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000858 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000859 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860 [(set VR128:$dst, (v2i64
861 (or VR128:$src1, VR128:$src2)))]>;
862 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000863 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000864 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 [(set VR128:$dst, (v2i64
866 (xor VR128:$src1, VR128:$src2)))]>;
867 }
868
869 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000870 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000871 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000872 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
873 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000875 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000876 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000877 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
878 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000880 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000881 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000882 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
883 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884 def ANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000885 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000886 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000887 [(set VR128:$dst,
888 (v2i64 (and (xor VR128:$src1,
889 (bc_v2i64 (v4i32 immAllOnesV))),
890 VR128:$src2)))]>;
891 def ANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000892 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000893 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000894 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000895 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000896 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000897 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898}
899
Evan Cheng3ea4d672008-03-05 08:19:16 +0000900let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000901 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Nate Begeman061db5f2008-05-12 20:34:32 +0000902 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
903 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
904 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
905 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000906 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Nate Begeman061db5f2008-05-12 20:34:32 +0000907 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
908 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
909 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +0000910 (memop addr:$src), imm:$cc))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000911}
Nate Begeman03605a02008-07-17 16:51:19 +0000912def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
913 (CMPPSrri VR128:$src1, VR128:$src2, imm:$cc)>;
914def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
915 (CMPPSrmi VR128:$src1, addr:$src2, imm:$cc)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000916
917// Shuffle and unpack instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +0000918let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000919 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000920 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000921 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +0000922 VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000923 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000925 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000926 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000927 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +0000928 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000931 (v4f32 (shufp:$src3
932 VR128:$src1, (memopv4f32 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000933
934 let AddedComplexity = 10 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000935 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000936 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000939 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000940 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000941 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000942 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000944 (v4f32 (unpckh VR128:$src1,
945 (memopv4f32 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000947 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000948 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000949 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000950 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000951 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000952 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000953 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000956 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000958} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000959
960// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000961def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengd8296b82009-05-28 18:55:28 +0000964def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000965 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
967
Evan Chengd1d68072008-03-08 00:58:38 +0000968// Prefetch intrinsic.
969def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
970 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
971def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
972 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
973def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
974 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
975def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
976 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977
978// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000979def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000980 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000981 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
982
983// Load, store, and memory fence
Evan Cheng68cca152009-05-27 18:38:01 +0000984def SFENCE : PSI<0xAE, MRM7r, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985
986// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000987def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000988 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000989def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000990 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991
992// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman5574cc72008-12-03 18:15:48 +0000993// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman37eb6c82008-12-03 05:21:24 +0000994// load of an all-zeros value if folding it would be beneficial.
Dan Gohman5574cc72008-12-03 18:15:48 +0000995let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000996def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000997 "xorps\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000998 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000999
Evan Chenga15896e2008-03-12 07:02:50 +00001000let Predicates = [HasSSE1] in {
1001 def : Pat<(v2i64 immAllZerosV), (V_SET0)>;
1002 def : Pat<(v8i16 immAllZerosV), (V_SET0)>;
1003 def : Pat<(v16i8 immAllZerosV), (V_SET0)>;
1004 def : Pat<(v2f64 immAllZerosV), (V_SET0)>;
1005 def : Pat<(v4f32 immAllZerosV), (V_SET0)>;
1006}
1007
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001008// FR32 to 128-bit vector conversion.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001009let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001010def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001011 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001012 [(set VR128:$dst,
1013 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001014def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001015 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001016 [(set VR128:$dst,
1017 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
1018
1019// FIXME: may not be able to eliminate this movss with coalescing the src and
1020// dest register classes are different. We really want to write this pattern
1021// like this:
1022// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1023// (f32 FR32:$src)>;
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001024let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001025def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001026 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001027 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
1028 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001029def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001030 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 [(store (f32 (vector_extract (v4f32 VR128:$src),
1032 (iPTR 0))), addr:$dst)]>;
1033
1034
1035// Move to lower bits of a VR128, leaving upper bits alone.
1036// Three operand (but two address) aliases.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001037let Constraints = "$src1 = $dst" in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001038let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001040 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001041 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001042
1043 let AddedComplexity = 15 in
1044 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001045 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001046 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001048 (v4f32 (movl VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049}
1050
1051// Move to lower bits of a VR128 and zeroing upper bits.
1052// Loading from memory automatically zeroing upper bits.
1053let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00001054def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001055 "movss\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00001056 [(set VR128:$dst, (v4f32 (X86vzmovl (v4f32 (scalar_to_vector
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001057 (loadf32 addr:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001058
Evan Cheng056afe12008-05-20 18:24:47 +00001059def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
Evan Cheng40ee6e52008-05-08 00:57:18 +00001060 (MOVZSS2PSrm addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001062//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063// SSE2 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001064//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001067let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001068def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001069 "movsd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001070let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001071def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001072 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001074def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001075 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076 [(store FR64:$src, addr:$dst)]>;
1077
1078// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001079def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001080 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001082def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001083 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001085def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001086 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087 [(set FR32:$dst, (fround FR64:$src))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001088def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001089 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001091def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001092 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001094def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001095 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1097
1098// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001099def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001100 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1102 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001103def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001104 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1106 Requires<[HasSSE2]>;
1107
1108// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +00001109def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001110 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001112def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001113 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1115 (load addr:$src)))]>;
1116
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001117// Match intrinisics which expect MM and XMM operand(s).
1118def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1119 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1120 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1121def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1122 "cvtpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001123 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
Evan Cheng00b66ef2008-05-23 00:37:07 +00001124 (memop addr:$src)))]>;
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001125def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1126 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1127 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1128def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1129 "cvttpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001130 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
Evan Cheng00b66ef2008-05-23 00:37:07 +00001131 (memop addr:$src)))]>;
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001132def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1133 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1134 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1135def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1136 "cvtpi2pd\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001137 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001138 (load addr:$src)))]>;
1139
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +00001141def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001142 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001143 [(set GR32:$dst,
1144 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001145def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001146 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1148 (load addr:$src)))]>;
1149
1150// Comparison instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +00001151let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001152 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001153 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001154 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001155let mayLoad = 1 in
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001156 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001157 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001158 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001159}
1160
Evan Cheng950aac02007-09-25 01:57:46 +00001161let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001162def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001163 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001164 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001165def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001166 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001167 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001168 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +00001169} // Defs = [EFLAGS]
Evan Cheng950aac02007-09-25 01:57:46 +00001170
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171// Aliases to match intrinsics which expect XMM operand(s).
Evan Cheng3ea4d672008-03-05 08:19:16 +00001172let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001173 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1174 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
1175 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001176 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1178 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001179 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1180 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src,
1181 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001182 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001183 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1184 (load addr:$src), imm:$cc))]>;
1185}
1186
Evan Cheng950aac02007-09-25 01:57:46 +00001187let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001188def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001189 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001190 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1191 (implicit EFLAGS)]>;
1192def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001194 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1195 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001196
Evan Chengb783fa32007-07-19 01:14:50 +00001197def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001198 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001199 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1200 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001201def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001202 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001203 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001204 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +00001205} // Defs = [EFLAGS]
Evan Cheng950aac02007-09-25 01:57:46 +00001206
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001207// Aliases of packed SSE2 instructions for scalar use. These all have names
1208// that start with 'Fs'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001209
1210// Alias instructions that map fld0 to pxor for sse.
Evan Chengbf81b9b2008-08-28 07:52:25 +00001211let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001212def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001213 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001214 Requires<[HasSSE2]>, TB, OpSize;
1215
1216// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1217// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001218let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001219def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001220 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001221
1222// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1223// disregarded.
Dan Gohman5574cc72008-12-03 18:15:48 +00001224let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001225def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001226 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001227 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001228
1229// Alias bitwise logical operations using SSE logical ops on packed FP values.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001230let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231let isCommutable = 1 in {
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001232 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst),
1233 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001234 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001235 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001236 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst),
1237 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001238 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001239 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001240 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst),
1241 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001242 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1244}
1245
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001246def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst),
1247 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001250 (memopfsf64 addr:$src2)))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001251def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst),
1252 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001253 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001254 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001255 (memopfsf64 addr:$src2)))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001256def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst),
1257 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001258 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001259 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001260 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001261
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001262let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001263def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001264 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001265 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001266let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001267def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001268 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001269 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001270}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001271}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272
1273/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1274///
1275/// In addition, we also have a special variant of the scalar form here to
1276/// represent the associated intrinsic operation. This form is unlike the
1277/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng5d5dbbc2009-02-26 03:12:02 +00001278/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279///
1280/// These three forms can each be reg+reg or reg+mem, so there are a total of
1281/// six "instructions".
1282///
Evan Cheng3ea4d672008-03-05 08:19:16 +00001283let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001284multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1285 SDNode OpNode, Intrinsic F64Int,
1286 bit Commutable = 0> {
1287 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001288 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001289 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001290 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1291 let isCommutable = Commutable;
1292 }
1293
1294 // Scalar operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001295 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1296 (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001299
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300 // Vector operation, reg+reg.
Dan Gohmanf221da12009-01-09 02:27:34 +00001301 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1302 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001303 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001304 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1305 let isCommutable = Commutable;
1306 }
1307
1308 // Vector operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001309 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1310 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001311 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf221da12009-01-09 02:27:34 +00001312 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313
1314 // Intrinsic operation, reg+reg.
Dan Gohmanf221da12009-01-09 02:27:34 +00001315 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1316 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001317 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng5d5dbbc2009-02-26 03:12:02 +00001318 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001319
1320 // Intrinsic operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001321 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1322 (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001323 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001324 [(set VR128:$dst, (F64Int VR128:$src1,
1325 sse_load_f64:$src2))]>;
1326}
1327}
1328
1329// Arithmetic instructions
1330defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1331defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1332defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1333defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1334
1335/// sse2_fp_binop_rm - Other SSE2 binops
1336///
1337/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1338/// instructions for a full-vector intrinsic form. Operations that map
1339/// onto C operators don't use this form since they just use the plain
1340/// vector form instead of having a separate vector intrinsic form.
1341///
1342/// This provides a total of eight "instructions".
1343///
Evan Cheng3ea4d672008-03-05 08:19:16 +00001344let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001345multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1346 SDNode OpNode,
1347 Intrinsic F64Int,
1348 Intrinsic V2F64Int,
1349 bit Commutable = 0> {
1350
1351 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001352 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001353 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001354 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1355 let isCommutable = Commutable;
1356 }
1357
1358 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001359 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1360 (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001361 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001362 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001363
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001365 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1366 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001367 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001368 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1369 let isCommutable = Commutable;
1370 }
1371
1372 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001373 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1374 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001375 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001376 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001377
1378 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001379 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1380 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001381 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001382 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1383 let isCommutable = Commutable;
1384 }
1385
1386 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001387 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1388 (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001389 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001390 [(set VR128:$dst, (F64Int VR128:$src1,
1391 sse_load_f64:$src2))]>;
1392
1393 // Vector intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001394 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1395 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001396 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001397 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1398 let isCommutable = Commutable;
1399 }
1400
1401 // Vector intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001402 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1403 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001404 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001405 [(set VR128:$dst, (V2F64Int VR128:$src1,
1406 (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001407}
1408}
1409
1410defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1411 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1412defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1413 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1414
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001415//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001416// SSE packed FP Instructions
1417
1418// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001419let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001420def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001421 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001422let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001423def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001424 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001425 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001426
Evan Chengb783fa32007-07-19 01:14:50 +00001427def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001428 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001429 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001430
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001431let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001432def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001433 "movupd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001434let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001435def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001436 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001437 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001438def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001439 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001440 [(store (v2f64 VR128:$src), addr:$dst)]>;
1441
1442// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001443def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001444 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001445 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001446def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001447 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001448 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001449
Evan Cheng3ea4d672008-03-05 08:19:16 +00001450let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451 let AddedComplexity = 20 in {
1452 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001453 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001454 "movlpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001455 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001456 (v2f64 (movlp VR128:$src1,
1457 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001458 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001459 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001460 "movhpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001461 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001462 (v2f64 (movhp VR128:$src1,
1463 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001464 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +00001465} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001466
Evan Chengb783fa32007-07-19 01:14:50 +00001467def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001468 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001469 [(store (f64 (vector_extract (v2f64 VR128:$src),
1470 (iPTR 0))), addr:$dst)]>;
1471
1472// v2f64 extract element 1 is always custom lowered to unpack high to low
1473// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001474def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001475 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001476 [(store (f64 (vector_extract
Nate Begeman543d2142009-04-27 18:41:29 +00001477 (v2f64 (unpckh VR128:$src, (undef))),
1478 (iPTR 0))), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001479
1480// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001481def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001482 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001483 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1484 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001485def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001486 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1487 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1488 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001489 TB, Requires<[HasSSE2]>;
1490
1491// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001492def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001493 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001494 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1495 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001496def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001497 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1498 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1499 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001500 XS, Requires<[HasSSE2]>;
1501
Evan Chengb783fa32007-07-19 01:14:50 +00001502def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001503 "cvtps2dq\t{$src, $dst|$dst, $src}",
1504 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001505def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001506 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001507 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001508 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001509// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001510def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001511 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001512 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1513 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001514def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001515 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001516 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001517 (memop addr:$src)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518 XS, Requires<[HasSSE2]>;
1519
1520// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001521def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001522 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001523 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1524 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001525def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001526 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001528 (memop addr:$src)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001529 XD, Requires<[HasSSE2]>;
1530
Evan Chengb783fa32007-07-19 01:14:50 +00001531def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001532 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Cheng14c97c32008-03-14 07:46:48 +00001534def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001535 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001536 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001537 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001538
1539// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001540def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001541 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001542 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1543 TB, Requires<[HasSSE2]>;
Mon P Wangaa3f2662008-05-28 00:42:27 +00001544def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001545 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001546 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1547 (load addr:$src)))]>,
1548 TB, Requires<[HasSSE2]>;
1549
Evan Chengb783fa32007-07-19 01:14:50 +00001550def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001551 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001552 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Mon P Wangaa3f2662008-05-28 00:42:27 +00001553def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001554 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001555 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
Evan Cheng00b66ef2008-05-23 00:37:07 +00001556 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001557
1558// Match intrinsics which expect XMM operand(s).
1559// Aliases for intrinsics
Evan Cheng3ea4d672008-03-05 08:19:16 +00001560let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001561def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001562 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001563 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001564 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1565 GR32:$src2))]>;
1566def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001567 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001568 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001569 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1570 (loadi32 addr:$src2)))]>;
1571def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001572 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001573 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001574 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1575 VR128:$src2))]>;
1576def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001577 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001578 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001579 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1580 (load addr:$src2)))]>;
1581def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001582 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001583 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001584 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1585 VR128:$src2))]>, XS,
1586 Requires<[HasSSE2]>;
1587def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001588 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001589 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001590 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1591 (load addr:$src2)))]>, XS,
1592 Requires<[HasSSE2]>;
1593}
1594
1595// Arithmetic
1596
1597/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1598///
1599/// In addition, we also have a special variant of the scalar form here to
1600/// represent the associated intrinsic operation. This form is unlike the
1601/// plain scalar form, in that it takes an entire vector (instead of a
1602/// scalar) and leaves the top elements undefined.
1603///
1604/// And, we have a special variant form for a full-vector intrinsic form.
1605///
1606/// These four forms can each have a reg or a mem operand, so there are a
1607/// total of eight "instructions".
1608///
1609multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1610 SDNode OpNode,
1611 Intrinsic F64Int,
1612 Intrinsic V2F64Int,
1613 bit Commutable = 0> {
1614 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001615 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001616 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001617 [(set FR64:$dst, (OpNode FR64:$src))]> {
1618 let isCommutable = Commutable;
1619 }
1620
1621 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001622 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001623 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001624 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001625
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001626 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001627 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001628 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001629 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1630 let isCommutable = Commutable;
1631 }
1632
1633 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001634 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001635 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001636 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001637
1638 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001639 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001640 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001641 [(set VR128:$dst, (F64Int VR128:$src))]> {
1642 let isCommutable = Commutable;
1643 }
1644
1645 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001646 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001647 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001648 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1649
1650 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001651 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001652 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001653 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1654 let isCommutable = Commutable;
1655 }
1656
1657 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001658 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001659 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001660 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001661}
1662
1663// Square root.
1664defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1665 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1666
1667// There is no f64 version of the reciprocal approximation instructions.
1668
1669// Logical
Evan Cheng3ea4d672008-03-05 08:19:16 +00001670let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001671 let isCommutable = 1 in {
1672 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001673 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001674 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001675 [(set VR128:$dst,
1676 (and (bc_v2i64 (v2f64 VR128:$src1)),
1677 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1678 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001679 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001680 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001681 [(set VR128:$dst,
1682 (or (bc_v2i64 (v2f64 VR128:$src1)),
1683 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1684 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001685 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001686 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001687 [(set VR128:$dst,
1688 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1689 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1690 }
1691
1692 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001693 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001694 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001695 [(set VR128:$dst,
1696 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001697 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001698 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001699 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001700 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001701 [(set VR128:$dst,
1702 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001703 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001704 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001705 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001706 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001707 [(set VR128:$dst,
1708 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001709 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001710 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001711 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001712 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001713 [(set VR128:$dst,
1714 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1715 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1716 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001717 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001718 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001719 [(set VR128:$dst,
1720 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001721 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001722}
1723
Evan Cheng3ea4d672008-03-05 08:19:16 +00001724let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001725 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Cheng14c97c32008-03-14 07:46:48 +00001726 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1727 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1728 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Nate Begeman061db5f2008-05-12 20:34:32 +00001729 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001730 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Cheng14c97c32008-03-14 07:46:48 +00001731 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1732 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1733 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00001734 (memop addr:$src), imm:$cc))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001735}
Evan Cheng33754092008-08-05 22:19:15 +00001736def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
Nate Begeman03605a02008-07-17 16:51:19 +00001737 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
Evan Cheng33754092008-08-05 22:19:15 +00001738def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
Nate Begeman03605a02008-07-17 16:51:19 +00001739 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001740
1741// Shuffle and unpack instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +00001742let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001743 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Cheng14c97c32008-03-14 07:46:48 +00001744 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1745 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begeman543d2142009-04-27 18:41:29 +00001746 [(set VR128:$dst,
1747 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001748 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001749 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001751 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001752 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001753 (v2f64 (shufp:$src3
1754 VR128:$src1, (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001755
1756 let AddedComplexity = 10 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001757 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001758 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001759 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001760 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001761 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001762 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001763 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001764 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001765 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001766 (v2f64 (unpckh VR128:$src1,
1767 (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001768
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001769 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001770 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001771 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001772 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001773 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001774 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001775 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001776 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001777 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001778 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001779 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +00001780} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001781
1782
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001783//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001784// SSE integer instructions
1785
1786// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001787let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001788def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001789 "movdqa\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001790let canFoldAsLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001791def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001792 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001793 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001794let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001795def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001796 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001797 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001798let canFoldAsLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001799def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001800 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001801 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001802 XS, Requires<[HasSSE2]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001803let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001804def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001805 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001806 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001807 XS, Requires<[HasSSE2]>;
1808
Dan Gohman4a4f1512007-07-18 20:23:34 +00001809// Intrinsic forms of MOVDQU load and store
Dan Gohman5574cc72008-12-03 18:15:48 +00001810let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001811def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001812 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001813 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1814 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001815def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001816 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001817 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1818 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001819
Evan Cheng88004752008-03-05 08:11:27 +00001820let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001821
1822multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1823 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001824 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001825 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001826 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1827 let isCommutable = Commutable;
1828 }
Evan Chengb783fa32007-07-19 01:14:50 +00001829 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001830 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001831 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001832 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001833}
1834
Evan Chengf90f8f82008-05-03 00:52:09 +00001835multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1836 string OpcodeStr,
1837 Intrinsic IntId, Intrinsic IntId2> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001838 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1839 VR128:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001840 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1841 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001842 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1843 i128mem:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001844 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1845 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001846 (bitconvert (memopv2i64 addr:$src2))))]>;
1847 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1,
1848 i32i8imm:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001849 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1850 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1851}
1852
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001853/// PDI_binop_rm - Simple SSE2 binary operator.
1854multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1855 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001856 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1857 VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001858 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001859 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1860 let isCommutable = Commutable;
1861 }
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001862 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1863 i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001864 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001865 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001866 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001867}
1868
1869/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1870///
1871/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1872/// to collapse (bitconvert VT to VT) into its operand.
1873///
1874multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1875 bit Commutable = 0> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001876 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1877 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001878 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001879 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1880 let isCommutable = Commutable;
1881 }
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001882 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1883 (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001884 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001885 [(set VR128:$dst, (OpNode VR128:$src1,
1886 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001887}
1888
Evan Cheng3ea4d672008-03-05 08:19:16 +00001889} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001890
1891// 128-bit Integer Arithmetic
1892
1893defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1894defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1895defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1896defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1897
1898defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1899defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1900defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1901defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1902
1903defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1904defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1905defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1906defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1907
1908defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1909defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1910defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1911defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1912
1913defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1914
1915defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1916defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1917defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1918
1919defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1920
1921defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1922defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1923
1924
1925defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1926defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1927defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1928defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
Bill Wendling953ad2e2009-05-28 02:04:00 +00001929defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001930
1931
Evan Chengf90f8f82008-05-03 00:52:09 +00001932defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1933 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1934defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1935 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
1936defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
1937 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001938
Evan Chengf90f8f82008-05-03 00:52:09 +00001939defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
1940 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
1941defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
1942 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
Nate Begemanc2ca5f62008-05-13 17:52:09 +00001943defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Chengf90f8f82008-05-03 00:52:09 +00001944 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001945
Evan Chengf90f8f82008-05-03 00:52:09 +00001946defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
1947 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
Nate Begemand66fc342008-05-13 01:47:52 +00001948defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Chengf90f8f82008-05-03 00:52:09 +00001949 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001950
1951// 128-bit logical shifts.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001952let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001953 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001954 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001955 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001956 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001957 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001958 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001959 // PSRADQri doesn't exist in SSE[1-3].
1960}
1961
1962let Predicates = [HasSSE2] in {
1963 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1964 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1965 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1966 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
Bill Wendling314ee052008-10-02 05:56:52 +00001967 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
1968 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
1969 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
1970 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001971 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1972 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
Evan Chengdea99362008-05-29 08:22:04 +00001973
1974 // Shift up / down and insert zero's.
1975 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
1976 (v2i64 (PSLLDQri VR128:$src, (PSxLDQ_imm imm:$amt)))>;
1977 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
1978 (v2i64 (PSRLDQri VR128:$src, (PSxLDQ_imm imm:$amt)))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001979}
1980
1981// Logical
1982defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1983defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1984defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1985
Evan Cheng3ea4d672008-03-05 08:19:16 +00001986let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001987 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001988 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001989 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001990 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1991 VR128:$src2)))]>;
1992
1993 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001994 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001995 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001996 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7dc19012007-08-02 21:17:01 +00001997 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001998}
1999
2000// SSE2 Integer comparison
2001defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2002defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2003defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2004defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2005defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2006defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2007
Nate Begeman03605a02008-07-17 16:51:19 +00002008def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002009 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002010def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002011 (PCMPEQBrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002012def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002013 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002014def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002015 (PCMPEQWrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002016def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002017 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002018def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002019 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2020
Nate Begeman03605a02008-07-17 16:51:19 +00002021def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002022 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002023def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002024 (PCMPGTBrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002025def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002026 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002027def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002028 (PCMPGTWrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002029def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002030 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002031def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002032 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2033
2034
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002035// Pack instructions
2036defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2037defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2038defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2039
2040// Shuffle and unpack instructions
2041def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002042 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002043 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002044 [(set VR128:$dst, (v4i32 (pshufd:$src2
2045 VR128:$src1, (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002046def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002047 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002048 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002049 [(set VR128:$dst, (v4i32 (pshufd:$src2
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002050 (bc_v4i32(memopv2i64 addr:$src1)),
2051 (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002052
2053// SSE2 with ImmT == Imm8 and XS prefix.
2054def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002055 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002056 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002057 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2058 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002059 XS, Requires<[HasSSE2]>;
2060def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002061 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002062 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002063 [(set VR128:$dst, (v8i16 (pshufhw:$src2
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002064 (bc_v8i16 (memopv2i64 addr:$src1)),
2065 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002066 XS, Requires<[HasSSE2]>;
2067
2068// SSE2 with ImmT == Imm8 and XD prefix.
2069def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Nate Begeman543d2142009-04-27 18:41:29 +00002070 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002071 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002072 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2073 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002074 XD, Requires<[HasSSE2]>;
2075def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Nate Begeman543d2142009-04-27 18:41:29 +00002076 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002077 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002078 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2079 (bc_v8i16 (memopv2i64 addr:$src1)),
2080 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002081 XD, Requires<[HasSSE2]>;
2082
2083
Evan Cheng3ea4d672008-03-05 08:19:16 +00002084let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002085 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002086 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002087 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002088 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002089 (v16i8 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002090 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002091 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002092 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002093 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002094 (unpckl VR128:$src1,
2095 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002096 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002097 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002098 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002099 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002100 (v8i16 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002101 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002102 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002103 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002104 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002105 (unpckl VR128:$src1,
2106 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002107 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002108 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002109 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002110 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002111 (v4i32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002112 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002113 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002114 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002115 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002116 (unpckl VR128:$src1,
2117 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002118 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002119 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002120 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002121 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002122 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002123 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002124 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002125 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002126 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002127 (v2i64 (unpckl VR128:$src1,
2128 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002129
2130 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002131 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002132 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002133 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002134 (v16i8 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002135 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002136 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002137 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002138 [(set VR128:$dst,
2139 (unpckh VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002140 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002141 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002142 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002143 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002144 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002145 (v8i16 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002146 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002147 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002148 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002149 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002150 (unpckh VR128:$src1,
2151 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002152 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002153 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002154 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002155 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002156 (v4i32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002157 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002158 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002159 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002160 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002161 (unpckh VR128:$src1,
2162 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002163 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002164 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002165 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002166 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002167 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002168 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002169 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002170 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002171 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002172 (v2i64 (unpckh VR128:$src1,
2173 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002174}
2175
2176// Extract / Insert
2177def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002178 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002179 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002180 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begemand77e59e2008-02-11 04:19:36 +00002181 imm:$src2))]>;
Evan Cheng3ea4d672008-03-05 08:19:16 +00002182let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002183 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002184 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002185 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002186 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002187 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002188 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002189 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002190 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002191 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002192 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002193 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002194 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2195 imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002196}
2197
2198// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00002199def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002200 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002201 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2202
2203// Conditional store
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002204let Uses = [EDI] in
Evan Chengb783fa32007-07-19 01:14:50 +00002205def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00002206 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002207 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002208
Evan Cheng430de082009-02-10 22:06:28 +00002209let Uses = [RDI] in
2210def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2211 "maskmovdqu\t{$mask, $src|$src, $mask}",
2212 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2213
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002214// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00002215def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002216 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002217 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002218def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002219 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002220 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002221def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002222 "movnti\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002223 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002224 TB, Requires<[HasSSE2]>;
2225
2226// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002227def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002228 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002229 TB, Requires<[HasSSE2]>;
2230
2231// Load, store, and memory fence
Evan Cheng5d0d34e2008-10-17 17:14:20 +00002232def LFENCE : I<0xAE, MRM5r, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002233 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Cheng5d0d34e2008-10-17 17:14:20 +00002234def MFENCE : I<0xAE, MRM6r, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002235 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2236
Andrew Lenharth785610d2008-02-16 01:24:58 +00002237//TODO: custom lower this so as to never even generate the noop
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002238def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
Andrew Lenharth785610d2008-02-16 01:24:58 +00002239 (i8 0)), (NOOP)>;
2240def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2241def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002242def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
Andrew Lenharth785610d2008-02-16 01:24:58 +00002243 (i8 1)), (MFENCE)>;
2244
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002245// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman5574cc72008-12-03 18:15:48 +00002246// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman37eb6c82008-12-03 05:21:24 +00002247// load of an all-ones value if folding it would be beneficial.
Dan Gohman5574cc72008-12-03 18:15:48 +00002248let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002249 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002250 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +00002251 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002252
2253// FR64 to 128-bit vector conversion.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00002254let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002255def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002256 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002257 [(set VR128:$dst,
2258 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002259def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002260 "movsd\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002261 [(set VR128:$dst,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002262 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2263
Evan Chengb783fa32007-07-19 01:14:50 +00002264def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002265 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002266 [(set VR128:$dst,
2267 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002268def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002269 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002270 [(set VR128:$dst,
2271 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2272
Evan Chengb783fa32007-07-19 01:14:50 +00002273def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002274 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002275 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2276
Evan Chengb783fa32007-07-19 01:14:50 +00002277def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002278 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002279 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2280
2281// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002282def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002283 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002284 [(set VR128:$dst,
2285 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2286 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002287def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002288 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002289 [(store (i64 (vector_extract (v2i64 VR128:$src),
2290 (iPTR 0))), addr:$dst)]>;
2291
2292// FIXME: may not be able to eliminate this movss with coalescing the src and
2293// dest register classes are different. We really want to write this pattern
2294// like this:
2295// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2296// (f32 FR32:$src)>;
Evan Chengbd0ca9c2009-02-05 08:42:55 +00002297let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002298def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002299 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002300 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2301 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002302def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002303 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002304 [(store (f64 (vector_extract (v2f64 VR128:$src),
2305 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002306def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002307 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002308 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2309 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002310def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002311 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002312 [(store (i32 (vector_extract (v4i32 VR128:$src),
2313 (iPTR 0))), addr:$dst)]>;
2314
Evan Chengb783fa32007-07-19 01:14:50 +00002315def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002316 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002317 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002318def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002319 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002320 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2321
2322
2323// Move to lower bits of a VR128, leaving upper bits alone.
2324// Three operand (but two address) aliases.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002325let Constraints = "$src1 = $dst" in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00002326 let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002327 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002328 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002329 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002330
2331 let AddedComplexity = 15 in
2332 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002333 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002334 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002335 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002336 (v2f64 (movl VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002337}
2338
2339// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002340def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002341 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002342 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2343
2344// Move to lower bits of a VR128 and zeroing upper bits.
2345// Loading from memory automatically zeroing upper bits.
Evan Chengd743a5f2008-05-10 00:59:18 +00002346let AddedComplexity = 20 in {
2347def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2348 "movsd\t{$src, $dst|$dst, $src}",
2349 [(set VR128:$dst,
2350 (v2f64 (X86vzmovl (v2f64 (scalar_to_vector
2351 (loadf64 addr:$src))))))]>;
Evan Cheng40ee6e52008-05-08 00:57:18 +00002352
Evan Cheng056afe12008-05-20 18:24:47 +00002353def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
2354 (MOVZSD2PDrm addr:$src)>;
2355def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
Evan Chengd743a5f2008-05-10 00:59:18 +00002356 (MOVZSD2PDrm addr:$src)>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002357def : Pat<(v2f64 (X86vzload addr:$src)), (MOVZSD2PDrm addr:$src)>;
Evan Chengd743a5f2008-05-10 00:59:18 +00002358}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002359
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002360// movd / movq to XMM register zero-extends
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002361let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002362def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002363 "movd\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002364 [(set VR128:$dst, (v4i32 (X86vzmovl
Evan Cheng40ee6e52008-05-08 00:57:18 +00002365 (v4i32 (scalar_to_vector GR32:$src)))))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002366// This is X86-64 only.
2367def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2368 "mov{d|q}\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002369 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng40ee6e52008-05-08 00:57:18 +00002370 (v2i64 (scalar_to_vector GR64:$src)))))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002371}
2372
2373let AddedComplexity = 20 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002374def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002375 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002376 [(set VR128:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +00002377 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
Evan Cheng40ee6e52008-05-08 00:57:18 +00002378 (loadi32 addr:$src))))))]>;
Evan Cheng3ad16c42008-05-22 18:56:56 +00002379
2380def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2381 (MOVZDI2PDIrm addr:$src)>;
2382def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2383 (MOVZDI2PDIrm addr:$src)>;
Duncan Sands2418bec2008-06-13 19:07:40 +00002384def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2385 (MOVZDI2PDIrm addr:$src)>;
Evan Cheng3ad16c42008-05-22 18:56:56 +00002386
Evan Chengb783fa32007-07-19 01:14:50 +00002387def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002388 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002389 [(set VR128:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +00002390 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
Evan Cheng40ee6e52008-05-08 00:57:18 +00002391 (loadi64 addr:$src))))))]>, XS,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002392 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002393
Evan Cheng3ad16c42008-05-22 18:56:56 +00002394def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2395 (MOVZQI2PQIrm addr:$src)>;
2396def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2397 (MOVZQI2PQIrm addr:$src)>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002398def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
Evan Chengd743a5f2008-05-10 00:59:18 +00002399}
Evan Chenge9b9c672008-05-09 21:53:03 +00002400
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002401// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2402// IA32 document. movq xmm1, xmm2 does clear the high bits.
2403let AddedComplexity = 15 in
2404def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2405 "movq\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002406 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002407 XS, Requires<[HasSSE2]>;
2408
Evan Cheng056afe12008-05-20 18:24:47 +00002409let AddedComplexity = 20 in {
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002410def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2411 "movq\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002412 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng056afe12008-05-20 18:24:47 +00002413 (loadv2i64 addr:$src))))]>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002414 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002415
Evan Cheng056afe12008-05-20 18:24:47 +00002416def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2417 (MOVZPQILo2PQIrm addr:$src)>;
2418}
2419
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002420//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002421// SSE3 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002422//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002423
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002424// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002425def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002426 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002427 [(set VR128:$dst, (v4f32 (movshdup
2428 VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002429def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002430 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002431 [(set VR128:$dst, (movshdup
2432 (memopv4f32 addr:$src), (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002433
Evan Chengb783fa32007-07-19 01:14:50 +00002434def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002435 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002436 [(set VR128:$dst, (v4f32 (movsldup
2437 VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002438def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002439 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002440 [(set VR128:$dst, (movsldup
2441 (memopv4f32 addr:$src), (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002442
Evan Chengb783fa32007-07-19 01:14:50 +00002443def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002444 "movddup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002445 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002446def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002447 "movddup\t{$src, $dst|$dst, $src}",
Evan Chenga2497eb2008-09-25 20:50:48 +00002448 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002449 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2450 (undef))))]>;
Evan Chenga2497eb2008-09-25 20:50:48 +00002451
Nate Begeman543d2142009-04-27 18:41:29 +00002452def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2453 (undef)),
Evan Chenga2497eb2008-09-25 20:50:48 +00002454 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanb44aad72009-04-29 22:47:44 +00002455
2456let AddedComplexity = 5 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002457def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
Evan Chenga2497eb2008-09-25 20:50:48 +00002458 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanb44aad72009-04-29 22:47:44 +00002459def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2460 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2461def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2462 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2463def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2464 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2465}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002466
2467// Arithmetic
Evan Cheng3ea4d672008-03-05 08:19:16 +00002468let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002469 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002470 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002471 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002472 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2473 VR128:$src2))]>;
2474 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002475 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002476 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002477 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00002478 (memop addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002479 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002480 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002481 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002482 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2483 VR128:$src2))]>;
2484 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002485 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002486 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002487 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00002488 (memop addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002489}
2490
Evan Chengb783fa32007-07-19 01:14:50 +00002491def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002492 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002493 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2494
2495// Horizontal ops
2496class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002497 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002498 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002499 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2500class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002501 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002502 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00002503 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002504class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002505 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002506 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002507 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2508class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002509 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002510 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00002511 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002512
Evan Cheng3ea4d672008-03-05 08:19:16 +00002513let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002514 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2515 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2516 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2517 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2518 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2519 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2520 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2521 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2522}
2523
2524// Thread synchronization
Bill Wendling6ee76552009-05-28 23:40:46 +00002525def MONITOR : I<0x01, MRM1r, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002526 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Bill Wendling6ee76552009-05-28 23:40:46 +00002527def MWAIT : I<0x01, MRM1r, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002528 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2529
2530// vector_shuffle v1, <undef> <1, 1, 3, 3>
2531let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00002532def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002533 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2534let AddedComplexity = 20 in
Nate Begeman543d2142009-04-27 18:41:29 +00002535def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002536 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2537
2538// vector_shuffle v1, <undef> <0, 0, 2, 2>
2539let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00002540 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002541 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2542let AddedComplexity = 20 in
Nate Begeman543d2142009-04-27 18:41:29 +00002543 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002544 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2545
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002546//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002547// SSSE3 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002548//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002549
Bill Wendling98680292007-08-10 06:22:27 +00002550/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002551multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2552 Intrinsic IntId64, Intrinsic IntId128> {
2553 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2554 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2555 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002556
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002557 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2558 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2559 [(set VR64:$dst,
2560 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2561
2562 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2563 (ins VR128:$src),
2564 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2565 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2566 OpSize;
2567
2568 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2569 (ins i128mem:$src),
2570 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2571 [(set VR128:$dst,
2572 (IntId128
2573 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002574}
2575
Bill Wendling98680292007-08-10 06:22:27 +00002576/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002577multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2578 Intrinsic IntId64, Intrinsic IntId128> {
2579 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2580 (ins VR64:$src),
2581 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2582 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002583
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002584 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2585 (ins i64mem:$src),
2586 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2587 [(set VR64:$dst,
2588 (IntId64
2589 (bitconvert (memopv4i16 addr:$src))))]>;
2590
2591 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2592 (ins VR128:$src),
2593 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2594 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2595 OpSize;
2596
2597 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2598 (ins i128mem:$src),
2599 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2600 [(set VR128:$dst,
2601 (IntId128
2602 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002603}
2604
2605/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002606multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2607 Intrinsic IntId64, Intrinsic IntId128> {
2608 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2609 (ins VR64:$src),
2610 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2611 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002612
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002613 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2614 (ins i64mem:$src),
2615 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2616 [(set VR64:$dst,
2617 (IntId64
2618 (bitconvert (memopv2i32 addr:$src))))]>;
2619
2620 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2621 (ins VR128:$src),
2622 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2623 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2624 OpSize;
2625
2626 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2627 (ins i128mem:$src),
2628 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2629 [(set VR128:$dst,
2630 (IntId128
2631 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002632}
2633
2634defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2635 int_x86_ssse3_pabs_b,
2636 int_x86_ssse3_pabs_b_128>;
2637defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2638 int_x86_ssse3_pabs_w,
2639 int_x86_ssse3_pabs_w_128>;
2640defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2641 int_x86_ssse3_pabs_d,
2642 int_x86_ssse3_pabs_d_128>;
2643
2644/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002645let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002646 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2647 Intrinsic IntId64, Intrinsic IntId128,
2648 bit Commutable = 0> {
2649 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2650 (ins VR64:$src1, VR64:$src2),
2651 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2652 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2653 let isCommutable = Commutable;
2654 }
2655 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2656 (ins VR64:$src1, i64mem:$src2),
2657 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2658 [(set VR64:$dst,
2659 (IntId64 VR64:$src1,
2660 (bitconvert (memopv8i8 addr:$src2))))]>;
2661
2662 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2663 (ins VR128:$src1, VR128:$src2),
2664 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2665 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2666 OpSize {
2667 let isCommutable = Commutable;
2668 }
2669 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2670 (ins VR128:$src1, i128mem:$src2),
2671 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2672 [(set VR128:$dst,
2673 (IntId128 VR128:$src1,
2674 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2675 }
2676}
2677
2678/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002679let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002680 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2681 Intrinsic IntId64, Intrinsic IntId128,
2682 bit Commutable = 0> {
2683 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2684 (ins VR64:$src1, VR64:$src2),
2685 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2686 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2687 let isCommutable = Commutable;
2688 }
2689 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2690 (ins VR64:$src1, i64mem:$src2),
2691 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2692 [(set VR64:$dst,
2693 (IntId64 VR64:$src1,
2694 (bitconvert (memopv4i16 addr:$src2))))]>;
2695
2696 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2697 (ins VR128:$src1, VR128:$src2),
2698 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2699 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2700 OpSize {
2701 let isCommutable = Commutable;
2702 }
2703 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2704 (ins VR128:$src1, i128mem:$src2),
2705 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2706 [(set VR128:$dst,
2707 (IntId128 VR128:$src1,
2708 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2709 }
2710}
2711
2712/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002713let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002714 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2715 Intrinsic IntId64, Intrinsic IntId128,
2716 bit Commutable = 0> {
2717 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2718 (ins VR64:$src1, VR64:$src2),
2719 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2720 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2721 let isCommutable = Commutable;
2722 }
2723 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2724 (ins VR64:$src1, i64mem:$src2),
2725 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2726 [(set VR64:$dst,
2727 (IntId64 VR64:$src1,
2728 (bitconvert (memopv2i32 addr:$src2))))]>;
2729
2730 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2731 (ins VR128:$src1, VR128:$src2),
2732 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2733 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2734 OpSize {
2735 let isCommutable = Commutable;
2736 }
2737 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2738 (ins VR128:$src1, i128mem:$src2),
2739 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2740 [(set VR128:$dst,
2741 (IntId128 VR128:$src1,
2742 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2743 }
2744}
2745
2746defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2747 int_x86_ssse3_phadd_w,
Evan Cheng944e4412008-06-16 21:16:24 +00002748 int_x86_ssse3_phadd_w_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002749defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2750 int_x86_ssse3_phadd_d,
Evan Cheng944e4412008-06-16 21:16:24 +00002751 int_x86_ssse3_phadd_d_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002752defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2753 int_x86_ssse3_phadd_sw,
Evan Cheng944e4412008-06-16 21:16:24 +00002754 int_x86_ssse3_phadd_sw_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002755defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2756 int_x86_ssse3_phsub_w,
2757 int_x86_ssse3_phsub_w_128>;
2758defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2759 int_x86_ssse3_phsub_d,
2760 int_x86_ssse3_phsub_d_128>;
2761defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2762 int_x86_ssse3_phsub_sw,
2763 int_x86_ssse3_phsub_sw_128>;
2764defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2765 int_x86_ssse3_pmadd_ub_sw,
Evan Cheng944e4412008-06-16 21:16:24 +00002766 int_x86_ssse3_pmadd_ub_sw_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002767defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2768 int_x86_ssse3_pmul_hr_sw,
2769 int_x86_ssse3_pmul_hr_sw_128, 1>;
2770defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2771 int_x86_ssse3_pshuf_b,
2772 int_x86_ssse3_pshuf_b_128>;
2773defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2774 int_x86_ssse3_psign_b,
2775 int_x86_ssse3_psign_b_128>;
2776defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2777 int_x86_ssse3_psign_w,
2778 int_x86_ssse3_psign_w_128>;
Evan Chengabfed472009-05-28 18:48:53 +00002779defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
Bill Wendling98680292007-08-10 06:22:27 +00002780 int_x86_ssse3_psign_d,
2781 int_x86_ssse3_psign_d_128>;
2782
Evan Cheng3ea4d672008-03-05 08:19:16 +00002783let Constraints = "$src1 = $dst" in {
Bill Wendling1dc817c2007-08-10 09:00:17 +00002784 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2785 (ins VR64:$src1, VR64:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002786 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002787 [(set VR64:$dst,
2788 (int_x86_ssse3_palign_r
2789 VR64:$src1, VR64:$src2,
2790 imm:$src3))]>;
Dan Gohmanbcb9d462008-05-28 01:50:19 +00002791 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
Bill Wendling1dc817c2007-08-10 09:00:17 +00002792 (ins VR64:$src1, i64mem:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002793 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002794 [(set VR64:$dst,
2795 (int_x86_ssse3_palign_r
2796 VR64:$src1,
2797 (bitconvert (memopv2i32 addr:$src2)),
2798 imm:$src3))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002799
Bill Wendling1dc817c2007-08-10 09:00:17 +00002800 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2801 (ins VR128:$src1, VR128:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002802 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002803 [(set VR128:$dst,
2804 (int_x86_ssse3_palign_r_128
2805 VR128:$src1, VR128:$src2,
2806 imm:$src3))]>, OpSize;
Dan Gohmanbcb9d462008-05-28 01:50:19 +00002807 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
Bill Wendling1dc817c2007-08-10 09:00:17 +00002808 (ins VR128:$src1, i128mem:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002809 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002810 [(set VR128:$dst,
2811 (int_x86_ssse3_palign_r_128
2812 VR128:$src1,
2813 (bitconvert (memopv4i32 addr:$src2)),
2814 imm:$src3))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002815}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002816
Nate Begeman2c87c422009-02-23 08:49:38 +00002817def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2818 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2819def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2820 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2821
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002822//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002823// Non-Instruction Patterns
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002824//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002825
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002826// extload f32 -> f64. This matches load+fextend because we have a hack in
2827// the isel (PreprocessForFPConvert) that can introduce loads after dag
2828// combine.
Chris Lattnerdec9cb52008-01-24 08:07:48 +00002829// Since these loads aren't folded into the fextend, we have to match it
2830// explicitly here.
2831let Predicates = [HasSSE2] in
2832 def : Pat<(fextend (loadf32 addr:$src)),
2833 (CVTSS2SDrm addr:$src)>;
2834
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002835// bit_convert
2836let Predicates = [HasSSE2] in {
2837 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2838 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2839 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2840 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2841 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2842 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2843 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2844 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2845 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2846 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2847 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2848 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2849 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2850 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2851 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2852 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2853 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2854 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2855 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2856 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2857 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2858 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2859 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2860 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2861 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2862 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2863 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2864 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2865 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2866 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2867}
2868
2869// Move scalar to XMM zero-extended
2870// movd to XMM register zero-extends
2871let AddedComplexity = 15 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002872// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Evan Chenge9b9c672008-05-09 21:53:03 +00002873def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002874 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002875def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002876 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE1]>;
Evan Chenge259e872008-05-09 23:37:55 +00002877def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002878 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
Evan Cheng7fe0ff02008-07-10 01:08:23 +00002879def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002880 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002881}
2882
2883// Splat v2f64 / v2i64
2884let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002885def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002886 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002887def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002888 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002889def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002890 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002891def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002892 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2893}
2894
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002895// Special unary SHUFPSrri case.
Nate Begeman543d2142009-04-27 18:41:29 +00002896def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2897 (SHUFPSrri VR128:$src1, VR128:$src1,
2898 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002899 Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002900let AddedComplexity = 5 in
2901def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2902 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2903 Requires<[HasSSE2]>;
Dan Gohman7dc19012007-08-02 21:17:01 +00002904// Special unary SHUFPDrri case.
Nate Begeman543d2142009-04-27 18:41:29 +00002905def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002906 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002907 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2908 Requires<[HasSSE2]>;
2909// Special unary SHUFPDrri case.
2910def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002911 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002912 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohman7dc19012007-08-02 21:17:01 +00002913 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002914// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Nate Begeman543d2142009-04-27 18:41:29 +00002915def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2916 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002917 Requires<[HasSSE2]>;
Evan Cheng13559d62008-09-26 23:41:32 +00002918
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002919// Special binary v4i32 shuffle cases with SHUFPS.
Nate Begeman543d2142009-04-27 18:41:29 +00002920def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002921 (SHUFPSrri VR128:$src1, VR128:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002922 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002923 Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002924def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002925 (SHUFPSrmi VR128:$src1, addr:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002926 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002927 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002928// Special binary v2i64 shuffle cases using SHUFPDrri.
Nate Begeman543d2142009-04-27 18:41:29 +00002929def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002930 (SHUFPDrri VR128:$src1, VR128:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002931 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002932 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002933
2934// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Evan Cheng13559d62008-09-26 23:41:32 +00002935let AddedComplexity = 15 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002936def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2937 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002938 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002939def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2940 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002941 Requires<[OptForSpeed, HasSSE2]>;
2942}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002943let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002944def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002945 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002946def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002947 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002948def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002949 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002950def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002951 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002952}
2953
2954// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Evan Cheng13559d62008-09-26 23:41:32 +00002955let AddedComplexity = 15 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002956def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
2957 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002958 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002959def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
2960 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002961 Requires<[OptForSpeed, HasSSE2]>;
2962}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002963let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002964def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002965 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002966def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002967 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002968def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002969 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002970def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002971 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002972}
2973
Evan Cheng13559d62008-09-26 23:41:32 +00002974let AddedComplexity = 20 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002975// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
Nate Begeman543d2142009-04-27 18:41:29 +00002976def : Pat<(v4i32 (movhp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002977 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2978
2979// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
Nate Begeman543d2142009-04-27 18:41:29 +00002980def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002981 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2982
2983// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
Nate Begeman543d2142009-04-27 18:41:29 +00002984def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002985 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Nate Begeman543d2142009-04-27 18:41:29 +00002986def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002987 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2988}
2989
2990let AddedComplexity = 20 in {
2991// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2992// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Nate Begeman543d2142009-04-27 18:41:29 +00002993def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002994 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002995def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002996 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002997def : Pat<(v4f32 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002998 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002999def : Pat<(v2f64 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003000 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3001
Nate Begeman543d2142009-04-27 18:41:29 +00003002def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003003 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003004def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003005 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003006def : Pat<(v4i32 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003007 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003008def : Pat<(v2i64 (movhp VR128:$src1, (load addr:$src2))),
Evan Cheng1ff2ea52008-05-23 18:00:18 +00003009 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003010}
3011
Evan Cheng2b2a7012008-05-23 21:23:16 +00003012// (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3013// (store (vector_shuffle (load addr), v2, <0, 1, 4, 5>), addr) using MOVHPS
Nate Begeman543d2142009-04-27 18:41:29 +00003014def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003015 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003016def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003017 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003018def : Pat<(store (v4f32 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003019 (MOVHPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003020def : Pat<(store (v2f64 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003021 (MOVHPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3022
Nate Begeman543d2142009-04-27 18:41:29 +00003023def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3024 addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003025 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003026def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003027 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003028def : Pat<(store (v4i32 (movhp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3029 addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003030 (MOVHPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003031def : Pat<(store (v2i64 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003032 (MOVHPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3033
3034
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003035let AddedComplexity = 15 in {
3036// Setting the lowest element in the vector.
Nate Begeman543d2142009-04-27 18:41:29 +00003037def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003038 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003039def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003040 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3041
3042// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
Nate Begeman543d2142009-04-27 18:41:29 +00003043def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003044 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003045def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003046 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3047}
3048
Eli Friedman27d19742009-06-19 07:00:55 +00003049// vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3050// fall back to this for SSE1)
3051def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003052 (SHUFPSrri VR128:$src2, VR128:$src1,
Eli Friedman27d19742009-06-19 07:00:55 +00003053 (SHUFFLE_get_shuf_imm VR128:$src3))>, Requires<[HasSSE1]>;
3054
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003055// Set lowest element and zero upper elements.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00003056let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00003057def : Pat<(v2f64 (movl immAllZerosV_bc, VR128:$src)),
Evan Cheng15e8f5a2007-12-15 03:00:47 +00003058 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Evan Chenge9b9c672008-05-09 21:53:03 +00003059def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
Evan Chengd09a8a02008-05-08 22:35:02 +00003060 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003061
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003062// Some special case pandn patterns.
3063def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3064 VR128:$src2)),
3065 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3066def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3067 VR128:$src2)),
3068 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3069def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3070 VR128:$src2)),
3071 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3072
3073def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003074 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003075 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3076def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003077 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003078 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3079def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003080 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003081 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3082
Nate Begeman78246ca2007-11-17 03:58:34 +00003083// vector -> vector casts
3084def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3085 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3086def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3087 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
Eli Friedman7fa52ca2008-09-05 23:07:03 +00003088def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3089 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3090def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3091 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman78246ca2007-11-17 03:58:34 +00003092
Evan Cheng51a49b22007-07-20 00:27:43 +00003093// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00003094def : Pat<(alignedloadv4i32 addr:$src),
3095 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
3096def : Pat<(loadv4i32 addr:$src),
3097 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00003098def : Pat<(alignedloadv2i64 addr:$src),
3099 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
3100def : Pat<(loadv2i64 addr:$src),
3101 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
3102
3103def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3104 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3105def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3106 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3107def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3108 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3109def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3110 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3111def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3112 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3113def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3114 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3115def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3116 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3117def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3118 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003119
Nate Begemanb2975562008-02-03 07:18:54 +00003120//===----------------------------------------------------------------------===//
3121// SSE4.1 Instructions
3122//===----------------------------------------------------------------------===//
3123
Dale Johannesena7d2b442008-10-10 23:51:03 +00003124multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
Nate Begemanb2975562008-02-03 07:18:54 +00003125 string OpcodeStr,
Nate Begemanb2975562008-02-03 07:18:54 +00003126 Intrinsic V4F32Int,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003127 Intrinsic V2F64Int> {
Nate Begemanb2975562008-02-03 07:18:54 +00003128 // Intrinsic operation, reg.
Nate Begemanb2975562008-02-03 07:18:54 +00003129 // Vector intrinsic operation, reg
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003130 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003131 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003132 !strconcat(OpcodeStr,
3133 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003134 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3135 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003136
3137 // Vector intrinsic operation, mem
Evan Cheng78d00612008-03-14 07:39:27 +00003138 def PSm_Int : SS4AIi8<opcps, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003139 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003140 !strconcat(OpcodeStr,
3141 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003142 [(set VR128:$dst,
3143 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003144 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003145
Nate Begemanb2975562008-02-03 07:18:54 +00003146 // Vector intrinsic operation, reg
Evan Cheng78d00612008-03-14 07:39:27 +00003147 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003148 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003149 !strconcat(OpcodeStr,
3150 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003151 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3152 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003153
3154 // Vector intrinsic operation, mem
Evan Cheng78d00612008-03-14 07:39:27 +00003155 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003156 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003157 !strconcat(OpcodeStr,
3158 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003159 [(set VR128:$dst,
3160 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003161 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003162}
3163
Dale Johannesena7d2b442008-10-10 23:51:03 +00003164let Constraints = "$src1 = $dst" in {
3165multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3166 string OpcodeStr,
3167 Intrinsic F32Int,
3168 Intrinsic F64Int> {
3169 // Intrinsic operation, reg.
3170 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003171 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003172 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3173 !strconcat(OpcodeStr,
3174 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003175 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003176 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3177 OpSize;
3178
3179 // Intrinsic operation, mem.
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003180 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3181 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003182 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003183 !strconcat(OpcodeStr,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003184 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003185 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003186 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3187 OpSize;
3188
3189 // Intrinsic operation, reg.
3190 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003191 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003192 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3193 !strconcat(OpcodeStr,
3194 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003195 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003196 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3197 OpSize;
3198
3199 // Intrinsic operation, mem.
3200 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003201 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003202 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3203 !strconcat(OpcodeStr,
3204 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003205 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003206 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3207 OpSize;
3208}
3209}
3210
Nate Begemanb2975562008-02-03 07:18:54 +00003211// FP round - roundss, roundps, roundsd, roundpd
Dale Johannesena7d2b442008-10-10 23:51:03 +00003212defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3213 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3214defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3215 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003216
3217// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3218multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3219 Intrinsic IntId128> {
3220 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3221 (ins VR128:$src),
3222 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3223 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3224 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3225 (ins i128mem:$src),
3226 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3227 [(set VR128:$dst,
3228 (IntId128
3229 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3230}
3231
3232defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3233 int_x86_sse41_phminposuw>;
3234
3235/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003236let Constraints = "$src1 = $dst" in {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003237 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3238 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003239 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3240 (ins VR128:$src1, VR128:$src2),
3241 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3242 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3243 OpSize {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003244 let isCommutable = Commutable;
3245 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003246 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3247 (ins VR128:$src1, i128mem:$src2),
3248 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3249 [(set VR128:$dst,
3250 (IntId128 VR128:$src1,
3251 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003252 }
3253}
3254
3255defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3256 int_x86_sse41_pcmpeqq, 1>;
3257defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3258 int_x86_sse41_packusdw, 0>;
3259defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3260 int_x86_sse41_pminsb, 1>;
3261defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3262 int_x86_sse41_pminsd, 1>;
3263defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3264 int_x86_sse41_pminud, 1>;
3265defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3266 int_x86_sse41_pminuw, 1>;
3267defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3268 int_x86_sse41_pmaxsb, 1>;
3269defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3270 int_x86_sse41_pmaxsd, 1>;
3271defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3272 int_x86_sse41_pmaxud, 1>;
3273defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3274 int_x86_sse41_pmaxuw, 1>;
Nate Begeman72d802a2008-02-04 06:00:24 +00003275
Mon P Wang14edb092008-12-18 21:42:19 +00003276defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3277
Nate Begeman03605a02008-07-17 16:51:19 +00003278def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3279 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3280def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3281 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3282
Nate Begeman58057962008-02-09 01:38:08 +00003283/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003284let Constraints = "$src1 = $dst" in {
Dan Gohmane3731f52008-05-23 17:49:40 +00003285 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3286 SDNode OpNode, Intrinsic IntId128,
3287 bit Commutable = 0> {
Nate Begeman58057962008-02-09 01:38:08 +00003288 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3289 (ins VR128:$src1, VR128:$src2),
3290 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmane3731f52008-05-23 17:49:40 +00003291 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3292 VR128:$src2))]>, OpSize {
Nate Begeman58057962008-02-09 01:38:08 +00003293 let isCommutable = Commutable;
3294 }
3295 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3296 (ins VR128:$src1, VR128:$src2),
3297 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3298 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3299 OpSize {
3300 let isCommutable = Commutable;
3301 }
3302 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3303 (ins VR128:$src1, i128mem:$src2),
3304 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3305 [(set VR128:$dst,
Evan Cheng00b66ef2008-05-23 00:37:07 +00003306 (OpNode VR128:$src1, (memop addr:$src2)))]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003307 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3308 (ins VR128:$src1, i128mem:$src2),
3309 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3310 [(set VR128:$dst,
Evan Cheng00b66ef2008-05-23 00:37:07 +00003311 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
Nate Begeman58057962008-02-09 01:38:08 +00003312 OpSize;
3313 }
3314}
Dan Gohmane3731f52008-05-23 17:49:40 +00003315defm PMULLD : SS41I_binop_patint<0x40, "pmulld", v4i32, mul,
Nate Begeman58057962008-02-09 01:38:08 +00003316 int_x86_sse41_pmulld, 1>;
Nate Begeman58057962008-02-09 01:38:08 +00003317
Evan Cheng78d00612008-03-14 07:39:27 +00003318/// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
Evan Cheng3ea4d672008-03-05 08:19:16 +00003319let Constraints = "$src1 = $dst" in {
Nate Begeman72d802a2008-02-04 06:00:24 +00003320 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3321 Intrinsic IntId128, bit Commutable = 0> {
Evan Cheng78d00612008-03-14 07:39:27 +00003322 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003323 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003324 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003325 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003326 [(set VR128:$dst,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003327 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3328 OpSize {
Nate Begeman72d802a2008-02-04 06:00:24 +00003329 let isCommutable = Commutable;
3330 }
Evan Cheng78d00612008-03-14 07:39:27 +00003331 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003332 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3333 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003334 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003335 [(set VR128:$dst,
3336 (IntId128 VR128:$src1,
3337 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3338 OpSize;
Nate Begeman72d802a2008-02-04 06:00:24 +00003339 }
3340}
3341
3342defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3343 int_x86_sse41_blendps, 0>;
3344defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3345 int_x86_sse41_blendpd, 0>;
3346defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3347 int_x86_sse41_pblendw, 0>;
3348defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3349 int_x86_sse41_dpps, 1>;
3350defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3351 int_x86_sse41_dppd, 1>;
3352defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
Evan Cheng81ed9852008-06-16 20:25:59 +00003353 int_x86_sse41_mpsadbw, 1>;
Nate Begeman58057962008-02-09 01:38:08 +00003354
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003355
Evan Cheng78d00612008-03-14 07:39:27 +00003356/// SS41I_ternary_int - SSE 4.1 ternary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003357let Uses = [XMM0], Constraints = "$src1 = $dst" in {
Nate Begemanb4e9a042008-02-10 18:47:57 +00003358 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3359 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3360 (ins VR128:$src1, VR128:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003361 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003362 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3363 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3364 OpSize;
3365
3366 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3367 (ins VR128:$src1, i128mem:$src2),
3368 !strconcat(OpcodeStr,
3369 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3370 [(set VR128:$dst,
3371 (IntId VR128:$src1,
3372 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3373 }
3374}
3375
3376defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3377defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3378defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3379
3380
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003381multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3382 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3383 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3384 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3385
3386 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3387 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003388 [(set VR128:$dst,
3389 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3390 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003391}
3392
3393defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3394defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3395defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3396defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3397defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3398defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3399
Evan Cheng56ec77b2008-09-24 23:27:55 +00003400// Common patterns involving scalar load.
3401def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3402 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3403def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3404 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3405
3406def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3407 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3408def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3409 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3410
3411def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3412 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3413def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3414 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3415
3416def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3417 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3418def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3419 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3420
3421def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3422 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3423def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3424 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3425
3426def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3427 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3428def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3429 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3430
3431
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003432multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3433 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3434 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3435 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3436
3437 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3438 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003439 [(set VR128:$dst,
3440 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3441 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003442}
3443
3444defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3445defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3446defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3447defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3448
Evan Cheng56ec77b2008-09-24 23:27:55 +00003449// Common patterns involving scalar load
3450def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003451 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003452def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003453 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003454
3455def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003456 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003457def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003458 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003459
3460
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003461multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3462 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3463 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3464 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3465
Evan Cheng56ec77b2008-09-24 23:27:55 +00003466 // Expecting a i16 load any extended to i32 value.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003467 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3468 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003469 [(set VR128:$dst, (IntId (bitconvert
3470 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3471 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003472}
3473
3474defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
Eli Friedman75a89d62009-06-06 05:55:37 +00003475defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003476
Evan Cheng56ec77b2008-09-24 23:27:55 +00003477// Common patterns involving scalar load
3478def : Pat<(int_x86_sse41_pmovsxbq
3479 (bitconvert (v4i32 (X86vzmovl
3480 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003481 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003482
3483def : Pat<(int_x86_sse41_pmovzxbq
3484 (bitconvert (v4i32 (X86vzmovl
3485 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003486 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003487
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003488
Nate Begemand77e59e2008-02-11 04:19:36 +00003489/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3490multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003491 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003492 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003493 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003494 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003495 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3496 OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003497 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003498 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003499 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003500 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003501 []>, OpSize;
3502// FIXME:
3503// There's an AssertZext in the way of writing the store pattern
3504// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003505}
3506
Nate Begemand77e59e2008-02-11 04:19:36 +00003507defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003508
Nate Begemand77e59e2008-02-11 04:19:36 +00003509
3510/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3511multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003512 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemand77e59e2008-02-11 04:19:36 +00003513 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003514 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003515 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3516 []>, OpSize;
3517// FIXME:
3518// There's an AssertZext in the way of writing the store pattern
3519// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3520}
3521
3522defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3523
3524
3525/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3526multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003527 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003528 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003529 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003530 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3531 [(set GR32:$dst,
3532 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003533 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003534 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003535 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003536 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3537 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3538 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003539}
3540
Nate Begemand77e59e2008-02-11 04:19:36 +00003541defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman58057962008-02-09 01:38:08 +00003542
Nate Begemand77e59e2008-02-11 04:19:36 +00003543
Evan Cheng6c249332008-03-24 21:52:23 +00003544/// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3545/// destination
Nate Begemand77e59e2008-02-11 04:19:36 +00003546multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003547 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003548 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003549 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003550 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Dan Gohman788db592008-04-16 02:32:24 +00003551 [(set GR32:$dst,
3552 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
Evan Cheng6c249332008-03-24 21:52:23 +00003553 OpSize;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003554 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003555 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003556 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003557 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng6c249332008-03-24 21:52:23 +00003558 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003559 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003560}
3561
Nate Begemand77e59e2008-02-11 04:19:36 +00003562defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003563
Dan Gohmana41862a2008-08-08 18:30:21 +00003564// Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3565def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3566 imm:$src2))),
3567 addr:$dst),
3568 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3569 Requires<[HasSSE41]>;
3570
Evan Cheng3ea4d672008-03-05 08:19:16 +00003571let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003572 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003573 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003574 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003575 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003576 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003577 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003578 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003579 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003580 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3581 !strconcat(OpcodeStr,
3582 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003583 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003584 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3585 imm:$src3))]>, OpSize;
3586 }
3587}
3588
3589defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3590
Evan Cheng3ea4d672008-03-05 08:19:16 +00003591let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003592 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003593 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003594 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003595 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003596 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003597 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003598 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3599 OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003600 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003601 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3602 !strconcat(OpcodeStr,
3603 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003604 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003605 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3606 imm:$src3)))]>, OpSize;
3607 }
3608}
3609
3610defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3611
Eric Christophera0443602009-07-23 02:22:41 +00003612// insertps has a few different modes, there's the first two here below which
3613// are optimized inserts that won't zero arbitrary elements in the destination
3614// vector. The next one matches the intrinsic and could zero arbitrary elements
3615// in the target vector.
Evan Cheng3ea4d672008-03-05 08:19:16 +00003616let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003617 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
Eric Christopherefb657e2009-07-24 00:33:09 +00003618 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3619 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003620 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003621 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003622 [(set VR128:$dst,
3623 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3624 OpSize;
Eric Christopherefb657e2009-07-24 00:33:09 +00003625 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003626 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3627 !strconcat(OpcodeStr,
3628 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003629 [(set VR128:$dst,
Eric Christopherefb657e2009-07-24 00:33:09 +00003630 (X86insrtps VR128:$src1,
3631 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
Nate Begemand77e59e2008-02-11 04:19:36 +00003632 imm:$src3))]>, OpSize;
3633 }
3634}
3635
Evan Chengc2054be2008-03-26 08:11:49 +00003636defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003637
Eric Christopherefb657e2009-07-24 00:33:09 +00003638def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3639 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3640
Eric Christopher95d79262009-07-29 00:28:05 +00003641// ptest instruction we'll lower to this in X86ISelLowering primarily from
3642// the intel intrinsic that corresponds to this.
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003643let Defs = [EFLAGS] in {
3644def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Eric Christopher95d79262009-07-29 00:28:05 +00003645 "ptest \t{$src2, $src1|$src1, $src2}",
3646 [(X86ptest VR128:$src1, VR128:$src2),
3647 (implicit EFLAGS)]>, OpSize;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003648def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
Eric Christopher95d79262009-07-29 00:28:05 +00003649 "ptest \t{$src2, $src1|$src1, $src2}",
3650 [(X86ptest VR128:$src1, (load addr:$src2)),
3651 (implicit EFLAGS)]>, OpSize;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003652}
3653
3654def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3655 "movntdqa\t{$src, $dst|$dst, $src}",
3656 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>;
Nate Begeman03605a02008-07-17 16:51:19 +00003657
3658/// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3659let Constraints = "$src1 = $dst" in {
3660 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3661 Intrinsic IntId128, bit Commutable = 0> {
3662 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3663 (ins VR128:$src1, VR128:$src2),
3664 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3665 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3666 OpSize {
3667 let isCommutable = Commutable;
3668 }
3669 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3670 (ins VR128:$src1, i128mem:$src2),
3671 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3672 [(set VR128:$dst,
3673 (IntId128 VR128:$src1,
3674 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3675 }
3676}
3677
Nate Begeman235666b2008-07-17 17:04:58 +00003678defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
Nate Begeman03605a02008-07-17 16:51:19 +00003679
3680def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3681 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3682def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3683 (PCMPGTQrm VR128:$src1, addr:$src2)>;
Eric Christopherb5f948c2009-08-08 21:55:08 +00003684
3685// crc intrinsic instruction
3686// This set of instructions are only rm, the only difference is the size
3687// of r and m.
3688let Constraints = "$src1 = $dst" in {
Eric Christopher85f187b2009-08-10 21:48:58 +00003689 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003690 (ins GR32:$src1, i8mem:$src2),
3691 "crc32 \t{$src2, $src1|$src1, $src2}",
3692 [(set GR32:$dst,
3693 (int_x86_sse42_crc32_8 GR32:$src1,
3694 (load addr:$src2)))]>, OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003695 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003696 (ins GR32:$src1, GR8:$src2),
3697 "crc32 \t{$src2, $src1|$src1, $src2}",
3698 [(set GR32:$dst,
Eric Christopher85f187b2009-08-10 21:48:58 +00003699 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>,
Eric Christopherb5f948c2009-08-08 21:55:08 +00003700 OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003701 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003702 (ins GR32:$src1, i16mem:$src2),
3703 "crc32 \t{$src2, $src1|$src1, $src2}",
3704 [(set GR32:$dst,
3705 (int_x86_sse42_crc32_16 GR32:$src1,
3706 (load addr:$src2)))]>,
3707 OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003708 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003709 (ins GR32:$src1, GR16:$src2),
3710 "crc32 \t{$src2, $src1|$src1, $src2}",
3711 [(set GR32:$dst,
Eric Christopher85f187b2009-08-10 21:48:58 +00003712 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
Eric Christopherb5f948c2009-08-08 21:55:08 +00003713 OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003714 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003715 (ins GR32:$src1, i32mem:$src2),
3716 "crc32 \t{$src2, $src1|$src1, $src2}",
3717 [(set GR32:$dst,
3718 (int_x86_sse42_crc32_32 GR32:$src1,
3719 (load addr:$src2)))]>, OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003720 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003721 (ins GR32:$src1, GR32:$src2),
3722 "crc32 \t{$src2, $src1|$src1, $src2}",
3723 [(set GR32:$dst,
Eric Christopher85f187b2009-08-10 21:48:58 +00003724 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>,
Eric Christopherb5f948c2009-08-08 21:55:08 +00003725 OpSize;
Eric Christopher85f187b2009-08-10 21:48:58 +00003726 def CRC64m64 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003727 (ins GR64:$src1, i64mem:$src2),
3728 "crc32 \t{$src2, $src1|$src1, $src2}",
3729 [(set GR64:$dst,
3730 (int_x86_sse42_crc32_64 GR64:$src1,
3731 (load addr:$src2)))]>,
3732 OpSize, REX_W;
Eric Christopher85f187b2009-08-10 21:48:58 +00003733 def CRC64r64 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
Eric Christopherb5f948c2009-08-08 21:55:08 +00003734 (ins GR64:$src1, GR64:$src2),
3735 "crc32 \t{$src2, $src1|$src1, $src2}",
3736 [(set GR64:$dst,
Eric Christopher85f187b2009-08-10 21:48:58 +00003737 (int_x86_sse42_crc32_64 GR64:$src1, GR64:$src2))]>,
Eric Christopherb5f948c2009-08-08 21:55:08 +00003738 OpSize, REX_W;
Eric Christopherb5f948c2009-08-08 21:55:08 +00003739}