blob: 1c84cc7198c01e3db899696ebd754426d72fd7fc [file] [log] [blame]
Arnold Schwaighofer48abc5c2007-10-12 21:30:57 +00001//====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
Eric Christopher44b93ff2009-07-31 20:07:27 +00002//
Evan Chengffcb95b2006-02-21 19:13:53 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Christopher44b93ff2009-07-31 20:07:27 +00007//
Evan Chengffcb95b2006-02-21 19:13:53 +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
Chris Lattner3a7cd952006-10-07 21:55:32 +000016
Evan Cheng4e4c71e2006-02-21 20:00:20 +000017//===----------------------------------------------------------------------===//
Evan Cheng2246f842006-03-18 01:23:20 +000018// SSE specific DAG Nodes.
19//===----------------------------------------------------------------------===//
20
Evan Cheng68c47cb2007-01-05 07:55:56 +000021def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
Nate Begeman30a0de92008-07-17 16:51:19 +000023def SDTX86VFCMP : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<1, 2>,
24 SDTCisFP<1>, SDTCisVT<3, i8>]>;
Evan Cheng68c47cb2007-01-05 07:55:56 +000025
Evan Cheng8ca29322006-11-10 21:43:37 +000026def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
27def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
Evan Cheng6be2c582006-04-05 23:38:46 +000028def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
Evan Chengb9df0ca2006-03-22 02:53:00 +000029 [SDNPCommutative, SDNPAssociative]>;
Evan Cheng68c47cb2007-01-05 07:55:56 +000030def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
Evan Cheng6be2c582006-04-05 23:38:46 +000032def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
Evan Chengb9df0ca2006-03-22 02:53:00 +000033 [SDNPCommutative, SDNPAssociative]>;
Dan Gohman20382522007-07-10 00:05:58 +000034def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
35def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
Evan Cheng68c47cb2007-01-05 07:55:56 +000036def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
Evan Chengfef922a2007-10-01 18:12:48 +000037def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
Evan Chenge5f62042007-09-29 00:00:36 +000038def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
Eric Christopher44b93ff2009-07-31 20:07:27 +000039def X86pshufb : SDNode<"X86ISD::PSHUFB",
Nate Begemanb9a47b82009-02-23 08:49:38 +000040 SDTypeProfile<1, 2, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
41 SDTCisSameAs<0,2>]>>;
Nate Begeman14d12ca2008-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 Christopher44b93ff2009-07-31 20:07:27 +000046def X86pinsrb : SDNode<"X86ISD::PINSRB",
Nate Begeman14d12ca2008-02-11 04:19:36 +000047 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
48 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
Eric Christopher44b93ff2009-07-31 20:07:27 +000049def X86pinsrw : SDNode<"X86ISD::PINSRW",
Nate Begeman14d12ca2008-02-11 04:19:36 +000050 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
51 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
Eric Christopher44b93ff2009-07-31 20:07:27 +000052def X86insrtps : SDNode<"X86ISD::INSERTPS",
Nate Begeman14d12ca2008-02-11 04:19:36 +000053 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
Eric Christopherfbd66872009-07-24 00:33:09 +000054 SDTCisVT<2, v4f32>, SDTCisPtrTy<3>]>>;
Evan Chengd880b972008-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 Chengf26ffe92008-05-29 08:22:04 +000059def X86vshl : SDNode<"X86ISD::VSHL", SDTIntShiftOp>;
60def X86vshr : SDNode<"X86ISD::VSRL", SDTIntShiftOp>;
Nate Begeman30a0de92008-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>;
Evan Chengc60bd972006-03-25 09:37:23 +000071
Chris Lattnerd486d772010-03-28 05:07:17 +000072def SDTX86CmpPTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
73 SDTCisVT<1, v4f32>,
74 SDTCisVT<2, v4f32>]>;
Eric Christopher71c67532009-07-29 00:28:05 +000075def X86ptest : SDNode<"X86ISD::PTEST", SDTX86CmpPTest>;
76
Evan Cheng2246f842006-03-18 01:23:20 +000077//===----------------------------------------------------------------------===//
Chris Lattner3a7cd952006-10-07 21:55:32 +000078// SSE Complex Patterns
79//===----------------------------------------------------------------------===//
80
81// These are 'extloads' from a scalar to the low element of a vector, zeroing
82// the top elements. These are used for the SSE 'ss' and 'sd' instruction
83// forms.
Rafael Espindola094fad32009-04-08 21:14:34 +000084def sse_load_f32 : ComplexPattern<v4f32, 5, "SelectScalarSSELoad", [],
Chris Lattnerba7e7562008-01-10 07:59:24 +000085 [SDNPHasChain, SDNPMayLoad]>;
Rafael Espindola094fad32009-04-08 21:14:34 +000086def sse_load_f64 : ComplexPattern<v2f64, 5, "SelectScalarSSELoad", [],
Chris Lattnerba7e7562008-01-10 07:59:24 +000087 [SDNPHasChain, SDNPMayLoad]>;
Chris Lattner3a7cd952006-10-07 21:55:32 +000088
89def ssmem : Operand<v4f32> {
90 let PrintMethod = "printf32mem";
Dan Gohmana4714e02009-07-30 01:56:29 +000091 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar338825c2009-08-10 18:41:10 +000092 let ParserMatchClass = X86MemAsmOperand;
Chris Lattner3a7cd952006-10-07 21:55:32 +000093}
94def sdmem : Operand<v2f64> {
95 let PrintMethod = "printf64mem";
Dan Gohmana4714e02009-07-30 01:56:29 +000096 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar338825c2009-08-10 18:41:10 +000097 let ParserMatchClass = X86MemAsmOperand;
Chris Lattner3a7cd952006-10-07 21:55:32 +000098}
99
100//===----------------------------------------------------------------------===//
Evan Cheng06a8aa12006-03-17 19:55:52 +0000101// SSE pattern fragments
102//===----------------------------------------------------------------------===//
103
Evan Cheng2246f842006-03-18 01:23:20 +0000104def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
105def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
Dan Gohman01976302007-06-25 15:19:03 +0000106def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
Evan Cheng24dc1f52006-03-23 07:44:07 +0000107def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
Evan Cheng06a8aa12006-03-17 19:55:52 +0000108
Dan Gohmand3006222007-07-27 17:16:43 +0000109// Like 'store', but always requires vector alignment.
Dan Gohman4106f372007-07-18 20:23:34 +0000110def alignedstore : PatFrag<(ops node:$val, node:$ptr),
Dan Gohman33586292008-10-15 06:50:19 +0000111 (store node:$val, node:$ptr), [{
112 return cast<StoreSDNode>(N)->getAlignment() >= 16;
Dan Gohman4106f372007-07-18 20:23:34 +0000113}]>;
114
Dan Gohmand3006222007-07-27 17:16:43 +0000115// Like 'load', but always requires vector alignment.
Dan Gohman33586292008-10-15 06:50:19 +0000116def alignedload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
117 return cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4106f372007-07-18 20:23:34 +0000118}]>;
119
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000120def alignedloadfsf32 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000121 (f32 (alignedload node:$ptr))>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000122def alignedloadfsf64 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000123 (f64 (alignedload node:$ptr))>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000124def alignedloadv4f32 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000125 (v4f32 (alignedload node:$ptr))>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000126def alignedloadv2f64 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000127 (v2f64 (alignedload node:$ptr))>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000128def alignedloadv4i32 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000129 (v4i32 (alignedload node:$ptr))>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000130def alignedloadv2i64 : PatFrag<(ops node:$ptr),
Sean Callanan108934c2009-12-18 00:01:26 +0000131 (v2i64 (alignedload node:$ptr))>;
Dan Gohman4106f372007-07-18 20:23:34 +0000132
133// Like 'load', but uses special alignment checks suitable for use in
134// memory operands in most SSE instructions, which are required to
David Greene95eb2ee2010-01-11 16:29:42 +0000135// be naturally aligned on some targets but not on others. If the subtarget
136// allows unaligned accesses, match any load, though this may require
137// setting a feature bit in the processor (on startup, for example).
138// Opteron 10h and later implement such a feature.
Dan Gohman33586292008-10-15 06:50:19 +0000139def memop : PatFrag<(ops node:$ptr), (load node:$ptr), [{
David Greene95eb2ee2010-01-11 16:29:42 +0000140 return Subtarget->hasVectorUAMem()
141 || cast<LoadSDNode>(N)->getAlignment() >= 16;
Dan Gohman4106f372007-07-18 20:23:34 +0000142}]>;
143
Dan Gohmand3006222007-07-27 17:16:43 +0000144def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
145def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4106f372007-07-18 20:23:34 +0000146def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
147def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
148def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
149def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
Nate Begemanfea2be52008-02-09 23:46:37 +0000150def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
Dan Gohman4106f372007-07-18 20:23:34 +0000151
Bill Wendling01284b42007-08-11 09:52:53 +0000152// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
153// 16-byte boundary.
Nate Begemanfea2be52008-02-09 23:46:37 +0000154// FIXME: 8 byte alignment for mmx reads is not required
Dan Gohmana7250dd2008-10-16 00:03:00 +0000155def memop64 : PatFrag<(ops node:$ptr), (load node:$ptr), [{
Dan Gohman33586292008-10-15 06:50:19 +0000156 return cast<LoadSDNode>(N)->getAlignment() >= 8;
Bill Wendling01284b42007-08-11 09:52:53 +0000157}]>;
158
159def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
Bill Wendling01284b42007-08-11 09:52:53 +0000160def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
161def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
162def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
163
David Greene8939b0d2010-02-16 20:50:18 +0000164// MOVNT Support
165// Like 'store', but requires the non-temporal bit to be set
166def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
167 (st node:$val, node:$ptr), [{
168 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
169 return ST->isNonTemporal();
170 return false;
171}]>;
172
173def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
174 (st node:$val, node:$ptr), [{
175 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
176 return ST->isNonTemporal() && !ST->isTruncatingStore() &&
177 ST->getAddressingMode() == ISD::UNINDEXED &&
178 ST->getAlignment() >= 16;
179 return false;
180}]>;
181
182def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
183 (st node:$val, node:$ptr), [{
184 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
185 return ST->isNonTemporal() &&
186 ST->getAlignment() < 16;
187 return false;
188}]>;
189
Evan Cheng1b32f222006-03-30 07:33:32 +0000190def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
191def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
Evan Cheng506d3df2006-03-29 23:07:14 +0000192def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
193def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
Evan Cheng5aa97b22006-03-29 18:47:40 +0000194def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
195def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
196
Evan Chengca57f782008-09-24 23:27:55 +0000197def vzmovl_v2i64 : PatFrag<(ops node:$src),
198 (bitconvert (v2i64 (X86vzmovl
199 (v2i64 (scalar_to_vector (loadi64 node:$src))))))>;
200def vzmovl_v4i32 : PatFrag<(ops node:$src),
201 (bitconvert (v4i32 (X86vzmovl
202 (v4i32 (scalar_to_vector (loadi32 node:$src))))))>;
203
204def vzload_v2i64 : PatFrag<(ops node:$src),
205 (bitconvert (v2i64 (X86vzload node:$src)))>;
206
207
Evan Cheng386031a2006-03-24 07:29:27 +0000208def fp32imm0 : PatLeaf<(f32 fpimm), [{
209 return N->isExactlyValue(+0.0);
210}]>;
211
Evan Cheng89321162009-10-28 06:30:34 +0000212// BYTE_imm - Transform bit immediates into byte immediates.
213def BYTE_imm : SDNodeXForm<imm, [{
Evan Chengff65e382006-04-04 21:49:39 +0000214 // Transformation function: imm >> 3
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000215 return getI32Imm(N->getZExtValue() >> 3);
Evan Chengff65e382006-04-04 21:49:39 +0000216}]>;
217
Evan Cheng63d33002006-03-22 08:01:21 +0000218// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
219// SHUFP* etc. imm.
Nate Begeman9008ca62009-04-27 18:41:29 +0000220def SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
Evan Cheng63d33002006-03-22 08:01:21 +0000221 return getI8Imm(X86::getShuffleSHUFImmediate(N));
Evan Chengb9df0ca2006-03-22 02:53:00 +0000222}]>;
223
Eric Christopher44b93ff2009-07-31 20:07:27 +0000224// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
Evan Cheng506d3df2006-03-29 23:07:14 +0000225// PSHUFHW imm.
Nate Begeman9008ca62009-04-27 18:41:29 +0000226def SHUFFLE_get_pshufhw_imm : SDNodeXForm<vector_shuffle, [{
Evan Cheng506d3df2006-03-29 23:07:14 +0000227 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
228}]>;
229
Eric Christopher44b93ff2009-07-31 20:07:27 +0000230// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
Evan Cheng506d3df2006-03-29 23:07:14 +0000231// PSHUFLW imm.
Nate Begeman9008ca62009-04-27 18:41:29 +0000232def SHUFFLE_get_pshuflw_imm : SDNodeXForm<vector_shuffle, [{
Evan Cheng506d3df2006-03-29 23:07:14 +0000233 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
234}]>;
235
Nate Begemana09008b2009-10-19 02:17:23 +0000236// SHUFFLE_get_palign_imm xform function: convert vector_shuffle mask to
237// a PALIGNR imm.
238def SHUFFLE_get_palign_imm : SDNodeXForm<vector_shuffle, [{
239 return getI8Imm(X86::getShufflePALIGNRImmediate(N));
240}]>;
241
Nate Begeman9008ca62009-04-27 18:41:29 +0000242def splat_lo : PatFrag<(ops node:$lhs, node:$rhs),
243 (vector_shuffle node:$lhs, node:$rhs), [{
244 ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N);
245 return SVOp->isSplat() && SVOp->getSplatIndex() == 0;
246}]>;
247
248def movddup : PatFrag<(ops node:$lhs, node:$rhs),
249 (vector_shuffle node:$lhs, node:$rhs), [{
250 return X86::isMOVDDUPMask(cast<ShuffleVectorSDNode>(N));
251}]>;
252
253def movhlps : PatFrag<(ops node:$lhs, node:$rhs),
254 (vector_shuffle node:$lhs, node:$rhs), [{
255 return X86::isMOVHLPSMask(cast<ShuffleVectorSDNode>(N));
256}]>;
257
258def movhlps_undef : PatFrag<(ops node:$lhs, node:$rhs),
259 (vector_shuffle node:$lhs, node:$rhs), [{
260 return X86::isMOVHLPS_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
261}]>;
262
Nate Begeman0b10b912009-11-07 23:17:15 +0000263def movlhps : PatFrag<(ops node:$lhs, node:$rhs),
264 (vector_shuffle node:$lhs, node:$rhs), [{
265 return X86::isMOVLHPSMask(cast<ShuffleVectorSDNode>(N));
Nate Begeman9008ca62009-04-27 18:41:29 +0000266}]>;
267
268def movlp : PatFrag<(ops node:$lhs, node:$rhs),
269 (vector_shuffle node:$lhs, node:$rhs), [{
270 return X86::isMOVLPMask(cast<ShuffleVectorSDNode>(N));
271}]>;
272
273def movl : PatFrag<(ops node:$lhs, node:$rhs),
274 (vector_shuffle node:$lhs, node:$rhs), [{
275 return X86::isMOVLMask(cast<ShuffleVectorSDNode>(N));
276}]>;
277
278def movshdup : PatFrag<(ops node:$lhs, node:$rhs),
279 (vector_shuffle node:$lhs, node:$rhs), [{
280 return X86::isMOVSHDUPMask(cast<ShuffleVectorSDNode>(N));
281}]>;
282
283def movsldup : PatFrag<(ops node:$lhs, node:$rhs),
284 (vector_shuffle node:$lhs, node:$rhs), [{
285 return X86::isMOVSLDUPMask(cast<ShuffleVectorSDNode>(N));
286}]>;
287
288def unpckl : PatFrag<(ops node:$lhs, node:$rhs),
289 (vector_shuffle node:$lhs, node:$rhs), [{
290 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
291}]>;
292
293def unpckh : PatFrag<(ops node:$lhs, node:$rhs),
294 (vector_shuffle node:$lhs, node:$rhs), [{
295 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
296}]>;
297
298def unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
299 (vector_shuffle node:$lhs, node:$rhs), [{
300 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
301}]>;
302
303def unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
304 (vector_shuffle node:$lhs, node:$rhs), [{
305 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
306}]>;
307
308def pshufd : PatFrag<(ops node:$lhs, node:$rhs),
309 (vector_shuffle node:$lhs, node:$rhs), [{
310 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
Evan Cheng691c9232006-03-29 19:02:40 +0000311}], SHUFFLE_get_shuf_imm>;
Evan Cheng0188ecb2006-03-22 18:59:22 +0000312
Nate Begeman9008ca62009-04-27 18:41:29 +0000313def shufp : PatFrag<(ops node:$lhs, node:$rhs),
314 (vector_shuffle node:$lhs, node:$rhs), [{
315 return X86::isSHUFPMask(cast<ShuffleVectorSDNode>(N));
Evan Cheng14aed5e2006-03-24 01:18:28 +0000316}], SHUFFLE_get_shuf_imm>;
Evan Cheng0188ecb2006-03-22 18:59:22 +0000317
Nate Begeman9008ca62009-04-27 18:41:29 +0000318def pshufhw : PatFrag<(ops node:$lhs, node:$rhs),
319 (vector_shuffle node:$lhs, node:$rhs), [{
320 return X86::isPSHUFHWMask(cast<ShuffleVectorSDNode>(N));
Evan Cheng506d3df2006-03-29 23:07:14 +0000321}], SHUFFLE_get_pshufhw_imm>;
322
Nate Begeman9008ca62009-04-27 18:41:29 +0000323def pshuflw : PatFrag<(ops node:$lhs, node:$rhs),
324 (vector_shuffle node:$lhs, node:$rhs), [{
325 return X86::isPSHUFLWMask(cast<ShuffleVectorSDNode>(N));
Evan Cheng506d3df2006-03-29 23:07:14 +0000326}], SHUFFLE_get_pshuflw_imm>;
327
Nate Begemana09008b2009-10-19 02:17:23 +0000328def palign : PatFrag<(ops node:$lhs, node:$rhs),
329 (vector_shuffle node:$lhs, node:$rhs), [{
330 return X86::isPALIGNRMask(cast<ShuffleVectorSDNode>(N));
331}], SHUFFLE_get_palign_imm>;
332
Evan Cheng06a8aa12006-03-17 19:55:52 +0000333//===----------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000334// SSE scalar FP Instructions
335//===----------------------------------------------------------------------===//
336
Dan Gohman533297b2009-10-29 18:10:34 +0000337// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded after
338// instruction selection into a branch sequence.
339let Uses = [EFLAGS], usesCustomInserter = 1 in {
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000340 def CMOV_FR32 : I<0, Pseudo,
Evan Cheng64d80e32007-07-19 01:14:50 +0000341 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000342 "#CMOV_FR32 PSEUDO!",
Evan Chenge5f62042007-09-29 00:00:36 +0000343 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
344 EFLAGS))]>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000345 def CMOV_FR64 : I<0, Pseudo,
Evan Cheng64d80e32007-07-19 01:14:50 +0000346 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000347 "#CMOV_FR64 PSEUDO!",
Evan Chenge5f62042007-09-29 00:00:36 +0000348 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
349 EFLAGS))]>;
Evan Chengf7c378e2006-04-10 07:23:14 +0000350 def CMOV_V4F32 : I<0, Pseudo,
Evan Cheng64d80e32007-07-19 01:14:50 +0000351 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Evan Chengf7c378e2006-04-10 07:23:14 +0000352 "#CMOV_V4F32 PSEUDO!",
353 [(set VR128:$dst,
Evan Chenge5f62042007-09-29 00:00:36 +0000354 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
355 EFLAGS)))]>;
Evan Chengf7c378e2006-04-10 07:23:14 +0000356 def CMOV_V2F64 : I<0, Pseudo,
Evan Cheng64d80e32007-07-19 01:14:50 +0000357 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Evan Chengf7c378e2006-04-10 07:23:14 +0000358 "#CMOV_V2F64 PSEUDO!",
359 [(set VR128:$dst,
Evan Chenge5f62042007-09-29 00:00:36 +0000360 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
361 EFLAGS)))]>;
Evan Chengf7c378e2006-04-10 07:23:14 +0000362 def CMOV_V2I64 : I<0, Pseudo,
Evan Cheng64d80e32007-07-19 01:14:50 +0000363 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Evan Chengf7c378e2006-04-10 07:23:14 +0000364 "#CMOV_V2I64 PSEUDO!",
365 [(set VR128:$dst,
Evan Chenge5f62042007-09-29 00:00:36 +0000366 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng0488db92007-09-25 01:57:46 +0000367 EFLAGS)))]>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000368}
369
Bill Wendlingddd35322007-05-02 23:11:52 +0000370//===----------------------------------------------------------------------===//
371// SSE1 Instructions
372//===----------------------------------------------------------------------===//
373
Dan Gohman874cada2010-02-28 00:17:42 +0000374// Move Instructions. Register-to-register movss is not used for FR32
375// register copies because it's a partial register update; FsMOVAPSrr is
376// used instead. Register-to-register movss is not modeled as an INSERT_SUBREG
377// because INSERT_SUBREG requires that the insert be implementable in terms of
378// a copy, and just mentioned, we don't use movss for copies.
379let Constraints = "$src1 = $dst" in
380def MOVSSrr : SSI<0x10, MRMSrcReg,
381 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
382 "movss\t{$src2, $dst|$dst, $src2}",
Chris Lattner3d005782010-03-15 05:53:30 +0000383 [(set (v4f32 VR128:$dst),
Dan Gohman874cada2010-02-28 00:17:42 +0000384 (movl VR128:$src1, (scalar_to_vector FR32:$src2)))]>;
385
386// Extract the low 32-bit value from one vector and insert it into another.
387let AddedComplexity = 15 in
388def : Pat<(v4f32 (movl VR128:$src1, VR128:$src2)),
Chris Lattner3485b512010-03-08 18:57:56 +0000389 (MOVSSrr (v4f32 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000390 (EXTRACT_SUBREG (v4f32 VR128:$src2), sub_ss))>;
Dan Gohman874cada2010-02-28 00:17:42 +0000391
392// Implicitly promote a 32-bit scalar to a vector.
393def : Pat<(v4f32 (scalar_to_vector FR32:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000394 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), FR32:$src, sub_ss)>;
Dan Gohman874cada2010-02-28 00:17:42 +0000395
396// Loading from memory automatically zeroing upper bits.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000397let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000398def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000399 "movss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000400 [(set FR32:$dst, (loadf32 addr:$src))]>;
Dan Gohman874cada2010-02-28 00:17:42 +0000401
402// MOVSSrm zeros the high parts of the register; represent this
403// with SUBREG_TO_REG.
404let AddedComplexity = 20 in {
405def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector (loadf32 addr:$src))))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000406 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
Dan Gohman874cada2010-02-28 00:17:42 +0000407def : Pat<(v4f32 (scalar_to_vector (loadf32 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000408 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
Dan Gohman874cada2010-02-28 00:17:42 +0000409def : Pat<(v4f32 (X86vzmovl (loadv4f32 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000410 (SUBREG_TO_REG (i32 0), (MOVSSrm addr:$src), sub_ss)>;
Dan Gohman874cada2010-02-28 00:17:42 +0000411}
412
413// Store scalar value to memory.
Evan Cheng64d80e32007-07-19 01:14:50 +0000414def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000415 "movss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000416 [(store FR32:$src, addr:$dst)]>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000417
Dan Gohman874cada2010-02-28 00:17:42 +0000418// Extract and store.
419def : Pat<(store (f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
420 addr:$dst),
421 (MOVSSmr addr:$dst,
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +0000422 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
Dan Gohman874cada2010-02-28 00:17:42 +0000423
Evan Chengc46349d2006-03-28 23:51:43 +0000424// Conversion instructions
Evan Cheng64d80e32007-07-19 01:14:50 +0000425def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000426 "cvttss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000427 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000428def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000429 "cvttss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000430 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000431def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000432 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000433 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000434def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000435 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000436 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
Evan Chengc46349d2006-03-28 23:51:43 +0000437
Evan Chengd2a6d542006-04-12 23:42:44 +0000438// Match intrinsics which expect XMM operand(s).
Sean Callanan108934c2009-12-18 00:01:26 +0000439def CVTSS2SIrr: SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
440 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
441def CVTSS2SIrm: SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
442 "cvtss2si{l}\t{$src, $dst|$dst, $src}", []>;
443
Evan Cheng64d80e32007-07-19 01:14:50 +0000444def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000445 "cvtss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000446 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000447def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000448 "cvtss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000449 [(set GR32:$dst, (int_x86_sse_cvtss2si
450 (load addr:$src)))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +0000451
Dan Gohmand9c2af52010-05-26 18:03:53 +0000452// Match intrinsics which expect MM and XMM operand(s).
Dale Johannesenc7842082007-10-30 22:15:38 +0000453def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
454 "cvtps2pi\t{$src, $dst|$dst, $src}",
455 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
456def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
457 "cvtps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000458 [(set VR64:$dst, (int_x86_sse_cvtps2pi
Dale Johannesenc7842082007-10-30 22:15:38 +0000459 (load addr:$src)))]>;
460def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
461 "cvttps2pi\t{$src, $dst|$dst, $src}",
462 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
463def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
464 "cvttps2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000465 [(set VR64:$dst, (int_x86_sse_cvttps2pi
Dale Johannesenc7842082007-10-30 22:15:38 +0000466 (load addr:$src)))]>;
Evan Chenge9083d62008-03-05 08:19:16 +0000467let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +0000468 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
Dale Johannesenc7842082007-10-30 22:15:38 +0000469 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
470 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
471 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
472 VR64:$src2))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +0000473 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
Dale Johannesenc7842082007-10-30 22:15:38 +0000474 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
475 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000476 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
Dale Johannesenc7842082007-10-30 22:15:38 +0000477 (load addr:$src2)))]>;
478}
479
Evan Chengd2a6d542006-04-12 23:42:44 +0000480// Aliases for intrinsics
Evan Cheng64d80e32007-07-19 01:14:50 +0000481def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000482 "cvttss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000483 [(set GR32:$dst,
484 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000485def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000486 "cvttss2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000487 [(set GR32:$dst,
488 (int_x86_sse_cvttss2si(load addr:$src)))]>;
Evan Chengd03db7a2006-04-12 05:20:24 +0000489
Evan Chenge9083d62008-03-05 08:19:16 +0000490let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +0000491 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +0000492 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000493 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000494 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
495 GR32:$src2))]>;
496 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000497 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000498 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000499 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
500 (loadi32 addr:$src2)))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +0000501}
Evan Chengd03db7a2006-04-12 05:20:24 +0000502
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000503// Comparison instructions
Dan Gohmanb1347092009-01-09 02:27:34 +0000504let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +0000505 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +0000506 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000507 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanb1347092009-01-09 02:27:34 +0000508let mayLoad = 1 in
Eric Christopher44b93ff2009-07-31 20:07:27 +0000509 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000510 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000511 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Daniel Dunbar79373682010-05-25 18:40:53 +0000512
513 // Accept explicit immediate argument form instead of comparison code.
514let isAsmParserOnly = 1 in {
515 def CMPSSrr_alt : SSIi8<0xC2, MRMSrcReg,
516 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, i8imm:$src2),
517 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
518let mayLoad = 1 in
519 def CMPSSrm_alt : SSIi8<0xC2, MRMSrcMem,
520 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, i8imm:$src2),
521 "cmpss\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
522}
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000523}
524
Evan Cheng24f2ea32007-09-14 21:48:26 +0000525let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000526def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000527 "ucomiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000528 [(set EFLAGS, (X86cmp FR32:$src1, FR32:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000529def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000530 "ucomiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000531 [(set EFLAGS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000532
Sean Callanan108934c2009-12-18 00:01:26 +0000533def COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
534 "comiss\t{$src2, $src1|$src1, $src2}", []>;
535def COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
536 "comiss\t{$src2, $src1|$src1, $src2}", []>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000537
Evan Cheng24f2ea32007-09-14 21:48:26 +0000538} // Defs = [EFLAGS]
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000539
Evan Cheng0876aa52006-03-30 06:21:22 +0000540// Aliases to match intrinsics which expect XMM operand(s).
Evan Chenge9083d62008-03-05 08:19:16 +0000541let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +0000542 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000543 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +0000544 (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000545 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000546 [(set VR128:$dst, (int_x86_sse_cmp_ss
Sean Callanan108934c2009-12-18 00:01:26 +0000547 VR128:$src1,
548 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +0000549 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +0000550 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +0000551 (ins VR128:$src1, f32mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000552 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +0000553 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
554 (load addr:$src), imm:$cc))]>;
Evan Cheng0876aa52006-03-30 06:21:22 +0000555}
556
Evan Cheng24f2ea32007-09-14 21:48:26 +0000557let Defs = [EFLAGS] in {
Dan Gohmanb1347092009-01-09 02:27:34 +0000558def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng0488db92007-09-25 01:57:46 +0000559 "ucomiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000560 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
561 VR128:$src2))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +0000562def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Evan Cheng0488db92007-09-25 01:57:46 +0000563 "ucomiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000564 [(set EFLAGS, (X86ucomi (v4f32 VR128:$src1),
565 (load addr:$src2)))]>;
Evan Cheng0488db92007-09-25 01:57:46 +0000566
Dan Gohmanb1347092009-01-09 02:27:34 +0000567def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Evan Cheng0488db92007-09-25 01:57:46 +0000568 "comiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000569 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
570 VR128:$src2))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +0000571def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Evan Cheng0488db92007-09-25 01:57:46 +0000572 "comiss\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +0000573 [(set EFLAGS, (X86comi (v4f32 VR128:$src1),
574 (load addr:$src2)))]>;
Evan Cheng24f2ea32007-09-14 21:48:26 +0000575} // Defs = [EFLAGS]
Evan Cheng0876aa52006-03-30 06:21:22 +0000576
Eric Christopher44b93ff2009-07-31 20:07:27 +0000577// Aliases of packed SSE1 instructions for scalar use. These all have names
578// that start with 'Fs'.
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000579
580// Alias instructions that map fld0 to pxor for sse.
Dan Gohman4a0b3e12009-09-21 18:30:38 +0000581let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
582 canFoldAsLoad = 1 in
Chris Lattner28c1d292010-02-05 21:30:49 +0000583 // FIXME: Set encoding to pseudo!
Chris Lattnerbe1778f2010-02-05 21:34:18 +0000584def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins), "",
585 [(set FR32:$dst, fp32imm0)]>,
586 Requires<[HasSSE1]>, TB, OpSize;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000587
Bill Wendlingddd35322007-05-02 23:11:52 +0000588// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
589// disregarded.
Eric Christopher44b93ff2009-07-31 20:07:27 +0000590let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000591def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000592 "movaps\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000593
Bill Wendlingddd35322007-05-02 23:11:52 +0000594// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
595// disregarded.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000596let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000597def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000598 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohmand3006222007-07-27 17:16:43 +0000599 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000600
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +0000601/// sse12_fp_alias_pack_logical - SSE 1 & 2 aliased packed FP logical ops
602///
603multiclass sse12_fp_alias_pack_logical<bits<8> opc, string OpcodeStr,
604 SDNode OpNode, int NoPat = 0,
605 bit MayLoad = 0, bit Commutable = 1> {
606 def PSrr : PSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
607 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
608 !if(NoPat, []<dag>,
609 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))])> {
610 let isCommutable = Commutable;
611 }
612
613 def PDrr : PDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
614 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
615 !if(NoPat, []<dag>,
616 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))])> {
617 let isCommutable = Commutable;
618 }
619
620 def PSrm : PSI<opc, MRMSrcMem, (outs FR32:$dst),
621 (ins FR32:$src1, f128mem:$src2),
622 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
623 !if(NoPat, []<dag>,
624 [(set FR32:$dst, (OpNode FR32:$src1,
625 (memopfsf32 addr:$src2)))])> {
626 let mayLoad = MayLoad;
627 }
628
629 def PDrm : PDI<opc, MRMSrcMem, (outs FR64:$dst),
630 (ins FR64:$src1, f128mem:$src2),
631 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
632 !if(NoPat, []<dag>,
633 [(set FR64:$dst, (OpNode FR64:$src1,
634 (memopfsf64 addr:$src2)))])> {
635 let mayLoad = MayLoad;
636 }
637}
638
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000639// Alias bitwise logical operations using SSE logical ops on packed FP values.
Evan Chenge9083d62008-03-05 08:19:16 +0000640let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +0000641 defm FsAND : sse12_fp_alias_pack_logical<0x54, "and", X86fand>;
642 defm FsOR : sse12_fp_alias_pack_logical<0x56, "or", X86for>;
643 defm FsXOR : sse12_fp_alias_pack_logical<0x57, "xor", X86fxor>;
Bill Wendlingddd35322007-05-02 23:11:52 +0000644
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +0000645 let neverHasSideEffects = 1 in
646 defm FsANDN : sse12_fp_alias_pack_logical<0x55, "andn", undef, 1, 1, 0>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000647}
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000648
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000649/// sse12_fp_scalar - SSE 1 & 2 scalar instructions class
650multiclass sse12_fp_scalar<bits<8> opc, string OpcodeStr, SDNode OpNode,
651 RegisterClass RC, X86MemOperand memop> {
652 let isCommutable = 1 in {
653 def rr : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
654 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, RC:$src2))]>;
655 }
656 def rm : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memop:$src2),
657 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1, (load addr:$src2)))]>;
658}
659
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000660/// sse12_fp_scalar_int - SSE 1 & 2 scalar instructions intrinsics class
661multiclass sse12_fp_scalar_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
662 string asm, string SSEVer, string FPSizeStr,
663 Operand memop, ComplexPattern mem_cpat> {
664 def rr_Int : SI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
665 asm, [(set RC:$dst, (
666 !nameconcat<Intrinsic>("int_x86_sse",
667 !strconcat(SSEVer, !strconcat("_",
668 !strconcat(OpcodeStr, FPSizeStr))))
669 RC:$src1, RC:$src2))]>;
670 def rm_Int : SI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memop:$src2),
671 asm, [(set RC:$dst, (
672 !nameconcat<Intrinsic>("int_x86_sse",
673 !strconcat(SSEVer, !strconcat("_",
674 !strconcat(OpcodeStr, FPSizeStr))))
675 RC:$src1, mem_cpat:$src2))]>;
676}
677
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000678/// sse12_fp_packed - SSE 1 & 2 packed instructions class
679multiclass sse12_fp_packed<bits<8> opc, string OpcodeStr, SDNode OpNode,
680 RegisterClass RC, ValueType vt,
681 X86MemOperand x86memop, PatFrag mem_frag,
682 Domain d> {
683 let isCommutable = 1 in
684 def rr : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
685 OpcodeStr, [(set RC:$dst, (vt (OpNode RC:$src1, RC:$src2)))],d>;
686 def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
687 OpcodeStr, [(set RC:$dst, (OpNode RC:$src1,
688 (mem_frag addr:$src2)))],d>;
689}
690
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000691/// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
692/// vector forms.
Bill Wendlingddd35322007-05-02 23:11:52 +0000693///
Dan Gohman20382522007-07-10 00:05:58 +0000694/// In addition, we also have a special variant of the scalar form here to
695/// represent the associated intrinsic operation. This form is unlike the
696/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng236aa8a2009-02-26 03:12:02 +0000697/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohman20382522007-07-10 00:05:58 +0000698///
699/// These three forms can each be reg+reg or reg+mem, so there are a total of
700/// six "instructions".
Bill Wendlingddd35322007-05-02 23:11:52 +0000701///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000702multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
703 SDNode OpNode, bit Commutable = 0> {
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000704
Bruno Cardoso Lopesfda1acb2010-06-19 00:09:27 +0000705 let isAsmParserOnly = 1 in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000706 defm V#NAME#SS : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000707 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000708 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000709
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000710 defm V#NAME#SD : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000711 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000712 OpNode, FR64, f64mem>, XD, VEX_4V;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000713
714 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
715 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
716 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
717 VEX_4V;
718
719 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
720 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
721 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
722 OpSize, VEX_4V;
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000723
724 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
725 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
726 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
727
728 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
729 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
730 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
Bill Wendlingddd35322007-05-02 23:11:52 +0000731 }
732
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000733 let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000734 defm SS : sse12_fp_scalar<opc,
735 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
736 OpNode, FR32, f32mem>, XS;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000737
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000738 defm SD : sse12_fp_scalar<opc,
739 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
740 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesc902a592010-06-11 23:50:47 +0000741
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000742 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
743 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
744 f128mem, memopv4f32, SSEPackedSingle>, TB;
Dan Gohman20382522007-07-10 00:05:58 +0000745
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000746 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
747 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
748 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
Bruno Cardoso Lopescf125d02010-06-12 01:53:48 +0000749
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000750 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000751 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000752 "", "_ss", ssmem, sse_load_f32>, XS;
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000753
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000754 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000755 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000756 "2", "_sd", sdmem, sse_load_f64>, XD;
Bruno Cardoso Lopes2dcf6d62010-06-12 03:12:14 +0000757 }
Bill Wendlingddd35322007-05-02 23:11:52 +0000758}
Bill Wendlingddd35322007-05-02 23:11:52 +0000759
760// Arithmetic instructions
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000761defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd, 1>;
762defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul, 1>;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000763
764let isCommutable = 0 in {
765 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
766 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
767}
Bill Wendlingddd35322007-05-02 23:11:52 +0000768
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000769/// sse12_fp_binop_rm - Other SSE 1 & 2 binops
Dan Gohman20382522007-07-10 00:05:58 +0000770///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000771/// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
Dan Gohman20382522007-07-10 00:05:58 +0000772/// instructions for a full-vector intrinsic form. Operations that map
773/// onto C operators don't use this form since they just use the plain
774/// vector form instead of having a separate vector intrinsic form.
775///
776/// This provides a total of eight "instructions".
777///
Evan Chenge9083d62008-03-05 08:19:16 +0000778let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000779multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
780 SDNode OpNode, bit Commutable = 0> {
Dan Gohman20382522007-07-10 00:05:58 +0000781
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000782 let Constraints = "", isAsmParserOnly = 1 in {
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000783 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000784 defm V#NAME#SS : sse12_fp_scalar<opc,
785 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
786 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000787
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000788 defm V#NAME#SD : sse12_fp_scalar<opc,
789 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
790 OpNode, FR64, f64mem>, XD, VEX_4V;
Dan Gohman20382522007-07-10 00:05:58 +0000791 }
792
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000793 let Constraints = "$src1 = $dst" in {
794 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000795 defm SS : sse12_fp_scalar<opc,
796 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
797 OpNode, FR32, f32mem>, XS;
798 defm SD : sse12_fp_scalar<opc,
799 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
800 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000801 }
802
Dan Gohman20382522007-07-10 00:05:58 +0000803 // Vector operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000804 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
805 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000806 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman20382522007-07-10 00:05:58 +0000807 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
808 let isCommutable = Commutable;
809 }
810
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000811 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
812 (ins VR128:$src1, VR128:$src2),
813 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
814 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
815 let isCommutable = Commutable;
816 }
817
Dan Gohman20382522007-07-10 00:05:58 +0000818 // Vector operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000819 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
820 (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000821 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +0000822 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohman20382522007-07-10 00:05:58 +0000823
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000824 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
825 (ins VR128:$src1, f128mem:$src2),
826 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
827 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
828
Dan Gohman20382522007-07-10 00:05:58 +0000829 // Intrinsic operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000830 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
831 (ins VR128:$src1, VR128:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000832 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
833 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
834 !strconcat(OpcodeStr, "_ss")) VR128:$src1,
835 VR128:$src2))]> {
836 // int_x86_sse_xxx_ss
837 let isCommutable = Commutable;
838 }
839
840 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
841 (ins VR128:$src1, VR128:$src2),
842 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
843 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
844 !strconcat(OpcodeStr, "_sd")) VR128:$src1,
845 VR128:$src2))]> {
846 // int_x86_sse2_xxx_sd
Dan Gohman20382522007-07-10 00:05:58 +0000847 let isCommutable = Commutable;
848 }
849
850 // Intrinsic operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000851 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
852 (ins VR128:$src1, ssmem:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000853 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
854 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
855 !strconcat(OpcodeStr, "_ss")) VR128:$src1,
Dan Gohman20382522007-07-10 00:05:58 +0000856 sse_load_f32:$src2))]>;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000857 // int_x86_sse_xxx_ss
858
859 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
860 (ins VR128:$src1, sdmem:$src2),
861 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
862 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
863 !strconcat(OpcodeStr, "_sd")) VR128:$src1,
864 sse_load_f64:$src2))]>;
865 // int_x86_sse2_xxx_sd
Dan Gohman20382522007-07-10 00:05:58 +0000866
867 // Vector intrinsic operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000868 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst),
869 (ins VR128:$src1, VR128:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000870 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
871 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
872 !strconcat(OpcodeStr, "_ps")) VR128:$src1,
873 VR128:$src2))]> {
874 // int_x86_sse_xxx_ps
875 let isCommutable = Commutable;
876 }
877
878 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst),
879 (ins VR128:$src1, VR128:$src2),
880 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
881 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
882 !strconcat(OpcodeStr, "_pd")) VR128:$src1,
883 VR128:$src2))]> {
884 // int_x86_sse2_xxx_pd
Dan Gohman20382522007-07-10 00:05:58 +0000885 let isCommutable = Commutable;
886 }
887
888 // Vector intrinsic operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000889 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst),
890 (ins VR128:$src1, f128mem:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000891 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
892 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
893 !strconcat(OpcodeStr, "_ps")) VR128:$src1,
894 (memopv4f32 addr:$src2)))]>;
895 // int_x86_sse_xxx_ps
896
897 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst),
898 (ins VR128:$src1, f128mem:$src2),
899 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
900 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
901 !strconcat(OpcodeStr, "_pd")) VR128:$src1,
902 (memopv2f64 addr:$src2)))]>;
903 // int_x86_sse2_xxx_pd
Dan Gohman20382522007-07-10 00:05:58 +0000904}
905}
906
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000907let isCommutable = 0 in {
908 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
909 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
910}
Bill Wendlingddd35322007-05-02 23:11:52 +0000911
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000912//===----------------------------------------------------------------------===//
Evan Cheng9ab1ac52006-04-14 23:32:40 +0000913// SSE packed FP Instructions
Evan Chengc12e6c42006-03-19 09:38:54 +0000914
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000915// Move Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +0000916let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000917def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000918 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000919let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000920def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000921 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000922 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Evan Chengffcb95b2006-02-21 19:13:53 +0000923
Evan Cheng64d80e32007-07-19 01:14:50 +0000924def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000925 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000926 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000927
Chris Lattnerf77e0372008-01-11 06:59:07 +0000928let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000929def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000930 "movups\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000931let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000932def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000933 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000934 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000935def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000936 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000937 [(store (v4f32 VR128:$src), addr:$dst)]>;
938
939// Intrinsic forms of MOVUPS load and store
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000940let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000941def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000942 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000943 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000944def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000945 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000946 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000947
Evan Chenge9083d62008-03-05 08:19:16 +0000948let Constraints = "$src1 = $dst" in {
Dan Gohman32791e02007-06-25 15:44:19 +0000949 let AddedComplexity = 20 in {
950 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000951 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000952 "movlps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000953 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000954 (movlp VR128:$src1,
955 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000956 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000957 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000958 "movhps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000959 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000960 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +0000961 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000962 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000963} // Constraints = "$src1 = $dst"
Evan Cheng4fcb9222006-03-28 02:43:26 +0000964
Evan Chengb70ea0b2008-05-10 00:59:18 +0000965
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000966def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
Chris Lattner3485b512010-03-08 18:57:56 +0000967 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000968
Evan Cheng64d80e32007-07-19 01:14:50 +0000969def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000970 "movlps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000971 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
Evan Cheng015188f2006-06-15 08:14:54 +0000972 (iPTR 0))), addr:$dst)]>;
Evan Cheng9bbfd4f2006-03-28 07:01:28 +0000973
Evan Cheng664ade72006-04-07 21:20:58 +0000974// v2f64 extract element 1 is always custom lowered to unpack high to low
975// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +0000976def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000977 "movhps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000978 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +0000979 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
980 (undef)), (iPTR 0))), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000981
Evan Chenge9083d62008-03-05 08:19:16 +0000982let Constraints = "$src1 = $dst" in {
Evan Chengb7a75a52008-09-26 23:41:32 +0000983let AddedComplexity = 20 in {
Evan Cheng0af934e2009-05-12 20:17:52 +0000984def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
985 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000986 "movlhps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000987 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000988 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2c0dbd02006-03-24 02:58:06 +0000989
Evan Cheng0af934e2009-05-12 20:17:52 +0000990def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
991 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000992 "movhlps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000993 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000994 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2dadaea2006-04-19 20:37:34 +0000995} // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000996} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +0000997
Nate Begemanec8eee22009-04-29 22:47:44 +0000998let AddedComplexity = 20 in {
Nate Begeman9008ca62009-04-27 18:41:29 +0000999def : Pat<(v4f32 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +00001000 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +00001001def : Pat<(v2i64 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +00001002 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +00001003}
Evan Cheng0b457f02008-09-25 20:50:48 +00001004
Bill Wendlingddd35322007-05-02 23:11:52 +00001005
1006
Dan Gohman20382522007-07-10 00:05:58 +00001007// Arithmetic
1008
1009/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
Bill Wendlingddd35322007-05-02 23:11:52 +00001010///
Dan Gohman20382522007-07-10 00:05:58 +00001011/// In addition, we also have a special variant of the scalar form here to
1012/// represent the associated intrinsic operation. This form is unlike the
1013/// plain scalar form, in that it takes an entire vector (instead of a
1014/// scalar) and leaves the top elements undefined.
1015///
1016/// And, we have a special variant form for a full-vector intrinsic form.
1017///
1018/// These four forms can each have a reg or a mem operand, so there are a
1019/// total of eight "instructions".
1020///
1021multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1022 SDNode OpNode,
1023 Intrinsic F32Int,
1024 Intrinsic V4F32Int,
1025 bit Commutable = 0> {
1026 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001027 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001028 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001029 [(set FR32:$dst, (OpNode FR32:$src))]> {
Bill Wendlingddd35322007-05-02 23:11:52 +00001030 let isCommutable = Commutable;
1031 }
1032
Dan Gohman20382522007-07-10 00:05:58 +00001033 // Scalar operation, mem.
Evan Cheng400073d2009-12-18 07:40:29 +00001034 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001035 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Evan Cheng400073d2009-12-18 07:40:29 +00001036 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001037 Requires<[HasSSE1, OptForSize]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001038
Dan Gohman20382522007-07-10 00:05:58 +00001039 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001040 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001041 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001042 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1043 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001044 }
1045
Dan Gohman20382522007-07-10 00:05:58 +00001046 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001047 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001048 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001049 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001050
1051 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001052 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001053 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001054 [(set VR128:$dst, (F32Int VR128:$src))]> {
1055 let isCommutable = Commutable;
1056 }
1057
1058 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001059 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001060 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001061 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1062
1063 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001064 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001065 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001066 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1067 let isCommutable = Commutable;
1068 }
1069
1070 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001071 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001072 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001073 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001074}
1075
Dan Gohman20382522007-07-10 00:05:58 +00001076// Square root.
1077defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1078 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1079
1080// Reciprocal approximations. Note that these typically require refinement
1081// in order to obtain suitable precision.
1082defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1083 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1084defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1085 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1086
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001087/// sse12_fp_pack_logical - SSE 1 & 2 packed FP logical ops
1088///
1089multiclass sse12_fp_pack_logical<bits<8> opc, string OpcodeStr,
1090 SDNode OpNode, int HasPat = 0,
1091 bit Commutable = 1,
1092 list<list<dag>> Pattern = []> {
1093 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
1094 (ins VR128:$src1, VR128:$src2),
1095 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1096 !if(HasPat, Pattern[0],
1097 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1098 VR128:$src2)))])>
1099 { let isCommutable = Commutable; }
1100
1101 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1102 (ins VR128:$src1, VR128:$src2),
1103 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1104 !if(HasPat, Pattern[1],
1105 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1106 (bc_v2i64 (v2f64 VR128:$src2))))])>
1107 { let isCommutable = Commutable; }
1108
1109 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
1110 (ins VR128:$src1, f128mem:$src2),
1111 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1112 !if(HasPat, Pattern[2],
1113 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1114 (memopv2i64 addr:$src2)))])>;
1115
1116 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1117 (ins VR128:$src1, f128mem:$src2),
1118 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1119 !if(HasPat, Pattern[3],
1120 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1121 (memopv2i64 addr:$src2)))])>;
1122}
1123
Bill Wendlingddd35322007-05-02 23:11:52 +00001124// Logical
Evan Chenge9083d62008-03-05 08:19:16 +00001125let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001126 defm AND : sse12_fp_pack_logical<0x54, "and", and>;
1127 defm OR : sse12_fp_pack_logical<0x56, "or", or>;
1128 defm XOR : sse12_fp_pack_logical<0x57, "xor", xor>;
1129 defm ANDN : sse12_fp_pack_logical<0x55, "andn", undef /* dummy */, 1, 0, [
1130 // single r+r
1131 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1132 (bc_v2i64 (v4i32 immAllOnesV))),
1133 VR128:$src2)))],
1134 // double r+r
1135 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1136 (bc_v2i64 (v2f64 VR128:$src2))))],
1137 // single r+m
1138 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1139 (bc_v2i64 (v4i32 immAllOnesV))),
1140 (memopv2i64 addr:$src2))))],
1141 // double r+m
1142 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1143 (memopv2i64 addr:$src2)))]]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001144}
1145
Evan Chenge9083d62008-03-05 08:19:16 +00001146let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001147 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Nate Begemanc2616e42008-05-12 20:34:32 +00001148 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1149 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1150 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1151 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001152 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Nate Begemanc2616e42008-05-12 20:34:32 +00001153 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1154 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1155 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001156 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001157
1158 // Accept explicit immediate argument form instead of comparison code.
1159let isAsmParserOnly = 1 in {
1160 def CMPPSrri_alt : PSIi8<0xC2, MRMSrcReg,
1161 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1162 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1163 def CMPPSrmi_alt : PSIi8<0xC2, MRMSrcMem,
1164 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1165 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1166}
Bill Wendlingddd35322007-05-02 23:11:52 +00001167}
Nate Begeman30a0de92008-07-17 16:51:19 +00001168def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001169 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00001170def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001171 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001172
1173// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001174let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001175 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
Eric Christopher44b93ff2009-07-31 20:07:27 +00001176 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001177 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001178 VR128:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001179 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001180 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001181 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001182 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001183 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001184 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001185 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001186 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001187 (v4f32 (shufp:$src3
1188 VR128:$src1, (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001189
1190 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001191 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001192 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001193 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001194 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001195 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001196 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001197 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001198 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001199 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001200 (v4f32 (unpckh VR128:$src1,
1201 (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001202
Eric Christopher44b93ff2009-07-31 20:07:27 +00001203 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001204 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001205 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001206 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001207 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001208 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001209 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001210 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001211 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001212 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001213 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001214} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001215
1216// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00001217def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001218 "movmskps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001219 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Cheng8a0b2da2009-05-28 18:55:28 +00001220def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001221 "movmskpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001222 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1223
Evan Cheng27b7db52008-03-08 00:58:38 +00001224// Prefetch intrinsic.
1225def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1226 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1227def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1228 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1229def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1230 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1231def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1232 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001233
1234// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00001235def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001236 "movntps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001237 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1238
David Greene8939b0d2010-02-16 20:50:18 +00001239let AddedComplexity = 400 in { // Prefer non-temporal versions
1240def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1241 "movntps\t{$src, $dst|$dst, $src}",
1242 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1243
1244def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1245 "movntdq\t{$src, $dst|$dst, $src}",
1246 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1247
David Greene8939b0d2010-02-16 20:50:18 +00001248def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1249 "movnti\t{$src, $dst|$dst, $src}",
1250 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1251 TB, Requires<[HasSSE2]>;
1252
1253def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1254 "movnti\t{$src, $dst|$dst, $src}",
1255 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1256 TB, Requires<[HasSSE2]>;
1257}
1258
Bill Wendlingddd35322007-05-02 23:11:52 +00001259// Load, store, and memory fence
Dan Gohmanee5673b2010-05-20 01:23:41 +00001260def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1261 TB, Requires<[HasSSE1]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001262
1263// MXCSR register
Evan Cheng64d80e32007-07-19 01:14:50 +00001264def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001265 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001266def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001267 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001268
1269// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00001270// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00001271// load of an all-zeros value if folding it would be beneficial.
Chris Lattner28c1d292010-02-05 21:30:49 +00001272// FIXME: Change encoding to pseudo!
Daniel Dunbar7417b762009-08-11 22:17:52 +00001273let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001274 isCodeGenOnly = 1 in {
1275def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1276 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1277def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1278 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1279let ExeDomain = SSEPackedInt in
1280def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00001281 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001282}
Bill Wendlingddd35322007-05-02 23:11:52 +00001283
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001284def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1285def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1286def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
Evan Chengc8e3b142008-03-12 07:02:50 +00001287
Dan Gohman874cada2010-02-28 00:17:42 +00001288def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001289 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001290
Eric Christopher44b93ff2009-07-31 20:07:27 +00001291//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001292// SSE2 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00001293//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001294
Dan Gohman874cada2010-02-28 00:17:42 +00001295// Move Instructions. Register-to-register movsd is not used for FR64
1296// register copies because it's a partial register update; FsMOVAPDrr is
1297// used instead. Register-to-register movsd is not modeled as an INSERT_SUBREG
1298// because INSERT_SUBREG requires that the insert be implementable in terms of
1299// a copy, and just mentioned, we don't use movsd for copies.
1300let Constraints = "$src1 = $dst" in
1301def MOVSDrr : SDI<0x10, MRMSrcReg,
1302 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
1303 "movsd\t{$src2, $dst|$dst, $src2}",
Chris Lattner3d005782010-03-15 05:53:30 +00001304 [(set (v2f64 VR128:$dst),
Dan Gohman874cada2010-02-28 00:17:42 +00001305 (movl VR128:$src1, (scalar_to_vector FR64:$src2)))]>;
1306
1307// Extract the low 64-bit value from one vector and insert it into another.
1308let AddedComplexity = 15 in
1309def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
Chris Lattner3485b512010-03-08 18:57:56 +00001310 (MOVSDrr (v2f64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001311 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001312
1313// Implicitly promote a 64-bit scalar to a vector.
1314def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001315 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001316
1317// Loading from memory automatically zeroing upper bits.
1318let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 20 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001319def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001320 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001321 [(set FR64:$dst, (loadf64 addr:$src))]>;
Dan Gohman874cada2010-02-28 00:17:42 +00001322
1323// MOVSDrm zeros the high parts of the register; represent this
1324// with SUBREG_TO_REG.
1325let AddedComplexity = 20 in {
1326def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001327 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001328def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001329 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001330def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001331 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001332def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001333 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001334def : Pat<(v2f64 (X86vzload addr:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001335 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001336}
1337
1338// Store scalar value to memory.
Evan Cheng64d80e32007-07-19 01:14:50 +00001339def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001340 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001341 [(store FR64:$src, addr:$dst)]>;
1342
Dan Gohman874cada2010-02-28 00:17:42 +00001343// Extract and store.
1344def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
1345 addr:$dst),
1346 (MOVSDmr addr:$dst,
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001347 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001348
Bill Wendlingddd35322007-05-02 23:11:52 +00001349// Conversion instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00001350def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001351 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001352 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001353def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001354 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001355 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001356def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001357 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001358 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001359def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001360 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Evan Cheng400073d2009-12-18 07:40:29 +00001361 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
Evan Chengb1f49812009-12-22 17:47:23 +00001362 Requires<[HasSSE2, OptForSize]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001363def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001364 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001365 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001366def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001367 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001368 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1369
Sean Callanan5ab94032009-09-16 01:13:52 +00001370def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1371 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1372def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1373 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1374def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1375 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1376def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1377 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1378def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1379 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1380def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1381 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1382def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1383 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1384def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1385 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1386def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1387 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1388def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1389 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1390
Bill Wendlingddd35322007-05-02 23:11:52 +00001391// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001392def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001393 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001394 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1395 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001396def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001397 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001398 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001399 Requires<[HasSSE2, OptForSize]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001400
1401def : Pat<(extloadf32 addr:$src),
Dan Gohman874cada2010-02-28 00:17:42 +00001402 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1403 Requires<[HasSSE2, OptForSpeed]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001404
1405// Match intrinsics which expect XMM operand(s).
Evan Cheng64d80e32007-07-19 01:14:50 +00001406def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001407 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001408 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001409def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001410 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001411 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1412 (load addr:$src)))]>;
1413
Dan Gohmand9c2af52010-05-26 18:03:53 +00001414// Match intrinsics which expect MM and XMM operand(s).
Dale Johannesenc7842082007-10-30 22:15:38 +00001415def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1416 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1417 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1418def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1419 "cvtpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001420 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001421 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001422def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1423 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1424 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1425def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1426 "cvttpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001427 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001428 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001429def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1430 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1431 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1432def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1433 "cvtpi2pd\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001434 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
Dale Johannesenc7842082007-10-30 22:15:38 +00001435 (load addr:$src)))]>;
1436
Bill Wendlingddd35322007-05-02 23:11:52 +00001437// Aliases for intrinsics
Evan Cheng64d80e32007-07-19 01:14:50 +00001438def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001439 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001440 [(set GR32:$dst,
1441 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001442def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001443 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001444 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1445 (load addr:$src)))]>;
1446
1447// Comparison instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001448let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001449 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001450 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001451 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001452let mayLoad = 1 in
Eric Christopher44b93ff2009-07-31 20:07:27 +00001453 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001454 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001455 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001456
1457 // Accept explicit immediate argument form instead of comparison code.
1458let isAsmParserOnly = 1 in {
1459 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
1460 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
1461 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1462let mayLoad = 1 in
1463 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
1464 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
1465 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1466}
Bill Wendlingddd35322007-05-02 23:11:52 +00001467}
1468
Evan Cheng0488db92007-09-25 01:57:46 +00001469let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001470def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001471 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001472 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001473def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001474 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001475 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001476} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001477
Bill Wendlingddd35322007-05-02 23:11:52 +00001478// Aliases to match intrinsics which expect XMM operand(s).
Evan Chenge9083d62008-03-05 08:19:16 +00001479let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001480 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001481 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001482 (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001483 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001484 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1485 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001486 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001487 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001488 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001489 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001490 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1491 (load addr:$src), imm:$cc))]>;
1492}
1493
Evan Cheng0488db92007-09-25 01:57:46 +00001494let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001495def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001496 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001497 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1498 VR128:$src2))]>;
Evan Chenge5f62042007-09-29 00:00:36 +00001499def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001500 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001501 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1502 (load addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001503
Evan Cheng64d80e32007-07-19 01:14:50 +00001504def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001505 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001506 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1507 VR128:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001508def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001509 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001510 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1511 (load addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001512} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001513
Eric Christopher44b93ff2009-07-31 20:07:27 +00001514// Aliases of packed SSE2 instructions for scalar use. These all have names
1515// that start with 'Fs'.
Bill Wendlingddd35322007-05-02 23:11:52 +00001516
1517// Alias instructions that map fld0 to pxor for sse.
Dan Gohman4a0b3e12009-09-21 18:30:38 +00001518let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1519 canFoldAsLoad = 1 in
Chris Lattnerbe1778f2010-02-05 21:34:18 +00001520def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1521 [(set FR64:$dst, fpimm0)]>,
Bill Wendlingddd35322007-05-02 23:11:52 +00001522 Requires<[HasSSE2]>, TB, OpSize;
1523
Dan Gohman32791e02007-06-25 15:44:19 +00001524// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001525// disregarded.
Chris Lattnerba7e7562008-01-10 07:59:24 +00001526let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001527def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001528 "movapd\t{$src, $dst|$dst, $src}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001529
Dan Gohman32791e02007-06-25 15:44:19 +00001530// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001531// disregarded.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001532let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001533def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001534 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohmand3006222007-07-27 17:16:43 +00001535 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001536
Eric Christopher44b93ff2009-07-31 20:07:27 +00001537//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001538// SSE packed FP Instructions
1539
1540// Move Instructions
Chris Lattnerba7e7562008-01-10 07:59:24 +00001541let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001542def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001543 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001544let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001545def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001546 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001547 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001548
Evan Cheng64d80e32007-07-19 01:14:50 +00001549def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001550 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001551 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001552
Chris Lattnerf77e0372008-01-11 06:59:07 +00001553let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001554def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001555 "movupd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001556let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001557def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001558 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001559 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001560def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001561 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001562 [(store (v2f64 VR128:$src), addr:$dst)]>;
1563
1564// Intrinsic forms of MOVUPD load and store
Evan Cheng64d80e32007-07-19 01:14:50 +00001565def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001566 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001567 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001568def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001569 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001570 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001571
Evan Chenge9083d62008-03-05 08:19:16 +00001572let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001573 let AddedComplexity = 20 in {
1574 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001575 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001576 "movlpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001577 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001578 (v2f64 (movlp VR128:$src1,
1579 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001580 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001581 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001582 "movhpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001583 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +00001584 (v2f64 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001585 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001586 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001587} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001588
Evan Cheng64d80e32007-07-19 01:14:50 +00001589def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001590 "movlpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001591 [(store (f64 (vector_extract (v2f64 VR128:$src),
1592 (iPTR 0))), addr:$dst)]>;
1593
1594// v2f64 extract element 1 is always custom lowered to unpack high to low
1595// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +00001596def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001597 "movhpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001598 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +00001599 (v2f64 (unpckh VR128:$src, (undef))),
1600 (iPTR 0))), addr:$dst)]>;
Evan Chengd9539472006-04-14 21:59:03 +00001601
Evan Cheng470a6ad2006-02-22 02:26:30 +00001602// SSE2 instructions without OpSize prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001603def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001604 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001605 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1606 TB, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001607def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001608 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1609 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1610 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001611 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001612
1613// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001614def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001615 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001616 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1617 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001618def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001619 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1620 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1621 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001622 XS, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001623
Evan Cheng64d80e32007-07-19 01:14:50 +00001624def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001625 "cvtps2dq\t{$src, $dst|$dst, $src}",
1626 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001627def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001628 "cvtps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001629 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001630 (memop addr:$src)))]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001631// SSE2 packed instructions with XS prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001632def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1633 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1634def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1635 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1636
Evan Cheng64d80e32007-07-19 01:14:50 +00001637def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001638 "cvttps2dq\t{$src, $dst|$dst, $src}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001639 [(set VR128:$dst,
Sean Callanan108934c2009-12-18 00:01:26 +00001640 (int_x86_sse2_cvttps2dq VR128:$src))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001641 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001642def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001643 "cvttps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001644 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001645 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001646 XS, Requires<[HasSSE2]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001647
Evan Cheng470a6ad2006-02-22 02:26:30 +00001648// SSE2 packed instructions with XD prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001649def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001650 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001651 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1652 XD, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001653def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001654 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001655 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001656 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001657 XD, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001658
Evan Cheng64d80e32007-07-19 01:14:50 +00001659def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001660 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001661 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Cheng029d9da2008-03-14 07:46:48 +00001662def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001663 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001664 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001665 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001666
1667// SSE2 instructions without OpSize prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001668def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1669 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1670def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1671 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1672
Evan Cheng64d80e32007-07-19 01:14:50 +00001673def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001674 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001675 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1676 TB, Requires<[HasSSE2]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001677def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001678 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001679 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
Chris Lattner15258d52006-10-07 06:17:43 +00001680 (load addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001681 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001682
Sean Callanan108934c2009-12-18 00:01:26 +00001683def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1684 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1685def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1686 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1687
1688
Evan Cheng64d80e32007-07-19 01:14:50 +00001689def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001690 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001691 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001692def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001693 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001694 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
Evan Chengb1938262008-05-23 00:37:07 +00001695 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001696
Evan Chengd2a6d542006-04-12 23:42:44 +00001697// Match intrinsics which expect XMM operand(s).
1698// Aliases for intrinsics
Evan Chenge9083d62008-03-05 08:19:16 +00001699let Constraints = "$src1 = $dst" in {
Evan Chengd2a6d542006-04-12 23:42:44 +00001700def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001701 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001702 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001703 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
Evan Cheng069287d2006-05-16 07:21:53 +00001704 GR32:$src2))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001705def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001706 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001707 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001708 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1709 (loadi32 addr:$src2)))]>;
1710def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001711 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001712 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001713 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1714 VR128:$src2))]>;
1715def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001716 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001717 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001718 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001719 (load addr:$src2)))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001720def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001721 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001722 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001723 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1724 VR128:$src2))]>, XS,
1725 Requires<[HasSSE2]>;
1726def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001727 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001728 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001729 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001730 (load addr:$src2)))]>, XS,
Evan Chengd2a6d542006-04-12 23:42:44 +00001731 Requires<[HasSSE2]>;
1732}
1733
Dan Gohman20382522007-07-10 00:05:58 +00001734// Arithmetic
1735
1736/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
Chris Lattner6f987732006-10-07 21:17:13 +00001737///
Dan Gohman20382522007-07-10 00:05:58 +00001738/// In addition, we also have a special variant of the scalar form here to
1739/// represent the associated intrinsic operation. This form is unlike the
1740/// plain scalar form, in that it takes an entire vector (instead of a
1741/// scalar) and leaves the top elements undefined.
1742///
1743/// And, we have a special variant form for a full-vector intrinsic form.
1744///
1745/// These four forms can each have a reg or a mem operand, so there are a
1746/// total of eight "instructions".
1747///
1748multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1749 SDNode OpNode,
1750 Intrinsic F64Int,
1751 Intrinsic V2F64Int,
1752 bit Commutable = 0> {
1753 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001754 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001755 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001756 [(set FR64:$dst, (OpNode FR64:$src))]> {
Chris Lattner6f987732006-10-07 21:17:13 +00001757 let isCommutable = Commutable;
1758 }
Bill Wendlingddd35322007-05-02 23:11:52 +00001759
Dan Gohman20382522007-07-10 00:05:58 +00001760 // Scalar operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001761 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001762 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001763 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001764
Dan Gohman20382522007-07-10 00:05:58 +00001765 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001766 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001767 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001768 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1769 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001770 }
1771
Dan Gohman20382522007-07-10 00:05:58 +00001772 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001773 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001774 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001775 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001776
1777 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001778 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001779 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001780 [(set VR128:$dst, (F64Int VR128:$src))]> {
1781 let isCommutable = Commutable;
1782 }
1783
1784 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001785 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001786 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001787 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1788
1789 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001790 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001791 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001792 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1793 let isCommutable = Commutable;
1794 }
1795
1796 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001797 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001798 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001799 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
Evan Cheng97ac5fa2006-04-03 23:49:17 +00001800}
Evan Chengffcb95b2006-02-21 19:13:53 +00001801
Dan Gohman20382522007-07-10 00:05:58 +00001802// Square root.
1803defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1804 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1805
1806// There is no f64 version of the reciprocal approximation instructions.
1807
Evan Chenge9083d62008-03-05 08:19:16 +00001808let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001809 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001810 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1811 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1812 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Nate Begemanc2616e42008-05-12 20:34:32 +00001813 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001814 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Cheng029d9da2008-03-14 07:46:48 +00001815 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1816 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1817 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001818 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001819
1820 // Accept explicit immediate argument form instead of comparison code.
1821let isAsmParserOnly = 1 in {
1822 def CMPPDrri_alt : PDIi8<0xC2, MRMSrcReg,
1823 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1824 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1825 def CMPPDrmi_alt : PDIi8<0xC2, MRMSrcMem,
1826 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1827 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1828}
Evan Cheng470a6ad2006-02-22 02:26:30 +00001829}
Evan Chenge9d50352008-08-05 22:19:15 +00001830def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001831 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
Evan Chenge9d50352008-08-05 22:19:15 +00001832def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001833 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001834
1835// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001836let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001837 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001838 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1839 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begeman9008ca62009-04-27 18:41:29 +00001840 [(set VR128:$dst,
1841 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001842 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001843 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00001844 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001845 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001846 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001847 (v2f64 (shufp:$src3
1848 VR128:$src1, (memopv2f64 addr:$src2))))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001849
Bill Wendlingddd35322007-05-02 23:11:52 +00001850 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001851 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001852 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001853 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001854 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001855 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001856 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001857 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001858 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001859 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001860 (v2f64 (unpckh VR128:$src1,
1861 (memopv2f64 addr:$src2))))]>;
Evan Cheng4fcb9222006-03-28 02:43:26 +00001862
Eric Christopher44b93ff2009-07-31 20:07:27 +00001863 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001864 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001865 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001866 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001867 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001868 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001869 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001870 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001871 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001872 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001873 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001874} // Constraints = "$src1 = $dst"
Evan Cheng470a6ad2006-02-22 02:26:30 +00001875
Evan Cheng4b1734f2006-03-31 21:29:33 +00001876
Eric Christopher44b93ff2009-07-31 20:07:27 +00001877//===---------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001878// SSE integer instructions
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001879let ExeDomain = SSEPackedInt in {
Evan Chengbf156d12006-02-21 19:26:52 +00001880
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001881// Move Instructions
Chris Lattnerf77e0372008-01-11 06:59:07 +00001882let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001883def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001884 "movdqa\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001885let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001886def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001887 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001888 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001889let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001890def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001891 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001892 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001893let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001894def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001895 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001896 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001897 XS, Requires<[HasSSE2]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001898let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001899def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001900 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001901 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001902 XS, Requires<[HasSSE2]>;
Evan Cheng24dc1f52006-03-23 07:44:07 +00001903
Dan Gohman4106f372007-07-18 20:23:34 +00001904// Intrinsic forms of MOVDQU load and store
Dan Gohman15511cf2008-12-03 18:15:48 +00001905let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001906def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001907 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001908 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1909 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001910def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001911 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001912 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1913 XS, Requires<[HasSSE2]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001914
Evan Chenge7b8a8b2008-03-05 08:11:27 +00001915let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001916
Chris Lattner45e123c2006-10-07 19:02:31 +00001917multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1918 bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001919 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001920 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001921 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001922 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1923 let isCommutable = Commutable;
1924 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001925 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001926 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001927 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001928 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001929 (bitconvert (memopv2i64
Sean Callanan108934c2009-12-18 00:01:26 +00001930 addr:$src2))))]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001931}
Chris Lattner8139e282006-10-07 18:39:00 +00001932
Evan Cheng22b942a2008-05-03 00:52:09 +00001933multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1934 string OpcodeStr,
1935 Intrinsic IntId, Intrinsic IntId2> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001936 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001937 (ins VR128:$src1, VR128:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001938 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1939 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001940 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1941 (ins VR128:$src1, i128mem:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001942 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1943 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001944 (bitconvert (memopv2i64 addr:$src2))))]>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001945 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001946 (ins VR128:$src1, i32i8imm:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001947 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1948 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1949}
1950
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001951/// PDI_binop_rm - Simple SSE2 binary operator.
1952multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1953 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001954 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001955 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001956 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001957 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1958 let isCommutable = Commutable;
1959 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001960 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001961 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001962 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001963 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001964 (bitconvert (memopv2i64 addr:$src2)))))]>;
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001965}
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001966
1967/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1968///
1969/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1970/// to collapse (bitconvert VT to VT) into its operand.
1971///
1972multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1973 bit Commutable = 0> {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001974 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001975 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001976 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001977 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1978 let isCommutable = Commutable;
1979 }
Eric Christopher44b93ff2009-07-31 20:07:27 +00001980 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001981 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001982 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00001983 [(set VR128:$dst, (OpNode VR128:$src1,
Sean Callanan108934c2009-12-18 00:01:26 +00001984 (memopv2i64 addr:$src2)))]>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001985}
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001986
Evan Chenge9083d62008-03-05 08:19:16 +00001987} // Constraints = "$src1 = $dst"
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001988} // ExeDomain = SSEPackedInt
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001989
1990// 128-bit Integer Arithmetic
1991
1992defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1993defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1994defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001995defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001996
Chris Lattner45e123c2006-10-07 19:02:31 +00001997defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1998defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1999defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2000defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002001
Chris Lattner7c47f9a2006-10-07 19:14:49 +00002002defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2003defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2004defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00002005defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002006
Chris Lattner45e123c2006-10-07 19:02:31 +00002007defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2008defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2009defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2010defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002011
Chris Lattner7c47f9a2006-10-07 19:14:49 +00002012defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00002013
Chris Lattner45e123c2006-10-07 19:02:31 +00002014defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2015defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
2016defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00002017
Chris Lattner45e123c2006-10-07 19:02:31 +00002018defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
Chris Lattner77337992006-10-07 07:06:17 +00002019
Chris Lattner45e123c2006-10-07 19:02:31 +00002020defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2021defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
Chris Lattner8139e282006-10-07 18:39:00 +00002022
Chris Lattner77337992006-10-07 07:06:17 +00002023
Chris Lattner45e123c2006-10-07 19:02:31 +00002024defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2025defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2026defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2027defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
Bill Wendling3b1259b2009-05-28 02:04:00 +00002028defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
Evan Chengc60bd972006-03-25 09:37:23 +00002029
Chris Lattner77337992006-10-07 07:06:17 +00002030
Evan Cheng22b942a2008-05-03 00:52:09 +00002031defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2032 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2033defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2034 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2035defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2036 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002037
Evan Cheng22b942a2008-05-03 00:52:09 +00002038defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2039 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2040defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2041 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
Nate Begeman32097bd2008-05-13 17:52:09 +00002042defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Cheng22b942a2008-05-03 00:52:09 +00002043 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002044
Evan Cheng22b942a2008-05-03 00:52:09 +00002045defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2046 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
Nate Begemanc9bdb002008-05-13 01:47:52 +00002047defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Cheng22b942a2008-05-03 00:52:09 +00002048 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
Chris Lattner77337992006-10-07 07:06:17 +00002049
Chris Lattner6970eda2006-10-07 19:49:05 +00002050// 128-bit logical shifts.
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002051let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2052 ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002053 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002054 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002055 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002056 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002057 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002058 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002059 // PSRADQri doesn't exist in SSE[1-3].
Evan Chengff65e382006-04-04 21:49:39 +00002060}
2061
Chris Lattner6970eda2006-10-07 19:49:05 +00002062let Predicates = [HasSSE2] in {
2063 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002064 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002065 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002066 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Bill Wendling5e249b42008-10-02 05:56:52 +00002067 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2068 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2069 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2070 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
Evan Cheng68c47cb2007-01-05 07:55:56 +00002071 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
Evan Cheng89321162009-10-28 06:30:34 +00002072 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002073
2074 // Shift up / down and insert zero's.
2075 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002076 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002077 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002078 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002079}
2080
Evan Cheng506d3df2006-03-29 23:07:14 +00002081// Logical
Chris Lattnera7ebe552006-10-07 19:37:30 +00002082defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2083defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2084defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2085
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002086let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002087 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002088 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002089 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002090 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2091 VR128:$src2)))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002092
Bill Wendlingddd35322007-05-02 23:11:52 +00002093 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002094 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002095 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002096 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002097 (memopv2i64 addr:$src2))))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002098}
2099
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002100// SSE2 Integer comparison
Bill Wendlingddd35322007-05-02 23:11:52 +00002101defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2102defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2103defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2104defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2105defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2106defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002107
Nate Begeman30a0de92008-07-17 16:51:19 +00002108def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002109 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002110def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002111 (PCMPEQBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002112def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002113 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002114def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002115 (PCMPEQWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002116def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002117 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002118def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002119 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2120
Nate Begeman30a0de92008-07-17 16:51:19 +00002121def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002122 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002123def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002124 (PCMPGTBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002125def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002126 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002127def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002128 (PCMPGTWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002129def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002130 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002131def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002132 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2133
2134
Evan Cheng506d3df2006-03-29 23:07:14 +00002135// Pack instructions
Chris Lattner45e123c2006-10-07 19:02:31 +00002136defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2137defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2138defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002139
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002140let ExeDomain = SSEPackedInt in {
2141
Evan Cheng506d3df2006-03-29 23:07:14 +00002142// Shuffle and unpack instructions
Nate Begemana09008b2009-10-19 02:17:23 +00002143let AddedComplexity = 5 in {
Evan Cheng8703be42006-04-04 19:12:30 +00002144def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002145 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002146 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002147 [(set VR128:$dst, (v4i32 (pshufd:$src2
2148 VR128:$src1, (undef))))]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002149def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002150 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002151 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002152 [(set VR128:$dst, (v4i32 (pshufd:$src2
Evan Chengc3630942009-12-09 21:00:30 +00002153 (bc_v4i32 (memopv2i64 addr:$src1)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002154 (undef))))]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002155}
Evan Cheng506d3df2006-03-29 23:07:14 +00002156
2157// SSE2 with ImmT == Imm8 and XS prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002158def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002159 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002160 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002161 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2162 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002163 XS, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002164def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002165 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002166 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002167 [(set VR128:$dst, (v8i16 (pshufhw:$src2
Eric Christopher44b93ff2009-07-31 20:07:27 +00002168 (bc_v8i16 (memopv2i64 addr:$src1)),
2169 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002170 XS, Requires<[HasSSE2]>;
2171
2172// SSE2 with ImmT == Imm8 and XD prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002173def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Nate Begeman9008ca62009-04-27 18:41:29 +00002174 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002175 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002176 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2177 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002178 XD, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002179def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Nate Begeman9008ca62009-04-27 18:41:29 +00002180 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002181 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002182 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2183 (bc_v8i16 (memopv2i64 addr:$src1)),
2184 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002185 XD, Requires<[HasSSE2]>;
2186
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002187// Unpack instructions
2188multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2189 PatFrag unp_frag, PatFrag bc_frag> {
2190 def rr : PDI<opc, MRMSrcReg,
2191 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2192 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2193 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2194 def rm : PDI<opc, MRMSrcMem,
2195 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2196 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2197 [(set VR128:$dst, (unp_frag VR128:$src1,
2198 (bc_frag (memopv2i64
2199 addr:$src2))))]>;
2200}
Evan Chengc60bd972006-03-25 09:37:23 +00002201
Evan Chenge9083d62008-03-05 08:19:16 +00002202let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002203 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2204 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2205 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2206
2207 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2208 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002209 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002210 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002211 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002212 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002213 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002214 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002215 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002216 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002217 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002218 (v2i64 (unpckl VR128:$src1,
2219 (memopv2i64 addr:$src2))))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002220
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002221 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2222 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2223 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2224
2225 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2226 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002227 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002228 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002229 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002230 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002231 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002232 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002233 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002234 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002235 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002236 (v2i64 (unpckh VR128:$src1,
2237 (memopv2i64 addr:$src2))))]>;
Evan Chenga971f6f2006-03-23 01:57:24 +00002238}
Evan Cheng82521dd2006-03-21 07:09:35 +00002239
Evan Chengb067a1e2006-03-31 19:22:53 +00002240// Extract / Insert
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002241def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002242 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002243 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002244 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begeman14d12ca2008-02-11 04:19:36 +00002245 imm:$src2))]>;
Evan Chenge9083d62008-03-05 08:19:16 +00002246let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002247 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002248 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002249 GR32:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002250 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002251 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002252 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002253 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002254 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002255 i16mem:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002256 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002257 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002258 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2259 imm:$src3))]>;
Evan Chengb067a1e2006-03-31 19:22:53 +00002260}
2261
Evan Chengc5fb2b12006-03-30 00:33:26 +00002262// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00002263def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002264 "pmovmskb\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002265 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
Evan Chengc5fb2b12006-03-30 00:33:26 +00002266
Evan Chengfcf5e212006-04-11 06:57:30 +00002267// Conditional store
Evan Cheng071a2792007-09-11 19:55:27 +00002268let Uses = [EDI] in
Evan Cheng64d80e32007-07-19 01:14:50 +00002269def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002270 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng071a2792007-09-11 19:55:27 +00002271 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Evan Chengfcf5e212006-04-11 06:57:30 +00002272
Evan Cheng1d768642009-02-10 22:06:28 +00002273let Uses = [RDI] in
2274def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2275 "maskmovdqu\t{$mask, $src|$src, $mask}",
2276 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2277
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002278} // ExeDomain = SSEPackedInt
2279
Evan Chengecac9cb2006-03-25 06:03:26 +00002280// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00002281def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2282 "movntpd\t{$src, $dst|$dst, $src}",
2283 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002284let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002285def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2286 "movntdq\t{$src, $dst|$dst, $src}",
2287 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2288def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002289 "movnti\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002290 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
Evan Chengfcf5e212006-04-11 06:57:30 +00002291 TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002292
David Greene8939b0d2010-02-16 20:50:18 +00002293let AddedComplexity = 400 in { // Prefer non-temporal versions
2294def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2295 "movntpd\t{$src, $dst|$dst, $src}",
2296 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2297
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002298let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002299def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2300 "movntdq\t{$src, $dst|$dst, $src}",
2301 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
David Greene8939b0d2010-02-16 20:50:18 +00002302}
2303
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002304// Flush cache
Evan Cheng64d80e32007-07-19 01:14:50 +00002305def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002306 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002307 TB, Requires<[HasSSE2]>;
2308
2309// Load, store, and memory fence
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002310def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002311 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002312def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002313 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002314
Dan Gohman14aaeac2010-05-20 01:35:50 +00002315// Pause. This "instruction" is encoded as "rep; nop", so even though it
Dan Gohmand9c2af52010-05-26 18:03:53 +00002316// was introduced with SSE2, it's backward compatible.
Dan Gohman14aaeac2010-05-20 01:35:50 +00002317def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2318
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002319//TODO: custom lower this so as to never even generate the noop
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002320def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002321 (i8 0)), (NOOP)>;
2322def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2323def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002324def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002325 (i8 1)), (MFENCE)>;
2326
Evan Chengffea91e2006-03-26 09:53:12 +00002327// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00002328// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00002329// load of an all-ones value if folding it would be beneficial.
Daniel Dunbar7417b762009-08-11 22:17:52 +00002330let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesen428e1522010-03-30 22:46:55 +00002331 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
Chris Lattner28c1d292010-02-05 21:30:49 +00002332 // FIXME: Change encoding to pseudo.
2333 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00002334 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Evan Cheng386031a2006-03-24 07:29:27 +00002335
Evan Cheng64d80e32007-07-19 01:14:50 +00002336def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002337 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002338 [(set VR128:$dst,
Evan Cheng069287d2006-05-16 07:21:53 +00002339 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002340def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002341 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002342 [(set VR128:$dst,
2343 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
Evan Chengebf01d62006-11-16 23:33:25 +00002344
Evan Cheng64d80e32007-07-19 01:14:50 +00002345def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002346 "movd\t{$src, $dst|$dst, $src}",
Chris Lattnerf3597a12006-12-05 18:45:06 +00002347 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2348
Evan Cheng64d80e32007-07-19 01:14:50 +00002349def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002350 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002351 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002352
Evan Cheng11e15b32006-04-03 20:53:28 +00002353// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00002354def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002355 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002356 [(set VR128:$dst,
2357 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2358 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002359def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002360 "movq\t{$src, $dst|$dst, $src}",
Evan Chengebf01d62006-11-16 23:33:25 +00002361 [(store (i64 (vector_extract (v2i64 VR128:$src),
2362 (iPTR 0))), addr:$dst)]>;
2363
Dan Gohman874cada2010-02-28 00:17:42 +00002364def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002365 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00002366
Evan Cheng64d80e32007-07-19 01:14:50 +00002367def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002368 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002369 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002370 (iPTR 0)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002371def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002372 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002373 [(store (i32 (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002374 (iPTR 0))), addr:$dst)]>;
Evan Cheng11e15b32006-04-03 20:53:28 +00002375
Evan Cheng64d80e32007-07-19 01:14:50 +00002376def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002377 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002378 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002379def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002380 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002381 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002382
Evan Cheng397edef2006-04-11 22:28:25 +00002383// Store / copy lower 64-bits of a XMM register.
Evan Cheng64d80e32007-07-19 01:14:50 +00002384def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002385 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng397edef2006-04-11 22:28:25 +00002386 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2387
Evan Cheng017dcc62006-04-21 01:05:10 +00002388// movd / movq to XMM register zero-extends
Evan Cheng7a831ce2007-12-15 03:00:47 +00002389let AddedComplexity = 15 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002390def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002391 "movd\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002392 [(set VR128:$dst, (v4i32 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002393 (v4i32 (scalar_to_vector GR32:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002394// This is X86-64 only.
2395def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2396 "mov{d|q}\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002397 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002398 (v2i64 (scalar_to_vector GR64:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002399}
2400
2401let AddedComplexity = 20 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002402def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002403 "movd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002404 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002405 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002406 (loadi32 addr:$src))))))]>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002407
2408def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2409 (MOVZDI2PDIrm addr:$src)>;
2410def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2411 (MOVZDI2PDIrm addr:$src)>;
Duncan Sandsd4b9c172008-06-13 19:07:40 +00002412def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2413 (MOVZDI2PDIrm addr:$src)>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002414
Evan Cheng64d80e32007-07-19 01:14:50 +00002415def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002416 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng7a831ce2007-12-15 03:00:47 +00002417 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002418 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002419 (loadi64 addr:$src))))))]>, XS,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002420 Requires<[HasSSE2]>;
Evan Cheng48090aa2006-03-21 23:01:21 +00002421
Evan Chengc36c0ab2008-05-22 18:56:56 +00002422def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2423 (MOVZQI2PQIrm addr:$src)>;
2424def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2425 (MOVZQI2PQIrm addr:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002426def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
Evan Chengb70ea0b2008-05-10 00:59:18 +00002427}
Evan Chengd880b972008-05-09 21:53:03 +00002428
Evan Cheng7a831ce2007-12-15 03:00:47 +00002429// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2430// IA32 document. movq xmm1, xmm2 does clear the high bits.
2431let AddedComplexity = 15 in
2432def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2433 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002434 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002435 XS, Requires<[HasSSE2]>;
2436
Evan Cheng8e8de682008-05-20 18:24:47 +00002437let AddedComplexity = 20 in {
Evan Cheng7a831ce2007-12-15 03:00:47 +00002438def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2439 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002440 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng8e8de682008-05-20 18:24:47 +00002441 (loadv2i64 addr:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002442 XS, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002443
Evan Cheng8e8de682008-05-20 18:24:47 +00002444def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2445 (MOVZPQILo2PQIrm addr:$src)>;
2446}
2447
Sean Callanan108934c2009-12-18 00:01:26 +00002448// Instructions for the disassembler
2449// xr = XMM register
2450// xm = mem64
2451
2452def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2453 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2454
Eric Christopher44b93ff2009-07-31 20:07:27 +00002455//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002456// SSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002457//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002458
Bill Wendlingddd35322007-05-02 23:11:52 +00002459// Move Instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00002460def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002461 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002462 [(set VR128:$dst, (v4f32 (movshdup
2463 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002464def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002465 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002466 [(set VR128:$dst, (movshdup
2467 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002468
Evan Cheng64d80e32007-07-19 01:14:50 +00002469def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002470 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002471 [(set VR128:$dst, (v4f32 (movsldup
2472 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002473def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002474 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002475 [(set VR128:$dst, (movsldup
2476 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002477
Evan Cheng64d80e32007-07-19 01:14:50 +00002478def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002479 "movddup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002480 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002481def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002482 "movddup\t{$src, $dst|$dst, $src}",
Evan Cheng0b457f02008-09-25 20:50:48 +00002483 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002484 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2485 (undef))))]>;
Evan Cheng0b457f02008-09-25 20:50:48 +00002486
Nate Begeman9008ca62009-04-27 18:41:29 +00002487def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2488 (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002489 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002490
2491let AddedComplexity = 5 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002492def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002493 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002494def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2495 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2496def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2497 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2498def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2499 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2500}
Bill Wendlingddd35322007-05-02 23:11:52 +00002501
2502// Arithmetic
Evan Chenge9083d62008-03-05 08:19:16 +00002503let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002504 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002505 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002506 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002507 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2508 VR128:$src2))]>;
2509 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002510 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002511 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002512 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002513 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002514 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002515 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002516 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002517 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2518 VR128:$src2))]>;
2519 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002520 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002521 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002522 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002523 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002524}
2525
Evan Cheng64d80e32007-07-19 01:14:50 +00002526def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002527 "lddqu\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002528 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2529
2530// Horizontal ops
2531class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002532 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002533 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002534 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2535class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002536 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002537 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002538 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002539class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002540 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002541 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002542 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2543class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002544 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002545 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002546 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002547
Evan Chenge9083d62008-03-05 08:19:16 +00002548let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002549 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2550 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2551 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2552 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2553 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2554 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2555 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2556 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2557}
2558
2559// Thread synchronization
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002560def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
Bill Wendlingddd35322007-05-02 23:11:52 +00002561 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002562def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
Bill Wendlingddd35322007-05-02 23:11:52 +00002563 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2564
2565// vector_shuffle v1, <undef> <1, 1, 3, 3>
2566let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002567def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002568 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2569let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002570def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002571 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2572
2573// vector_shuffle v1, <undef> <0, 0, 2, 2>
2574let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002575 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002576 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2577let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002578 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002579 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2580
Eric Christopher44b93ff2009-07-31 20:07:27 +00002581//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002582// SSSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002583//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002584
Bill Wendling76d708b2007-08-10 06:22:27 +00002585/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begemanfea2be52008-02-09 23:46:37 +00002586multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2587 Intrinsic IntId64, Intrinsic IntId128> {
2588 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2589 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2590 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002591
Nate Begemanfea2be52008-02-09 23:46:37 +00002592 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2593 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2594 [(set VR64:$dst,
2595 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2596
2597 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2598 (ins VR128:$src),
2599 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2600 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2601 OpSize;
2602
2603 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2604 (ins i128mem:$src),
2605 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2606 [(set VR128:$dst,
2607 (IntId128
2608 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Bill Wendlingddd35322007-05-02 23:11:52 +00002609}
2610
Bill Wendling76d708b2007-08-10 06:22:27 +00002611/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begemanfea2be52008-02-09 23:46:37 +00002612multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2613 Intrinsic IntId64, Intrinsic IntId128> {
2614 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2615 (ins VR64:$src),
2616 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2617 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002618
Nate Begemanfea2be52008-02-09 23:46:37 +00002619 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2620 (ins i64mem:$src),
2621 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2622 [(set VR64:$dst,
2623 (IntId64
2624 (bitconvert (memopv4i16 addr:$src))))]>;
2625
2626 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2627 (ins VR128:$src),
2628 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2629 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2630 OpSize;
2631
2632 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2633 (ins i128mem:$src),
2634 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2635 [(set VR128:$dst,
2636 (IntId128
2637 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002638}
2639
2640/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begemanfea2be52008-02-09 23:46:37 +00002641multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2642 Intrinsic IntId64, Intrinsic IntId128> {
2643 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2644 (ins VR64:$src),
2645 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2646 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002647
Nate Begemanfea2be52008-02-09 23:46:37 +00002648 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2649 (ins i64mem:$src),
2650 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2651 [(set VR64:$dst,
2652 (IntId64
2653 (bitconvert (memopv2i32 addr:$src))))]>;
2654
2655 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2656 (ins VR128:$src),
2657 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2658 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2659 OpSize;
2660
2661 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2662 (ins i128mem:$src),
2663 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2664 [(set VR128:$dst,
2665 (IntId128
2666 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002667}
2668
2669defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2670 int_x86_ssse3_pabs_b,
2671 int_x86_ssse3_pabs_b_128>;
2672defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2673 int_x86_ssse3_pabs_w,
2674 int_x86_ssse3_pabs_w_128>;
2675defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2676 int_x86_ssse3_pabs_d,
2677 int_x86_ssse3_pabs_d_128>;
2678
2679/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
Evan Chenge9083d62008-03-05 08:19:16 +00002680let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002681 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2682 Intrinsic IntId64, Intrinsic IntId128,
2683 bit Commutable = 0> {
2684 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2685 (ins VR64:$src1, VR64:$src2),
2686 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2687 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2688 let isCommutable = Commutable;
2689 }
2690 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2691 (ins VR64:$src1, i64mem:$src2),
2692 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2693 [(set VR64:$dst,
2694 (IntId64 VR64:$src1,
2695 (bitconvert (memopv8i8 addr:$src2))))]>;
2696
2697 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2698 (ins VR128:$src1, VR128:$src2),
2699 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2700 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2701 OpSize {
2702 let isCommutable = Commutable;
2703 }
2704 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2705 (ins VR128:$src1, i128mem:$src2),
2706 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2707 [(set VR128:$dst,
2708 (IntId128 VR128:$src1,
2709 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2710 }
2711}
2712
2713/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
Evan Chenge9083d62008-03-05 08:19:16 +00002714let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002715 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2716 Intrinsic IntId64, Intrinsic IntId128,
2717 bit Commutable = 0> {
2718 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2719 (ins VR64:$src1, VR64:$src2),
2720 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2721 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2722 let isCommutable = Commutable;
2723 }
2724 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2725 (ins VR64:$src1, i64mem:$src2),
2726 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2727 [(set VR64:$dst,
2728 (IntId64 VR64:$src1,
2729 (bitconvert (memopv4i16 addr:$src2))))]>;
2730
2731 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2732 (ins VR128:$src1, VR128:$src2),
2733 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2734 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2735 OpSize {
2736 let isCommutable = Commutable;
2737 }
2738 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2739 (ins VR128:$src1, i128mem:$src2),
2740 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2741 [(set VR128:$dst,
2742 (IntId128 VR128:$src1,
2743 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2744 }
2745}
2746
2747/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
Evan Chenge9083d62008-03-05 08:19:16 +00002748let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002749 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2750 Intrinsic IntId64, Intrinsic IntId128,
2751 bit Commutable = 0> {
2752 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2753 (ins VR64:$src1, VR64:$src2),
2754 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2755 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2756 let isCommutable = Commutable;
2757 }
2758 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2759 (ins VR64:$src1, i64mem:$src2),
2760 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2761 [(set VR64:$dst,
2762 (IntId64 VR64:$src1,
2763 (bitconvert (memopv2i32 addr:$src2))))]>;
2764
2765 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2766 (ins VR128:$src1, VR128:$src2),
2767 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2768 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2769 OpSize {
2770 let isCommutable = Commutable;
2771 }
2772 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2773 (ins VR128:$src1, i128mem:$src2),
2774 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2775 [(set VR128:$dst,
2776 (IntId128 VR128:$src1,
2777 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2778 }
2779}
2780
Chris Lattner65de1b92010-04-17 07:38:24 +00002781let ImmT = NoImm in { // None of these have i8 immediate fields.
Bill Wendling76d708b2007-08-10 06:22:27 +00002782defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2783 int_x86_ssse3_phadd_w,
Evan Cheng4e444432008-06-16 21:16:24 +00002784 int_x86_ssse3_phadd_w_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002785defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2786 int_x86_ssse3_phadd_d,
Evan Cheng4e444432008-06-16 21:16:24 +00002787 int_x86_ssse3_phadd_d_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002788defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2789 int_x86_ssse3_phadd_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002790 int_x86_ssse3_phadd_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002791defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2792 int_x86_ssse3_phsub_w,
2793 int_x86_ssse3_phsub_w_128>;
2794defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2795 int_x86_ssse3_phsub_d,
2796 int_x86_ssse3_phsub_d_128>;
2797defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2798 int_x86_ssse3_phsub_sw,
2799 int_x86_ssse3_phsub_sw_128>;
2800defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2801 int_x86_ssse3_pmadd_ub_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002802 int_x86_ssse3_pmadd_ub_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002803defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2804 int_x86_ssse3_pmul_hr_sw,
2805 int_x86_ssse3_pmul_hr_sw_128, 1>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00002806
Bill Wendling76d708b2007-08-10 06:22:27 +00002807defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2808 int_x86_ssse3_pshuf_b,
2809 int_x86_ssse3_pshuf_b_128>;
2810defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2811 int_x86_ssse3_psign_b,
2812 int_x86_ssse3_psign_b_128>;
2813defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2814 int_x86_ssse3_psign_w,
2815 int_x86_ssse3_psign_w_128>;
Evan Chenged7f56b2009-05-28 18:48:53 +00002816defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
Bill Wendling76d708b2007-08-10 06:22:27 +00002817 int_x86_ssse3_psign_d,
2818 int_x86_ssse3_psign_d_128>;
Chris Lattner65de1b92010-04-17 07:38:24 +00002819}
Bill Wendling76d708b2007-08-10 06:22:27 +00002820
Eric Christophercff6f852010-04-15 01:40:20 +00002821// palignr patterns.
Evan Chenge9083d62008-03-05 08:19:16 +00002822let Constraints = "$src1 = $dst" in {
Bill Wendlingae9671b2007-08-10 09:00:17 +00002823 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002824 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002825 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002826 []>;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002827 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002828 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002829 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002830 []>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002831
Bill Wendlingae9671b2007-08-10 09:00:17 +00002832 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002833 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002834 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002835 []>, OpSize;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002836 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002837 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002838 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002839 []>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002840}
Bill Wendlingddd35322007-05-02 23:11:52 +00002841
Eric Christopher6d972fd2010-04-20 00:59:54 +00002842let AddedComplexity = 5 in {
2843
Eric Christophercff6f852010-04-15 01:40:20 +00002844def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2845 (PALIGNR64rr VR64:$src2, VR64:$src1,
2846 (SHUFFLE_get_palign_imm VR64:$src3))>,
2847 Requires<[HasSSSE3]>;
2848def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2849 (PALIGNR64rr VR64:$src2, VR64:$src1,
2850 (SHUFFLE_get_palign_imm VR64:$src3))>,
2851 Requires<[HasSSSE3]>;
2852def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2853 (PALIGNR64rr VR64:$src2, VR64:$src1,
2854 (SHUFFLE_get_palign_imm VR64:$src3))>,
2855 Requires<[HasSSSE3]>;
2856def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2857 (PALIGNR64rr VR64:$src2, VR64:$src1,
2858 (SHUFFLE_get_palign_imm VR64:$src3))>,
2859 Requires<[HasSSSE3]>;
2860def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2861 (PALIGNR64rr VR64:$src2, VR64:$src1,
2862 (SHUFFLE_get_palign_imm VR64:$src3))>,
2863 Requires<[HasSSSE3]>;
Evan Cheng89321162009-10-28 06:30:34 +00002864
Nate Begemana09008b2009-10-19 02:17:23 +00002865def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2866 (PALIGNR128rr VR128:$src2, VR128:$src1,
2867 (SHUFFLE_get_palign_imm VR128:$src3))>,
2868 Requires<[HasSSSE3]>;
2869def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2870 (PALIGNR128rr VR128:$src2, VR128:$src1,
2871 (SHUFFLE_get_palign_imm VR128:$src3))>,
2872 Requires<[HasSSSE3]>;
2873def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2874 (PALIGNR128rr VR128:$src2, VR128:$src1,
2875 (SHUFFLE_get_palign_imm VR128:$src3))>,
2876 Requires<[HasSSSE3]>;
2877def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2878 (PALIGNR128rr VR128:$src2, VR128:$src1,
2879 (SHUFFLE_get_palign_imm VR128:$src3))>,
2880 Requires<[HasSSSE3]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002881}
Nate Begemana09008b2009-10-19 02:17:23 +00002882
Nate Begemanb9a47b82009-02-23 08:49:38 +00002883def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2884 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2885def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2886 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2887
Eric Christopher44b93ff2009-07-31 20:07:27 +00002888//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002889// Non-Instruction Patterns
Eric Christopher44b93ff2009-07-31 20:07:27 +00002890//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002891
Eric Christopher44b93ff2009-07-31 20:07:27 +00002892// extload f32 -> f64. This matches load+fextend because we have a hack in
2893// the isel (PreprocessForFPConvert) that can introduce loads after dag
2894// combine.
Chris Lattnerd43d00c2008-01-24 08:07:48 +00002895// Since these loads aren't folded into the fextend, we have to match it
2896// explicitly here.
2897let Predicates = [HasSSE2] in
2898 def : Pat<(fextend (loadf32 addr:$src)),
2899 (CVTSS2SDrm addr:$src)>;
2900
Evan Cheng2c0dbd02006-03-24 02:58:06 +00002901// bit_convert
Chris Lattner4cc84ed2006-10-07 04:52:09 +00002902let Predicates = [HasSSE2] in {
2903 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2904 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2905 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2906 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2907 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2908 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2909 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2910 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2911 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2912 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2913 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2914 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2915 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2916 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2917 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2918 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2919 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2920 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2921 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2922 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2923 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2924 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2925 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2926 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2927 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2928 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2929 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2930 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2931 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2932 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2933}
Evan Chengb9df0ca2006-03-22 02:53:00 +00002934
Evan Cheng017dcc62006-04-21 01:05:10 +00002935// Move scalar to XMM zero-extended
2936// movd to XMM register zero-extends
Evan Chengf2ea84a2006-10-09 21:42:15 +00002937let AddedComplexity = 15 in {
Evan Cheng017dcc62006-04-21 01:05:10 +00002938// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Evan Chengd880b972008-05-09 21:53:03 +00002939def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002940 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002941def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002942 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
Evan Cheng23573e52008-05-09 23:37:55 +00002943def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002944 (MOVSSrr (v4f32 (V_SET0PS)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002945 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
Evan Cheng331e2bd2008-07-10 01:08:23 +00002946def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002947 (MOVSSrr (v4i32 (V_SET0PI)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002948 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
Evan Cheng017dcc62006-04-21 01:05:10 +00002949}
Evan Chengbc4832b2006-03-24 23:15:12 +00002950
Evan Chengb9df0ca2006-03-22 02:53:00 +00002951// Splat v2f64 / v2i64
Evan Chengfd111b52006-04-19 21:15:24 +00002952let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002953def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002954 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002955def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002956 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002957def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002958 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002959def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002960 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengfd111b52006-04-19 21:15:24 +00002961}
Evan Cheng475aecf2006-03-29 03:04:49 +00002962
Evan Chengb7a5c522006-04-18 21:55:35 +00002963// Special unary SHUFPSrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002964def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2965 (SHUFPSrri VR128:$src1, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00002966 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002967let AddedComplexity = 5 in
2968def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2969 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2970 Requires<[HasSSE2]>;
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002971// Special unary SHUFPDrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002972def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002973 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002974 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2975 Requires<[HasSSE2]>;
2976// Special unary SHUFPDrri case.
2977def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002978 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002979 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002980 Requires<[HasSSE2]>;
Evan Cheng3d60df42006-04-10 22:35:16 +00002981// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Nate Begeman9008ca62009-04-27 18:41:29 +00002982def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2983 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng7d9061e2006-03-30 19:54:57 +00002984 Requires<[HasSSE2]>;
Evan Chengb7a75a52008-09-26 23:41:32 +00002985
Evan Cheng3d60df42006-04-10 22:35:16 +00002986// Special binary v4i32 shuffle cases with SHUFPS.
Nate Begeman9008ca62009-04-27 18:41:29 +00002987def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002988 (SHUFPSrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002989 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002990 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002991def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002992 (SHUFPSrmi VR128:$src1, addr:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002993 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002994 Requires<[HasSSE2]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002995// Special binary v2i64 shuffle cases using SHUFPDrri.
Nate Begeman9008ca62009-04-27 18:41:29 +00002996def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002997 (SHUFPDrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002998 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002999 Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00003000
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00003001// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00003002let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003003def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3004 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003005 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003006def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3007 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003008 Requires<[OptForSpeed, HasSSE2]>;
3009}
Evan Chengfd111b52006-04-19 21:15:24 +00003010let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003011def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003012 (UNPCKLPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003013def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003014 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003015def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003016 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003017def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003018 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
Evan Chengfd111b52006-04-19 21:15:24 +00003019}
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00003020
Evan Cheng174f8032007-05-17 18:44:37 +00003021// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00003022let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003023def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3024 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003025 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003026def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3027 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003028 Requires<[OptForSpeed, HasSSE2]>;
3029}
Evan Cheng174f8032007-05-17 18:44:37 +00003030let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003031def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003032 (UNPCKHPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003033def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003034 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003035def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003036 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003037def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003038 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
Evan Cheng174f8032007-05-17 18:44:37 +00003039}
3040
Evan Chengb7a75a52008-09-26 23:41:32 +00003041let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003042// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
Nate Begeman0b10b912009-11-07 23:17:15 +00003043def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003044 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003045
3046// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003047def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003048 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003049
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003050// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003051def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003052 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003053def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003054 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003055}
Evan Cheng9d09b892006-05-31 00:51:37 +00003056
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003057let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003058// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003059def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003060 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003061def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003062 (MOVLPDrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003063def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003064 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003065def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003066 (MOVLPDrm VR128:$src1, addr:$src2)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003067}
Evan Cheng64e97692006-04-24 21:58:20 +00003068
Evan Chengcd0baf22008-05-23 21:23:16 +00003069// (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003070def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003071 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003072def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003073 (MOVLPDmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003074def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3075 addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003076 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003077def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003078 (MOVLPDmr addr:$src1, VR128:$src2)>;
Evan Chengcd0baf22008-05-23 21:23:16 +00003079
Evan Chengf2ea84a2006-10-09 21:42:15 +00003080let AddedComplexity = 15 in {
Evan Cheng64e97692006-04-24 21:58:20 +00003081// Setting the lowest element in the vector.
Nate Begeman9008ca62009-04-27 18:41:29 +00003082def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003083 (MOVSSrr (v4i32 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003084 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003085def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003086 (MOVSDrr (v2i64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003087 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
Evan Chenga7fc6422006-04-24 23:34:56 +00003088
Dan Gohman874cada2010-02-28 00:17:42 +00003089// vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
Nate Begeman9008ca62009-04-27 18:41:29 +00003090def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003091 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003092 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003093def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003094 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003095 Requires<[HasSSE2]>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003096}
Evan Cheng9e062ed2006-05-03 20:32:03 +00003097
Eli Friedman7e2242b2009-06-19 07:00:55 +00003098// vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3099// fall back to this for SSE1)
3100def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003101 (SHUFPSrri VR128:$src2, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00003102 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Eli Friedman7e2242b2009-06-19 07:00:55 +00003103
Evan Chenga7fc6422006-04-24 23:34:56 +00003104// Set lowest element and zero upper elements.
Evan Chengd880b972008-05-09 21:53:03 +00003105def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
Evan Chengfd17f422008-05-08 22:35:02 +00003106 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengcdfc3c82006-04-17 22:45:49 +00003107
Evan Cheng2c3ae372006-04-12 21:21:57 +00003108// Some special case pandn patterns.
3109def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3110 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003111 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003112def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3113 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003114 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003115def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3116 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003117 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00003118
Evan Cheng2c3ae372006-04-12 21:21:57 +00003119def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003120 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003121 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003122def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003123 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003124 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003125def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003126 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003127 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng206ee9d2006-07-07 08:33:52 +00003128
Nate Begemanb348d182007-11-17 03:58:34 +00003129// vector -> vector casts
3130def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3131 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3132def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3133 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
Eli Friedmand0c0fae2008-09-05 23:07:03 +00003134def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3135 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3136def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3137 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
Nate Begemanb348d182007-11-17 03:58:34 +00003138
Evan Chengb4162fd2007-07-20 00:27:43 +00003139// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohmand3006222007-07-27 17:16:43 +00003140def : Pat<(alignedloadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003141 (MOVAPSrm addr:$src)>;
Dan Gohmand3006222007-07-27 17:16:43 +00003142def : Pat<(loadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003143 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003144def : Pat<(alignedloadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003145 (MOVAPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003146def : Pat<(loadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003147 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003148
3149def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003150 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003151def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003152 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003153def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003154 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003155def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003156 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003157def : Pat<(store (v2i64 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003158 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003159def : Pat<(store (v4i32 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003160 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003161def : Pat<(store (v8i16 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003162 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003163def : Pat<(store (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003164 (MOVUPSmr addr:$dst, VR128:$src)>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003165
Nate Begeman63ec90a2008-02-03 07:18:54 +00003166//===----------------------------------------------------------------------===//
3167// SSE4.1 Instructions
3168//===----------------------------------------------------------------------===//
3169
Dale Johannesene397acc2008-10-10 23:51:03 +00003170multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003171 string OpcodeStr,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003172 Intrinsic V4F32Int,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003173 Intrinsic V2F64Int> {
Nate Begeman63ec90a2008-02-03 07:18:54 +00003174 // Intrinsic operation, reg.
Nate Begeman63ec90a2008-02-03 07:18:54 +00003175 // Vector intrinsic operation, reg
Eric Christopher44b93ff2009-07-31 20:07:27 +00003176 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003177 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003178 !strconcat(OpcodeStr,
3179 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003180 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3181 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003182
3183 // Vector intrinsic operation, mem
Evan Cheng400073d2009-12-18 07:40:29 +00003184 def PSm_Int : Ii8<opcps, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003185 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003186 !strconcat(OpcodeStr,
3187 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003188 [(set VR128:$dst,
3189 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
Evan Cheng400073d2009-12-18 07:40:29 +00003190 TA, OpSize,
Evan Chengb1f49812009-12-22 17:47:23 +00003191 Requires<[HasSSE41]>;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003192
Nate Begeman63ec90a2008-02-03 07:18:54 +00003193 // Vector intrinsic operation, reg
Evan Cheng172b7942008-03-14 07:39:27 +00003194 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003195 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003196 !strconcat(OpcodeStr,
3197 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003198 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3199 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003200
3201 // Vector intrinsic operation, mem
Evan Cheng172b7942008-03-14 07:39:27 +00003202 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003203 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003204 !strconcat(OpcodeStr,
3205 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003206 [(set VR128:$dst,
3207 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003208 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003209}
3210
Dale Johannesene397acc2008-10-10 23:51:03 +00003211let Constraints = "$src1 = $dst" in {
3212multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3213 string OpcodeStr,
3214 Intrinsic F32Int,
3215 Intrinsic F64Int> {
3216 // Intrinsic operation, reg.
3217 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003218 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003219 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3220 !strconcat(OpcodeStr,
3221 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003222 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003223 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3224 OpSize;
3225
3226 // Intrinsic operation, mem.
Eric Christopher44b93ff2009-07-31 20:07:27 +00003227 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3228 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003229 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003230 !strconcat(OpcodeStr,
Dale Johannesene397acc2008-10-10 23:51:03 +00003231 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003232 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003233 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3234 OpSize;
3235
3236 // Intrinsic operation, reg.
3237 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003238 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003239 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3240 !strconcat(OpcodeStr,
3241 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003242 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003243 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3244 OpSize;
3245
3246 // Intrinsic operation, mem.
3247 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003248 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003249 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3250 !strconcat(OpcodeStr,
3251 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003252 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003253 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3254 OpSize;
3255}
3256}
3257
Nate Begeman63ec90a2008-02-03 07:18:54 +00003258// FP round - roundss, roundps, roundsd, roundpd
Dale Johannesene397acc2008-10-10 23:51:03 +00003259defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3260 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3261defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3262 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003263
3264// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3265multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3266 Intrinsic IntId128> {
3267 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3268 (ins VR128:$src),
3269 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3270 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3271 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3272 (ins i128mem:$src),
3273 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3274 [(set VR128:$dst,
3275 (IntId128
3276 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3277}
3278
3279defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3280 int_x86_sse41_phminposuw>;
3281
3282/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003283let Constraints = "$src1 = $dst" in {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003284 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3285 Intrinsic IntId128, bit Commutable = 0> {
Nate Begemanfea2be52008-02-09 23:46:37 +00003286 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3287 (ins VR128:$src1, VR128:$src2),
3288 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3289 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3290 OpSize {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003291 let isCommutable = Commutable;
3292 }
Nate Begemanfea2be52008-02-09 23:46:37 +00003293 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3294 (ins VR128:$src1, i128mem:$src2),
3295 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3296 [(set VR128:$dst,
3297 (IntId128 VR128:$src1,
3298 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003299 }
3300}
3301
3302defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3303 int_x86_sse41_pcmpeqq, 1>;
3304defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3305 int_x86_sse41_packusdw, 0>;
3306defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3307 int_x86_sse41_pminsb, 1>;
3308defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3309 int_x86_sse41_pminsd, 1>;
3310defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3311 int_x86_sse41_pminud, 1>;
3312defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3313 int_x86_sse41_pminuw, 1>;
3314defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3315 int_x86_sse41_pmaxsb, 1>;
3316defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3317 int_x86_sse41_pmaxsd, 1>;
3318defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3319 int_x86_sse41_pmaxud, 1>;
3320defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3321 int_x86_sse41_pmaxuw, 1>;
Nate Begeman204e84e2008-02-04 06:00:24 +00003322
Mon P Wangaf9b9522008-12-18 21:42:19 +00003323defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3324
Nate Begeman30a0de92008-07-17 16:51:19 +00003325def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3326 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3327def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3328 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3329
Nate Begeman1426d522008-02-09 01:38:08 +00003330/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003331let Constraints = "$src1 = $dst" in {
Dan Gohman0b924dc2008-05-23 17:49:40 +00003332 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3333 SDNode OpNode, Intrinsic IntId128,
3334 bit Commutable = 0> {
Nate Begeman1426d522008-02-09 01:38:08 +00003335 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3336 (ins VR128:$src1, VR128:$src2),
3337 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman0b924dc2008-05-23 17:49:40 +00003338 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3339 VR128:$src2))]>, OpSize {
Nate Begeman1426d522008-02-09 01:38:08 +00003340 let isCommutable = Commutable;
3341 }
3342 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3343 (ins VR128:$src1, VR128:$src2),
3344 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3345 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3346 OpSize {
3347 let isCommutable = Commutable;
3348 }
3349 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3350 (ins VR128:$src1, i128mem:$src2),
3351 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3352 [(set VR128:$dst,
Chris Lattner1a7d0872010-02-18 06:33:42 +00003353 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003354 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3355 (ins VR128:$src1, i128mem:$src2),
3356 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3357 [(set VR128:$dst,
Evan Chengb1938262008-05-23 00:37:07 +00003358 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
Nate Begeman1426d522008-02-09 01:38:08 +00003359 OpSize;
3360 }
3361}
Eric Christopher8258d0b2010-03-30 18:49:01 +00003362
3363/// SS48I_binop_rm - Simple SSE41 binary operator.
3364let Constraints = "$src1 = $dst" in {
3365multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3366 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003367 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003368 (ins VR128:$src1, VR128:$src2),
3369 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3370 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3371 OpSize {
3372 let isCommutable = Commutable;
3373 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003374 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003375 (ins VR128:$src1, i128mem:$src2),
3376 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3377 [(set VR128:$dst, (OpNode VR128:$src1,
3378 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3379 OpSize;
3380}
3381}
3382
3383defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
Nate Begeman1426d522008-02-09 01:38:08 +00003384
Evan Cheng172b7942008-03-14 07:39:27 +00003385/// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
Evan Chenge9083d62008-03-05 08:19:16 +00003386let Constraints = "$src1 = $dst" in {
Nate Begeman204e84e2008-02-04 06:00:24 +00003387 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3388 Intrinsic IntId128, bit Commutable = 0> {
Evan Cheng172b7942008-03-14 07:39:27 +00003389 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003390 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003391 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003392 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003393 [(set VR128:$dst,
Nate Begemanfea2be52008-02-09 23:46:37 +00003394 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3395 OpSize {
Nate Begeman204e84e2008-02-04 06:00:24 +00003396 let isCommutable = Commutable;
3397 }
Evan Cheng172b7942008-03-14 07:39:27 +00003398 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003399 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3400 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003401 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begemanfea2be52008-02-09 23:46:37 +00003402 [(set VR128:$dst,
3403 (IntId128 VR128:$src1,
3404 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3405 OpSize;
Nate Begeman204e84e2008-02-04 06:00:24 +00003406 }
3407}
3408
3409defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3410 int_x86_sse41_blendps, 0>;
3411defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3412 int_x86_sse41_blendpd, 0>;
3413defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3414 int_x86_sse41_pblendw, 0>;
3415defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3416 int_x86_sse41_dpps, 1>;
3417defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3418 int_x86_sse41_dppd, 1>;
3419defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
Eric Christopher419e2232010-04-08 00:52:02 +00003420 int_x86_sse41_mpsadbw, 0>;
Nate Begeman1426d522008-02-09 01:38:08 +00003421
Nate Begemanfea2be52008-02-09 23:46:37 +00003422
Evan Cheng172b7942008-03-14 07:39:27 +00003423/// SS41I_ternary_int - SSE 4.1 ternary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003424let Uses = [XMM0], Constraints = "$src1 = $dst" in {
Nate Begemanab5d56c2008-02-10 18:47:57 +00003425 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3426 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3427 (ins VR128:$src1, VR128:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003428 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003429 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3430 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3431 OpSize;
3432
3433 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3434 (ins VR128:$src1, i128mem:$src2),
3435 !strconcat(OpcodeStr,
3436 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3437 [(set VR128:$dst,
3438 (IntId VR128:$src1,
3439 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3440 }
3441}
3442
3443defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3444defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3445defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3446
3447
Nate Begemanfea2be52008-02-09 23:46:37 +00003448multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3449 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3450 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3451 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3452
3453 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3454 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003455 [(set VR128:$dst,
3456 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3457 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003458}
3459
3460defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3461defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3462defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3463defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3464defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3465defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3466
Evan Chengca57f782008-09-24 23:27:55 +00003467// Common patterns involving scalar load.
3468def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3469 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3470def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3471 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3472
3473def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3474 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3475def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3476 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3477
3478def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3479 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3480def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3481 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3482
3483def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3484 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3485def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3486 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3487
3488def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3489 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3490def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3491 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3492
3493def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3494 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3495def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3496 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3497
3498
Nate Begemanfea2be52008-02-09 23:46:37 +00003499multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3500 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3501 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3502 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3503
3504 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3505 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003506 [(set VR128:$dst,
3507 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3508 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003509}
3510
3511defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3512defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3513defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3514defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3515
Evan Chengca57f782008-09-24 23:27:55 +00003516// Common patterns involving scalar load
3517def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003518 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003519def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003520 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003521
3522def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003523 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003524def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003525 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003526
3527
Nate Begemanfea2be52008-02-09 23:46:37 +00003528multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3529 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3530 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3531 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3532
Evan Chengca57f782008-09-24 23:27:55 +00003533 // Expecting a i16 load any extended to i32 value.
Nate Begemanfea2be52008-02-09 23:46:37 +00003534 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3535 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003536 [(set VR128:$dst, (IntId (bitconvert
3537 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3538 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003539}
3540
3541defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
Eli Friedman9d47b8d2009-06-06 05:55:37 +00003542defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
Nate Begemanfea2be52008-02-09 23:46:37 +00003543
Evan Chengca57f782008-09-24 23:27:55 +00003544// Common patterns involving scalar load
3545def : Pat<(int_x86_sse41_pmovsxbq
3546 (bitconvert (v4i32 (X86vzmovl
3547 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003548 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003549
3550def : Pat<(int_x86_sse41_pmovzxbq
3551 (bitconvert (v4i32 (X86vzmovl
3552 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003553 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003554
Nate Begemanfea2be52008-02-09 23:46:37 +00003555
Nate Begeman14d12ca2008-02-11 04:19:36 +00003556/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3557multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003558 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003559 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003560 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003561 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003562 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3563 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003564 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003565 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003566 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003567 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003568 []>, OpSize;
3569// FIXME:
3570// There's an AssertZext in the way of writing the store pattern
3571// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begemanfea2be52008-02-09 23:46:37 +00003572}
3573
Nate Begeman14d12ca2008-02-11 04:19:36 +00003574defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003575
Nate Begeman14d12ca2008-02-11 04:19:36 +00003576
3577/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3578multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003579 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003580 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003581 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003582 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3583 []>, OpSize;
3584// FIXME:
3585// There's an AssertZext in the way of writing the store pattern
3586// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3587}
3588
3589defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3590
3591
3592/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3593multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003594 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003595 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003596 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003597 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3598 [(set GR32:$dst,
3599 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003600 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003601 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003602 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003603 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3604 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3605 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003606}
3607
Nate Begeman14d12ca2008-02-11 04:19:36 +00003608defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman1426d522008-02-09 01:38:08 +00003609
Nate Begeman14d12ca2008-02-11 04:19:36 +00003610
Evan Cheng62a3f152008-03-24 21:52:23 +00003611/// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3612/// destination
Nate Begeman14d12ca2008-02-11 04:19:36 +00003613multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003614 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003615 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003616 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003617 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Dan Gohman171c11e2008-04-16 02:32:24 +00003618 [(set GR32:$dst,
3619 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
Evan Cheng62a3f152008-03-24 21:52:23 +00003620 OpSize;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003621 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003622 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003623 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003624 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng62a3f152008-03-24 21:52:23 +00003625 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
Nate Begemanfea2be52008-02-09 23:46:37 +00003626 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003627}
3628
Nate Begeman14d12ca2008-02-11 04:19:36 +00003629defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003630
Dan Gohmand9ced092008-08-08 18:30:21 +00003631// Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3632def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3633 imm:$src2))),
3634 addr:$dst),
3635 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3636 Requires<[HasSSE41]>;
3637
Evan Chenge9083d62008-03-05 08:19:16 +00003638let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003639 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003640 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003641 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003642 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003643 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003644 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003645 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003646 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003647 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3648 !strconcat(OpcodeStr,
3649 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003650 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003651 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3652 imm:$src3))]>, OpSize;
3653 }
3654}
3655
3656defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3657
Evan Chenge9083d62008-03-05 08:19:16 +00003658let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003659 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003660 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003661 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003662 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003663 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003664 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003665 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3666 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003667 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003668 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3669 !strconcat(OpcodeStr,
3670 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003671 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003672 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3673 imm:$src3)))]>, OpSize;
3674 }
3675}
3676
3677defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3678
Eric Christopher1e5cdea2009-07-23 02:22:41 +00003679// insertps has a few different modes, there's the first two here below which
3680// are optimized inserts that won't zero arbitrary elements in the destination
3681// vector. The next one matches the intrinsic and could zero arbitrary elements
3682// in the target vector.
Evan Chenge9083d62008-03-05 08:19:16 +00003683let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003684 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
Eric Christopherfbd66872009-07-24 00:33:09 +00003685 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3686 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003687 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003688 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003689 [(set VR128:$dst,
3690 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003691 OpSize;
Eric Christopherfbd66872009-07-24 00:33:09 +00003692 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003693 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3694 !strconcat(OpcodeStr,
3695 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003696 [(set VR128:$dst,
Eric Christopherfbd66872009-07-24 00:33:09 +00003697 (X86insrtps VR128:$src1,
3698 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003699 imm:$src3))]>, OpSize;
3700 }
3701}
3702
Evan Cheng7aae8762008-03-26 08:11:49 +00003703defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003704
Eric Christopherfbd66872009-07-24 00:33:09 +00003705def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3706 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3707
Eric Christopher71c67532009-07-29 00:28:05 +00003708// ptest instruction we'll lower to this in X86ISelLowering primarily from
3709// the intel intrinsic that corresponds to this.
Nate Begemanbc4efb82008-03-16 21:14:46 +00003710let Defs = [EFLAGS] in {
3711def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003712 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003713 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3714 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003715def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003716 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003717 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3718 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003719}
3720
3721def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3722 "movntdqa\t{$src, $dst|$dst, $src}",
Kevin Enderby40fe18f2010-02-10 00:10:31 +00003723 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3724 OpSize;
Nate Begeman30a0de92008-07-17 16:51:19 +00003725
Eric Christopherb120ab42009-08-18 22:50:32 +00003726
3727//===----------------------------------------------------------------------===//
3728// SSE4.2 Instructions
3729//===----------------------------------------------------------------------===//
3730
Nate Begeman30a0de92008-07-17 16:51:19 +00003731/// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3732let Constraints = "$src1 = $dst" in {
3733 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3734 Intrinsic IntId128, bit Commutable = 0> {
3735 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3736 (ins VR128:$src1, VR128:$src2),
3737 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3738 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3739 OpSize {
3740 let isCommutable = Commutable;
3741 }
3742 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3743 (ins VR128:$src1, i128mem:$src2),
3744 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3745 [(set VR128:$dst,
3746 (IntId128 VR128:$src1,
3747 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3748 }
3749}
3750
Nate Begemane99b2552008-07-17 17:04:58 +00003751defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
Nate Begeman30a0de92008-07-17 16:51:19 +00003752
3753def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3754 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3755def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3756 (PCMPGTQrm VR128:$src1, addr:$src2)>;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003757
3758// crc intrinsic instruction
3759// This set of instructions are only rm, the only difference is the size
3760// of r and m.
3761let Constraints = "$src1 = $dst" in {
Eric Christopher027c2b12009-08-10 21:48:58 +00003762 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003763 (ins GR32:$src1, i8mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003764 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003765 [(set GR32:$dst,
3766 (int_x86_sse42_crc32_8 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003767 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003768 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003769 (ins GR32:$src1, GR8:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003770 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003771 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003772 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003773 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003774 (ins GR32:$src1, i16mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003775 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003776 [(set GR32:$dst,
3777 (int_x86_sse42_crc32_16 GR32:$src1,
3778 (load addr:$src2)))]>,
3779 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003780 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003781 (ins GR32:$src1, GR16:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003782 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003783 [(set GR32:$dst,
Eric Christopher027c2b12009-08-10 21:48:58 +00003784 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003785 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003786 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003787 (ins GR32:$src1, i32mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003788 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003789 [(set GR32:$dst,
3790 (int_x86_sse42_crc32_32 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003791 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003792 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003793 (ins GR32:$src1, GR32:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003794 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003795 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003796 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3797 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3798 (ins GR64:$src1, i8mem:$src2),
3799 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003800 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003801 (int_x86_sse42_crc64_8 GR64:$src1,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003802 (load addr:$src2)))]>,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003803 REX_W;
3804 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3805 (ins GR64:$src1, GR8:$src2),
3806 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003807 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003808 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3809 REX_W;
3810 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3811 (ins GR64:$src1, i64mem:$src2),
3812 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3813 [(set GR64:$dst,
3814 (int_x86_sse42_crc64_64 GR64:$src1,
3815 (load addr:$src2)))]>,
3816 REX_W;
3817 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3818 (ins GR64:$src1, GR64:$src2),
3819 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3820 [(set GR64:$dst,
3821 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3822 REX_W;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003823}
Eric Christopherb120ab42009-08-18 22:50:32 +00003824
3825// String/text processing instructions.
Dan Gohman533297b2009-10-29 18:10:34 +00003826let Defs = [EFLAGS], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003827def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003828 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3829 "#PCMPISTRM128rr PSEUDO!",
3830 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3831 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003832def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003833 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3834 "#PCMPISTRM128rm PSEUDO!",
3835 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3836 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003837}
3838
3839let Defs = [XMM0, EFLAGS] in {
3840def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003841 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3842 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003843def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003844 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3845 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003846}
3847
Sean Callanan108934c2009-12-18 00:01:26 +00003848let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003849def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003850 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3851 "#PCMPESTRM128rr PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003852 [(set VR128:$dst,
3853 (int_x86_sse42_pcmpestrm128
Sean Callanan108934c2009-12-18 00:01:26 +00003854 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3855
Eric Christopherb120ab42009-08-18 22:50:32 +00003856def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003857 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3858 "#PCMPESTRM128rm PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003859 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3860 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003861 OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003862}
3863
3864let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
Sean Callanan47234e62009-08-20 18:24:27 +00003865def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003866 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3867 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Sean Callanan47234e62009-08-20 18:24:27 +00003868def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003869 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3870 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003871}
3872
3873let Defs = [ECX, EFLAGS] in {
3874 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003875 def rr : SS42AI<0x63, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003876 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3877 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3878 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3879 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003880 def rm : SS42AI<0x63, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003881 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3882 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3883 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3884 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003885 }
3886}
3887
3888defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3889defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3890defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3891defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3892defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3893defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3894
3895let Defs = [ECX, EFLAGS] in {
3896let Uses = [EAX, EDX] in {
3897 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3898 def rr : SS42AI<0x61, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003899 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3900 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3901 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3902 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003903 def rm : SS42AI<0x61, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003904 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3905 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003906 [(set ECX,
Sean Callanan108934c2009-12-18 00:01:26 +00003907 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3908 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003909 }
3910}
3911}
3912
3913defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3914defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3915defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3916defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3917defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3918defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003919
3920//===----------------------------------------------------------------------===//
3921// AES-NI Instructions
3922//===----------------------------------------------------------------------===//
3923
3924let Constraints = "$src1 = $dst" in {
3925 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3926 Intrinsic IntId128, bit Commutable = 0> {
3927 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3928 (ins VR128:$src1, VR128:$src2),
3929 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3930 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3931 OpSize {
3932 let isCommutable = Commutable;
3933 }
3934 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3935 (ins VR128:$src1, i128mem:$src2),
3936 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3937 [(set VR128:$dst,
3938 (IntId128 VR128:$src1,
3939 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3940 }
3941}
3942
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003943defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3944 int_x86_aesni_aesenc>;
3945defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3946 int_x86_aesni_aesenclast>;
3947defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3948 int_x86_aesni_aesdec>;
3949defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3950 int_x86_aesni_aesdeclast>;
3951
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003952def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3953 (AESENCrr VR128:$src1, VR128:$src2)>;
3954def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3955 (AESENCrm VR128:$src1, addr:$src2)>;
3956def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3957 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3958def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3959 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3960def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3961 (AESDECrr VR128:$src1, VR128:$src2)>;
3962def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3963 (AESDECrm VR128:$src1, addr:$src2)>;
3964def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3965 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3966def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3967 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3968
Eric Christopherb3500fd2010-04-02 23:48:33 +00003969def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3970 (ins VR128:$src1),
3971 "aesimc\t{$src1, $dst|$dst, $src1}",
3972 [(set VR128:$dst,
3973 (int_x86_aesni_aesimc VR128:$src1))]>,
3974 OpSize;
3975
3976def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3977 (ins i128mem:$src1),
3978 "aesimc\t{$src1, $dst|$dst, $src1}",
3979 [(set VR128:$dst,
3980 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3981 OpSize;
3982
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003983def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003984 (ins VR128:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003985 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3986 [(set VR128:$dst,
3987 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3988 OpSize;
3989def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003990 (ins i128mem:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003991 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3992 [(set VR128:$dst,
3993 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
3994 imm:$src2))]>,
3995 OpSize;