blob: 4f20dbe0bf277b9c22fe7f0a6df471574d730466 [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///
Evan Chenge9083d62008-03-05 08:19:16 +0000702let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000703multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
704 SDNode OpNode, bit Commutable = 0> {
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000705
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000706 let Constraints = "", isAsmParserOnly = 1 in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000707 defm V#NAME#SS : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000708 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000709 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000710
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000711 defm V#NAME#SD : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000712 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000713 OpNode, FR64, f64mem>, XD, VEX_4V;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000714
715 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
716 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
717 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
718 VEX_4V;
719
720 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
721 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
722 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
723 OpSize, VEX_4V;
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000724
725 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
726 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
727 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
728
729 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
730 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
731 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
Bill Wendlingddd35322007-05-02 23:11:52 +0000732 }
733
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000734 let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000735 defm SS : sse12_fp_scalar<opc,
736 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
737 OpNode, FR32, f32mem>, XS;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000738
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000739 defm SD : sse12_fp_scalar<opc,
740 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
741 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesc902a592010-06-11 23:50:47 +0000742
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000743 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
744 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
745 f128mem, memopv4f32, SSEPackedSingle>, TB;
Dan Gohman20382522007-07-10 00:05:58 +0000746
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000747 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
748 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
749 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
Bruno Cardoso Lopescf125d02010-06-12 01:53:48 +0000750
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000751 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000752 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000753 "", "_ss", ssmem, sse_load_f32>, XS;
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000754
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000755 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000756 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000757 "2", "_sd", sdmem, sse_load_f64>, XD;
Bruno Cardoso Lopes2dcf6d62010-06-12 03:12:14 +0000758 }
Bill Wendlingddd35322007-05-02 23:11:52 +0000759}
760}
761
762// Arithmetic instructions
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000763defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd, 1>;
764defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul, 1>;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000765
766let isCommutable = 0 in {
767 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
768 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
769}
Bill Wendlingddd35322007-05-02 23:11:52 +0000770
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000771/// sse12_fp_binop_rm - Other SSE 1 & 2 binops
Dan Gohman20382522007-07-10 00:05:58 +0000772///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000773/// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
Dan Gohman20382522007-07-10 00:05:58 +0000774/// instructions for a full-vector intrinsic form. Operations that map
775/// onto C operators don't use this form since they just use the plain
776/// vector form instead of having a separate vector intrinsic form.
777///
778/// This provides a total of eight "instructions".
779///
Evan Chenge9083d62008-03-05 08:19:16 +0000780let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000781multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
782 SDNode OpNode, bit Commutable = 0> {
Dan Gohman20382522007-07-10 00:05:58 +0000783
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000784 let Constraints = "", isAsmParserOnly = 1 in {
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000785 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000786 defm V#NAME#SS : sse12_fp_scalar<opc,
787 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
788 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000789
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000790 defm V#NAME#SD : sse12_fp_scalar<opc,
791 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
792 OpNode, FR64, f64mem>, XD, VEX_4V;
Dan Gohman20382522007-07-10 00:05:58 +0000793 }
794
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000795 let Constraints = "$src1 = $dst" in {
796 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000797 defm SS : sse12_fp_scalar<opc,
798 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
799 OpNode, FR32, f32mem>, XS;
800 defm SD : sse12_fp_scalar<opc,
801 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
802 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000803 }
804
Dan Gohman20382522007-07-10 00:05:58 +0000805 // Vector operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000806 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
807 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000808 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman20382522007-07-10 00:05:58 +0000809 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
810 let isCommutable = Commutable;
811 }
812
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000813 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
814 (ins VR128:$src1, VR128:$src2),
815 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
816 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
817 let isCommutable = Commutable;
818 }
819
Dan Gohman20382522007-07-10 00:05:58 +0000820 // Vector operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000821 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
822 (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000823 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +0000824 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohman20382522007-07-10 00:05:58 +0000825
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000826 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
827 (ins VR128:$src1, f128mem:$src2),
828 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
829 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
830
Dan Gohman20382522007-07-10 00:05:58 +0000831 // Intrinsic operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000832 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst),
833 (ins VR128:$src1, VR128:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000834 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
835 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
836 !strconcat(OpcodeStr, "_ss")) VR128:$src1,
837 VR128:$src2))]> {
838 // int_x86_sse_xxx_ss
839 let isCommutable = Commutable;
840 }
841
842 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst),
843 (ins VR128:$src1, VR128:$src2),
844 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
845 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
846 !strconcat(OpcodeStr, "_sd")) VR128:$src1,
847 VR128:$src2))]> {
848 // int_x86_sse2_xxx_sd
Dan Gohman20382522007-07-10 00:05:58 +0000849 let isCommutable = Commutable;
850 }
851
852 // Intrinsic operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000853 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst),
854 (ins VR128:$src1, ssmem:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000855 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
856 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
857 !strconcat(OpcodeStr, "_ss")) VR128:$src1,
Dan Gohman20382522007-07-10 00:05:58 +0000858 sse_load_f32:$src2))]>;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000859 // int_x86_sse_xxx_ss
860
861 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst),
862 (ins VR128:$src1, sdmem:$src2),
863 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
864 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
865 !strconcat(OpcodeStr, "_sd")) VR128:$src1,
866 sse_load_f64:$src2))]>;
867 // int_x86_sse2_xxx_sd
Dan Gohman20382522007-07-10 00:05:58 +0000868
869 // Vector intrinsic operation, reg+reg.
Evan Chengb1938262008-05-23 00:37:07 +0000870 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst),
871 (ins VR128:$src1, VR128:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000872 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
873 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
874 !strconcat(OpcodeStr, "_ps")) VR128:$src1,
875 VR128:$src2))]> {
876 // int_x86_sse_xxx_ps
877 let isCommutable = Commutable;
878 }
879
880 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst),
881 (ins VR128:$src1, VR128:$src2),
882 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
883 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
884 !strconcat(OpcodeStr, "_pd")) VR128:$src1,
885 VR128:$src2))]> {
886 // int_x86_sse2_xxx_pd
Dan Gohman20382522007-07-10 00:05:58 +0000887 let isCommutable = Commutable;
888 }
889
890 // Vector intrinsic operation, reg+mem.
Evan Chengb1938262008-05-23 00:37:07 +0000891 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst),
892 (ins VR128:$src1, f128mem:$src2),
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000893 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
894 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse_",
895 !strconcat(OpcodeStr, "_ps")) VR128:$src1,
896 (memopv4f32 addr:$src2)))]>;
897 // int_x86_sse_xxx_ps
898
899 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst),
900 (ins VR128:$src1, f128mem:$src2),
901 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
902 [(set VR128:$dst, (!nameconcat<Intrinsic>("int_x86_sse2_",
903 !strconcat(OpcodeStr, "_pd")) VR128:$src1,
904 (memopv2f64 addr:$src2)))]>;
905 // int_x86_sse2_xxx_pd
Dan Gohman20382522007-07-10 00:05:58 +0000906}
907}
908
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000909let isCommutable = 0 in {
910 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
911 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
912}
Bill Wendlingddd35322007-05-02 23:11:52 +0000913
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000914//===----------------------------------------------------------------------===//
Evan Cheng9ab1ac52006-04-14 23:32:40 +0000915// SSE packed FP Instructions
Evan Chengc12e6c42006-03-19 09:38:54 +0000916
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000917// Move Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +0000918let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000919def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000920 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000921let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000922def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000923 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000924 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Evan Chengffcb95b2006-02-21 19:13:53 +0000925
Evan Cheng64d80e32007-07-19 01:14:50 +0000926def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000927 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000928 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000929
Chris Lattnerf77e0372008-01-11 06:59:07 +0000930let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000931def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000932 "movups\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000933let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000934def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000935 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000936 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000937def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000938 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000939 [(store (v4f32 VR128:$src), addr:$dst)]>;
940
941// Intrinsic forms of MOVUPS load and store
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000942let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000943def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000944 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000945 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000946def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000947 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000948 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000949
Evan Chenge9083d62008-03-05 08:19:16 +0000950let Constraints = "$src1 = $dst" in {
Dan Gohman32791e02007-06-25 15:44:19 +0000951 let AddedComplexity = 20 in {
952 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000953 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000954 "movlps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000955 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000956 (movlp VR128:$src1,
957 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000958 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000959 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000960 "movhps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000961 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000962 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +0000963 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000964 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000965} // Constraints = "$src1 = $dst"
Evan Cheng4fcb9222006-03-28 02:43:26 +0000966
Evan Chengb70ea0b2008-05-10 00:59:18 +0000967
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000968def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
Chris Lattner3485b512010-03-08 18:57:56 +0000969 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000970
Evan Cheng64d80e32007-07-19 01:14:50 +0000971def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000972 "movlps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000973 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
Evan Cheng015188f2006-06-15 08:14:54 +0000974 (iPTR 0))), addr:$dst)]>;
Evan Cheng9bbfd4f2006-03-28 07:01:28 +0000975
Evan Cheng664ade72006-04-07 21:20:58 +0000976// v2f64 extract element 1 is always custom lowered to unpack high to low
977// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +0000978def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000979 "movhps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000980 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +0000981 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
982 (undef)), (iPTR 0))), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000983
Evan Chenge9083d62008-03-05 08:19:16 +0000984let Constraints = "$src1 = $dst" in {
Evan Chengb7a75a52008-09-26 23:41:32 +0000985let AddedComplexity = 20 in {
Evan Cheng0af934e2009-05-12 20:17:52 +0000986def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
987 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000988 "movlhps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000989 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000990 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2c0dbd02006-03-24 02:58:06 +0000991
Evan Cheng0af934e2009-05-12 20:17:52 +0000992def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
993 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000994 "movhlps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000995 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000996 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2dadaea2006-04-19 20:37:34 +0000997} // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000998} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +0000999
Nate Begemanec8eee22009-04-29 22:47:44 +00001000let AddedComplexity = 20 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00001001def : Pat<(v4f32 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +00001002 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +00001003def : Pat<(v2i64 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +00001004 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +00001005}
Evan Cheng0b457f02008-09-25 20:50:48 +00001006
Bill Wendlingddd35322007-05-02 23:11:52 +00001007
1008
Dan Gohman20382522007-07-10 00:05:58 +00001009// Arithmetic
1010
1011/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
Bill Wendlingddd35322007-05-02 23:11:52 +00001012///
Dan Gohman20382522007-07-10 00:05:58 +00001013/// In addition, we also have a special variant of the scalar form here to
1014/// represent the associated intrinsic operation. This form is unlike the
1015/// plain scalar form, in that it takes an entire vector (instead of a
1016/// scalar) and leaves the top elements undefined.
1017///
1018/// And, we have a special variant form for a full-vector intrinsic form.
1019///
1020/// These four forms can each have a reg or a mem operand, so there are a
1021/// total of eight "instructions".
1022///
1023multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
1024 SDNode OpNode,
1025 Intrinsic F32Int,
1026 Intrinsic V4F32Int,
1027 bit Commutable = 0> {
1028 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001029 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001030 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001031 [(set FR32:$dst, (OpNode FR32:$src))]> {
Bill Wendlingddd35322007-05-02 23:11:52 +00001032 let isCommutable = Commutable;
1033 }
1034
Dan Gohman20382522007-07-10 00:05:58 +00001035 // Scalar operation, mem.
Evan Cheng400073d2009-12-18 07:40:29 +00001036 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001037 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Evan Cheng400073d2009-12-18 07:40:29 +00001038 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001039 Requires<[HasSSE1, OptForSize]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001040
Dan Gohman20382522007-07-10 00:05:58 +00001041 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001042 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001043 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001044 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1045 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001046 }
1047
Dan Gohman20382522007-07-10 00:05:58 +00001048 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001049 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001050 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001051 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001052
1053 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001054 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001055 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001056 [(set VR128:$dst, (F32Int VR128:$src))]> {
1057 let isCommutable = Commutable;
1058 }
1059
1060 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001061 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001062 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001063 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1064
1065 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001066 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001067 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001068 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1069 let isCommutable = Commutable;
1070 }
1071
1072 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001073 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001074 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001075 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001076}
1077
Dan Gohman20382522007-07-10 00:05:58 +00001078// Square root.
1079defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1080 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1081
1082// Reciprocal approximations. Note that these typically require refinement
1083// in order to obtain suitable precision.
1084defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1085 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1086defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1087 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1088
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001089/// sse12_fp_pack_logical - SSE 1 & 2 packed FP logical ops
1090///
1091multiclass sse12_fp_pack_logical<bits<8> opc, string OpcodeStr,
1092 SDNode OpNode, int HasPat = 0,
1093 bit Commutable = 1,
1094 list<list<dag>> Pattern = []> {
1095 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
1096 (ins VR128:$src1, VR128:$src2),
1097 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1098 !if(HasPat, Pattern[0],
1099 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1100 VR128:$src2)))])>
1101 { let isCommutable = Commutable; }
1102
1103 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1104 (ins VR128:$src1, VR128:$src2),
1105 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1106 !if(HasPat, Pattern[1],
1107 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1108 (bc_v2i64 (v2f64 VR128:$src2))))])>
1109 { let isCommutable = Commutable; }
1110
1111 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
1112 (ins VR128:$src1, f128mem:$src2),
1113 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1114 !if(HasPat, Pattern[2],
1115 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1116 (memopv2i64 addr:$src2)))])>;
1117
1118 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1119 (ins VR128:$src1, f128mem:$src2),
1120 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1121 !if(HasPat, Pattern[3],
1122 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1123 (memopv2i64 addr:$src2)))])>;
1124}
1125
Bill Wendlingddd35322007-05-02 23:11:52 +00001126// Logical
Evan Chenge9083d62008-03-05 08:19:16 +00001127let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001128 defm AND : sse12_fp_pack_logical<0x54, "and", and>;
1129 defm OR : sse12_fp_pack_logical<0x56, "or", or>;
1130 defm XOR : sse12_fp_pack_logical<0x57, "xor", xor>;
1131 defm ANDN : sse12_fp_pack_logical<0x55, "andn", undef /* dummy */, 1, 0, [
1132 // single r+r
1133 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1134 (bc_v2i64 (v4i32 immAllOnesV))),
1135 VR128:$src2)))],
1136 // double r+r
1137 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1138 (bc_v2i64 (v2f64 VR128:$src2))))],
1139 // single r+m
1140 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1141 (bc_v2i64 (v4i32 immAllOnesV))),
1142 (memopv2i64 addr:$src2))))],
1143 // double r+m
1144 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1145 (memopv2i64 addr:$src2)))]]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001146}
1147
Evan Chenge9083d62008-03-05 08:19:16 +00001148let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001149 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Nate Begemanc2616e42008-05-12 20:34:32 +00001150 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1151 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1152 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1153 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001154 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Nate Begemanc2616e42008-05-12 20:34:32 +00001155 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1156 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1157 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001158 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001159
1160 // Accept explicit immediate argument form instead of comparison code.
1161let isAsmParserOnly = 1 in {
1162 def CMPPSrri_alt : PSIi8<0xC2, MRMSrcReg,
1163 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1164 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1165 def CMPPSrmi_alt : PSIi8<0xC2, MRMSrcMem,
1166 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1167 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1168}
Bill Wendlingddd35322007-05-02 23:11:52 +00001169}
Nate Begeman30a0de92008-07-17 16:51:19 +00001170def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001171 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00001172def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001173 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001174
1175// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001176let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001177 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
Eric Christopher44b93ff2009-07-31 20:07:27 +00001178 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001179 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001180 VR128:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001181 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001182 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001183 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001184 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001185 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001186 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001187 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001188 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001189 (v4f32 (shufp:$src3
1190 VR128:$src1, (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001191
1192 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001193 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001194 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001195 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001196 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001197 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001198 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001199 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001200 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001201 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001202 (v4f32 (unpckh VR128:$src1,
1203 (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001204
Eric Christopher44b93ff2009-07-31 20:07:27 +00001205 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001206 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001207 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001208 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001209 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001210 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001211 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001212 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001213 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001214 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001215 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001216} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001217
1218// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00001219def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001220 "movmskps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001221 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Cheng8a0b2da2009-05-28 18:55:28 +00001222def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001223 "movmskpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001224 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1225
Evan Cheng27b7db52008-03-08 00:58:38 +00001226// Prefetch intrinsic.
1227def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1228 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1229def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1230 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1231def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1232 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1233def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1234 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001235
1236// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00001237def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001238 "movntps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001239 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1240
David Greene8939b0d2010-02-16 20:50:18 +00001241let AddedComplexity = 400 in { // Prefer non-temporal versions
1242def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1243 "movntps\t{$src, $dst|$dst, $src}",
1244 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1245
1246def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1247 "movntdq\t{$src, $dst|$dst, $src}",
1248 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1249
David Greene8939b0d2010-02-16 20:50:18 +00001250def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1251 "movnti\t{$src, $dst|$dst, $src}",
1252 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1253 TB, Requires<[HasSSE2]>;
1254
1255def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1256 "movnti\t{$src, $dst|$dst, $src}",
1257 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1258 TB, Requires<[HasSSE2]>;
1259}
1260
Bill Wendlingddd35322007-05-02 23:11:52 +00001261// Load, store, and memory fence
Dan Gohmanee5673b2010-05-20 01:23:41 +00001262def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1263 TB, Requires<[HasSSE1]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001264
1265// MXCSR register
Evan Cheng64d80e32007-07-19 01:14:50 +00001266def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001267 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001268def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001269 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001270
1271// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00001272// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00001273// load of an all-zeros value if folding it would be beneficial.
Chris Lattner28c1d292010-02-05 21:30:49 +00001274// FIXME: Change encoding to pseudo!
Daniel Dunbar7417b762009-08-11 22:17:52 +00001275let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001276 isCodeGenOnly = 1 in {
1277def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1278 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1279def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1280 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1281let ExeDomain = SSEPackedInt in
1282def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00001283 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001284}
Bill Wendlingddd35322007-05-02 23:11:52 +00001285
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001286def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1287def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1288def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
Evan Chengc8e3b142008-03-12 07:02:50 +00001289
Dan Gohman874cada2010-02-28 00:17:42 +00001290def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001291 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001292
Eric Christopher44b93ff2009-07-31 20:07:27 +00001293//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001294// SSE2 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00001295//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001296
Dan Gohman874cada2010-02-28 00:17:42 +00001297// Move Instructions. Register-to-register movsd is not used for FR64
1298// register copies because it's a partial register update; FsMOVAPDrr is
1299// used instead. Register-to-register movsd is not modeled as an INSERT_SUBREG
1300// because INSERT_SUBREG requires that the insert be implementable in terms of
1301// a copy, and just mentioned, we don't use movsd for copies.
1302let Constraints = "$src1 = $dst" in
1303def MOVSDrr : SDI<0x10, MRMSrcReg,
1304 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
1305 "movsd\t{$src2, $dst|$dst, $src2}",
Chris Lattner3d005782010-03-15 05:53:30 +00001306 [(set (v2f64 VR128:$dst),
Dan Gohman874cada2010-02-28 00:17:42 +00001307 (movl VR128:$src1, (scalar_to_vector FR64:$src2)))]>;
1308
1309// Extract the low 64-bit value from one vector and insert it into another.
1310let AddedComplexity = 15 in
1311def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
Chris Lattner3485b512010-03-08 18:57:56 +00001312 (MOVSDrr (v2f64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001313 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001314
1315// Implicitly promote a 64-bit scalar to a vector.
1316def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001317 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001318
1319// Loading from memory automatically zeroing upper bits.
1320let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 20 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001321def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001322 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001323 [(set FR64:$dst, (loadf64 addr:$src))]>;
Dan Gohman874cada2010-02-28 00:17:42 +00001324
1325// MOVSDrm zeros the high parts of the register; represent this
1326// with SUBREG_TO_REG.
1327let AddedComplexity = 20 in {
1328def : Pat<(v2f64 (X86vzmovl (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 (scalar_to_vector (loadf64 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 (loadv2f64 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 (X86vzmovl (bc_v2f64 (loadv4f32 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 +00001336def : Pat<(v2f64 (X86vzload addr:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001337 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001338}
1339
1340// Store scalar value to memory.
Evan Cheng64d80e32007-07-19 01:14:50 +00001341def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001342 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001343 [(store FR64:$src, addr:$dst)]>;
1344
Dan Gohman874cada2010-02-28 00:17:42 +00001345// Extract and store.
1346def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
1347 addr:$dst),
1348 (MOVSDmr addr:$dst,
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001349 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001350
Bill Wendlingddd35322007-05-02 23:11:52 +00001351// Conversion instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00001352def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001353 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001354 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001355def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001356 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001357 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001358def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001359 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001360 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001361def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001362 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Evan Cheng400073d2009-12-18 07:40:29 +00001363 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
Evan Chengb1f49812009-12-22 17:47:23 +00001364 Requires<[HasSSE2, OptForSize]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001365def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001366 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001367 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001368def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001369 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001370 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1371
Sean Callanan5ab94032009-09-16 01:13:52 +00001372def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1373 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1374def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1375 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1376def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1377 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1378def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1379 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1380def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1381 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1382def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1383 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1384def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1385 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1386def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1387 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1388def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1389 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1390def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1391 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1392
Bill Wendlingddd35322007-05-02 23:11:52 +00001393// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001394def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001395 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001396 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1397 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001398def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001399 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001400 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001401 Requires<[HasSSE2, OptForSize]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001402
1403def : Pat<(extloadf32 addr:$src),
Dan Gohman874cada2010-02-28 00:17:42 +00001404 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1405 Requires<[HasSSE2, OptForSpeed]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001406
1407// Match intrinsics which expect XMM operand(s).
Evan Cheng64d80e32007-07-19 01:14:50 +00001408def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001409 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001410 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001411def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001412 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001413 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1414 (load addr:$src)))]>;
1415
Dan Gohmand9c2af52010-05-26 18:03:53 +00001416// Match intrinsics which expect MM and XMM operand(s).
Dale Johannesenc7842082007-10-30 22:15:38 +00001417def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1418 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1419 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1420def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1421 "cvtpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001422 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001423 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001424def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1425 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1426 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1427def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1428 "cvttpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001429 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001430 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001431def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1432 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1433 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1434def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1435 "cvtpi2pd\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001436 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
Dale Johannesenc7842082007-10-30 22:15:38 +00001437 (load addr:$src)))]>;
1438
Bill Wendlingddd35322007-05-02 23:11:52 +00001439// Aliases for intrinsics
Evan Cheng64d80e32007-07-19 01:14:50 +00001440def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001441 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001442 [(set GR32:$dst,
1443 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001444def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001445 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001446 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1447 (load addr:$src)))]>;
1448
1449// Comparison instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001450let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001451 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001452 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001453 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001454let mayLoad = 1 in
Eric Christopher44b93ff2009-07-31 20:07:27 +00001455 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001456 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001457 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001458
1459 // Accept explicit immediate argument form instead of comparison code.
1460let isAsmParserOnly = 1 in {
1461 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
1462 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
1463 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1464let mayLoad = 1 in
1465 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
1466 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
1467 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1468}
Bill Wendlingddd35322007-05-02 23:11:52 +00001469}
1470
Evan Cheng0488db92007-09-25 01:57:46 +00001471let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001472def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001473 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001474 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001475def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001476 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001477 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001478} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001479
Bill Wendlingddd35322007-05-02 23:11:52 +00001480// Aliases to match intrinsics which expect XMM operand(s).
Evan Chenge9083d62008-03-05 08:19:16 +00001481let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001482 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001483 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001484 (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001485 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001486 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1487 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001488 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001489 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001490 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001491 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001492 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1493 (load addr:$src), imm:$cc))]>;
1494}
1495
Evan Cheng0488db92007-09-25 01:57:46 +00001496let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001497def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001498 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001499 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1500 VR128:$src2))]>;
Evan Chenge5f62042007-09-29 00:00:36 +00001501def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001502 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001503 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1504 (load addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001505
Evan Cheng64d80e32007-07-19 01:14:50 +00001506def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001507 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001508 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1509 VR128:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001510def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001511 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001512 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1513 (load addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001514} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001515
Eric Christopher44b93ff2009-07-31 20:07:27 +00001516// Aliases of packed SSE2 instructions for scalar use. These all have names
1517// that start with 'Fs'.
Bill Wendlingddd35322007-05-02 23:11:52 +00001518
1519// Alias instructions that map fld0 to pxor for sse.
Dan Gohman4a0b3e12009-09-21 18:30:38 +00001520let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1521 canFoldAsLoad = 1 in
Chris Lattnerbe1778f2010-02-05 21:34:18 +00001522def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1523 [(set FR64:$dst, fpimm0)]>,
Bill Wendlingddd35322007-05-02 23:11:52 +00001524 Requires<[HasSSE2]>, TB, OpSize;
1525
Dan Gohman32791e02007-06-25 15:44:19 +00001526// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001527// disregarded.
Chris Lattnerba7e7562008-01-10 07:59:24 +00001528let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001529def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001530 "movapd\t{$src, $dst|$dst, $src}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001531
Dan Gohman32791e02007-06-25 15:44:19 +00001532// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001533// disregarded.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001534let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001535def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001536 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohmand3006222007-07-27 17:16:43 +00001537 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001538
Eric Christopher44b93ff2009-07-31 20:07:27 +00001539//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001540// SSE packed FP Instructions
1541
1542// Move Instructions
Chris Lattnerba7e7562008-01-10 07:59:24 +00001543let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001544def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001545 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001546let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001547def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001548 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001549 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001550
Evan Cheng64d80e32007-07-19 01:14:50 +00001551def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001552 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001553 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001554
Chris Lattnerf77e0372008-01-11 06:59:07 +00001555let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001556def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001557 "movupd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001558let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001559def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001560 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001561 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001562def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001563 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001564 [(store (v2f64 VR128:$src), addr:$dst)]>;
1565
1566// Intrinsic forms of MOVUPD load and store
Evan Cheng64d80e32007-07-19 01:14:50 +00001567def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001568 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001569 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001570def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001571 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001572 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001573
Evan Chenge9083d62008-03-05 08:19:16 +00001574let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001575 let AddedComplexity = 20 in {
1576 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001577 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001578 "movlpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001579 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001580 (v2f64 (movlp VR128:$src1,
1581 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001582 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001583 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001584 "movhpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001585 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +00001586 (v2f64 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001587 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001588 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001589} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001590
Evan Cheng64d80e32007-07-19 01:14:50 +00001591def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001592 "movlpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001593 [(store (f64 (vector_extract (v2f64 VR128:$src),
1594 (iPTR 0))), addr:$dst)]>;
1595
1596// v2f64 extract element 1 is always custom lowered to unpack high to low
1597// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +00001598def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001599 "movhpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001600 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +00001601 (v2f64 (unpckh VR128:$src, (undef))),
1602 (iPTR 0))), addr:$dst)]>;
Evan Chengd9539472006-04-14 21:59:03 +00001603
Evan Cheng470a6ad2006-02-22 02:26:30 +00001604// SSE2 instructions without OpSize prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001605def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001606 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001607 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1608 TB, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001609def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001610 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1611 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1612 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001613 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001614
1615// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001616def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001617 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001618 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1619 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001620def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001621 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1622 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1623 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001624 XS, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001625
Evan Cheng64d80e32007-07-19 01:14:50 +00001626def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001627 "cvtps2dq\t{$src, $dst|$dst, $src}",
1628 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001629def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001630 "cvtps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001631 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001632 (memop addr:$src)))]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001633// SSE2 packed instructions with XS prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001634def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1635 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1636def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1637 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1638
Evan Cheng64d80e32007-07-19 01:14:50 +00001639def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001640 "cvttps2dq\t{$src, $dst|$dst, $src}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001641 [(set VR128:$dst,
Sean Callanan108934c2009-12-18 00:01:26 +00001642 (int_x86_sse2_cvttps2dq VR128:$src))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001643 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001644def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001645 "cvttps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001646 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001647 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001648 XS, Requires<[HasSSE2]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001649
Evan Cheng470a6ad2006-02-22 02:26:30 +00001650// SSE2 packed instructions with XD prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001651def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001652 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001653 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1654 XD, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001655def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001656 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001657 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001658 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001659 XD, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001660
Evan Cheng64d80e32007-07-19 01:14:50 +00001661def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001662 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001663 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Cheng029d9da2008-03-14 07:46:48 +00001664def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001665 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001666 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001667 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001668
1669// SSE2 instructions without OpSize prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001670def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1671 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1672def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1673 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1674
Evan Cheng64d80e32007-07-19 01:14:50 +00001675def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001676 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001677 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1678 TB, Requires<[HasSSE2]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001679def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001680 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001681 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
Chris Lattner15258d52006-10-07 06:17:43 +00001682 (load addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001683 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001684
Sean Callanan108934c2009-12-18 00:01:26 +00001685def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1686 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1687def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1688 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1689
1690
Evan Cheng64d80e32007-07-19 01:14:50 +00001691def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001692 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001693 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001694def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001695 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001696 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
Evan Chengb1938262008-05-23 00:37:07 +00001697 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001698
Evan Chengd2a6d542006-04-12 23:42:44 +00001699// Match intrinsics which expect XMM operand(s).
1700// Aliases for intrinsics
Evan Chenge9083d62008-03-05 08:19:16 +00001701let Constraints = "$src1 = $dst" in {
Evan Chengd2a6d542006-04-12 23:42:44 +00001702def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001703 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001704 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001705 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
Evan Cheng069287d2006-05-16 07:21:53 +00001706 GR32:$src2))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001707def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001708 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001709 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001710 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1711 (loadi32 addr:$src2)))]>;
1712def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001713 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001714 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001715 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1716 VR128:$src2))]>;
1717def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001718 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001719 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001720 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001721 (load addr:$src2)))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001722def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001723 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001724 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001725 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1726 VR128:$src2))]>, XS,
1727 Requires<[HasSSE2]>;
1728def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001729 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001730 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001731 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001732 (load addr:$src2)))]>, XS,
Evan Chengd2a6d542006-04-12 23:42:44 +00001733 Requires<[HasSSE2]>;
1734}
1735
Dan Gohman20382522007-07-10 00:05:58 +00001736// Arithmetic
1737
1738/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
Chris Lattner6f987732006-10-07 21:17:13 +00001739///
Dan Gohman20382522007-07-10 00:05:58 +00001740/// In addition, we also have a special variant of the scalar form here to
1741/// represent the associated intrinsic operation. This form is unlike the
1742/// plain scalar form, in that it takes an entire vector (instead of a
1743/// scalar) and leaves the top elements undefined.
1744///
1745/// And, we have a special variant form for a full-vector intrinsic form.
1746///
1747/// These four forms can each have a reg or a mem operand, so there are a
1748/// total of eight "instructions".
1749///
1750multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1751 SDNode OpNode,
1752 Intrinsic F64Int,
1753 Intrinsic V2F64Int,
1754 bit Commutable = 0> {
1755 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001756 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001757 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001758 [(set FR64:$dst, (OpNode FR64:$src))]> {
Chris Lattner6f987732006-10-07 21:17:13 +00001759 let isCommutable = Commutable;
1760 }
Bill Wendlingddd35322007-05-02 23:11:52 +00001761
Dan Gohman20382522007-07-10 00:05:58 +00001762 // Scalar operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001763 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001764 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001765 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001766
Dan Gohman20382522007-07-10 00:05:58 +00001767 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001768 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001769 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001770 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1771 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001772 }
1773
Dan Gohman20382522007-07-10 00:05:58 +00001774 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001775 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001776 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001777 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001778
1779 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001780 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001781 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001782 [(set VR128:$dst, (F64Int VR128:$src))]> {
1783 let isCommutable = Commutable;
1784 }
1785
1786 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001787 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001788 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001789 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1790
1791 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001792 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001793 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001794 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1795 let isCommutable = Commutable;
1796 }
1797
1798 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001799 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001800 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001801 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
Evan Cheng97ac5fa2006-04-03 23:49:17 +00001802}
Evan Chengffcb95b2006-02-21 19:13:53 +00001803
Dan Gohman20382522007-07-10 00:05:58 +00001804// Square root.
1805defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1806 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1807
1808// There is no f64 version of the reciprocal approximation instructions.
1809
Evan Chenge9083d62008-03-05 08:19:16 +00001810let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001811 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001812 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1813 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1814 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Nate Begemanc2616e42008-05-12 20:34:32 +00001815 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001816 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Cheng029d9da2008-03-14 07:46:48 +00001817 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1818 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1819 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001820 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001821
1822 // Accept explicit immediate argument form instead of comparison code.
1823let isAsmParserOnly = 1 in {
1824 def CMPPDrri_alt : PDIi8<0xC2, MRMSrcReg,
1825 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1826 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1827 def CMPPDrmi_alt : PDIi8<0xC2, MRMSrcMem,
1828 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1829 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1830}
Evan Cheng470a6ad2006-02-22 02:26:30 +00001831}
Evan Chenge9d50352008-08-05 22:19:15 +00001832def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001833 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
Evan Chenge9d50352008-08-05 22:19:15 +00001834def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001835 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001836
1837// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001838let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001839 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001840 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1841 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begeman9008ca62009-04-27 18:41:29 +00001842 [(set VR128:$dst,
1843 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001844 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001845 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00001846 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001847 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001848 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001849 (v2f64 (shufp:$src3
1850 VR128:$src1, (memopv2f64 addr:$src2))))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001851
Bill Wendlingddd35322007-05-02 23:11:52 +00001852 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001853 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001854 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001855 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001856 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001857 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001858 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001859 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001860 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001861 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001862 (v2f64 (unpckh VR128:$src1,
1863 (memopv2f64 addr:$src2))))]>;
Evan Cheng4fcb9222006-03-28 02:43:26 +00001864
Eric Christopher44b93ff2009-07-31 20:07:27 +00001865 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001866 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001867 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001868 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001869 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001870 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001871 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001872 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001873 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001874 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001875 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001876} // Constraints = "$src1 = $dst"
Evan Cheng470a6ad2006-02-22 02:26:30 +00001877
Evan Cheng4b1734f2006-03-31 21:29:33 +00001878
Eric Christopher44b93ff2009-07-31 20:07:27 +00001879//===---------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001880// SSE integer instructions
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001881let ExeDomain = SSEPackedInt in {
Evan Chengbf156d12006-02-21 19:26:52 +00001882
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001883// Move Instructions
Chris Lattnerf77e0372008-01-11 06:59:07 +00001884let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001885def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001886 "movdqa\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001887let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001888def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001889 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001890 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001891let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001892def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001893 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001894 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001895let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001896def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001897 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001898 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001899 XS, Requires<[HasSSE2]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001900let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001901def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001902 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001903 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001904 XS, Requires<[HasSSE2]>;
Evan Cheng24dc1f52006-03-23 07:44:07 +00001905
Dan Gohman4106f372007-07-18 20:23:34 +00001906// Intrinsic forms of MOVDQU load and store
Dan Gohman15511cf2008-12-03 18:15:48 +00001907let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001908def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001909 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001910 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1911 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001912def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001913 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001914 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1915 XS, Requires<[HasSSE2]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001916
Evan Chenge7b8a8b2008-03-05 08:11:27 +00001917let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001918
Chris Lattner45e123c2006-10-07 19:02:31 +00001919multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1920 bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001921 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001922 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001923 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001924 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1925 let isCommutable = Commutable;
1926 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001927 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001928 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001929 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001930 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001931 (bitconvert (memopv2i64
Sean Callanan108934c2009-12-18 00:01:26 +00001932 addr:$src2))))]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001933}
Chris Lattner8139e282006-10-07 18:39:00 +00001934
Evan Cheng22b942a2008-05-03 00:52:09 +00001935multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1936 string OpcodeStr,
1937 Intrinsic IntId, Intrinsic IntId2> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001938 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001939 (ins VR128:$src1, VR128:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001940 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1941 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001942 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1943 (ins VR128:$src1, i128mem:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001944 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1945 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001946 (bitconvert (memopv2i64 addr:$src2))))]>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001947 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001948 (ins VR128:$src1, i32i8imm:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001949 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1950 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1951}
1952
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001953/// PDI_binop_rm - Simple SSE2 binary operator.
1954multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1955 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001956 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001957 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001958 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001959 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1960 let isCommutable = Commutable;
1961 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001962 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001963 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001964 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001965 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001966 (bitconvert (memopv2i64 addr:$src2)))))]>;
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001967}
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001968
1969/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1970///
1971/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1972/// to collapse (bitconvert VT to VT) into its operand.
1973///
1974multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1975 bit Commutable = 0> {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001976 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001977 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001978 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001979 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1980 let isCommutable = Commutable;
1981 }
Eric Christopher44b93ff2009-07-31 20:07:27 +00001982 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001983 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001984 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00001985 [(set VR128:$dst, (OpNode VR128:$src1,
Sean Callanan108934c2009-12-18 00:01:26 +00001986 (memopv2i64 addr:$src2)))]>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001987}
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001988
Evan Chenge9083d62008-03-05 08:19:16 +00001989} // Constraints = "$src1 = $dst"
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001990} // ExeDomain = SSEPackedInt
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001991
1992// 128-bit Integer Arithmetic
1993
1994defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1995defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1996defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001997defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001998
Chris Lattner45e123c2006-10-07 19:02:31 +00001999defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
2000defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
2001defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
2002defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002003
Chris Lattner7c47f9a2006-10-07 19:14:49 +00002004defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
2005defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
2006defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00002007defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002008
Chris Lattner45e123c2006-10-07 19:02:31 +00002009defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
2010defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
2011defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
2012defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00002013
Chris Lattner7c47f9a2006-10-07 19:14:49 +00002014defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00002015
Chris Lattner45e123c2006-10-07 19:02:31 +00002016defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
2017defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
2018defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00002019
Chris Lattner45e123c2006-10-07 19:02:31 +00002020defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
Chris Lattner77337992006-10-07 07:06:17 +00002021
Chris Lattner45e123c2006-10-07 19:02:31 +00002022defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
2023defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
Chris Lattner8139e282006-10-07 18:39:00 +00002024
Chris Lattner77337992006-10-07 07:06:17 +00002025
Chris Lattner45e123c2006-10-07 19:02:31 +00002026defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
2027defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
2028defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
2029defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
Bill Wendling3b1259b2009-05-28 02:04:00 +00002030defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
Evan Chengc60bd972006-03-25 09:37:23 +00002031
Chris Lattner77337992006-10-07 07:06:17 +00002032
Evan Cheng22b942a2008-05-03 00:52:09 +00002033defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
2034 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
2035defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
2036 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2037defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2038 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002039
Evan Cheng22b942a2008-05-03 00:52:09 +00002040defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2041 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2042defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2043 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
Nate Begeman32097bd2008-05-13 17:52:09 +00002044defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Cheng22b942a2008-05-03 00:52:09 +00002045 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002046
Evan Cheng22b942a2008-05-03 00:52:09 +00002047defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2048 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
Nate Begemanc9bdb002008-05-13 01:47:52 +00002049defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Cheng22b942a2008-05-03 00:52:09 +00002050 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
Chris Lattner77337992006-10-07 07:06:17 +00002051
Chris Lattner6970eda2006-10-07 19:49:05 +00002052// 128-bit logical shifts.
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002053let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2054 ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002055 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002056 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002057 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002058 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002059 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002060 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002061 // PSRADQri doesn't exist in SSE[1-3].
Evan Chengff65e382006-04-04 21:49:39 +00002062}
2063
Chris Lattner6970eda2006-10-07 19:49:05 +00002064let Predicates = [HasSSE2] in {
2065 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002066 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002067 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002068 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Bill Wendling5e249b42008-10-02 05:56:52 +00002069 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2070 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2071 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2072 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
Evan Cheng68c47cb2007-01-05 07:55:56 +00002073 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
Evan Cheng89321162009-10-28 06:30:34 +00002074 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002075
2076 // Shift up / down and insert zero's.
2077 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002078 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002079 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002080 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002081}
2082
Evan Cheng506d3df2006-03-29 23:07:14 +00002083// Logical
Chris Lattnera7ebe552006-10-07 19:37:30 +00002084defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2085defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2086defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2087
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002088let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002089 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002090 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002091 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002092 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2093 VR128:$src2)))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002094
Bill Wendlingddd35322007-05-02 23:11:52 +00002095 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002096 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002097 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002098 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002099 (memopv2i64 addr:$src2))))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002100}
2101
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002102// SSE2 Integer comparison
Bill Wendlingddd35322007-05-02 23:11:52 +00002103defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2104defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2105defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2106defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2107defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2108defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002109
Nate Begeman30a0de92008-07-17 16:51:19 +00002110def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002111 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002112def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002113 (PCMPEQBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002114def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002115 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002116def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002117 (PCMPEQWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002118def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002119 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002120def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002121 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2122
Nate Begeman30a0de92008-07-17 16:51:19 +00002123def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002124 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002125def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002126 (PCMPGTBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002127def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002128 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002129def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002130 (PCMPGTWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002131def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002132 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002133def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002134 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2135
2136
Evan Cheng506d3df2006-03-29 23:07:14 +00002137// Pack instructions
Chris Lattner45e123c2006-10-07 19:02:31 +00002138defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2139defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2140defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002141
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002142let ExeDomain = SSEPackedInt in {
2143
Evan Cheng506d3df2006-03-29 23:07:14 +00002144// Shuffle and unpack instructions
Nate Begemana09008b2009-10-19 02:17:23 +00002145let AddedComplexity = 5 in {
Evan Cheng8703be42006-04-04 19:12:30 +00002146def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002147 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002148 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002149 [(set VR128:$dst, (v4i32 (pshufd:$src2
2150 VR128:$src1, (undef))))]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002151def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002152 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002153 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002154 [(set VR128:$dst, (v4i32 (pshufd:$src2
Evan Chengc3630942009-12-09 21:00:30 +00002155 (bc_v4i32 (memopv2i64 addr:$src1)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002156 (undef))))]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002157}
Evan Cheng506d3df2006-03-29 23:07:14 +00002158
2159// SSE2 with ImmT == Imm8 and XS prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002160def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002161 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002162 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002163 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2164 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002165 XS, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002166def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002167 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002168 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002169 [(set VR128:$dst, (v8i16 (pshufhw:$src2
Eric Christopher44b93ff2009-07-31 20:07:27 +00002170 (bc_v8i16 (memopv2i64 addr:$src1)),
2171 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002172 XS, Requires<[HasSSE2]>;
2173
2174// SSE2 with ImmT == Imm8 and XD prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002175def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Nate Begeman9008ca62009-04-27 18:41:29 +00002176 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002177 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002178 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2179 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002180 XD, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002181def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Nate Begeman9008ca62009-04-27 18:41:29 +00002182 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002183 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002184 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2185 (bc_v8i16 (memopv2i64 addr:$src1)),
2186 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002187 XD, Requires<[HasSSE2]>;
2188
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002189// Unpack instructions
2190multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2191 PatFrag unp_frag, PatFrag bc_frag> {
2192 def rr : PDI<opc, MRMSrcReg,
2193 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2194 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2195 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2196 def rm : PDI<opc, MRMSrcMem,
2197 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2198 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2199 [(set VR128:$dst, (unp_frag VR128:$src1,
2200 (bc_frag (memopv2i64
2201 addr:$src2))))]>;
2202}
Evan Chengc60bd972006-03-25 09:37:23 +00002203
Evan Chenge9083d62008-03-05 08:19:16 +00002204let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002205 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2206 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2207 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2208
2209 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2210 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002211 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002212 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002213 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002214 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002215 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002216 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002217 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002218 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002219 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002220 (v2i64 (unpckl VR128:$src1,
2221 (memopv2i64 addr:$src2))))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002222
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002223 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2224 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2225 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2226
2227 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2228 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002229 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002230 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002231 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002232 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002233 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002234 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002235 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002236 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002237 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002238 (v2i64 (unpckh VR128:$src1,
2239 (memopv2i64 addr:$src2))))]>;
Evan Chenga971f6f2006-03-23 01:57:24 +00002240}
Evan Cheng82521dd2006-03-21 07:09:35 +00002241
Evan Chengb067a1e2006-03-31 19:22:53 +00002242// Extract / Insert
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002243def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002244 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002245 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002246 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begeman14d12ca2008-02-11 04:19:36 +00002247 imm:$src2))]>;
Evan Chenge9083d62008-03-05 08:19:16 +00002248let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002249 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002250 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002251 GR32:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002252 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002253 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002254 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002255 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002256 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002257 i16mem:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002258 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002259 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002260 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2261 imm:$src3))]>;
Evan Chengb067a1e2006-03-31 19:22:53 +00002262}
2263
Evan Chengc5fb2b12006-03-30 00:33:26 +00002264// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00002265def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002266 "pmovmskb\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002267 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
Evan Chengc5fb2b12006-03-30 00:33:26 +00002268
Evan Chengfcf5e212006-04-11 06:57:30 +00002269// Conditional store
Evan Cheng071a2792007-09-11 19:55:27 +00002270let Uses = [EDI] in
Evan Cheng64d80e32007-07-19 01:14:50 +00002271def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002272 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng071a2792007-09-11 19:55:27 +00002273 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Evan Chengfcf5e212006-04-11 06:57:30 +00002274
Evan Cheng1d768642009-02-10 22:06:28 +00002275let Uses = [RDI] in
2276def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2277 "maskmovdqu\t{$mask, $src|$src, $mask}",
2278 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2279
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002280} // ExeDomain = SSEPackedInt
2281
Evan Chengecac9cb2006-03-25 06:03:26 +00002282// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00002283def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2284 "movntpd\t{$src, $dst|$dst, $src}",
2285 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002286let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002287def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2288 "movntdq\t{$src, $dst|$dst, $src}",
2289 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2290def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002291 "movnti\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002292 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
Evan Chengfcf5e212006-04-11 06:57:30 +00002293 TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002294
David Greene8939b0d2010-02-16 20:50:18 +00002295let AddedComplexity = 400 in { // Prefer non-temporal versions
2296def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2297 "movntpd\t{$src, $dst|$dst, $src}",
2298 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2299
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002300let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002301def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2302 "movntdq\t{$src, $dst|$dst, $src}",
2303 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
David Greene8939b0d2010-02-16 20:50:18 +00002304}
2305
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002306// Flush cache
Evan Cheng64d80e32007-07-19 01:14:50 +00002307def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002308 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002309 TB, Requires<[HasSSE2]>;
2310
2311// Load, store, and memory fence
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002312def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002313 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002314def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002315 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002316
Dan Gohman14aaeac2010-05-20 01:35:50 +00002317// Pause. This "instruction" is encoded as "rep; nop", so even though it
Dan Gohmand9c2af52010-05-26 18:03:53 +00002318// was introduced with SSE2, it's backward compatible.
Dan Gohman14aaeac2010-05-20 01:35:50 +00002319def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2320
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002321//TODO: custom lower this so as to never even generate the noop
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002322def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002323 (i8 0)), (NOOP)>;
2324def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2325def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002326def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002327 (i8 1)), (MFENCE)>;
2328
Evan Chengffea91e2006-03-26 09:53:12 +00002329// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00002330// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00002331// load of an all-ones value if folding it would be beneficial.
Daniel Dunbar7417b762009-08-11 22:17:52 +00002332let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesen428e1522010-03-30 22:46:55 +00002333 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
Chris Lattner28c1d292010-02-05 21:30:49 +00002334 // FIXME: Change encoding to pseudo.
2335 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00002336 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Evan Cheng386031a2006-03-24 07:29:27 +00002337
Evan Cheng64d80e32007-07-19 01:14:50 +00002338def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002339 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002340 [(set VR128:$dst,
Evan Cheng069287d2006-05-16 07:21:53 +00002341 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002342def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002343 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002344 [(set VR128:$dst,
2345 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
Evan Chengebf01d62006-11-16 23:33:25 +00002346
Evan Cheng64d80e32007-07-19 01:14:50 +00002347def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002348 "movd\t{$src, $dst|$dst, $src}",
Chris Lattnerf3597a12006-12-05 18:45:06 +00002349 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2350
Evan Cheng64d80e32007-07-19 01:14:50 +00002351def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002352 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002353 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002354
Evan Cheng11e15b32006-04-03 20:53:28 +00002355// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00002356def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002357 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002358 [(set VR128:$dst,
2359 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2360 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002361def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002362 "movq\t{$src, $dst|$dst, $src}",
Evan Chengebf01d62006-11-16 23:33:25 +00002363 [(store (i64 (vector_extract (v2i64 VR128:$src),
2364 (iPTR 0))), addr:$dst)]>;
2365
Dan Gohman874cada2010-02-28 00:17:42 +00002366def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002367 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00002368
Evan Cheng64d80e32007-07-19 01:14:50 +00002369def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002370 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002371 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002372 (iPTR 0)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002373def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002374 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002375 [(store (i32 (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002376 (iPTR 0))), addr:$dst)]>;
Evan Cheng11e15b32006-04-03 20:53:28 +00002377
Evan Cheng64d80e32007-07-19 01:14:50 +00002378def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002379 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002380 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002381def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002382 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002383 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002384
Evan Cheng397edef2006-04-11 22:28:25 +00002385// Store / copy lower 64-bits of a XMM register.
Evan Cheng64d80e32007-07-19 01:14:50 +00002386def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002387 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng397edef2006-04-11 22:28:25 +00002388 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2389
Evan Cheng017dcc62006-04-21 01:05:10 +00002390// movd / movq to XMM register zero-extends
Evan Cheng7a831ce2007-12-15 03:00:47 +00002391let AddedComplexity = 15 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002392def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002393 "movd\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002394 [(set VR128:$dst, (v4i32 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002395 (v4i32 (scalar_to_vector GR32:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002396// This is X86-64 only.
2397def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2398 "mov{d|q}\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002399 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002400 (v2i64 (scalar_to_vector GR64:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002401}
2402
2403let AddedComplexity = 20 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002404def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002405 "movd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002406 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002407 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002408 (loadi32 addr:$src))))))]>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002409
2410def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2411 (MOVZDI2PDIrm addr:$src)>;
2412def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2413 (MOVZDI2PDIrm addr:$src)>;
Duncan Sandsd4b9c172008-06-13 19:07:40 +00002414def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2415 (MOVZDI2PDIrm addr:$src)>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002416
Evan Cheng64d80e32007-07-19 01:14:50 +00002417def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002418 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng7a831ce2007-12-15 03:00:47 +00002419 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002420 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002421 (loadi64 addr:$src))))))]>, XS,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002422 Requires<[HasSSE2]>;
Evan Cheng48090aa2006-03-21 23:01:21 +00002423
Evan Chengc36c0ab2008-05-22 18:56:56 +00002424def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2425 (MOVZQI2PQIrm addr:$src)>;
2426def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2427 (MOVZQI2PQIrm addr:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002428def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
Evan Chengb70ea0b2008-05-10 00:59:18 +00002429}
Evan Chengd880b972008-05-09 21:53:03 +00002430
Evan Cheng7a831ce2007-12-15 03:00:47 +00002431// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2432// IA32 document. movq xmm1, xmm2 does clear the high bits.
2433let AddedComplexity = 15 in
2434def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2435 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002436 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002437 XS, Requires<[HasSSE2]>;
2438
Evan Cheng8e8de682008-05-20 18:24:47 +00002439let AddedComplexity = 20 in {
Evan Cheng7a831ce2007-12-15 03:00:47 +00002440def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2441 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002442 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng8e8de682008-05-20 18:24:47 +00002443 (loadv2i64 addr:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002444 XS, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002445
Evan Cheng8e8de682008-05-20 18:24:47 +00002446def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2447 (MOVZPQILo2PQIrm addr:$src)>;
2448}
2449
Sean Callanan108934c2009-12-18 00:01:26 +00002450// Instructions for the disassembler
2451// xr = XMM register
2452// xm = mem64
2453
2454def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2455 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2456
Eric Christopher44b93ff2009-07-31 20:07:27 +00002457//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002458// SSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002459//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002460
Bill Wendlingddd35322007-05-02 23:11:52 +00002461// Move Instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00002462def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002463 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002464 [(set VR128:$dst, (v4f32 (movshdup
2465 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002466def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002467 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002468 [(set VR128:$dst, (movshdup
2469 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002470
Evan Cheng64d80e32007-07-19 01:14:50 +00002471def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002472 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002473 [(set VR128:$dst, (v4f32 (movsldup
2474 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002475def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002476 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002477 [(set VR128:$dst, (movsldup
2478 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002479
Evan Cheng64d80e32007-07-19 01:14:50 +00002480def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002481 "movddup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002482 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002483def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002484 "movddup\t{$src, $dst|$dst, $src}",
Evan Cheng0b457f02008-09-25 20:50:48 +00002485 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002486 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2487 (undef))))]>;
Evan Cheng0b457f02008-09-25 20:50:48 +00002488
Nate Begeman9008ca62009-04-27 18:41:29 +00002489def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2490 (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002491 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002492
2493let AddedComplexity = 5 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002494def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002495 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002496def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2497 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2498def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2499 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2500def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2501 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2502}
Bill Wendlingddd35322007-05-02 23:11:52 +00002503
2504// Arithmetic
Evan Chenge9083d62008-03-05 08:19:16 +00002505let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002506 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002507 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002508 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002509 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2510 VR128:$src2))]>;
2511 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002512 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002513 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002514 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002515 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002516 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002517 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002518 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002519 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2520 VR128:$src2))]>;
2521 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002522 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002523 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002524 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002525 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002526}
2527
Evan Cheng64d80e32007-07-19 01:14:50 +00002528def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002529 "lddqu\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002530 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2531
2532// Horizontal ops
2533class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002534 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002535 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002536 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2537class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002538 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002539 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002540 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002541class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002542 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002543 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002544 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2545class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002546 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002547 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002548 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002549
Evan Chenge9083d62008-03-05 08:19:16 +00002550let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002551 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2552 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2553 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2554 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2555 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2556 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2557 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2558 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2559}
2560
2561// Thread synchronization
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002562def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
Bill Wendlingddd35322007-05-02 23:11:52 +00002563 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002564def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
Bill Wendlingddd35322007-05-02 23:11:52 +00002565 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2566
2567// vector_shuffle v1, <undef> <1, 1, 3, 3>
2568let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002569def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002570 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2571let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002572def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002573 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2574
2575// vector_shuffle v1, <undef> <0, 0, 2, 2>
2576let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002577 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002578 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2579let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002580 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002581 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2582
Eric Christopher44b93ff2009-07-31 20:07:27 +00002583//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002584// SSSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002585//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002586
Bill Wendling76d708b2007-08-10 06:22:27 +00002587/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begemanfea2be52008-02-09 23:46:37 +00002588multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2589 Intrinsic IntId64, Intrinsic IntId128> {
2590 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2591 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2592 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002593
Nate Begemanfea2be52008-02-09 23:46:37 +00002594 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2595 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2596 [(set VR64:$dst,
2597 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2598
2599 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2600 (ins VR128:$src),
2601 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2602 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2603 OpSize;
2604
2605 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2606 (ins i128mem:$src),
2607 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2608 [(set VR128:$dst,
2609 (IntId128
2610 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Bill Wendlingddd35322007-05-02 23:11:52 +00002611}
2612
Bill Wendling76d708b2007-08-10 06:22:27 +00002613/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begemanfea2be52008-02-09 23:46:37 +00002614multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2615 Intrinsic IntId64, Intrinsic IntId128> {
2616 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2617 (ins VR64:$src),
2618 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2619 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002620
Nate Begemanfea2be52008-02-09 23:46:37 +00002621 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2622 (ins i64mem:$src),
2623 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2624 [(set VR64:$dst,
2625 (IntId64
2626 (bitconvert (memopv4i16 addr:$src))))]>;
2627
2628 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2629 (ins VR128:$src),
2630 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2631 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2632 OpSize;
2633
2634 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2635 (ins i128mem:$src),
2636 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2637 [(set VR128:$dst,
2638 (IntId128
2639 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002640}
2641
2642/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begemanfea2be52008-02-09 23:46:37 +00002643multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2644 Intrinsic IntId64, Intrinsic IntId128> {
2645 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2646 (ins VR64:$src),
2647 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2648 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002649
Nate Begemanfea2be52008-02-09 23:46:37 +00002650 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2651 (ins i64mem:$src),
2652 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2653 [(set VR64:$dst,
2654 (IntId64
2655 (bitconvert (memopv2i32 addr:$src))))]>;
2656
2657 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2658 (ins VR128:$src),
2659 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2660 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2661 OpSize;
2662
2663 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2664 (ins i128mem:$src),
2665 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2666 [(set VR128:$dst,
2667 (IntId128
2668 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002669}
2670
2671defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2672 int_x86_ssse3_pabs_b,
2673 int_x86_ssse3_pabs_b_128>;
2674defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2675 int_x86_ssse3_pabs_w,
2676 int_x86_ssse3_pabs_w_128>;
2677defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2678 int_x86_ssse3_pabs_d,
2679 int_x86_ssse3_pabs_d_128>;
2680
2681/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
Evan Chenge9083d62008-03-05 08:19:16 +00002682let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002683 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2684 Intrinsic IntId64, Intrinsic IntId128,
2685 bit Commutable = 0> {
2686 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2687 (ins VR64:$src1, VR64:$src2),
2688 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2689 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2690 let isCommutable = Commutable;
2691 }
2692 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2693 (ins VR64:$src1, i64mem:$src2),
2694 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2695 [(set VR64:$dst,
2696 (IntId64 VR64:$src1,
2697 (bitconvert (memopv8i8 addr:$src2))))]>;
2698
2699 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2700 (ins VR128:$src1, VR128:$src2),
2701 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2702 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2703 OpSize {
2704 let isCommutable = Commutable;
2705 }
2706 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2707 (ins VR128:$src1, i128mem:$src2),
2708 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2709 [(set VR128:$dst,
2710 (IntId128 VR128:$src1,
2711 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2712 }
2713}
2714
2715/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
Evan Chenge9083d62008-03-05 08:19:16 +00002716let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002717 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2718 Intrinsic IntId64, Intrinsic IntId128,
2719 bit Commutable = 0> {
2720 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2721 (ins VR64:$src1, VR64:$src2),
2722 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2723 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2724 let isCommutable = Commutable;
2725 }
2726 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2727 (ins VR64:$src1, i64mem:$src2),
2728 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2729 [(set VR64:$dst,
2730 (IntId64 VR64:$src1,
2731 (bitconvert (memopv4i16 addr:$src2))))]>;
2732
2733 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2734 (ins VR128:$src1, VR128:$src2),
2735 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2736 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2737 OpSize {
2738 let isCommutable = Commutable;
2739 }
2740 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2741 (ins VR128:$src1, i128mem:$src2),
2742 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2743 [(set VR128:$dst,
2744 (IntId128 VR128:$src1,
2745 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2746 }
2747}
2748
2749/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
Evan Chenge9083d62008-03-05 08:19:16 +00002750let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002751 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2752 Intrinsic IntId64, Intrinsic IntId128,
2753 bit Commutable = 0> {
2754 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2755 (ins VR64:$src1, VR64:$src2),
2756 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2757 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2758 let isCommutable = Commutable;
2759 }
2760 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2761 (ins VR64:$src1, i64mem:$src2),
2762 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2763 [(set VR64:$dst,
2764 (IntId64 VR64:$src1,
2765 (bitconvert (memopv2i32 addr:$src2))))]>;
2766
2767 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2768 (ins VR128:$src1, VR128:$src2),
2769 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2770 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2771 OpSize {
2772 let isCommutable = Commutable;
2773 }
2774 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2775 (ins VR128:$src1, i128mem:$src2),
2776 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2777 [(set VR128:$dst,
2778 (IntId128 VR128:$src1,
2779 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2780 }
2781}
2782
Chris Lattner65de1b92010-04-17 07:38:24 +00002783let ImmT = NoImm in { // None of these have i8 immediate fields.
Bill Wendling76d708b2007-08-10 06:22:27 +00002784defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2785 int_x86_ssse3_phadd_w,
Evan Cheng4e444432008-06-16 21:16:24 +00002786 int_x86_ssse3_phadd_w_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002787defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2788 int_x86_ssse3_phadd_d,
Evan Cheng4e444432008-06-16 21:16:24 +00002789 int_x86_ssse3_phadd_d_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002790defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2791 int_x86_ssse3_phadd_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002792 int_x86_ssse3_phadd_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002793defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2794 int_x86_ssse3_phsub_w,
2795 int_x86_ssse3_phsub_w_128>;
2796defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2797 int_x86_ssse3_phsub_d,
2798 int_x86_ssse3_phsub_d_128>;
2799defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2800 int_x86_ssse3_phsub_sw,
2801 int_x86_ssse3_phsub_sw_128>;
2802defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2803 int_x86_ssse3_pmadd_ub_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002804 int_x86_ssse3_pmadd_ub_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002805defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2806 int_x86_ssse3_pmul_hr_sw,
2807 int_x86_ssse3_pmul_hr_sw_128, 1>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00002808
Bill Wendling76d708b2007-08-10 06:22:27 +00002809defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2810 int_x86_ssse3_pshuf_b,
2811 int_x86_ssse3_pshuf_b_128>;
2812defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2813 int_x86_ssse3_psign_b,
2814 int_x86_ssse3_psign_b_128>;
2815defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2816 int_x86_ssse3_psign_w,
2817 int_x86_ssse3_psign_w_128>;
Evan Chenged7f56b2009-05-28 18:48:53 +00002818defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
Bill Wendling76d708b2007-08-10 06:22:27 +00002819 int_x86_ssse3_psign_d,
2820 int_x86_ssse3_psign_d_128>;
Chris Lattner65de1b92010-04-17 07:38:24 +00002821}
Bill Wendling76d708b2007-08-10 06:22:27 +00002822
Eric Christophercff6f852010-04-15 01:40:20 +00002823// palignr patterns.
Evan Chenge9083d62008-03-05 08:19:16 +00002824let Constraints = "$src1 = $dst" in {
Bill Wendlingae9671b2007-08-10 09:00:17 +00002825 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002826 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002827 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002828 []>;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002829 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002830 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002831 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002832 []>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002833
Bill Wendlingae9671b2007-08-10 09:00:17 +00002834 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002835 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002836 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002837 []>, OpSize;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002838 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002839 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002840 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002841 []>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002842}
Bill Wendlingddd35322007-05-02 23:11:52 +00002843
Eric Christopher6d972fd2010-04-20 00:59:54 +00002844let AddedComplexity = 5 in {
2845
Eric Christophercff6f852010-04-15 01:40:20 +00002846def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2847 (PALIGNR64rr VR64:$src2, VR64:$src1,
2848 (SHUFFLE_get_palign_imm VR64:$src3))>,
2849 Requires<[HasSSSE3]>;
2850def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2851 (PALIGNR64rr VR64:$src2, VR64:$src1,
2852 (SHUFFLE_get_palign_imm VR64:$src3))>,
2853 Requires<[HasSSSE3]>;
2854def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2855 (PALIGNR64rr VR64:$src2, VR64:$src1,
2856 (SHUFFLE_get_palign_imm VR64:$src3))>,
2857 Requires<[HasSSSE3]>;
2858def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2859 (PALIGNR64rr VR64:$src2, VR64:$src1,
2860 (SHUFFLE_get_palign_imm VR64:$src3))>,
2861 Requires<[HasSSSE3]>;
2862def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2863 (PALIGNR64rr VR64:$src2, VR64:$src1,
2864 (SHUFFLE_get_palign_imm VR64:$src3))>,
2865 Requires<[HasSSSE3]>;
Evan Cheng89321162009-10-28 06:30:34 +00002866
Nate Begemana09008b2009-10-19 02:17:23 +00002867def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2868 (PALIGNR128rr VR128:$src2, VR128:$src1,
2869 (SHUFFLE_get_palign_imm VR128:$src3))>,
2870 Requires<[HasSSSE3]>;
2871def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2872 (PALIGNR128rr VR128:$src2, VR128:$src1,
2873 (SHUFFLE_get_palign_imm VR128:$src3))>,
2874 Requires<[HasSSSE3]>;
2875def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2876 (PALIGNR128rr VR128:$src2, VR128:$src1,
2877 (SHUFFLE_get_palign_imm VR128:$src3))>,
2878 Requires<[HasSSSE3]>;
2879def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2880 (PALIGNR128rr VR128:$src2, VR128:$src1,
2881 (SHUFFLE_get_palign_imm VR128:$src3))>,
2882 Requires<[HasSSSE3]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002883}
Nate Begemana09008b2009-10-19 02:17:23 +00002884
Nate Begemanb9a47b82009-02-23 08:49:38 +00002885def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2886 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2887def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2888 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2889
Eric Christopher44b93ff2009-07-31 20:07:27 +00002890//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002891// Non-Instruction Patterns
Eric Christopher44b93ff2009-07-31 20:07:27 +00002892//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002893
Eric Christopher44b93ff2009-07-31 20:07:27 +00002894// extload f32 -> f64. This matches load+fextend because we have a hack in
2895// the isel (PreprocessForFPConvert) that can introduce loads after dag
2896// combine.
Chris Lattnerd43d00c2008-01-24 08:07:48 +00002897// Since these loads aren't folded into the fextend, we have to match it
2898// explicitly here.
2899let Predicates = [HasSSE2] in
2900 def : Pat<(fextend (loadf32 addr:$src)),
2901 (CVTSS2SDrm addr:$src)>;
2902
Evan Cheng2c0dbd02006-03-24 02:58:06 +00002903// bit_convert
Chris Lattner4cc84ed2006-10-07 04:52:09 +00002904let Predicates = [HasSSE2] in {
2905 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2906 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2907 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2908 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2909 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2910 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2911 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2912 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2913 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2914 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2915 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2916 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2917 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2918 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2919 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2920 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2921 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2922 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2923 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2924 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2925 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2926 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2927 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2928 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2929 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2930 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2931 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2932 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2933 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2934 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2935}
Evan Chengb9df0ca2006-03-22 02:53:00 +00002936
Evan Cheng017dcc62006-04-21 01:05:10 +00002937// Move scalar to XMM zero-extended
2938// movd to XMM register zero-extends
Evan Chengf2ea84a2006-10-09 21:42:15 +00002939let AddedComplexity = 15 in {
Evan Cheng017dcc62006-04-21 01:05:10 +00002940// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Evan Chengd880b972008-05-09 21:53:03 +00002941def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002942 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002943def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002944 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
Evan Cheng23573e52008-05-09 23:37:55 +00002945def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002946 (MOVSSrr (v4f32 (V_SET0PS)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002947 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
Evan Cheng331e2bd2008-07-10 01:08:23 +00002948def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002949 (MOVSSrr (v4i32 (V_SET0PI)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002950 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
Evan Cheng017dcc62006-04-21 01:05:10 +00002951}
Evan Chengbc4832b2006-03-24 23:15:12 +00002952
Evan Chengb9df0ca2006-03-22 02:53:00 +00002953// Splat v2f64 / v2i64
Evan Chengfd111b52006-04-19 21:15:24 +00002954let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002955def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002956 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002957def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002958 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002959def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002960 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002961def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002962 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengfd111b52006-04-19 21:15:24 +00002963}
Evan Cheng475aecf2006-03-29 03:04:49 +00002964
Evan Chengb7a5c522006-04-18 21:55:35 +00002965// Special unary SHUFPSrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002966def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2967 (SHUFPSrri VR128:$src1, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00002968 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002969let AddedComplexity = 5 in
2970def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2971 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2972 Requires<[HasSSE2]>;
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002973// Special unary SHUFPDrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002974def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002975 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002976 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2977 Requires<[HasSSE2]>;
2978// Special unary SHUFPDrri case.
2979def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002980 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002981 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002982 Requires<[HasSSE2]>;
Evan Cheng3d60df42006-04-10 22:35:16 +00002983// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Nate Begeman9008ca62009-04-27 18:41:29 +00002984def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2985 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng7d9061e2006-03-30 19:54:57 +00002986 Requires<[HasSSE2]>;
Evan Chengb7a75a52008-09-26 23:41:32 +00002987
Evan Cheng3d60df42006-04-10 22:35:16 +00002988// Special binary v4i32 shuffle cases with SHUFPS.
Nate Begeman9008ca62009-04-27 18:41:29 +00002989def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002990 (SHUFPSrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002991 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002992 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002993def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002994 (SHUFPSrmi VR128:$src1, addr:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002995 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002996 Requires<[HasSSE2]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002997// Special binary v2i64 shuffle cases using SHUFPDrri.
Nate Begeman9008ca62009-04-27 18:41:29 +00002998def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002999 (SHUFPDrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00003000 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00003001 Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00003002
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00003003// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00003004let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003005def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
3006 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003007 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003008def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
3009 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003010 Requires<[OptForSpeed, HasSSE2]>;
3011}
Evan Chengfd111b52006-04-19 21:15:24 +00003012let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003013def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003014 (UNPCKLPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003015def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003016 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003017def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003018 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003019def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003020 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
Evan Chengfd111b52006-04-19 21:15:24 +00003021}
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00003022
Evan Cheng174f8032007-05-17 18:44:37 +00003023// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00003024let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003025def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
3026 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003027 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003028def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
3029 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00003030 Requires<[OptForSpeed, HasSSE2]>;
3031}
Evan Cheng174f8032007-05-17 18:44:37 +00003032let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00003033def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003034 (UNPCKHPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003035def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003036 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003037def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003038 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003039def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003040 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
Evan Cheng174f8032007-05-17 18:44:37 +00003041}
3042
Evan Chengb7a75a52008-09-26 23:41:32 +00003043let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003044// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
Nate Begeman0b10b912009-11-07 23:17:15 +00003045def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003046 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003047
3048// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003049def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003050 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003051
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003052// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003053def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003054 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003055def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003056 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003057}
Evan Cheng9d09b892006-05-31 00:51:37 +00003058
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003059let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003060// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003061def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003062 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003063def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003064 (MOVLPDrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003065def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003066 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003067def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003068 (MOVLPDrm VR128:$src1, addr:$src2)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003069}
Evan Cheng64e97692006-04-24 21:58:20 +00003070
Evan Chengcd0baf22008-05-23 21:23:16 +00003071// (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003072def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003073 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003074def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003075 (MOVLPDmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003076def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3077 addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003078 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003079def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003080 (MOVLPDmr addr:$src1, VR128:$src2)>;
Evan Chengcd0baf22008-05-23 21:23:16 +00003081
Evan Chengf2ea84a2006-10-09 21:42:15 +00003082let AddedComplexity = 15 in {
Evan Cheng64e97692006-04-24 21:58:20 +00003083// Setting the lowest element in the vector.
Nate Begeman9008ca62009-04-27 18:41:29 +00003084def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003085 (MOVSSrr (v4i32 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003086 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003087def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003088 (MOVSDrr (v2i64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003089 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
Evan Chenga7fc6422006-04-24 23:34:56 +00003090
Dan Gohman874cada2010-02-28 00:17:42 +00003091// vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
Nate Begeman9008ca62009-04-27 18:41:29 +00003092def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003093 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003094 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003095def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003096 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003097 Requires<[HasSSE2]>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003098}
Evan Cheng9e062ed2006-05-03 20:32:03 +00003099
Eli Friedman7e2242b2009-06-19 07:00:55 +00003100// vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3101// fall back to this for SSE1)
3102def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003103 (SHUFPSrri VR128:$src2, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00003104 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Eli Friedman7e2242b2009-06-19 07:00:55 +00003105
Evan Chenga7fc6422006-04-24 23:34:56 +00003106// Set lowest element and zero upper elements.
Evan Chengd880b972008-05-09 21:53:03 +00003107def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
Evan Chengfd17f422008-05-08 22:35:02 +00003108 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengcdfc3c82006-04-17 22:45:49 +00003109
Evan Cheng2c3ae372006-04-12 21:21:57 +00003110// Some special case pandn patterns.
3111def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3112 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003113 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003114def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3115 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003116 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003117def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3118 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003119 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00003120
Evan Cheng2c3ae372006-04-12 21:21:57 +00003121def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003122 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003123 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003124def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003125 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003126 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003127def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003128 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003129 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng206ee9d2006-07-07 08:33:52 +00003130
Nate Begemanb348d182007-11-17 03:58:34 +00003131// vector -> vector casts
3132def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3133 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3134def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3135 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
Eli Friedmand0c0fae2008-09-05 23:07:03 +00003136def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3137 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3138def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3139 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
Nate Begemanb348d182007-11-17 03:58:34 +00003140
Evan Chengb4162fd2007-07-20 00:27:43 +00003141// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohmand3006222007-07-27 17:16:43 +00003142def : Pat<(alignedloadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003143 (MOVAPSrm addr:$src)>;
Dan Gohmand3006222007-07-27 17:16:43 +00003144def : Pat<(loadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003145 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003146def : Pat<(alignedloadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003147 (MOVAPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003148def : Pat<(loadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003149 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003150
3151def : Pat<(alignedstore (v2i64 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 (v4i32 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 (v8i16 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<(alignedstore (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003158 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003159def : Pat<(store (v2i64 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 (v4i32 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 (v8i16 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003164 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003165def : Pat<(store (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003166 (MOVUPSmr addr:$dst, VR128:$src)>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003167
Nate Begeman63ec90a2008-02-03 07:18:54 +00003168//===----------------------------------------------------------------------===//
3169// SSE4.1 Instructions
3170//===----------------------------------------------------------------------===//
3171
Dale Johannesene397acc2008-10-10 23:51:03 +00003172multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003173 string OpcodeStr,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003174 Intrinsic V4F32Int,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003175 Intrinsic V2F64Int> {
Nate Begeman63ec90a2008-02-03 07:18:54 +00003176 // Intrinsic operation, reg.
Nate Begeman63ec90a2008-02-03 07:18:54 +00003177 // Vector intrinsic operation, reg
Eric Christopher44b93ff2009-07-31 20:07:27 +00003178 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003179 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003180 !strconcat(OpcodeStr,
3181 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003182 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3183 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003184
3185 // Vector intrinsic operation, mem
Evan Cheng400073d2009-12-18 07:40:29 +00003186 def PSm_Int : Ii8<opcps, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003187 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003188 !strconcat(OpcodeStr,
3189 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003190 [(set VR128:$dst,
3191 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
Evan Cheng400073d2009-12-18 07:40:29 +00003192 TA, OpSize,
Evan Chengb1f49812009-12-22 17:47:23 +00003193 Requires<[HasSSE41]>;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003194
Nate Begeman63ec90a2008-02-03 07:18:54 +00003195 // Vector intrinsic operation, reg
Evan Cheng172b7942008-03-14 07:39:27 +00003196 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003197 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003198 !strconcat(OpcodeStr,
3199 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003200 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3201 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003202
3203 // Vector intrinsic operation, mem
Evan Cheng172b7942008-03-14 07:39:27 +00003204 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003205 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003206 !strconcat(OpcodeStr,
3207 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003208 [(set VR128:$dst,
3209 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003210 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003211}
3212
Dale Johannesene397acc2008-10-10 23:51:03 +00003213let Constraints = "$src1 = $dst" in {
3214multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3215 string OpcodeStr,
3216 Intrinsic F32Int,
3217 Intrinsic F64Int> {
3218 // Intrinsic operation, reg.
3219 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003220 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003221 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3222 !strconcat(OpcodeStr,
3223 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003224 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003225 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3226 OpSize;
3227
3228 // Intrinsic operation, mem.
Eric Christopher44b93ff2009-07-31 20:07:27 +00003229 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3230 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003231 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003232 !strconcat(OpcodeStr,
Dale Johannesene397acc2008-10-10 23:51:03 +00003233 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003234 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003235 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3236 OpSize;
3237
3238 // Intrinsic operation, reg.
3239 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003240 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003241 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3242 !strconcat(OpcodeStr,
3243 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003244 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003245 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3246 OpSize;
3247
3248 // Intrinsic operation, mem.
3249 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003250 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003251 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3252 !strconcat(OpcodeStr,
3253 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003254 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003255 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3256 OpSize;
3257}
3258}
3259
Nate Begeman63ec90a2008-02-03 07:18:54 +00003260// FP round - roundss, roundps, roundsd, roundpd
Dale Johannesene397acc2008-10-10 23:51:03 +00003261defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3262 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3263defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3264 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003265
3266// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3267multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3268 Intrinsic IntId128> {
3269 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3270 (ins VR128:$src),
3271 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3272 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3273 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3274 (ins i128mem:$src),
3275 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3276 [(set VR128:$dst,
3277 (IntId128
3278 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3279}
3280
3281defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3282 int_x86_sse41_phminposuw>;
3283
3284/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003285let Constraints = "$src1 = $dst" in {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003286 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3287 Intrinsic IntId128, bit Commutable = 0> {
Nate Begemanfea2be52008-02-09 23:46:37 +00003288 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3289 (ins VR128:$src1, VR128:$src2),
3290 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3291 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3292 OpSize {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003293 let isCommutable = Commutable;
3294 }
Nate Begemanfea2be52008-02-09 23:46:37 +00003295 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3296 (ins VR128:$src1, i128mem:$src2),
3297 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3298 [(set VR128:$dst,
3299 (IntId128 VR128:$src1,
3300 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003301 }
3302}
3303
3304defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3305 int_x86_sse41_pcmpeqq, 1>;
3306defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3307 int_x86_sse41_packusdw, 0>;
3308defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3309 int_x86_sse41_pminsb, 1>;
3310defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3311 int_x86_sse41_pminsd, 1>;
3312defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3313 int_x86_sse41_pminud, 1>;
3314defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3315 int_x86_sse41_pminuw, 1>;
3316defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3317 int_x86_sse41_pmaxsb, 1>;
3318defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3319 int_x86_sse41_pmaxsd, 1>;
3320defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3321 int_x86_sse41_pmaxud, 1>;
3322defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3323 int_x86_sse41_pmaxuw, 1>;
Nate Begeman204e84e2008-02-04 06:00:24 +00003324
Mon P Wangaf9b9522008-12-18 21:42:19 +00003325defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3326
Nate Begeman30a0de92008-07-17 16:51:19 +00003327def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3328 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3329def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3330 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3331
Nate Begeman1426d522008-02-09 01:38:08 +00003332/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003333let Constraints = "$src1 = $dst" in {
Dan Gohman0b924dc2008-05-23 17:49:40 +00003334 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3335 SDNode OpNode, Intrinsic IntId128,
3336 bit Commutable = 0> {
Nate Begeman1426d522008-02-09 01:38:08 +00003337 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3338 (ins VR128:$src1, VR128:$src2),
3339 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman0b924dc2008-05-23 17:49:40 +00003340 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3341 VR128:$src2))]>, OpSize {
Nate Begeman1426d522008-02-09 01:38:08 +00003342 let isCommutable = Commutable;
3343 }
3344 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3345 (ins VR128:$src1, VR128:$src2),
3346 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3347 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3348 OpSize {
3349 let isCommutable = Commutable;
3350 }
3351 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3352 (ins VR128:$src1, i128mem:$src2),
3353 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3354 [(set VR128:$dst,
Chris Lattner1a7d0872010-02-18 06:33:42 +00003355 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003356 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3357 (ins VR128:$src1, i128mem:$src2),
3358 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3359 [(set VR128:$dst,
Evan Chengb1938262008-05-23 00:37:07 +00003360 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
Nate Begeman1426d522008-02-09 01:38:08 +00003361 OpSize;
3362 }
3363}
Eric Christopher8258d0b2010-03-30 18:49:01 +00003364
3365/// SS48I_binop_rm - Simple SSE41 binary operator.
3366let Constraints = "$src1 = $dst" in {
3367multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3368 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003369 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003370 (ins VR128:$src1, VR128:$src2),
3371 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3372 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3373 OpSize {
3374 let isCommutable = Commutable;
3375 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003376 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003377 (ins VR128:$src1, i128mem:$src2),
3378 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3379 [(set VR128:$dst, (OpNode VR128:$src1,
3380 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3381 OpSize;
3382}
3383}
3384
3385defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
Nate Begeman1426d522008-02-09 01:38:08 +00003386
Evan Cheng172b7942008-03-14 07:39:27 +00003387/// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
Evan Chenge9083d62008-03-05 08:19:16 +00003388let Constraints = "$src1 = $dst" in {
Nate Begeman204e84e2008-02-04 06:00:24 +00003389 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3390 Intrinsic IntId128, bit Commutable = 0> {
Evan Cheng172b7942008-03-14 07:39:27 +00003391 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003392 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003393 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003394 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003395 [(set VR128:$dst,
Nate Begemanfea2be52008-02-09 23:46:37 +00003396 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3397 OpSize {
Nate Begeman204e84e2008-02-04 06:00:24 +00003398 let isCommutable = Commutable;
3399 }
Evan Cheng172b7942008-03-14 07:39:27 +00003400 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003401 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3402 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003403 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begemanfea2be52008-02-09 23:46:37 +00003404 [(set VR128:$dst,
3405 (IntId128 VR128:$src1,
3406 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3407 OpSize;
Nate Begeman204e84e2008-02-04 06:00:24 +00003408 }
3409}
3410
3411defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3412 int_x86_sse41_blendps, 0>;
3413defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3414 int_x86_sse41_blendpd, 0>;
3415defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3416 int_x86_sse41_pblendw, 0>;
3417defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3418 int_x86_sse41_dpps, 1>;
3419defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3420 int_x86_sse41_dppd, 1>;
3421defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
Eric Christopher419e2232010-04-08 00:52:02 +00003422 int_x86_sse41_mpsadbw, 0>;
Nate Begeman1426d522008-02-09 01:38:08 +00003423
Nate Begemanfea2be52008-02-09 23:46:37 +00003424
Evan Cheng172b7942008-03-14 07:39:27 +00003425/// SS41I_ternary_int - SSE 4.1 ternary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003426let Uses = [XMM0], Constraints = "$src1 = $dst" in {
Nate Begemanab5d56c2008-02-10 18:47:57 +00003427 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3428 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3429 (ins VR128:$src1, VR128:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003430 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003431 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3432 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3433 OpSize;
3434
3435 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3436 (ins VR128:$src1, i128mem:$src2),
3437 !strconcat(OpcodeStr,
3438 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3439 [(set VR128:$dst,
3440 (IntId VR128:$src1,
3441 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3442 }
3443}
3444
3445defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3446defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3447defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3448
3449
Nate Begemanfea2be52008-02-09 23:46:37 +00003450multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3451 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3452 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3453 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3454
3455 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3456 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003457 [(set VR128:$dst,
3458 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3459 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003460}
3461
3462defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3463defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3464defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3465defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3466defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3467defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3468
Evan Chengca57f782008-09-24 23:27:55 +00003469// Common patterns involving scalar load.
3470def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3471 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3472def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3473 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3474
3475def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3476 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3477def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3478 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3479
3480def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3481 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3482def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3483 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3484
3485def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3486 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3487def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3488 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3489
3490def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3491 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3492def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3493 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3494
3495def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3496 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3497def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3498 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3499
3500
Nate Begemanfea2be52008-02-09 23:46:37 +00003501multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3502 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3503 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3504 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3505
3506 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3507 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003508 [(set VR128:$dst,
3509 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3510 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003511}
3512
3513defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3514defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3515defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3516defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3517
Evan Chengca57f782008-09-24 23:27:55 +00003518// Common patterns involving scalar load
3519def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003520 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003521def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003522 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003523
3524def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003525 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003526def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003527 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003528
3529
Nate Begemanfea2be52008-02-09 23:46:37 +00003530multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3531 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3532 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3533 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3534
Evan Chengca57f782008-09-24 23:27:55 +00003535 // Expecting a i16 load any extended to i32 value.
Nate Begemanfea2be52008-02-09 23:46:37 +00003536 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3537 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003538 [(set VR128:$dst, (IntId (bitconvert
3539 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3540 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003541}
3542
3543defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
Eli Friedman9d47b8d2009-06-06 05:55:37 +00003544defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
Nate Begemanfea2be52008-02-09 23:46:37 +00003545
Evan Chengca57f782008-09-24 23:27:55 +00003546// Common patterns involving scalar load
3547def : Pat<(int_x86_sse41_pmovsxbq
3548 (bitconvert (v4i32 (X86vzmovl
3549 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003550 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003551
3552def : Pat<(int_x86_sse41_pmovzxbq
3553 (bitconvert (v4i32 (X86vzmovl
3554 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003555 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003556
Nate Begemanfea2be52008-02-09 23:46:37 +00003557
Nate Begeman14d12ca2008-02-11 04:19:36 +00003558/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3559multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003560 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003561 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003562 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003563 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003564 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3565 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003566 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003567 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003568 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003569 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003570 []>, OpSize;
3571// FIXME:
3572// There's an AssertZext in the way of writing the store pattern
3573// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begemanfea2be52008-02-09 23:46:37 +00003574}
3575
Nate Begeman14d12ca2008-02-11 04:19:36 +00003576defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003577
Nate Begeman14d12ca2008-02-11 04:19:36 +00003578
3579/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3580multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003581 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003582 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003583 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003584 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3585 []>, OpSize;
3586// FIXME:
3587// There's an AssertZext in the way of writing the store pattern
3588// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3589}
3590
3591defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3592
3593
3594/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3595multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003596 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003597 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003598 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003599 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3600 [(set GR32:$dst,
3601 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003602 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003603 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003604 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003605 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3606 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3607 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003608}
3609
Nate Begeman14d12ca2008-02-11 04:19:36 +00003610defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman1426d522008-02-09 01:38:08 +00003611
Nate Begeman14d12ca2008-02-11 04:19:36 +00003612
Evan Cheng62a3f152008-03-24 21:52:23 +00003613/// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3614/// destination
Nate Begeman14d12ca2008-02-11 04:19:36 +00003615multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003616 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003617 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003618 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003619 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Dan Gohman171c11e2008-04-16 02:32:24 +00003620 [(set GR32:$dst,
3621 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
Evan Cheng62a3f152008-03-24 21:52:23 +00003622 OpSize;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003623 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003624 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003625 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003626 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng62a3f152008-03-24 21:52:23 +00003627 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
Nate Begemanfea2be52008-02-09 23:46:37 +00003628 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003629}
3630
Nate Begeman14d12ca2008-02-11 04:19:36 +00003631defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003632
Dan Gohmand9ced092008-08-08 18:30:21 +00003633// Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3634def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3635 imm:$src2))),
3636 addr:$dst),
3637 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3638 Requires<[HasSSE41]>;
3639
Evan Chenge9083d62008-03-05 08:19:16 +00003640let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003641 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003642 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003643 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003644 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003645 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003646 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003647 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003648 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003649 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3650 !strconcat(OpcodeStr,
3651 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003652 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003653 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3654 imm:$src3))]>, OpSize;
3655 }
3656}
3657
3658defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3659
Evan Chenge9083d62008-03-05 08:19:16 +00003660let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003661 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003662 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003663 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003664 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003665 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003666 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003667 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3668 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003669 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003670 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3671 !strconcat(OpcodeStr,
3672 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003673 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003674 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3675 imm:$src3)))]>, OpSize;
3676 }
3677}
3678
3679defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3680
Eric Christopher1e5cdea2009-07-23 02:22:41 +00003681// insertps has a few different modes, there's the first two here below which
3682// are optimized inserts that won't zero arbitrary elements in the destination
3683// vector. The next one matches the intrinsic and could zero arbitrary elements
3684// in the target vector.
Evan Chenge9083d62008-03-05 08:19:16 +00003685let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003686 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
Eric Christopherfbd66872009-07-24 00:33:09 +00003687 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3688 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003689 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003690 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003691 [(set VR128:$dst,
3692 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003693 OpSize;
Eric Christopherfbd66872009-07-24 00:33:09 +00003694 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003695 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3696 !strconcat(OpcodeStr,
3697 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003698 [(set VR128:$dst,
Eric Christopherfbd66872009-07-24 00:33:09 +00003699 (X86insrtps VR128:$src1,
3700 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003701 imm:$src3))]>, OpSize;
3702 }
3703}
3704
Evan Cheng7aae8762008-03-26 08:11:49 +00003705defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003706
Eric Christopherfbd66872009-07-24 00:33:09 +00003707def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3708 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3709
Eric Christopher71c67532009-07-29 00:28:05 +00003710// ptest instruction we'll lower to this in X86ISelLowering primarily from
3711// the intel intrinsic that corresponds to this.
Nate Begemanbc4efb82008-03-16 21:14:46 +00003712let Defs = [EFLAGS] in {
3713def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003714 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003715 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3716 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003717def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003718 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003719 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3720 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003721}
3722
3723def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3724 "movntdqa\t{$src, $dst|$dst, $src}",
Kevin Enderby40fe18f2010-02-10 00:10:31 +00003725 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3726 OpSize;
Nate Begeman30a0de92008-07-17 16:51:19 +00003727
Eric Christopherb120ab42009-08-18 22:50:32 +00003728
3729//===----------------------------------------------------------------------===//
3730// SSE4.2 Instructions
3731//===----------------------------------------------------------------------===//
3732
Nate Begeman30a0de92008-07-17 16:51:19 +00003733/// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3734let Constraints = "$src1 = $dst" in {
3735 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3736 Intrinsic IntId128, bit Commutable = 0> {
3737 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3738 (ins VR128:$src1, VR128:$src2),
3739 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3740 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3741 OpSize {
3742 let isCommutable = Commutable;
3743 }
3744 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3745 (ins VR128:$src1, i128mem:$src2),
3746 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3747 [(set VR128:$dst,
3748 (IntId128 VR128:$src1,
3749 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3750 }
3751}
3752
Nate Begemane99b2552008-07-17 17:04:58 +00003753defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
Nate Begeman30a0de92008-07-17 16:51:19 +00003754
3755def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3756 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3757def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3758 (PCMPGTQrm VR128:$src1, addr:$src2)>;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003759
3760// crc intrinsic instruction
3761// This set of instructions are only rm, the only difference is the size
3762// of r and m.
3763let Constraints = "$src1 = $dst" in {
Eric Christopher027c2b12009-08-10 21:48:58 +00003764 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003765 (ins GR32:$src1, i8mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003766 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003767 [(set GR32:$dst,
3768 (int_x86_sse42_crc32_8 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003769 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003770 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003771 (ins GR32:$src1, GR8:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003772 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003773 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003774 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003775 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003776 (ins GR32:$src1, i16mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003777 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003778 [(set GR32:$dst,
3779 (int_x86_sse42_crc32_16 GR32:$src1,
3780 (load addr:$src2)))]>,
3781 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003782 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003783 (ins GR32:$src1, GR16:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003784 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003785 [(set GR32:$dst,
Eric Christopher027c2b12009-08-10 21:48:58 +00003786 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003787 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003788 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003789 (ins GR32:$src1, i32mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003790 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003791 [(set GR32:$dst,
3792 (int_x86_sse42_crc32_32 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003793 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003794 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003795 (ins GR32:$src1, GR32:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003796 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003797 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003798 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3799 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3800 (ins GR64:$src1, i8mem:$src2),
3801 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003802 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003803 (int_x86_sse42_crc64_8 GR64:$src1,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003804 (load addr:$src2)))]>,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003805 REX_W;
3806 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3807 (ins GR64:$src1, GR8:$src2),
3808 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003809 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003810 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3811 REX_W;
3812 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3813 (ins GR64:$src1, i64mem:$src2),
3814 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3815 [(set GR64:$dst,
3816 (int_x86_sse42_crc64_64 GR64:$src1,
3817 (load addr:$src2)))]>,
3818 REX_W;
3819 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3820 (ins GR64:$src1, GR64:$src2),
3821 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3822 [(set GR64:$dst,
3823 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3824 REX_W;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003825}
Eric Christopherb120ab42009-08-18 22:50:32 +00003826
3827// String/text processing instructions.
Dan Gohman533297b2009-10-29 18:10:34 +00003828let Defs = [EFLAGS], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003829def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003830 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3831 "#PCMPISTRM128rr PSEUDO!",
3832 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3833 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003834def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003835 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3836 "#PCMPISTRM128rm PSEUDO!",
3837 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3838 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003839}
3840
3841let Defs = [XMM0, EFLAGS] in {
3842def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003843 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3844 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003845def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003846 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3847 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003848}
3849
Sean Callanan108934c2009-12-18 00:01:26 +00003850let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003851def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003852 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3853 "#PCMPESTRM128rr PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003854 [(set VR128:$dst,
3855 (int_x86_sse42_pcmpestrm128
Sean Callanan108934c2009-12-18 00:01:26 +00003856 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3857
Eric Christopherb120ab42009-08-18 22:50:32 +00003858def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003859 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3860 "#PCMPESTRM128rm PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003861 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3862 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003863 OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003864}
3865
3866let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
Sean Callanan47234e62009-08-20 18:24:27 +00003867def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003868 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3869 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Sean Callanan47234e62009-08-20 18:24:27 +00003870def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003871 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3872 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003873}
3874
3875let Defs = [ECX, EFLAGS] in {
3876 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003877 def rr : SS42AI<0x63, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003878 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3879 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3880 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3881 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003882 def rm : SS42AI<0x63, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003883 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3884 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3885 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3886 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003887 }
3888}
3889
3890defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3891defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3892defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3893defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3894defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3895defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3896
3897let Defs = [ECX, EFLAGS] in {
3898let Uses = [EAX, EDX] in {
3899 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3900 def rr : SS42AI<0x61, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003901 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3902 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3903 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3904 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003905 def rm : SS42AI<0x61, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003906 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3907 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003908 [(set ECX,
Sean Callanan108934c2009-12-18 00:01:26 +00003909 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3910 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003911 }
3912}
3913}
3914
3915defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3916defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3917defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3918defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3919defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3920defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003921
3922//===----------------------------------------------------------------------===//
3923// AES-NI Instructions
3924//===----------------------------------------------------------------------===//
3925
3926let Constraints = "$src1 = $dst" in {
3927 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3928 Intrinsic IntId128, bit Commutable = 0> {
3929 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3930 (ins VR128:$src1, VR128:$src2),
3931 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3932 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3933 OpSize {
3934 let isCommutable = Commutable;
3935 }
3936 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3937 (ins VR128:$src1, i128mem:$src2),
3938 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3939 [(set VR128:$dst,
3940 (IntId128 VR128:$src1,
3941 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3942 }
3943}
3944
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003945defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3946 int_x86_aesni_aesenc>;
3947defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3948 int_x86_aesni_aesenclast>;
3949defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3950 int_x86_aesni_aesdec>;
3951defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3952 int_x86_aesni_aesdeclast>;
3953
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003954def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3955 (AESENCrr VR128:$src1, VR128:$src2)>;
3956def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3957 (AESENCrm VR128:$src1, addr:$src2)>;
3958def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3959 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3960def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3961 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3962def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3963 (AESDECrr VR128:$src1, VR128:$src2)>;
3964def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3965 (AESDECrm VR128:$src1, addr:$src2)>;
3966def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3967 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3968def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3969 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3970
Eric Christopherb3500fd2010-04-02 23:48:33 +00003971def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3972 (ins VR128:$src1),
3973 "aesimc\t{$src1, $dst|$dst, $src1}",
3974 [(set VR128:$dst,
3975 (int_x86_aesni_aesimc VR128:$src1))]>,
3976 OpSize;
3977
3978def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3979 (ins i128mem:$src1),
3980 "aesimc\t{$src1, $dst|$dst, $src1}",
3981 [(set VR128:$dst,
3982 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3983 OpSize;
3984
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003985def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003986 (ins VR128:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003987 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3988 [(set VR128:$dst,
3989 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3990 OpSize;
3991def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003992 (ins i128mem:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003993 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3994 [(set VR128:$dst,
3995 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
3996 imm:$src2))]>,
3997 OpSize;