blob: a0dbe620b86fb6c1df703a08ec2cc206602bbe46 [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 Christopher95d79262009-07-29 00:28:05 +000072def SDTX86CmpPTest : SDTypeProfile<0, 2, [SDTCisVT<0, v4f32>, SDTCisVT<1, v4f32>]>;
73def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
74
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076// SSE Complex Patterns
77//===----------------------------------------------------------------------===//
78
79// These are 'extloads' from a scalar to the low element of a vector, zeroing
80// the top elements. These are used for the SSE 'ss' and 'sd' instruction
81// forms.
Rafael Espindolabca99f72009-04-08 21:14:34 +000082def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000083 [SDNPHasChain, SDNPMayLoad]>;
Rafael Espindolabca99f72009-04-08 21:14:34 +000084def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000085 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086
87def ssmem : Operand<v4f32> {
88 let PrintMethod = "printf32mem";
Dan Gohmanfe606822009-07-30 01:56:29 +000089 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000090 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091}
92def sdmem : Operand<v2f64> {
93 let PrintMethod = "printf64mem";
Dan Gohmanfe606822009-07-30 01:56:29 +000094 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar0f10cbf2009-08-10 18:41:10 +000095 let ParserMatchClass = X86MemAsmOperand;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000096}
97
98//===----------------------------------------------------------------------===//
99// SSE pattern fragments
100//===----------------------------------------------------------------------===//
101
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
103def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
104def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
105def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
106
Dan Gohman11821702007-07-27 17:16:43 +0000107// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +0000108def alignedstore : PatFrag<(ops node:$val, node:$ptr),
Dan Gohman2a174122008-10-15 06:50:19 +0000109 (store node:$val, node:$ptr), [{
110 return cast<StoreSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000111}]>;
112
Dan Gohman11821702007-07-27 17:16:43 +0000113// Like 'load', but always requires vector alignment.
Dan Gohman2a174122008-10-15 06:50:19 +0000114def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
115 return cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000116}]>;
117
Dan Gohman11821702007-07-27 17:16:43 +0000118def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
119def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000120def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
121def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
122def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
123def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
124
125// Like 'load', but uses special alignment checks suitable for use in
126// memory operands in most SSE instructions, which are required to
127// be naturally aligned on some targets but not on others.
128// FIXME: Actually implement support for targets that don't require the
129// alignment. This probably wants a subtarget predicate.
Dan Gohman2a174122008-10-15 06:50:19 +0000130def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
131 return cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000132}]>;
133
Dan Gohman11821702007-07-27 17:16:43 +0000134def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
135def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000136def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
137def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
138def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
139def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000140def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000141
Bill Wendling3b15d722007-08-11 09:52:53 +0000142// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
143// 16-byte boundary.
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000144// FIXME: 8 byte alignment for mmx reads is not required
Dan Gohman61efc5a2008-10-16 00:03:00 +0000145def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
Dan Gohman2a174122008-10-15 06:50:19 +0000146 return cast<LoadSDNode>(N)->getAlignment() >= 8;
Bill Wendling3b15d722007-08-11 09:52:53 +0000147}]>;
148
149def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
Bill Wendling3b15d722007-08-11 09:52:53 +0000150def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
151def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
152def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
153
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000154def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
155def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
156def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
157def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
158def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
159def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
160
Evan Cheng56ec77b2008-09-24 23:27:55 +0000161def vzmovl_v2i64 : PatFrag<(ops node:$src),
162 (bitconvert (v2i64 (X86vzmovl
163 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
164def vzmovl_v4i32 : PatFrag<(ops node:$src),
165 (bitconvert (v4i32 (X86vzmovl
166 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
167
168def vzload_v2i64 : PatFrag<(ops node:$src),
169 (bitconvert (v2i64 (X86vzload node:$src)))>;
170
171
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172def fp32imm0 : PatLeaf<(f32 fpimm), [{
173 return N->isExactlyValue(+0.0);
174}]>;
175
176def PSxLDQ_imm : SDNodeXForm<imm, [{
177 // Transformation function: imm >> 3
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000178 return getI32Imm(N->getZExtValue() >> 3);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179}]>;
180
181// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
182// SHUFP* etc. imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000183def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 return getI8Imm(X86::getShuffleSHUFImmediate(N));
185}]>;
186
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000187// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188// PSHUFHW imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000189def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
191}]>;
192
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000193// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194// PSHUFLW imm.
Nate Begeman543d2142009-04-27 18:41:29 +0000195def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
197}]>;
198
Nate Begeman543d2142009-04-27 18:41:29 +0000199def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
200 (vector_shuffle node:$lhs, node:$rhs), [{
201 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
202 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
203}]>;
204
205def movddup : PatFrag<(ops node:$lhs, node:$rhs),
206 (vector_shuffle node:$lhs, node:$rhs), [{
207 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
208}]>;
209
210def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
211 (vector_shuffle node:$lhs, node:$rhs), [{
212 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
213}]>;
214
215def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
216 (vector_shuffle node:$lhs, node:$rhs), [{
217 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
218}]>;
219
220def movhp : PatFrag<(ops node:$lhs, node:$rhs),
221 (vector_shuffle node:$lhs, node:$rhs), [{
222 return X86::isMOVHPMask(cast<ShuffleVectorSDNode>(N));
223}]>;
224
225def movlp : PatFrag<(ops node:$lhs, node:$rhs),
226 (vector_shuffle node:$lhs, node:$rhs), [{
227 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
228}]>;
229
230def movl : PatFrag<(ops node:$lhs, node:$rhs),
231 (vector_shuffle node:$lhs, node:$rhs), [{
232 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
233}]>;
234
235def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
236 (vector_shuffle node:$lhs, node:$rhs), [{
237 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
238}]>;
239
240def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
241 (vector_shuffle node:$lhs, node:$rhs), [{
242 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
243}]>;
244
245def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
246 (vector_shuffle node:$lhs, node:$rhs), [{
247 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
248}]>;
249
250def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
251 (vector_shuffle node:$lhs, node:$rhs), [{
252 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
253}]>;
254
255def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
256 (vector_shuffle node:$lhs, node:$rhs), [{
257 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
258}]>;
259
260def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
261 (vector_shuffle node:$lhs, node:$rhs), [{
262 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
263}]>;
264
265def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
266 (vector_shuffle node:$lhs, node:$rhs), [{
267 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268}], SHUFFLE_get_shuf_imm>;
269
Nate Begeman543d2142009-04-27 18:41:29 +0000270def shufp : PatFrag<(ops node:$lhs, node:$rhs),
271 (vector_shuffle node:$lhs, node:$rhs), [{
272 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273}], SHUFFLE_get_shuf_imm>;
274
Nate Begeman543d2142009-04-27 18:41:29 +0000275def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
276 (vector_shuffle node:$lhs, node:$rhs), [{
277 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278}], SHUFFLE_get_pshufhw_imm>;
279
Nate Begeman543d2142009-04-27 18:41:29 +0000280def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
281 (vector_shuffle node:$lhs, node:$rhs), [{
282 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000283}], SHUFFLE_get_pshuflw_imm>;
284
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285//===----------------------------------------------------------------------===//
286// SSE scalar FP Instructions
287//===----------------------------------------------------------------------===//
288
289// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
290// scheduler into a branch sequence.
Evan Cheng950aac02007-09-25 01:57:46 +0000291// These are expanded by the scheduler.
292let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000294 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295 "#CMOV_FR32 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000296 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
297 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000299 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 "#CMOV_FR64 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000301 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
302 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000304 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305 "#CMOV_V4F32 PSEUDO!",
306 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000307 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
308 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000310 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 "#CMOV_V2F64 PSEUDO!",
312 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000313 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
314 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000316 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 "#CMOV_V2I64 PSEUDO!",
318 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000319 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng950aac02007-09-25 01:57:46 +0000320 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321}
322
323//===----------------------------------------------------------------------===//
324// SSE1 Instructions
325//===----------------------------------------------------------------------===//
326
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000328let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000329def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "movss\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000331let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000332def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000333 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000335def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000336 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 [(store FR32:$src, addr:$dst)]>;
338
339// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000340def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000343def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000346def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000347 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000349def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000350 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
352
353// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000354def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000355 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000357def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000358 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 [(set GR32:$dst, (int_x86_sse_cvtss2si
360 (load addr:$src)))]>;
361
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000362// Match intrinisics which expect MM and XMM operand(s).
363def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
364 "cvtps2pi\t{$src, $dst|$dst, $src}",
365 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
366def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
367 "cvtps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000368 [(set VR64:$dst, (int_x86_sse_cvtps2pi
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000369 (load addr:$src)))]>;
370def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
371 "cvttps2pi\t{$src, $dst|$dst, $src}",
372 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
373def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
374 "cvttps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000375 [(set VR64:$dst, (int_x86_sse_cvttps2pi
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000376 (load addr:$src)))]>;
Evan Cheng3ea4d672008-03-05 08:19:16 +0000377let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000378 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000379 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
380 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
381 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
382 VR64:$src2))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000383 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000384 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
385 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000386 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000387 (load addr:$src2)))]>;
388}
389
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000391def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000392 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 [(set GR32:$dst,
394 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000395def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000396 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 [(set GR32:$dst,
398 (int_x86_sse_cvttss2si(load addr:$src)))]>;
399
Evan Cheng3ea4d672008-03-05 08:19:16 +0000400let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000402 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000403 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
405 GR32:$src2))]>;
406 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000407 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000408 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
410 (loadi32 addr:$src2)))]>;
411}
412
413// Comparison instructions
Dan Gohmanf221da12009-01-09 02:27:34 +0000414let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000415 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000416 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000417 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000418let mayLoad = 1 in
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000419 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000420 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000421 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422}
423
Evan Cheng55687072007-09-14 21:48:26 +0000424let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000425def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000426 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000427 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000428def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000429 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000430 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000431 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000432} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433
434// Aliases to match intrinsics which expect XMM operand(s).
Evan Cheng3ea4d672008-03-05 08:19:16 +0000435let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000436 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
437 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
438 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000439 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000440 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000441 VR128:$src, imm:$cc))]>;
442 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
443 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src,
444 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000445 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
447 (load addr:$src), imm:$cc))]>;
448}
449
Evan Cheng55687072007-09-14 21:48:26 +0000450let Defs = [EFLAGS] in {
Dan Gohmanf221da12009-01-09 02:27:34 +0000451def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000452 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000453 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000454 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000455def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000456 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000457 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000458 (implicit EFLAGS)]>;
459
Dan Gohmanf221da12009-01-09 02:27:34 +0000460def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000461 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000462 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000463 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000464def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000465 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000466 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000467 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000468} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000470// Aliases of packed SSE1 instructions for scalar use. These all have names
471// that start with 'Fs'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
473// Alias instructions that map fld0 to pxor for sse.
Evan Chengbf81b9b2008-08-28 07:52:25 +0000474let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000475def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000476 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 Requires<[HasSSE1]>, TB, OpSize;
478
479// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
480// disregarded.
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000481let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000482def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000483 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484
485// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
486// disregarded.
Dan Gohman5574cc72008-12-03 18:15:48 +0000487let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000488def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000490 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491
492// Alias bitwise logical operations using SSE logical ops on packed FP values.
Evan Cheng3ea4d672008-03-05 08:19:16 +0000493let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494let isCommutable = 1 in {
Dan Gohmanf221da12009-01-09 02:27:34 +0000495 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst),
496 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000497 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000499 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst),
500 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000503 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst),
504 (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
507}
508
Dan Gohmanf221da12009-01-09 02:27:34 +0000509def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst),
510 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000511 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000513 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000514def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst),
515 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000516 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000518 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000519def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst),
520 (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000521 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000523 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf221da12009-01-09 02:27:34 +0000524
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000525let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000527 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000528 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000529let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000531 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000532 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000534}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535
536/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
537///
538/// In addition, we also have a special variant of the scalar form here to
539/// represent the associated intrinsic operation. This form is unlike the
540/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng5d5dbbc2009-02-26 03:12:02 +0000541/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542///
543/// These three forms can each be reg+reg or reg+mem, so there are a total of
544/// six "instructions".
545///
Evan Cheng3ea4d672008-03-05 08:19:16 +0000546let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
548 SDNode OpNode, Intrinsic F32Int,
549 bit Commutable = 0> {
550 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000551 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000552 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
554 let isCommutable = Commutable;
555 }
556
557 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000558 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
559 (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000560 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000562
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000564 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
565 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000566 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
568 let isCommutable = Commutable;
569 }
570
571 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000572 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
573 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000574 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000575 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576
577 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000578 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
579 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000580 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Evan Cheng5d5dbbc2009-02-26 03:12:02 +0000581 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582
583 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000584 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
585 (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000586 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000587 [(set VR128:$dst, (F32Int VR128:$src1,
588 sse_load_f32:$src2))]>;
589}
590}
591
592// Arithmetic instructions
593defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
594defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
595defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
596defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
597
598/// sse1_fp_binop_rm - Other SSE1 binops
599///
600/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
601/// instructions for a full-vector intrinsic form. Operations that map
602/// onto C operators don't use this form since they just use the plain
603/// vector form instead of having a separate vector intrinsic form.
604///
605/// This provides a total of eight "instructions".
606///
Evan Cheng3ea4d672008-03-05 08:19:16 +0000607let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
609 SDNode OpNode,
610 Intrinsic F32Int,
611 Intrinsic V4F32Int,
612 bit Commutable = 0> {
613
614 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000615 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000616 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
618 let isCommutable = Commutable;
619 }
620
621 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000622 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst),
623 (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000624 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000626
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000628 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
629 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000630 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
632 let isCommutable = Commutable;
633 }
634
635 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000636 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
637 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000638 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000639 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640
641 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000642 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
643 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000644 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
646 let isCommutable = Commutable;
647 }
648
649 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000650 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
651 (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000652 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 [(set VR128:$dst, (F32Int VR128:$src1,
654 sse_load_f32:$src2))]>;
655
656 // Vector intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000657 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst),
658 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000659 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
661 let isCommutable = Commutable;
662 }
663
664 // Vector intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +0000665 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst),
666 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000667 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000668 [(set VR128:$dst, (V4F32Int VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669}
670}
671
672defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
673 int_x86_sse_max_ss, int_x86_sse_max_ps>;
674defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
675 int_x86_sse_min_ss, int_x86_sse_min_ps>;
676
677//===----------------------------------------------------------------------===//
678// SSE packed FP Instructions
679
680// Move Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000681let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000682def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000683 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000684let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000685def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000686 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000687 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688
Evan Chengb783fa32007-07-19 01:14:50 +0000689def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000690 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000691 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000693let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000694def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000695 "movups\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000696let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000697def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000699 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000700def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000702 [(store (v4f32 VR128:$src), addr:$dst)]>;
703
704// Intrinsic forms of MOVUPS load and store
Dan Gohman5574cc72008-12-03 18:15:48 +0000705let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000706def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000707 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000708 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000709def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000710 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000711 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712
Evan Cheng3ea4d672008-03-05 08:19:16 +0000713let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 let AddedComplexity = 20 in {
715 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000716 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000717 "movlps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000718 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000719 (movlp VR128:$src1,
720 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000722 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "movhps\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000724 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000725 (movhp VR128:$src1,
726 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000728} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729
Evan Chengd743a5f2008-05-10 00:59:18 +0000730
Evan Chengb783fa32007-07-19 01:14:50 +0000731def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000732 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000733 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
734 (iPTR 0))), addr:$dst)]>;
735
736// v2f64 extract element 1 is always custom lowered to unpack high to low
737// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000738def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000739 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000740 [(store (f64 (vector_extract
Nate Begeman543d2142009-04-27 18:41:29 +0000741 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
742 (undef)), (iPTR 0))), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000743
Evan Cheng3ea4d672008-03-05 08:19:16 +0000744let Constraints = "$src1 = $dst" in {
Evan Cheng13559d62008-09-26 23:41:32 +0000745let AddedComplexity = 20 in {
Evan Cheng7581a822009-05-12 20:17:52 +0000746def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
747 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000748 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000750 (v4f32 (movhp VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751
Evan Cheng7581a822009-05-12 20:17:52 +0000752def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
753 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000754 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000756 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757} // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000758} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759
Nate Begemanb44aad72009-04-29 22:47:44 +0000760let AddedComplexity = 20 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000761def : Pat<(v4f32 (movddup VR128:$src, (undef))),
Evan Chenga2497eb2008-09-25 20:50:48 +0000762 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begemanb44aad72009-04-29 22:47:44 +0000763def : Pat<(v2i64 (movddup VR128:$src, (undef))),
764 (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
765}
Evan Chenga2497eb2008-09-25 20:50:48 +0000766
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767
768
769// Arithmetic
770
771/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
772///
773/// In addition, we also have a special variant of the scalar form here to
774/// represent the associated intrinsic operation. This form is unlike the
775/// plain scalar form, in that it takes an entire vector (instead of a
776/// scalar) and leaves the top elements undefined.
777///
778/// And, we have a special variant form for a full-vector intrinsic form.
779///
780/// These four forms can each have a reg or a mem operand, so there are a
781/// total of eight "instructions".
782///
783multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
784 SDNode OpNode,
785 Intrinsic F32Int,
786 Intrinsic V4F32Int,
787 bit Commutable = 0> {
788 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000789 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 [(set FR32:$dst, (OpNode FR32:$src))]> {
792 let isCommutable = Commutable;
793 }
794
795 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000796 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000797 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000799
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000801 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
804 let isCommutable = Commutable;
805 }
806
807 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000808 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000809 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000810 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811
812 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000813 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000814 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000815 [(set VR128:$dst, (F32Int VR128:$src))]> {
816 let isCommutable = Commutable;
817 }
818
819 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000820 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000821 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000822 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
823
824 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000825 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000826 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
828 let isCommutable = Commutable;
829 }
830
831 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000832 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000833 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +0000834 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835}
836
837// Square root.
838defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
839 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
840
841// Reciprocal approximations. Note that these typically require refinement
842// in order to obtain suitable precision.
843defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
844 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
845defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
846 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
847
848// Logical
Evan Cheng3ea4d672008-03-05 08:19:16 +0000849let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850 let isCommutable = 1 in {
851 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000852 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000853 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854 [(set VR128:$dst, (v2i64
855 (and VR128:$src1, VR128:$src2)))]>;
856 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000857 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000858 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 [(set VR128:$dst, (v2i64
860 (or VR128:$src1, VR128:$src2)))]>;
861 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000862 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000863 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864 [(set VR128:$dst, (v2i64
865 (xor VR128:$src1, VR128:$src2)))]>;
866 }
867
868 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000869 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000870 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000871 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
872 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000874 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000875 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000876 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
877 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000879 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000880 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000881 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
882 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883 def ANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000884 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886 [(set VR128:$dst,
887 (v2i64 (and (xor VR128:$src1,
888 (bc_v2i64 (v4i32 immAllOnesV))),
889 VR128:$src2)))]>;
890 def ANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000891 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000892 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000893 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000894 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000896 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897}
898
Evan Cheng3ea4d672008-03-05 08:19:16 +0000899let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000900 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Nate Begeman061db5f2008-05-12 20:34:32 +0000901 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
902 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
903 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
904 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000905 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Nate Begeman061db5f2008-05-12 20:34:32 +0000906 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
907 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
908 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +0000909 (memop addr:$src), imm:$cc))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000910}
Nate Begeman03605a02008-07-17 16:51:19 +0000911def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
912 (CMPPSrri VR128:$src1, VR128:$src2, imm:$cc)>;
913def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
914 (CMPPSrmi VR128:$src1, addr:$src2, imm:$cc)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915
916// Shuffle and unpack instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +0000917let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000918 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000919 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000920 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +0000921 VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000922 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000924 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000925 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000926 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +0000927 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000929 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000930 (v4f32 (shufp:$src3
931 VR128:$src1, (memopv4f32 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000932
933 let AddedComplexity = 10 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000934 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000935 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000938 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000939 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000940 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000941 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000942 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000943 (v4f32 (unpckh VR128:$src1,
944 (memopv4f32 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000945
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000946 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000947 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000948 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000950 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +0000951 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000952 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000953 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000955 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000956 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +0000957} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000958
959// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000960def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengd8296b82009-05-28 18:55:28 +0000963def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
966
Evan Chengd1d68072008-03-08 00:58:38 +0000967// Prefetch intrinsic.
968def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
969 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
970def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
971 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
972def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
973 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
974def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
975 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976
977// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000978def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000979 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
981
982// Load, store, and memory fence
Evan Cheng68cca152009-05-27 18:38:01 +0000983def SFENCE : PSI<0xAE, MRM7r, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000984
985// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000986def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000987 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000988def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990
991// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman5574cc72008-12-03 18:15:48 +0000992// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman37eb6c82008-12-03 05:21:24 +0000993// load of an all-zeros value if folding it would be beneficial.
Dan Gohman5574cc72008-12-03 18:15:48 +0000994let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000995def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000996 "xorps\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000997 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000998
Evan Chenga15896e2008-03-12 07:02:50 +0000999let Predicates = [HasSSE1] in {
1000 def : Pat<(v2i64 immAllZerosV), (V_SET0)>;
1001 def : Pat<(v8i16 immAllZerosV), (V_SET0)>;
1002 def : Pat<(v16i8 immAllZerosV), (V_SET0)>;
1003 def : Pat<(v2f64 immAllZerosV), (V_SET0)>;
1004 def : Pat<(v4f32 immAllZerosV), (V_SET0)>;
1005}
1006
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007// FR32 to 128-bit vector conversion.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001008let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001009def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001010 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001011 [(set VR128:$dst,
1012 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001013def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001014 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001015 [(set VR128:$dst,
1016 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
1017
1018// FIXME: may not be able to eliminate this movss with coalescing the src and
1019// dest register classes are different. We really want to write this pattern
1020// like this:
1021// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
1022// (f32 FR32:$src)>;
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001023let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001024def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001025 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
1027 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001028def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001029 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030 [(store (f32 (vector_extract (v4f32 VR128:$src),
1031 (iPTR 0))), addr:$dst)]>;
1032
1033
1034// Move to lower bits of a VR128, leaving upper bits alone.
1035// Three operand (but two address) aliases.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001036let Constraints = "$src1 = $dst" in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001037let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001039 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041
1042 let AddedComplexity = 15 in
1043 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001044 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001045 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001047 (v4f32 (movl VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048}
1049
1050// Move to lower bits of a VR128 and zeroing upper bits.
1051// Loading from memory automatically zeroing upper bits.
1052let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00001053def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001054 "movss\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00001055 [(set VR128:$dst, (v4f32 (X86vzmovl (v4f32 (scalar_to_vector
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001056 (loadf32 addr:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001057
Evan Cheng056afe12008-05-20 18:24:47 +00001058def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
Evan Cheng40ee6e52008-05-08 00:57:18 +00001059 (MOVZSS2PSrm addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001061//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001062// SSE2 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001063//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001066let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001067def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001068 "movsd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001069let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001070def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001071 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001073def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001074 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001075 [(store FR64:$src, addr:$dst)]>;
1076
1077// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001078def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001079 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001081def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001082 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001084def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001085 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086 [(set FR32:$dst, (fround FR64:$src))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001087def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001088 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001090def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001093def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001094 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1096
1097// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001098def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001099 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1101 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001102def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001103 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1105 Requires<[HasSSE2]>;
1106
1107// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +00001108def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001109 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001111def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001112 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1114 (load addr:$src)))]>;
1115
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001116// Match intrinisics which expect MM and XMM operand(s).
1117def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1118 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1119 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1120def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1121 "cvtpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001122 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
Evan Cheng00b66ef2008-05-23 00:37:07 +00001123 (memop addr:$src)))]>;
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001124def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1125 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1126 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1127def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1128 "cvttpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001129 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
Evan Cheng00b66ef2008-05-23 00:37:07 +00001130 (memop addr:$src)))]>;
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001131def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1132 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1133 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1134def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1135 "cvtpi2pd\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001136 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001137 (load addr:$src)))]>;
1138
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +00001140def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001141 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001142 [(set GR32:$dst,
1143 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001144def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001145 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1147 (load addr:$src)))]>;
1148
1149// Comparison instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +00001150let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001151 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001152 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001153 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001154let mayLoad = 1 in
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001155 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001156 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001157 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001158}
1159
Evan Cheng950aac02007-09-25 01:57:46 +00001160let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001161def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001162 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001163 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001164def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001165 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001166 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001167 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +00001168} // Defs = [EFLAGS]
Evan Cheng950aac02007-09-25 01:57:46 +00001169
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001170// Aliases to match intrinsics which expect XMM operand(s).
Evan Cheng3ea4d672008-03-05 08:19:16 +00001171let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001172 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
1173 (outs VR128:$dst), (ins VR128:$src1, VR128:$src,
1174 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001175 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001176 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1177 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001178 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
1179 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src,
1180 SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001181 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1183 (load addr:$src), imm:$cc))]>;
1184}
1185
Evan Cheng950aac02007-09-25 01:57:46 +00001186let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001187def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001188 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001189 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1190 (implicit EFLAGS)]>;
1191def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001192 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001193 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1194 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195
Evan Chengb783fa32007-07-19 01:14:50 +00001196def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001197 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001198 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1199 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001200def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001202 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001203 (implicit EFLAGS)]>;
Dan Gohmanf221da12009-01-09 02:27:34 +00001204} // Defs = [EFLAGS]
Evan Cheng950aac02007-09-25 01:57:46 +00001205
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001206// Aliases of packed SSE2 instructions for scalar use. These all have names
1207// that start with 'Fs'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001208
1209// Alias instructions that map fld0 to pxor for sse.
Evan Chengbf81b9b2008-08-28 07:52:25 +00001210let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001211def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001212 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001213 Requires<[HasSSE2]>, TB, OpSize;
1214
1215// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1216// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001217let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001218def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220
1221// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1222// disregarded.
Dan Gohman5574cc72008-12-03 18:15:48 +00001223let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001224def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001225 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001226 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001227
1228// Alias bitwise logical operations using SSE logical ops on packed FP values.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001229let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230let isCommutable = 1 in {
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001231 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst),
1232 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001233 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001234 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001235 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst),
1236 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001237 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001239 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst),
1240 (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001241 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001242 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1243}
1244
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001245def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst),
1246 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001247 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001248 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001249 (memopfsf64 addr:$src2)))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001250def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst),
1251 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001252 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001254 (memopfsf64 addr:$src2)))]>;
Evan Cheng0e3e01d2008-05-02 07:53:32 +00001255def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst),
1256 (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001259 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001260
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001261let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001262def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001263 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001264 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001265let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001267 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001268 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001270}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001271
1272/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1273///
1274/// In addition, we also have a special variant of the scalar form here to
1275/// represent the associated intrinsic operation. This form is unlike the
1276/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng5d5dbbc2009-02-26 03:12:02 +00001277/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001278///
1279/// These three forms can each be reg+reg or reg+mem, so there are a total of
1280/// six "instructions".
1281///
Evan Cheng3ea4d672008-03-05 08:19:16 +00001282let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001283multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1284 SDNode OpNode, Intrinsic F64Int,
1285 bit Commutable = 0> {
1286 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001287 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001288 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001289 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1290 let isCommutable = Commutable;
1291 }
1292
1293 // Scalar operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001294 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1295 (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001296 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001297 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001298
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001299 // Vector operation, reg+reg.
Dan Gohmanf221da12009-01-09 02:27:34 +00001300 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1301 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001302 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001303 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1304 let isCommutable = Commutable;
1305 }
1306
1307 // Vector operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001308 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1309 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001310 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf221da12009-01-09 02:27:34 +00001311 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312
1313 // Intrinsic operation, reg+reg.
Dan Gohmanf221da12009-01-09 02:27:34 +00001314 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1315 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001316 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng5d5dbbc2009-02-26 03:12:02 +00001317 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001318
1319 // Intrinsic operation, reg+mem.
Dan Gohmanf221da12009-01-09 02:27:34 +00001320 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1321 (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001322 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001323 [(set VR128:$dst, (F64Int VR128:$src1,
1324 sse_load_f64:$src2))]>;
1325}
1326}
1327
1328// Arithmetic instructions
1329defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1330defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1331defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1332defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1333
1334/// sse2_fp_binop_rm - Other SSE2 binops
1335///
1336/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1337/// instructions for a full-vector intrinsic form. Operations that map
1338/// onto C operators don't use this form since they just use the plain
1339/// vector form instead of having a separate vector intrinsic form.
1340///
1341/// This provides a total of eight "instructions".
1342///
Evan Cheng3ea4d672008-03-05 08:19:16 +00001343let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001344multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1345 SDNode OpNode,
1346 Intrinsic F64Int,
1347 Intrinsic V2F64Int,
1348 bit Commutable = 0> {
1349
1350 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001351 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001352 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001353 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1354 let isCommutable = Commutable;
1355 }
1356
1357 // Scalar operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001358 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst),
1359 (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001360 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001361 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001362
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001363 // Vector operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001364 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1365 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001366 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1368 let isCommutable = Commutable;
1369 }
1370
1371 // Vector operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001372 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1373 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001374 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001375 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001376
1377 // Intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001378 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
1379 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001380 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001381 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1382 let isCommutable = Commutable;
1383 }
1384
1385 // Intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001386 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
1387 (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001388 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001389 [(set VR128:$dst, (F64Int VR128:$src1,
1390 sse_load_f64:$src2))]>;
1391
1392 // Vector intrinsic operation, reg+reg.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001393 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1394 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001395 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001396 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1397 let isCommutable = Commutable;
1398 }
1399
1400 // Vector intrinsic operation, reg+mem.
Evan Cheng00b66ef2008-05-23 00:37:07 +00001401 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1402 (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001403 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001404 [(set VR128:$dst, (V2F64Int VR128:$src1,
1405 (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001406}
1407}
1408
1409defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1410 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1411defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1412 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1413
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001414//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001415// SSE packed FP Instructions
1416
1417// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001418let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001419def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001420 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001421let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001422def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001423 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001424 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001425
Evan Chengb783fa32007-07-19 01:14:50 +00001426def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001427 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001428 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001429
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001430let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001431def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001432 "movupd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001433let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001434def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001435 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001436 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001437def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001438 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001439 [(store (v2f64 VR128:$src), addr:$dst)]>;
1440
1441// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001442def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001443 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001444 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001445def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001446 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001447 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001448
Evan Cheng3ea4d672008-03-05 08:19:16 +00001449let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001450 let AddedComplexity = 20 in {
1451 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001452 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001453 "movlpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001454 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001455 (v2f64 (movlp VR128:$src1,
1456 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001457 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001458 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001459 "movhpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001460 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001461 (v2f64 (movhp VR128:$src1,
1462 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001463 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +00001464} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001465
Evan Chengb783fa32007-07-19 01:14:50 +00001466def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001467 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001468 [(store (f64 (vector_extract (v2f64 VR128:$src),
1469 (iPTR 0))), addr:$dst)]>;
1470
1471// v2f64 extract element 1 is always custom lowered to unpack high to low
1472// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001473def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001474 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001475 [(store (f64 (vector_extract
Nate Begeman543d2142009-04-27 18:41:29 +00001476 (v2f64 (unpckh VR128:$src, (undef))),
1477 (iPTR 0))), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001478
1479// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001480def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001481 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1483 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001484def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001485 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1486 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1487 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001488 TB, Requires<[HasSSE2]>;
1489
1490// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001491def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001492 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001493 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1494 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001495def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001496 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1497 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1498 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001499 XS, Requires<[HasSSE2]>;
1500
Evan Chengb783fa32007-07-19 01:14:50 +00001501def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Evan Cheng14c97c32008-03-14 07:46:48 +00001502 "cvtps2dq\t{$src, $dst|$dst, $src}",
1503 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001504def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001505 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001506 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001507 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001508// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001509def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001510 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001511 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1512 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001513def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001514 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001515 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001516 (memop addr:$src)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001517 XS, Requires<[HasSSE2]>;
1518
1519// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001520def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001521 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1523 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001524def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001525 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001526 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001527 (memop addr:$src)))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001528 XD, Requires<[HasSSE2]>;
1529
Evan Chengb783fa32007-07-19 01:14:50 +00001530def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001531 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001532 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Cheng14c97c32008-03-14 07:46:48 +00001533def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001534 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
Evan Cheng00b66ef2008-05-23 00:37:07 +00001536 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001537
1538// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001539def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001540 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001541 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1542 TB, Requires<[HasSSE2]>;
Mon P Wangaa3f2662008-05-28 00:42:27 +00001543def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001544 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001545 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1546 (load addr:$src)))]>,
1547 TB, Requires<[HasSSE2]>;
1548
Evan Chengb783fa32007-07-19 01:14:50 +00001549def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001550 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001551 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Mon P Wangaa3f2662008-05-28 00:42:27 +00001552def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001553 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001554 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
Evan Cheng00b66ef2008-05-23 00:37:07 +00001555 (memop addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001556
1557// Match intrinsics which expect XMM operand(s).
1558// Aliases for intrinsics
Evan Cheng3ea4d672008-03-05 08:19:16 +00001559let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001560def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001561 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001562 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001563 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1564 GR32:$src2))]>;
1565def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001566 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001567 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001568 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1569 (loadi32 addr:$src2)))]>;
1570def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001571 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001572 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001573 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1574 VR128:$src2))]>;
1575def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001576 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001577 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001578 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1579 (load addr:$src2)))]>;
1580def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001581 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001582 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001583 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1584 VR128:$src2))]>, XS,
1585 Requires<[HasSSE2]>;
1586def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001587 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001588 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001589 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1590 (load addr:$src2)))]>, XS,
1591 Requires<[HasSSE2]>;
1592}
1593
1594// Arithmetic
1595
1596/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1597///
1598/// In addition, we also have a special variant of the scalar form here to
1599/// represent the associated intrinsic operation. This form is unlike the
1600/// plain scalar form, in that it takes an entire vector (instead of a
1601/// scalar) and leaves the top elements undefined.
1602///
1603/// And, we have a special variant form for a full-vector intrinsic form.
1604///
1605/// These four forms can each have a reg or a mem operand, so there are a
1606/// total of eight "instructions".
1607///
1608multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1609 SDNode OpNode,
1610 Intrinsic F64Int,
1611 Intrinsic V2F64Int,
1612 bit Commutable = 0> {
1613 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001614 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001615 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001616 [(set FR64:$dst, (OpNode FR64:$src))]> {
1617 let isCommutable = Commutable;
1618 }
1619
1620 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001621 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001622 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001623 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001624
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001625 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001626 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001627 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001628 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1629 let isCommutable = Commutable;
1630 }
1631
1632 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001633 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001634 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001635 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001636
1637 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001638 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001639 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001640 [(set VR128:$dst, (F64Int VR128:$src))]> {
1641 let isCommutable = Commutable;
1642 }
1643
1644 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001645 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001646 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001647 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1648
1649 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001650 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001651 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001652 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1653 let isCommutable = Commutable;
1654 }
1655
1656 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001657 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001658 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00001659 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001660}
1661
1662// Square root.
1663defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1664 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1665
1666// There is no f64 version of the reciprocal approximation instructions.
1667
1668// Logical
Evan Cheng3ea4d672008-03-05 08:19:16 +00001669let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001670 let isCommutable = 1 in {
1671 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001672 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001673 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001674 [(set VR128:$dst,
1675 (and (bc_v2i64 (v2f64 VR128:$src1)),
1676 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1677 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001678 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001679 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001680 [(set VR128:$dst,
1681 (or (bc_v2i64 (v2f64 VR128:$src1)),
1682 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1683 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001684 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001685 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686 [(set VR128:$dst,
1687 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1688 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1689 }
1690
1691 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001692 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001693 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001694 [(set VR128:$dst,
1695 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001696 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001697 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001698 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001699 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001700 [(set VR128:$dst,
1701 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001702 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001703 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001704 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001705 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001706 [(set VR128:$dst,
1707 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001708 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001709 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001710 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001711 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001712 [(set VR128:$dst,
1713 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1714 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1715 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001716 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001717 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001718 [(set VR128:$dst,
1719 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001720 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001721}
1722
Evan Cheng3ea4d672008-03-05 08:19:16 +00001723let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001724 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Cheng14c97c32008-03-14 07:46:48 +00001725 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1726 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1727 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Nate Begeman061db5f2008-05-12 20:34:32 +00001728 VR128:$src, imm:$cc))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001729 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Cheng14c97c32008-03-14 07:46:48 +00001730 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1731 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1732 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00001733 (memop addr:$src), imm:$cc))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001734}
Evan Cheng33754092008-08-05 22:19:15 +00001735def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
Nate Begeman03605a02008-07-17 16:51:19 +00001736 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
Evan Cheng33754092008-08-05 22:19:15 +00001737def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
Nate Begeman03605a02008-07-17 16:51:19 +00001738 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001739
1740// Shuffle and unpack instructions
Evan Cheng3ea4d672008-03-05 08:19:16 +00001741let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001742 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Cheng14c97c32008-03-14 07:46:48 +00001743 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1744 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begeman543d2142009-04-27 18:41:29 +00001745 [(set VR128:$dst,
1746 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001747 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001748 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001749 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001750 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001751 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001752 (v2f64 (shufp:$src3
1753 VR128:$src1, (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754
1755 let AddedComplexity = 10 in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001756 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001757 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001758 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001759 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001760 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001761 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001762 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001763 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001764 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001765 (v2f64 (unpckh VR128:$src1,
1766 (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001767
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001768 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001769 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001770 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001771 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001772 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001773 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001774 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001775 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001776 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00001777 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778 } // AddedComplexity
Evan Cheng3ea4d672008-03-05 08:19:16 +00001779} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001780
1781
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001782//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001783// SSE integer instructions
1784
1785// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001786let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001787def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001788 "movdqa\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001789let canFoldAsLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001790def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001791 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001792 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001793let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001794def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001795 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001796 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Dan Gohman5574cc72008-12-03 18:15:48 +00001797let canFoldAsLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001798def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001799 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001800 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001801 XS, Requires<[HasSSE2]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001802let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001803def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001804 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001805 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001806 XS, Requires<[HasSSE2]>;
1807
Dan Gohman4a4f1512007-07-18 20:23:34 +00001808// Intrinsic forms of MOVDQU load and store
Dan Gohman5574cc72008-12-03 18:15:48 +00001809let canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001810def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001811 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001812 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1813 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001814def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001815 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001816 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1817 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001818
Evan Cheng88004752008-03-05 08:11:27 +00001819let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001820
1821multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1822 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001823 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001824 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001825 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1826 let isCommutable = Commutable;
1827 }
Evan Chengb783fa32007-07-19 01:14:50 +00001828 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001829 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001830 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001831 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001832}
1833
Evan Chengf90f8f82008-05-03 00:52:09 +00001834multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1835 string OpcodeStr,
1836 Intrinsic IntId, Intrinsic IntId2> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001837 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1838 VR128:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001839 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1840 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001841 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1842 i128mem:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001843 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1844 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001845 (bitconvert (memopv2i64 addr:$src2))))]>;
1846 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1,
1847 i32i8imm:$src2),
Evan Chengf90f8f82008-05-03 00:52:09 +00001848 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1849 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1850}
1851
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001852/// PDI_binop_rm - Simple SSE2 binary operator.
1853multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1854 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001855 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1,
1856 VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001857 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001858 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1859 let isCommutable = Commutable;
1860 }
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001861 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1,
1862 i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001863 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001865 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001866}
1867
1868/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1869///
1870/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1871/// to collapse (bitconvert VT to VT) into its operand.
1872///
1873multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1874 bit Commutable = 0> {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001875 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1876 (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001877 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001878 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1879 let isCommutable = Commutable;
1880 }
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001881 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1882 (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001883 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00001884 [(set VR128:$dst, (OpNode VR128:$src1,
1885 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001886}
1887
Evan Cheng3ea4d672008-03-05 08:19:16 +00001888} // Constraints = "$src1 = $dst"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889
1890// 128-bit Integer Arithmetic
1891
1892defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1893defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1894defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1895defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1896
1897defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1898defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1899defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1900defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1901
1902defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1903defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1904defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1905defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1906
1907defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1908defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1909defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1910defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1911
1912defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1913
1914defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1915defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1916defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1917
1918defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1919
1920defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1921defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1922
1923
1924defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1925defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1926defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1927defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
Bill Wendling953ad2e2009-05-28 02:04:00 +00001928defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001929
1930
Evan Chengf90f8f82008-05-03 00:52:09 +00001931defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1932 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1933defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1934 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
1935defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
1936 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001937
Evan Chengf90f8f82008-05-03 00:52:09 +00001938defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
1939 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
1940defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
1941 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
Nate Begemanc2ca5f62008-05-13 17:52:09 +00001942defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Chengf90f8f82008-05-03 00:52:09 +00001943 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001944
Evan Chengf90f8f82008-05-03 00:52:09 +00001945defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
1946 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
Nate Begemand66fc342008-05-13 01:47:52 +00001947defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Chengf90f8f82008-05-03 00:52:09 +00001948 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001949
1950// 128-bit logical shifts.
Evan Cheng3ea4d672008-03-05 08:19:16 +00001951let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001952 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001953 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001954 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001955 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001956 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001957 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001958 // PSRADQri doesn't exist in SSE[1-3].
1959}
1960
1961let Predicates = [HasSSE2] in {
1962 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1963 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1964 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1965 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
Bill Wendling314ee052008-10-02 05:56:52 +00001966 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
1967 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
1968 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
1969 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001970 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1971 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
Evan Chengdea99362008-05-29 08:22:04 +00001972
1973 // Shift up / down and insert zero's.
1974 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
1975 (v2i64 (PSLLDQri VR128:$src, (PSxLDQ_imm imm:$amt)))>;
1976 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
1977 (v2i64 (PSRLDQri VR128:$src, (PSxLDQ_imm imm:$amt)))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001978}
1979
1980// Logical
1981defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1982defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1983defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1984
Evan Cheng3ea4d672008-03-05 08:19:16 +00001985let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001986 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001987 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001988 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001989 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1990 VR128:$src2)))]>;
1991
1992 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001993 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001994 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001995 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7dc19012007-08-02 21:17:01 +00001996 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001997}
1998
1999// SSE2 Integer comparison
2000defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2001defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2002defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2003defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2004defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2005defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
2006
Nate Begeman03605a02008-07-17 16:51:19 +00002007def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002008 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002009def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002010 (PCMPEQBrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002011def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002012 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002013def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002014 (PCMPEQWrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002015def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002016 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002017def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002018 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2019
Nate Begeman03605a02008-07-17 16:51:19 +00002020def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002021 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002022def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002023 (PCMPGTBrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002024def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002025 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002026def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002027 (PCMPGTWrm VR128:$src1, addr:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002028def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002029 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
Nate Begeman03605a02008-07-17 16:51:19 +00002030def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
Nate Begeman78ca4f92008-05-12 23:09:43 +00002031 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2032
2033
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002034// Pack instructions
2035defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2036defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2037defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
2038
2039// Shuffle and unpack instructions
2040def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002041 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002042 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002043 [(set VR128:$dst, (v4i32 (pshufd:$src2
2044 VR128:$src1, (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002045def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002046 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002047 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002048 [(set VR128:$dst, (v4i32 (pshufd:$src2
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002049 (bc_v4i32(memopv2i64 addr:$src1)),
2050 (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002051
2052// SSE2 with ImmT == Imm8 and XS prefix.
2053def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002054 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002055 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002056 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2057 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002058 XS, Requires<[HasSSE2]>;
2059def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002060 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002061 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002062 [(set VR128:$dst, (v8i16 (pshufhw:$src2
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002063 (bc_v8i16 (memopv2i64 addr:$src1)),
2064 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002065 XS, Requires<[HasSSE2]>;
2066
2067// SSE2 with ImmT == Imm8 and XD prefix.
2068def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Nate Begeman543d2142009-04-27 18:41:29 +00002069 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002070 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002071 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2072 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002073 XD, Requires<[HasSSE2]>;
2074def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Nate Begeman543d2142009-04-27 18:41:29 +00002075 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002076 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman543d2142009-04-27 18:41:29 +00002077 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2078 (bc_v8i16 (memopv2i64 addr:$src1)),
2079 (undef))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002080 XD, Requires<[HasSSE2]>;
2081
2082
Evan Cheng3ea4d672008-03-05 08:19:16 +00002083let Constraints = "$src1 = $dst" in {
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002084 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002085 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002086 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002087 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002088 (v16i8 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002089 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002090 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002091 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002092 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002093 (unpckl VR128:$src1,
2094 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002095 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002096 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002097 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002098 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002099 (v8i16 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002100 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002101 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002102 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002103 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002104 (unpckl VR128:$src1,
2105 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002106 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002107 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002108 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002109 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002110 (v4i32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002111 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002112 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002113 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002114 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002115 (unpckl VR128:$src1,
2116 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002117 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002118 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002119 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002120 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002121 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002122 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002123 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002124 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002125 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002126 (v2i64 (unpckl VR128:$src1,
2127 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002128
2129 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002130 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002131 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002132 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002133 (v16i8 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002134 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002135 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002136 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002137 [(set VR128:$dst,
2138 (unpckh VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002139 (bc_v16i8 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002140 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002141 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002142 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002143 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002144 (v8i16 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002145 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002146 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002147 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002148 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002149 (unpckh VR128:$src1,
2150 (bc_v8i16 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002151 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002152 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002153 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002154 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002155 (v4i32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002156 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002157 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002158 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002159 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002160 (unpckh VR128:$src1,
2161 (bc_v4i32 (memopv2i64 addr:$src2))))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002162 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002163 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002164 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002165 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002166 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002167 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002168 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002169 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002170 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002171 (v2i64 (unpckh VR128:$src1,
2172 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002173}
2174
2175// Extract / Insert
2176def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002177 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002178 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002179 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begemand77e59e2008-02-11 04:19:36 +00002180 imm:$src2))]>;
Evan Cheng3ea4d672008-03-05 08:19:16 +00002181let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002182 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002183 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002184 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002185 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002186 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002187 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002188 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002189 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002190 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002191 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002192 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002193 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2194 imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002195}
2196
2197// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00002198def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002199 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002200 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2201
2202// Conditional store
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002203let Uses = [EDI] in
Evan Chengb783fa32007-07-19 01:14:50 +00002204def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00002205 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002206 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002207
Evan Cheng430de082009-02-10 22:06:28 +00002208let Uses = [RDI] in
2209def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2210 "maskmovdqu\t{$mask, $src|$src, $mask}",
2211 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2212
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002213// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00002214def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002215 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002216 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002217def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002218 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002219 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002220def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002221 "movnti\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002222 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002223 TB, Requires<[HasSSE2]>;
2224
2225// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002226def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002227 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002228 TB, Requires<[HasSSE2]>;
2229
2230// Load, store, and memory fence
Evan Cheng5d0d34e2008-10-17 17:14:20 +00002231def LFENCE : I<0xAE, MRM5r, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002232 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Cheng5d0d34e2008-10-17 17:14:20 +00002233def MFENCE : I<0xAE, MRM6r, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002234 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2235
Andrew Lenharth785610d2008-02-16 01:24:58 +00002236//TODO: custom lower this so as to never even generate the noop
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002237def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
Andrew Lenharth785610d2008-02-16 01:24:58 +00002238 (i8 0)), (NOOP)>;
2239def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2240def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002241def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
Andrew Lenharth785610d2008-02-16 01:24:58 +00002242 (i8 1)), (MFENCE)>;
2243
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002244// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman5574cc72008-12-03 18:15:48 +00002245// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman37eb6c82008-12-03 05:21:24 +00002246// load of an all-ones value if folding it would be beneficial.
Dan Gohman5574cc72008-12-03 18:15:48 +00002247let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002248 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002249 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +00002250 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002251
2252// FR64 to 128-bit vector conversion.
Evan Chengbd0ca9c2009-02-05 08:42:55 +00002253let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002254def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002255 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002256 [(set VR128:$dst,
2257 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002258def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002259 "movsd\t{$src, $dst|$dst, $src}",
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002260 [(set VR128:$dst,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002261 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2262
Evan Chengb783fa32007-07-19 01:14:50 +00002263def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002264 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002265 [(set VR128:$dst,
2266 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002267def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002268 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002269 [(set VR128:$dst,
2270 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2271
Evan Chengb783fa32007-07-19 01:14:50 +00002272def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002273 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002274 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2275
Evan Chengb783fa32007-07-19 01:14:50 +00002276def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002277 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002278 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2279
2280// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002281def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002282 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002283 [(set VR128:$dst,
2284 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2285 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002286def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002287 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002288 [(store (i64 (vector_extract (v2i64 VR128:$src),
2289 (iPTR 0))), addr:$dst)]>;
2290
2291// FIXME: may not be able to eliminate this movss with coalescing the src and
2292// dest register classes are different. We really want to write this pattern
2293// like this:
2294// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2295// (f32 FR32:$src)>;
Evan Chengbd0ca9c2009-02-05 08:42:55 +00002296let isAsCheapAsAMove = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002297def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002298 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002299 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2300 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002301def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002302 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002303 [(store (f64 (vector_extract (v2f64 VR128:$src),
2304 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002305def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002306 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002307 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2308 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002309def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002310 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002311 [(store (i32 (vector_extract (v4i32 VR128:$src),
2312 (iPTR 0))), addr:$dst)]>;
2313
Evan Chengb783fa32007-07-19 01:14:50 +00002314def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002315 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002316 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002317def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002318 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002319 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2320
2321
2322// Move to lower bits of a VR128, leaving upper bits alone.
2323// Three operand (but two address) aliases.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002324let Constraints = "$src1 = $dst" in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00002325 let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002326 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002327 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002328 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002329
2330 let AddedComplexity = 15 in
2331 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002332 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002333 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002334 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002335 (v2f64 (movl VR128:$src1, VR128:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002336}
2337
2338// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002339def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002340 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002341 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2342
2343// Move to lower bits of a VR128 and zeroing upper bits.
2344// Loading from memory automatically zeroing upper bits.
Evan Chengd743a5f2008-05-10 00:59:18 +00002345let AddedComplexity = 20 in {
2346def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
2347 "movsd\t{$src, $dst|$dst, $src}",
2348 [(set VR128:$dst,
2349 (v2f64 (X86vzmovl (v2f64 (scalar_to_vector
2350 (loadf64 addr:$src))))))]>;
Evan Cheng40ee6e52008-05-08 00:57:18 +00002351
Evan Cheng056afe12008-05-20 18:24:47 +00002352def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
2353 (MOVZSD2PDrm addr:$src)>;
2354def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
Evan Chengd743a5f2008-05-10 00:59:18 +00002355 (MOVZSD2PDrm addr:$src)>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002356def : Pat<(v2f64 (X86vzload addr:$src)), (MOVZSD2PDrm addr:$src)>;
Evan Chengd743a5f2008-05-10 00:59:18 +00002357}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002358
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002359// movd / movq to XMM register zero-extends
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002360let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002361def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002362 "movd\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002363 [(set VR128:$dst, (v4i32 (X86vzmovl
Evan Cheng40ee6e52008-05-08 00:57:18 +00002364 (v4i32 (scalar_to_vector GR32:$src)))))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002365// This is X86-64 only.
2366def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2367 "mov{d|q}\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002368 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng40ee6e52008-05-08 00:57:18 +00002369 (v2i64 (scalar_to_vector GR64:$src)))))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002370}
2371
2372let AddedComplexity = 20 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002373def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002374 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002375 [(set VR128:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +00002376 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
Evan Cheng40ee6e52008-05-08 00:57:18 +00002377 (loadi32 addr:$src))))))]>;
Evan Cheng3ad16c42008-05-22 18:56:56 +00002378
2379def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2380 (MOVZDI2PDIrm addr:$src)>;
2381def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2382 (MOVZDI2PDIrm addr:$src)>;
Duncan Sands2418bec2008-06-13 19:07:40 +00002383def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2384 (MOVZDI2PDIrm addr:$src)>;
Evan Cheng3ad16c42008-05-22 18:56:56 +00002385
Evan Chengb783fa32007-07-19 01:14:50 +00002386def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002387 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002388 [(set VR128:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +00002389 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
Evan Cheng40ee6e52008-05-08 00:57:18 +00002390 (loadi64 addr:$src))))))]>, XS,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002391 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002392
Evan Cheng3ad16c42008-05-22 18:56:56 +00002393def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2394 (MOVZQI2PQIrm addr:$src)>;
2395def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2396 (MOVZQI2PQIrm addr:$src)>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002397def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
Evan Chengd743a5f2008-05-10 00:59:18 +00002398}
Evan Chenge9b9c672008-05-09 21:53:03 +00002399
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002400// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2401// IA32 document. movq xmm1, xmm2 does clear the high bits.
2402let AddedComplexity = 15 in
2403def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2404 "movq\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002405 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002406 XS, Requires<[HasSSE2]>;
2407
Evan Cheng056afe12008-05-20 18:24:47 +00002408let AddedComplexity = 20 in {
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002409def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2410 "movq\t{$src, $dst|$dst, $src}",
Evan Chenge9b9c672008-05-09 21:53:03 +00002411 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng056afe12008-05-20 18:24:47 +00002412 (loadv2i64 addr:$src))))]>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002413 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002414
Evan Cheng056afe12008-05-20 18:24:47 +00002415def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2416 (MOVZPQILo2PQIrm addr:$src)>;
2417}
2418
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002419//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002420// SSE3 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002421//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002422
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002423// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002424def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002425 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002426 [(set VR128:$dst, (v4f32 (movshdup
2427 VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002428def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002429 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002430 [(set VR128:$dst, (movshdup
2431 (memopv4f32 addr:$src), (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002432
Evan Chengb783fa32007-07-19 01:14:50 +00002433def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002434 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002435 [(set VR128:$dst, (v4f32 (movsldup
2436 VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002437def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002438 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002439 [(set VR128:$dst, (movsldup
2440 (memopv4f32 addr:$src), (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002441
Evan Chengb783fa32007-07-19 01:14:50 +00002442def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002443 "movddup\t{$src, $dst|$dst, $src}",
Nate Begeman543d2142009-04-27 18:41:29 +00002444 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002445def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002446 "movddup\t{$src, $dst|$dst, $src}",
Evan Chenga2497eb2008-09-25 20:50:48 +00002447 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +00002448 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2449 (undef))))]>;
Evan Chenga2497eb2008-09-25 20:50:48 +00002450
Nate Begeman543d2142009-04-27 18:41:29 +00002451def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2452 (undef)),
Evan Chenga2497eb2008-09-25 20:50:48 +00002453 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanb44aad72009-04-29 22:47:44 +00002454
2455let AddedComplexity = 5 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002456def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
Evan Chenga2497eb2008-09-25 20:50:48 +00002457 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanb44aad72009-04-29 22:47:44 +00002458def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2459 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2460def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2461 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2462def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2463 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2464}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002465
2466// Arithmetic
Evan Cheng3ea4d672008-03-05 08:19:16 +00002467let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002468 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002469 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002470 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002471 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2472 VR128:$src2))]>;
2473 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002474 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002475 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002476 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00002477 (memop addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002478 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002479 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002480 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002481 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2482 VR128:$src2))]>;
2483 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002484 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002485 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002486 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
Evan Cheng00b66ef2008-05-23 00:37:07 +00002487 (memop addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002488}
2489
Evan Chengb783fa32007-07-19 01:14:50 +00002490def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002491 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002492 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2493
2494// Horizontal ops
2495class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002496 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002497 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002498 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2499class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002500 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002501 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00002502 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002503class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002504 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002505 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002506 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2507class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002508 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002509 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00002510 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002511
Evan Cheng3ea4d672008-03-05 08:19:16 +00002512let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002513 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2514 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2515 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2516 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2517 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2518 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2519 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2520 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2521}
2522
2523// Thread synchronization
Bill Wendling6ee76552009-05-28 23:40:46 +00002524def MONITOR : I<0x01, MRM1r, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002525 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Bill Wendling6ee76552009-05-28 23:40:46 +00002526def MWAIT : I<0x01, MRM1r, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002527 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2528
2529// vector_shuffle v1, <undef> <1, 1, 3, 3>
2530let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00002531def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002532 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2533let AddedComplexity = 20 in
Nate Begeman543d2142009-04-27 18:41:29 +00002534def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002535 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2536
2537// vector_shuffle v1, <undef> <0, 0, 2, 2>
2538let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00002539 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002540 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2541let AddedComplexity = 20 in
Nate Begeman543d2142009-04-27 18:41:29 +00002542 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002543 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2544
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002545//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002546// SSSE3 Instructions
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002547//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002548
Bill Wendling98680292007-08-10 06:22:27 +00002549/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002550multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2551 Intrinsic IntId64, Intrinsic IntId128> {
2552 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2553 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2554 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002555
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002556 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2557 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2558 [(set VR64:$dst,
2559 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2560
2561 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2562 (ins VR128:$src),
2563 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2564 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2565 OpSize;
2566
2567 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2568 (ins i128mem:$src),
2569 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2570 [(set VR128:$dst,
2571 (IntId128
2572 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002573}
2574
Bill Wendling98680292007-08-10 06:22:27 +00002575/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002576multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2577 Intrinsic IntId64, Intrinsic IntId128> {
2578 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2579 (ins VR64:$src),
2580 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2581 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002582
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002583 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2584 (ins i64mem:$src),
2585 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2586 [(set VR64:$dst,
2587 (IntId64
2588 (bitconvert (memopv4i16 addr:$src))))]>;
2589
2590 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2591 (ins VR128:$src),
2592 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2593 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2594 OpSize;
2595
2596 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2597 (ins i128mem:$src),
2598 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2599 [(set VR128:$dst,
2600 (IntId128
2601 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002602}
2603
2604/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002605multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2606 Intrinsic IntId64, Intrinsic IntId128> {
2607 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2608 (ins VR64:$src),
2609 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2610 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002611
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002612 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2613 (ins i64mem:$src),
2614 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2615 [(set VR64:$dst,
2616 (IntId64
2617 (bitconvert (memopv2i32 addr:$src))))]>;
2618
2619 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2620 (ins VR128:$src),
2621 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2622 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2623 OpSize;
2624
2625 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2626 (ins i128mem:$src),
2627 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2628 [(set VR128:$dst,
2629 (IntId128
2630 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002631}
2632
2633defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2634 int_x86_ssse3_pabs_b,
2635 int_x86_ssse3_pabs_b_128>;
2636defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2637 int_x86_ssse3_pabs_w,
2638 int_x86_ssse3_pabs_w_128>;
2639defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2640 int_x86_ssse3_pabs_d,
2641 int_x86_ssse3_pabs_d_128>;
2642
2643/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002644let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002645 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2646 Intrinsic IntId64, Intrinsic IntId128,
2647 bit Commutable = 0> {
2648 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2649 (ins VR64:$src1, VR64:$src2),
2650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2651 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2652 let isCommutable = Commutable;
2653 }
2654 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2655 (ins VR64:$src1, i64mem:$src2),
2656 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2657 [(set VR64:$dst,
2658 (IntId64 VR64:$src1,
2659 (bitconvert (memopv8i8 addr:$src2))))]>;
2660
2661 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2662 (ins VR128:$src1, VR128:$src2),
2663 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2664 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2665 OpSize {
2666 let isCommutable = Commutable;
2667 }
2668 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2669 (ins VR128:$src1, i128mem:$src2),
2670 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2671 [(set VR128:$dst,
2672 (IntId128 VR128:$src1,
2673 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2674 }
2675}
2676
2677/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002678let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002679 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2680 Intrinsic IntId64, Intrinsic IntId128,
2681 bit Commutable = 0> {
2682 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2683 (ins VR64:$src1, VR64:$src2),
2684 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2685 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2686 let isCommutable = Commutable;
2687 }
2688 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2689 (ins VR64:$src1, i64mem:$src2),
2690 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2691 [(set VR64:$dst,
2692 (IntId64 VR64:$src1,
2693 (bitconvert (memopv4i16 addr:$src2))))]>;
2694
2695 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2696 (ins VR128:$src1, VR128:$src2),
2697 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2698 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2699 OpSize {
2700 let isCommutable = Commutable;
2701 }
2702 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2703 (ins VR128:$src1, i128mem:$src2),
2704 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2705 [(set VR128:$dst,
2706 (IntId128 VR128:$src1,
2707 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2708 }
2709}
2710
2711/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
Evan Cheng3ea4d672008-03-05 08:19:16 +00002712let Constraints = "$src1 = $dst" in {
Bill Wendling98680292007-08-10 06:22:27 +00002713 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2714 Intrinsic IntId64, Intrinsic IntId128,
2715 bit Commutable = 0> {
2716 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2717 (ins VR64:$src1, VR64:$src2),
2718 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2719 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2720 let isCommutable = Commutable;
2721 }
2722 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2723 (ins VR64:$src1, i64mem:$src2),
2724 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2725 [(set VR64:$dst,
2726 (IntId64 VR64:$src1,
2727 (bitconvert (memopv2i32 addr:$src2))))]>;
2728
2729 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2730 (ins VR128:$src1, VR128:$src2),
2731 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2732 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2733 OpSize {
2734 let isCommutable = Commutable;
2735 }
2736 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2737 (ins VR128:$src1, i128mem:$src2),
2738 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2739 [(set VR128:$dst,
2740 (IntId128 VR128:$src1,
2741 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2742 }
2743}
2744
2745defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2746 int_x86_ssse3_phadd_w,
Evan Cheng944e4412008-06-16 21:16:24 +00002747 int_x86_ssse3_phadd_w_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002748defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2749 int_x86_ssse3_phadd_d,
Evan Cheng944e4412008-06-16 21:16:24 +00002750 int_x86_ssse3_phadd_d_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002751defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2752 int_x86_ssse3_phadd_sw,
Evan Cheng944e4412008-06-16 21:16:24 +00002753 int_x86_ssse3_phadd_sw_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002754defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2755 int_x86_ssse3_phsub_w,
2756 int_x86_ssse3_phsub_w_128>;
2757defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2758 int_x86_ssse3_phsub_d,
2759 int_x86_ssse3_phsub_d_128>;
2760defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2761 int_x86_ssse3_phsub_sw,
2762 int_x86_ssse3_phsub_sw_128>;
2763defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2764 int_x86_ssse3_pmadd_ub_sw,
Evan Cheng944e4412008-06-16 21:16:24 +00002765 int_x86_ssse3_pmadd_ub_sw_128>;
Bill Wendling98680292007-08-10 06:22:27 +00002766defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2767 int_x86_ssse3_pmul_hr_sw,
2768 int_x86_ssse3_pmul_hr_sw_128, 1>;
2769defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2770 int_x86_ssse3_pshuf_b,
2771 int_x86_ssse3_pshuf_b_128>;
2772defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2773 int_x86_ssse3_psign_b,
2774 int_x86_ssse3_psign_b_128>;
2775defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2776 int_x86_ssse3_psign_w,
2777 int_x86_ssse3_psign_w_128>;
Evan Chengabfed472009-05-28 18:48:53 +00002778defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
Bill Wendling98680292007-08-10 06:22:27 +00002779 int_x86_ssse3_psign_d,
2780 int_x86_ssse3_psign_d_128>;
2781
Evan Cheng3ea4d672008-03-05 08:19:16 +00002782let Constraints = "$src1 = $dst" in {
Bill Wendling1dc817c2007-08-10 09:00:17 +00002783 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2784 (ins VR64:$src1, VR64:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002785 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002786 [(set VR64:$dst,
2787 (int_x86_ssse3_palign_r
2788 VR64:$src1, VR64:$src2,
2789 imm:$src3))]>;
Dan Gohmanbcb9d462008-05-28 01:50:19 +00002790 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
Bill Wendling1dc817c2007-08-10 09:00:17 +00002791 (ins VR64:$src1, i64mem:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002792 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002793 [(set VR64:$dst,
2794 (int_x86_ssse3_palign_r
2795 VR64:$src1,
2796 (bitconvert (memopv2i32 addr:$src2)),
2797 imm:$src3))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002798
Bill Wendling1dc817c2007-08-10 09:00:17 +00002799 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2800 (ins VR128:$src1, VR128:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002801 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002802 [(set VR128:$dst,
2803 (int_x86_ssse3_palign_r_128
2804 VR128:$src1, VR128:$src2,
2805 imm:$src3))]>, OpSize;
Dan Gohmanbcb9d462008-05-28 01:50:19 +00002806 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
Bill Wendling1dc817c2007-08-10 09:00:17 +00002807 (ins VR128:$src1, i128mem:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002808 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002809 [(set VR128:$dst,
2810 (int_x86_ssse3_palign_r_128
2811 VR128:$src1,
2812 (bitconvert (memopv4i32 addr:$src2)),
2813 imm:$src3))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002814}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002815
Nate Begeman2c87c422009-02-23 08:49:38 +00002816def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2817 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2818def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2819 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2820
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002821//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002822// Non-Instruction Patterns
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002823//===---------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002824
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002825// extload f32 -> f64. This matches load+fextend because we have a hack in
2826// the isel (PreprocessForFPConvert) that can introduce loads after dag
2827// combine.
Chris Lattnerdec9cb52008-01-24 08:07:48 +00002828// Since these loads aren't folded into the fextend, we have to match it
2829// explicitly here.
2830let Predicates = [HasSSE2] in
2831 def : Pat<(fextend (loadf32 addr:$src)),
2832 (CVTSS2SDrm addr:$src)>;
2833
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002834// bit_convert
2835let Predicates = [HasSSE2] in {
2836 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2837 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2838 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2839 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2840 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2841 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2842 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2843 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2844 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2845 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2846 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2847 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2848 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2849 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2850 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2851 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2852 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2853 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2854 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2855 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2856 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2857 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2858 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2859 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2860 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2861 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2862 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2863 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2864 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2865 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2866}
2867
2868// Move scalar to XMM zero-extended
2869// movd to XMM register zero-extends
2870let AddedComplexity = 15 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002871// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Evan Chenge9b9c672008-05-09 21:53:03 +00002872def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002873 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
Evan Chenge9b9c672008-05-09 21:53:03 +00002874def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002875 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE1]>;
Evan Chenge259e872008-05-09 23:37:55 +00002876def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002877 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
Evan Cheng7fe0ff02008-07-10 01:08:23 +00002878def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
Anders Carlssonfd7e4502008-10-07 16:14:11 +00002879 (MOVLPSrr (V_SET0), VR128:$src)>, Requires<[HasSSE1]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002880}
2881
2882// Splat v2f64 / v2i64
2883let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002884def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002885 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002886def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002887 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002888def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002889 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002890def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002891 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2892}
2893
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002894// Special unary SHUFPSrri case.
Nate Begeman543d2142009-04-27 18:41:29 +00002895def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2896 (SHUFPSrri VR128:$src1, VR128:$src1,
2897 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002898 Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002899let AddedComplexity = 5 in
2900def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2901 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2902 Requires<[HasSSE2]>;
Dan Gohman7dc19012007-08-02 21:17:01 +00002903// Special unary SHUFPDrri case.
Nate Begeman543d2142009-04-27 18:41:29 +00002904def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002905 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002906 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2907 Requires<[HasSSE2]>;
2908// Special unary SHUFPDrri case.
2909def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002910 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman543d2142009-04-27 18:41:29 +00002911 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohman7dc19012007-08-02 21:17:01 +00002912 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002913// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Nate Begeman543d2142009-04-27 18:41:29 +00002914def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2915 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002916 Requires<[HasSSE2]>;
Evan Cheng13559d62008-09-26 23:41:32 +00002917
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002918// Special binary v4i32 shuffle cases with SHUFPS.
Nate Begeman543d2142009-04-27 18:41:29 +00002919def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002920 (SHUFPSrri VR128:$src1, VR128:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002921 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002922 Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002923def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002924 (SHUFPSrmi VR128:$src1, addr:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002925 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002926 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002927// Special binary v2i64 shuffle cases using SHUFPDrri.
Nate Begeman543d2142009-04-27 18:41:29 +00002928def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00002929 (SHUFPDrri VR128:$src1, VR128:$src2,
Nate Begeman543d2142009-04-27 18:41:29 +00002930 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002931 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002932
2933// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Evan Cheng13559d62008-09-26 23:41:32 +00002934let AddedComplexity = 15 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002935def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2936 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002937 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002938def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2939 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002940 Requires<[OptForSpeed, HasSSE2]>;
2941}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002942let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002943def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002944 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002945def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002946 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002947def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002948 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002949def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002950 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002951}
2952
2953// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Evan Cheng13559d62008-09-26 23:41:32 +00002954let AddedComplexity = 15 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002955def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
2956 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002957 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002958def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
2959 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng13559d62008-09-26 23:41:32 +00002960 Requires<[OptForSpeed, HasSSE2]>;
2961}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002962let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +00002963def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002964 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002965def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002966 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002967def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002968 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002969def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
Evan Cheng09d45072008-09-26 21:26:30 +00002970 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002971}
2972
Evan Cheng13559d62008-09-26 23:41:32 +00002973let AddedComplexity = 20 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002974// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
Nate Begeman543d2142009-04-27 18:41:29 +00002975def : Pat<(v4i32 (movhp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002976 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2977
2978// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
Nate Begeman543d2142009-04-27 18:41:29 +00002979def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002980 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2981
2982// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
Nate Begeman543d2142009-04-27 18:41:29 +00002983def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002984 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Nate Begeman543d2142009-04-27 18:41:29 +00002985def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002986 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2987}
2988
2989let AddedComplexity = 20 in {
2990// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2991// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Nate Begeman543d2142009-04-27 18:41:29 +00002992def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002993 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002994def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002995 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002996def : Pat<(v4f32 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002997 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00002998def : Pat<(v2f64 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002999 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3000
Nate Begeman543d2142009-04-27 18:41:29 +00003001def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003002 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003003def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003004 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003005def : Pat<(v4i32 (movhp VR128:$src1, (load addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003006 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003007def : Pat<(v2i64 (movhp VR128:$src1, (load addr:$src2))),
Evan Cheng1ff2ea52008-05-23 18:00:18 +00003008 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003009}
3010
Evan Cheng2b2a7012008-05-23 21:23:16 +00003011// (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
3012// (store (vector_shuffle (load addr), v2, <0, 1, 4, 5>), addr) using MOVHPS
Nate Begeman543d2142009-04-27 18:41:29 +00003013def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003014 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003015def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003016 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003017def : Pat<(store (v4f32 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003018 (MOVHPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003019def : Pat<(store (v2f64 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003020 (MOVHPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3021
Nate Begeman543d2142009-04-27 18:41:29 +00003022def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3023 addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003024 (MOVLPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003025def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003026 (MOVLPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003027def : Pat<(store (v4i32 (movhp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3028 addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003029 (MOVHPSmr addr:$src1, VR128:$src2)>, Requires<[HasSSE1]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003030def : Pat<(store (v2i64 (movhp (load addr:$src1), VR128:$src2)), addr:$src1),
Evan Cheng2b2a7012008-05-23 21:23:16 +00003031 (MOVHPDmr addr:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3032
3033
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003034let AddedComplexity = 15 in {
3035// Setting the lowest element in the vector.
Nate Begeman543d2142009-04-27 18:41:29 +00003036def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003037 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003038def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003039 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3040
3041// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
Nate Begeman543d2142009-04-27 18:41:29 +00003042def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003043 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Nate Begeman543d2142009-04-27 18:41:29 +00003044def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003045 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3046}
3047
Eli Friedman27d19742009-06-19 07:00:55 +00003048// vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3049// fall back to this for SSE1)
3050def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003051 (SHUFPSrri VR128:$src2, VR128:$src1,
Eli Friedman27d19742009-06-19 07:00:55 +00003052 (SHUFFLE_get_shuf_imm VR128:$src3))>, Requires<[HasSSE1]>;
3053
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003054// Set lowest element and zero upper elements.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00003055let AddedComplexity = 15 in
Nate Begeman543d2142009-04-27 18:41:29 +00003056def : Pat<(v2f64 (movl immAllZerosV_bc, VR128:$src)),
Evan Cheng15e8f5a2007-12-15 03:00:47 +00003057 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Evan Chenge9b9c672008-05-09 21:53:03 +00003058def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
Evan Chengd09a8a02008-05-08 22:35:02 +00003059 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003060
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003061// Some special case pandn patterns.
3062def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3063 VR128:$src2)),
3064 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3065def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3066 VR128:$src2)),
3067 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3068def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3069 VR128:$src2)),
3070 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3071
3072def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003073 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003074 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3075def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003076 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003077 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3078def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003079 (memop addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003080 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3081
Nate Begeman78246ca2007-11-17 03:58:34 +00003082// vector -> vector casts
3083def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3084 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3085def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3086 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
Eli Friedman7fa52ca2008-09-05 23:07:03 +00003087def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3088 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3089def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3090 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman78246ca2007-11-17 03:58:34 +00003091
Evan Cheng51a49b22007-07-20 00:27:43 +00003092// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00003093def : Pat<(alignedloadv4i32 addr:$src),
3094 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
3095def : Pat<(loadv4i32 addr:$src),
3096 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00003097def : Pat<(alignedloadv2i64 addr:$src),
3098 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
3099def : Pat<(loadv2i64 addr:$src),
3100 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
3101
3102def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3103 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3104def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3105 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3106def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3107 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3108def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3109 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3110def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3111 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3112def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3113 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3114def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3115 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3116def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3117 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003118
Nate Begemanb2975562008-02-03 07:18:54 +00003119//===----------------------------------------------------------------------===//
3120// SSE4.1 Instructions
3121//===----------------------------------------------------------------------===//
3122
Dale Johannesena7d2b442008-10-10 23:51:03 +00003123multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
Nate Begemanb2975562008-02-03 07:18:54 +00003124 string OpcodeStr,
Nate Begemanb2975562008-02-03 07:18:54 +00003125 Intrinsic V4F32Int,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003126 Intrinsic V2F64Int> {
Nate Begemanb2975562008-02-03 07:18:54 +00003127 // Intrinsic operation, reg.
Nate Begemanb2975562008-02-03 07:18:54 +00003128 // Vector intrinsic operation, reg
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003129 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003130 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003131 !strconcat(OpcodeStr,
3132 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003133 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3134 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003135
3136 // Vector intrinsic operation, mem
Evan Cheng78d00612008-03-14 07:39:27 +00003137 def PSm_Int : SS4AIi8<opcps, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003138 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003139 !strconcat(OpcodeStr,
3140 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003141 [(set VR128:$dst,
3142 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003143 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003144
Nate Begemanb2975562008-02-03 07:18:54 +00003145 // Vector intrinsic operation, reg
Evan Cheng78d00612008-03-14 07:39:27 +00003146 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003147 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003148 !strconcat(OpcodeStr,
3149 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003150 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3151 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003152
3153 // Vector intrinsic operation, mem
Evan Cheng78d00612008-03-14 07:39:27 +00003154 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003155 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003156 !strconcat(OpcodeStr,
3157 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng00b66ef2008-05-23 00:37:07 +00003158 [(set VR128:$dst,
3159 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003160 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003161}
3162
Dale Johannesena7d2b442008-10-10 23:51:03 +00003163let Constraints = "$src1 = $dst" in {
3164multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3165 string OpcodeStr,
3166 Intrinsic F32Int,
3167 Intrinsic F64Int> {
3168 // Intrinsic operation, reg.
3169 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003170 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003171 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3172 !strconcat(OpcodeStr,
3173 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003174 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003175 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3176 OpSize;
3177
3178 // Intrinsic operation, mem.
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003179 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3180 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003181 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003182 !strconcat(OpcodeStr,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003183 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003184 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003185 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3186 OpSize;
3187
3188 // Intrinsic operation, reg.
3189 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003190 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003191 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3192 !strconcat(OpcodeStr,
3193 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003194 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003195 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3196 OpSize;
3197
3198 // Intrinsic operation, mem.
3199 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003200 (outs VR128:$dst),
Dale Johannesena7d2b442008-10-10 23:51:03 +00003201 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3202 !strconcat(OpcodeStr,
3203 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003204 [(set VR128:$dst,
Dale Johannesena7d2b442008-10-10 23:51:03 +00003205 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3206 OpSize;
3207}
3208}
3209
Nate Begemanb2975562008-02-03 07:18:54 +00003210// FP round - roundss, roundps, roundsd, roundpd
Dale Johannesena7d2b442008-10-10 23:51:03 +00003211defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3212 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3213defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3214 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003215
3216// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3217multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3218 Intrinsic IntId128> {
3219 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3220 (ins VR128:$src),
3221 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3222 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3223 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3224 (ins i128mem:$src),
3225 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3226 [(set VR128:$dst,
3227 (IntId128
3228 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3229}
3230
3231defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3232 int_x86_sse41_phminposuw>;
3233
3234/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003235let Constraints = "$src1 = $dst" in {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003236 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3237 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003238 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3239 (ins VR128:$src1, VR128:$src2),
3240 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3241 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3242 OpSize {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003243 let isCommutable = Commutable;
3244 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003245 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3246 (ins VR128:$src1, i128mem:$src2),
3247 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3248 [(set VR128:$dst,
3249 (IntId128 VR128:$src1,
3250 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003251 }
3252}
3253
3254defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3255 int_x86_sse41_pcmpeqq, 1>;
3256defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3257 int_x86_sse41_packusdw, 0>;
3258defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3259 int_x86_sse41_pminsb, 1>;
3260defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3261 int_x86_sse41_pminsd, 1>;
3262defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3263 int_x86_sse41_pminud, 1>;
3264defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3265 int_x86_sse41_pminuw, 1>;
3266defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3267 int_x86_sse41_pmaxsb, 1>;
3268defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3269 int_x86_sse41_pmaxsd, 1>;
3270defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3271 int_x86_sse41_pmaxud, 1>;
3272defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3273 int_x86_sse41_pmaxuw, 1>;
Nate Begeman72d802a2008-02-04 06:00:24 +00003274
Mon P Wang14edb092008-12-18 21:42:19 +00003275defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3276
Nate Begeman03605a02008-07-17 16:51:19 +00003277def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3278 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3279def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3280 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3281
Nate Begeman58057962008-02-09 01:38:08 +00003282/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003283let Constraints = "$src1 = $dst" in {
Dan Gohmane3731f52008-05-23 17:49:40 +00003284 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3285 SDNode OpNode, Intrinsic IntId128,
3286 bit Commutable = 0> {
Nate Begeman58057962008-02-09 01:38:08 +00003287 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3288 (ins VR128:$src1, VR128:$src2),
3289 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmane3731f52008-05-23 17:49:40 +00003290 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3291 VR128:$src2))]>, OpSize {
Nate Begeman58057962008-02-09 01:38:08 +00003292 let isCommutable = Commutable;
3293 }
3294 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3295 (ins VR128:$src1, VR128:$src2),
3296 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3297 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3298 OpSize {
3299 let isCommutable = Commutable;
3300 }
3301 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3302 (ins VR128:$src1, i128mem:$src2),
3303 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3304 [(set VR128:$dst,
Evan Cheng00b66ef2008-05-23 00:37:07 +00003305 (OpNode VR128:$src1, (memop addr:$src2)))]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003306 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3307 (ins VR128:$src1, i128mem:$src2),
3308 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3309 [(set VR128:$dst,
Evan Cheng00b66ef2008-05-23 00:37:07 +00003310 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
Nate Begeman58057962008-02-09 01:38:08 +00003311 OpSize;
3312 }
3313}
Dan Gohmane3731f52008-05-23 17:49:40 +00003314defm PMULLD : SS41I_binop_patint<0x40, "pmulld", v4i32, mul,
Nate Begeman58057962008-02-09 01:38:08 +00003315 int_x86_sse41_pmulld, 1>;
Nate Begeman58057962008-02-09 01:38:08 +00003316
Evan Cheng78d00612008-03-14 07:39:27 +00003317/// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
Evan Cheng3ea4d672008-03-05 08:19:16 +00003318let Constraints = "$src1 = $dst" in {
Nate Begeman72d802a2008-02-04 06:00:24 +00003319 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3320 Intrinsic IntId128, bit Commutable = 0> {
Evan Cheng78d00612008-03-14 07:39:27 +00003321 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003322 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003323 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003324 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003325 [(set VR128:$dst,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003326 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3327 OpSize {
Nate Begeman72d802a2008-02-04 06:00:24 +00003328 let isCommutable = Commutable;
3329 }
Evan Cheng78d00612008-03-14 07:39:27 +00003330 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003331 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3332 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003333 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003334 [(set VR128:$dst,
3335 (IntId128 VR128:$src1,
3336 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3337 OpSize;
Nate Begeman72d802a2008-02-04 06:00:24 +00003338 }
3339}
3340
3341defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3342 int_x86_sse41_blendps, 0>;
3343defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3344 int_x86_sse41_blendpd, 0>;
3345defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3346 int_x86_sse41_pblendw, 0>;
3347defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3348 int_x86_sse41_dpps, 1>;
3349defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3350 int_x86_sse41_dppd, 1>;
3351defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
Evan Cheng81ed9852008-06-16 20:25:59 +00003352 int_x86_sse41_mpsadbw, 1>;
Nate Begeman58057962008-02-09 01:38:08 +00003353
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003354
Evan Cheng78d00612008-03-14 07:39:27 +00003355/// SS41I_ternary_int - SSE 4.1 ternary operator
Evan Cheng3ea4d672008-03-05 08:19:16 +00003356let Uses = [XMM0], Constraints = "$src1 = $dst" in {
Nate Begemanb4e9a042008-02-10 18:47:57 +00003357 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3358 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3359 (ins VR128:$src1, VR128:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003360 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003361 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3362 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3363 OpSize;
3364
3365 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3366 (ins VR128:$src1, i128mem:$src2),
3367 !strconcat(OpcodeStr,
3368 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3369 [(set VR128:$dst,
3370 (IntId VR128:$src1,
3371 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3372 }
3373}
3374
3375defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3376defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3377defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3378
3379
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003380multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3381 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3382 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3383 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3384
3385 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3386 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003387 [(set VR128:$dst,
3388 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3389 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003390}
3391
3392defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3393defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3394defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3395defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3396defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3397defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3398
Evan Cheng56ec77b2008-09-24 23:27:55 +00003399// Common patterns involving scalar load.
3400def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3401 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3402def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3403 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3404
3405def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3406 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3407def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3408 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3409
3410def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3411 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3412def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3413 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3414
3415def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3416 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3417def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3418 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3419
3420def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3421 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3422def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3423 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3424
3425def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3426 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3427def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3428 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3429
3430
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003431multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3432 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3433 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3434 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3435
3436 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3437 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003438 [(set VR128:$dst,
3439 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3440 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003441}
3442
3443defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3444defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3445defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3446defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3447
Evan Cheng56ec77b2008-09-24 23:27:55 +00003448// Common patterns involving scalar load
3449def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003450 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003451def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003452 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003453
3454def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003455 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003456def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003457 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003458
3459
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003460multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3461 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3462 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3463 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3464
Evan Cheng56ec77b2008-09-24 23:27:55 +00003465 // Expecting a i16 load any extended to i32 value.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003466 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3467 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Cheng56ec77b2008-09-24 23:27:55 +00003468 [(set VR128:$dst, (IntId (bitconvert
3469 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3470 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003471}
3472
3473defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
Eli Friedman75a89d62009-06-06 05:55:37 +00003474defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003475
Evan Cheng56ec77b2008-09-24 23:27:55 +00003476// Common patterns involving scalar load
3477def : Pat<(int_x86_sse41_pmovsxbq
3478 (bitconvert (v4i32 (X86vzmovl
3479 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003480 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003481
3482def : Pat<(int_x86_sse41_pmovzxbq
3483 (bitconvert (v4i32 (X86vzmovl
3484 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng00a3ec52008-09-25 00:49:51 +00003485 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Cheng56ec77b2008-09-24 23:27:55 +00003486
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003487
Nate Begemand77e59e2008-02-11 04:19:36 +00003488/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3489multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003490 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003491 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003492 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003493 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003494 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3495 OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003496 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003497 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003498 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003499 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003500 []>, OpSize;
3501// FIXME:
3502// There's an AssertZext in the way of writing the store pattern
3503// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003504}
3505
Nate Begemand77e59e2008-02-11 04:19:36 +00003506defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003507
Nate Begemand77e59e2008-02-11 04:19:36 +00003508
3509/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3510multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003511 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemand77e59e2008-02-11 04:19:36 +00003512 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003513 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003514 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3515 []>, OpSize;
3516// FIXME:
3517// There's an AssertZext in the way of writing the store pattern
3518// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3519}
3520
3521defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3522
3523
3524/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3525multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003526 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003527 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003528 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003529 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3530 [(set GR32:$dst,
3531 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003532 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003533 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003534 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003535 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3536 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3537 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003538}
3539
Nate Begemand77e59e2008-02-11 04:19:36 +00003540defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman58057962008-02-09 01:38:08 +00003541
Nate Begemand77e59e2008-02-11 04:19:36 +00003542
Evan Cheng6c249332008-03-24 21:52:23 +00003543/// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3544/// destination
Nate Begemand77e59e2008-02-11 04:19:36 +00003545multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Evan Chengc2054be2008-03-26 08:11:49 +00003546 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003547 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003548 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003549 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Dan Gohman788db592008-04-16 02:32:24 +00003550 [(set GR32:$dst,
3551 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
Evan Cheng6c249332008-03-24 21:52:23 +00003552 OpSize;
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003553 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003554 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003555 !strconcat(OpcodeStr,
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003556 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng6c249332008-03-24 21:52:23 +00003557 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003558 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003559}
3560
Nate Begemand77e59e2008-02-11 04:19:36 +00003561defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003562
Dan Gohmana41862a2008-08-08 18:30:21 +00003563// Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3564def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3565 imm:$src2))),
3566 addr:$dst),
3567 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3568 Requires<[HasSSE41]>;
3569
Evan Cheng3ea4d672008-03-05 08:19:16 +00003570let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003571 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003572 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003573 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003574 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003575 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003576 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003577 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003578 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003579 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3580 !strconcat(OpcodeStr,
3581 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003582 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003583 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3584 imm:$src3))]>, OpSize;
3585 }
3586}
3587
3588defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3589
Evan Cheng3ea4d672008-03-05 08:19:16 +00003590let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003591 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
Evan Cheng78d00612008-03-14 07:39:27 +00003592 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003593 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003594 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003595 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003596 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003597 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3598 OpSize;
Evan Cheng78d00612008-03-14 07:39:27 +00003599 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003600 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3601 !strconcat(OpcodeStr,
3602 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003603 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00003604 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3605 imm:$src3)))]>, OpSize;
3606 }
3607}
3608
3609defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3610
Eric Christophera0443602009-07-23 02:22:41 +00003611// insertps has a few different modes, there's the first two here below which
3612// are optimized inserts that won't zero arbitrary elements in the destination
3613// vector. The next one matches the intrinsic and could zero arbitrary elements
3614// in the target vector.
Evan Cheng3ea4d672008-03-05 08:19:16 +00003615let Constraints = "$src1 = $dst" in {
Nate Begemand77e59e2008-02-11 04:19:36 +00003616 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
Eric Christopherefb657e2009-07-24 00:33:09 +00003617 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3618 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003619 !strconcat(OpcodeStr,
Nate Begemand77e59e2008-02-11 04:19:36 +00003620 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003621 [(set VR128:$dst,
3622 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
3623 OpSize;
Eric Christopherefb657e2009-07-24 00:33:09 +00003624 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemand77e59e2008-02-11 04:19:36 +00003625 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3626 !strconcat(OpcodeStr,
3627 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher7f2d4f42009-07-31 20:07:27 +00003628 [(set VR128:$dst,
Eric Christopherefb657e2009-07-24 00:33:09 +00003629 (X86insrtps VR128:$src1,
3630 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
Nate Begemand77e59e2008-02-11 04:19:36 +00003631 imm:$src3))]>, OpSize;
3632 }
3633}
3634
Evan Chengc2054be2008-03-26 08:11:49 +00003635defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003636
Eric Christopherefb657e2009-07-24 00:33:09 +00003637def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3638 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3639
Eric Christopher95d79262009-07-29 00:28:05 +00003640// ptest instruction we'll lower to this in X86ISelLowering primarily from
3641// the intel intrinsic that corresponds to this.
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003642let Defs = [EFLAGS] in {
3643def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Eric Christopher95d79262009-07-29 00:28:05 +00003644 "ptest \t{$src2, $src1|$src1, $src2}",
3645 [(X86ptest VR128:$src1, VR128:$src2),
3646 (implicit EFLAGS)]>, OpSize;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003647def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
Eric Christopher95d79262009-07-29 00:28:05 +00003648 "ptest \t{$src2, $src1|$src1, $src2}",
3649 [(X86ptest VR128:$src1, (load addr:$src2)),
3650 (implicit EFLAGS)]>, OpSize;
Nate Begeman0dd3cb52008-03-16 21:14:46 +00003651}
3652
3653def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3654 "movntdqa\t{$src, $dst|$dst, $src}",
3655 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>;
Nate Begeman03605a02008-07-17 16:51:19 +00003656
3657/// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3658let Constraints = "$src1 = $dst" in {
3659 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3660 Intrinsic IntId128, bit Commutable = 0> {
3661 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3662 (ins VR128:$src1, VR128:$src2),
3663 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3664 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3665 OpSize {
3666 let isCommutable = Commutable;
3667 }
3668 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3669 (ins VR128:$src1, i128mem:$src2),
3670 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3671 [(set VR128:$dst,
3672 (IntId128 VR128:$src1,
3673 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3674 }
3675}
3676
Nate Begeman235666b2008-07-17 17:04:58 +00003677defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
Nate Begeman03605a02008-07-17 16:51:19 +00003678
3679def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3680 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3681def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3682 (PCMPGTQrm VR128:$src1, addr:$src2)>;
Eric Christopherb5f948c2009-08-08 21:55:08 +00003683
3684// crc intrinsic instruction
3685// This set of instructions are only rm, the only difference is the size
3686// of r and m.
3687let Constraints = "$src1 = $dst" in {
3688 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
3689 (ins GR32:$src1, i8mem:$src2),
3690 "crc32 \t{$src2, $src1|$src1, $src2}",
3691 [(set GR32:$dst,
3692 (int_x86_sse42_crc32_8 GR32:$src1,
3693 (load addr:$src2)))]>, OpSize;
3694 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
3695 (ins GR32:$src1, GR8:$src2),
3696 "crc32 \t{$src2, $src1|$src1, $src2}",
3697 [(set GR32:$dst,
3698 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>,
3699 OpSize;
3700 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3701 (ins GR32:$src1, i16mem:$src2),
3702 "crc32 \t{$src2, $src1|$src1, $src2}",
3703 [(set GR32:$dst,
3704 (int_x86_sse42_crc32_16 GR32:$src1,
3705 (load addr:$src2)))]>,
3706 OpSize;
3707 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3708 (ins GR32:$src1, GR16:$src2),
3709 "crc32 \t{$src2, $src1|$src1, $src2}",
3710 [(set GR32:$dst,
3711 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
3712 OpSize;
3713 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
3714 (ins GR32:$src1, i32mem:$src2),
3715 "crc32 \t{$src2, $src1|$src1, $src2}",
3716 [(set GR32:$dst,
3717 (int_x86_sse42_crc32_32 GR32:$src1,
3718 (load addr:$src2)))]>, OpSize;
3719 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
3720 (ins GR32:$src1, GR32:$src2),
3721 "crc32 \t{$src2, $src1|$src1, $src2}",
3722 [(set GR32:$dst,
3723 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>,
3724 OpSize;
3725 def CRC64m64 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3726 (ins GR64:$src1, i64mem:$src2),
3727 "crc32 \t{$src2, $src1|$src1, $src2}",
3728 [(set GR64:$dst,
3729 (int_x86_sse42_crc32_64 GR64:$src1,
3730 (load addr:$src2)))]>,
3731 OpSize, REX_W;
3732 def CRC64r64 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3733 (ins GR64:$src1, GR64:$src2),
3734 "crc32 \t{$src2, $src1|$src1, $src2}",
3735 [(set GR64:$dst,
3736 (int_x86_sse42_crc32_64 GR64:$src1, GR64:$src2))]>,
3737 OpSize, REX_W;
3738
3739 // TODO: These correspond to int_x86_sse42_crc32_8 but with a 64-bit src
3740 // and dest, figure it out.
3741 //def CRC64m8 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3742 // (ins GR32:$src1, i8mem:$src2),
3743 // "crc32 \t{$src2, $src1|$src1, $src2}",
3744 // [(set GR64:$dst,
3745 // (int_x86_sse42_crc32_8 GR64:$src1,
3746 // (load addr:$src2)))]>,
3747 // OpSize, REX_W;
3748 //def CRC64r8 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3749 // (ins GR64:$src1, GR8:$src2),
3750 // "crc32 \t{$src2, $src1|$src1, $src2}",
3751 // [(set GR64:$dst,
3752 // (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>,
3753 // OpSize, REX_W;
3754}