blob: 1211eff0d3d68db0dbe3727d42248620633493fa [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 Lopes17227db2010-06-19 01:17:05 +0000691/// sse12_fp_packed_int - SSE 1 & 2 packed instructions intrinsics class
692multiclass sse12_fp_packed_int<bits<8> opc, string OpcodeStr, RegisterClass RC,
693 string asm, string SSEVer, string FPSizeStr,
694 X86MemOperand memop, PatFrag mem_frag,
695 Domain d> {
696 def rr_Int : PI<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
697 asm, [(set RC:$dst, (
698 !nameconcat<Intrinsic>("int_x86_sse",
699 !strconcat(SSEVer, !strconcat("_",
700 !strconcat(OpcodeStr, FPSizeStr))))
701 RC:$src1, RC:$src2))], d>;
702 def rm_Int : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, memop:$src2),
703 asm, [(set RC:$dst, (
704 !nameconcat<Intrinsic>("int_x86_sse",
705 !strconcat(SSEVer, !strconcat("_",
706 !strconcat(OpcodeStr, FPSizeStr))))
707 RC:$src1, (mem_frag addr:$src2)))], d>;
708}
709
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000710/// basic_sse12_fp_binop_rm - SSE 1 & 2 binops come in both scalar and
711/// vector forms.
Bill Wendlingddd35322007-05-02 23:11:52 +0000712///
Dan Gohman20382522007-07-10 00:05:58 +0000713/// In addition, we also have a special variant of the scalar form here to
714/// represent the associated intrinsic operation. This form is unlike the
715/// plain scalar form, in that it takes an entire vector (instead of a scalar)
Evan Cheng236aa8a2009-02-26 03:12:02 +0000716/// and leaves the top elements unmodified (therefore these cannot be commuted).
Dan Gohman20382522007-07-10 00:05:58 +0000717///
718/// These three forms can each be reg+reg or reg+mem, so there are a total of
719/// six "instructions".
Bill Wendlingddd35322007-05-02 23:11:52 +0000720///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000721multiclass basic_sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
Bruno Cardoso Lopesefc9b692010-06-19 01:22:34 +0000722 SDNode OpNode> {
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000723
Bruno Cardoso Lopesfda1acb2010-06-19 00:09:27 +0000724 let isAsmParserOnly = 1 in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000725 defm V#NAME#SS : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000726 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000727 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000728
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000729 defm V#NAME#SD : sse12_fp_scalar<opc,
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000730 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000731 OpNode, FR64, f64mem>, XD, VEX_4V;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000732
733 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
734 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
735 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
736 VEX_4V;
737
738 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
739 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
740 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
741 OpSize, VEX_4V;
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000742
743 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
744 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
745 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
746
747 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
748 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
749 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
Bill Wendlingddd35322007-05-02 23:11:52 +0000750 }
751
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000752 let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000753 defm SS : sse12_fp_scalar<opc,
754 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
755 OpNode, FR32, f32mem>, XS;
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000756
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000757 defm SD : sse12_fp_scalar<opc,
758 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
759 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesc902a592010-06-11 23:50:47 +0000760
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000761 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
762 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
763 f128mem, memopv4f32, SSEPackedSingle>, TB;
Dan Gohman20382522007-07-10 00:05:58 +0000764
Bruno Cardoso Lopes8af5ed92010-06-18 23:13:35 +0000765 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
766 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
767 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
Bruno Cardoso Lopescf125d02010-06-12 01:53:48 +0000768
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000769 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000770 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000771 "", "_ss", ssmem, sse_load_f32>, XS;
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000772
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000773 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopes11ae95c2010-06-12 02:38:32 +0000774 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesc82f1992010-06-19 00:00:22 +0000775 "2", "_sd", sdmem, sse_load_f64>, XD;
Bruno Cardoso Lopes2dcf6d62010-06-12 03:12:14 +0000776 }
Bill Wendlingddd35322007-05-02 23:11:52 +0000777}
Bill Wendlingddd35322007-05-02 23:11:52 +0000778
779// Arithmetic instructions
Bruno Cardoso Lopesefc9b692010-06-19 01:22:34 +0000780defm ADD : basic_sse12_fp_binop_rm<0x58, "add", fadd>;
781defm MUL : basic_sse12_fp_binop_rm<0x59, "mul", fmul>;
Bruno Cardoso Lopes597ec8e2010-06-17 23:05:30 +0000782
783let isCommutable = 0 in {
784 defm SUB : basic_sse12_fp_binop_rm<0x5C, "sub", fsub>;
785 defm DIV : basic_sse12_fp_binop_rm<0x5E, "div", fdiv>;
786}
Bill Wendlingddd35322007-05-02 23:11:52 +0000787
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000788/// sse12_fp_binop_rm - Other SSE 1 & 2 binops
Dan Gohman20382522007-07-10 00:05:58 +0000789///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000790/// This multiclass is like basic_sse12_fp_binop_rm, with the addition of
Dan Gohman20382522007-07-10 00:05:58 +0000791/// instructions for a full-vector intrinsic form. Operations that map
792/// onto C operators don't use this form since they just use the plain
793/// vector form instead of having a separate vector intrinsic form.
794///
795/// This provides a total of eight "instructions".
796///
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000797multiclass sse12_fp_binop_rm<bits<8> opc, string OpcodeStr,
Bruno Cardoso Lopesefc9b692010-06-19 01:22:34 +0000798 SDNode OpNode> {
Dan Gohman20382522007-07-10 00:05:58 +0000799
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000800 let isAsmParserOnly = 1 in {
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000801 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000802 defm V#NAME#SS : sse12_fp_scalar<opc,
803 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
804 OpNode, FR32, f32mem>, XS, VEX_4V;
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000805
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000806 defm V#NAME#SD : sse12_fp_scalar<opc,
807 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
808 OpNode, FR64, f64mem>, XD, VEX_4V;
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000809
810 defm V#NAME#PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
811 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
812 VR128, v4f32, f128mem, memopv4f32, SSEPackedSingle>,
813 VEX_4V;
814
815 defm V#NAME#PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
816 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"), OpNode,
817 VR128, v2f64, f128mem, memopv2f64, SSEPackedDouble>,
818 OpSize, VEX_4V;
819
820 defm V#NAME#SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
821 !strconcat(OpcodeStr, "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
822 "", "_ss", ssmem, sse_load_f32>, XS, VEX_4V;
823
824 defm V#NAME#SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
825 !strconcat(OpcodeStr, "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
826 "2", "_sd", sdmem, sse_load_f64>, XD, VEX_4V;
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000827
828 defm V#NAME#PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
829 !strconcat(OpcodeStr, "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
830 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, VEX_4V;
831
832 defm V#NAME#PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
833 !strconcat(OpcodeStr, "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
834 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, OpSize,
835 VEX_4V;
Dan Gohman20382522007-07-10 00:05:58 +0000836 }
837
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000838 let Constraints = "$src1 = $dst" in {
839 // Scalar operation, reg+reg.
Bruno Cardoso Lopes4b8921d2010-06-18 22:10:11 +0000840 defm SS : sse12_fp_scalar<opc,
841 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
842 OpNode, FR32, f32mem>, XS;
843 defm SD : sse12_fp_scalar<opc,
844 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
845 OpNode, FR64, f64mem>, XD;
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000846 defm PS : sse12_fp_packed<opc, !strconcat(OpcodeStr,
847 "ps\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v4f32,
848 f128mem, memopv4f32, SSEPackedSingle>, TB;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000849
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000850 defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr,
851 "pd\t{$src2, $dst|$dst, $src2}"), OpNode, VR128, v2f64,
852 f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
Dan Gohman20382522007-07-10 00:05:58 +0000853
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000854 defm SS : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000855 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000856 "", "_ss", ssmem, sse_load_f32>, XS;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000857
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000858 defm SD : sse12_fp_scalar_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000859 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopesbe4d5952010-06-19 00:37:31 +0000860 "2", "_sd", sdmem, sse_load_f64>, XD;
Dan Gohman20382522007-07-10 00:05:58 +0000861
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000862 defm PS : sse12_fp_packed_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000863 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000864 "", "_ps", f128mem, memopv4f32, SSEPackedSingle>, TB;
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000865
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000866 defm PD : sse12_fp_packed_int<opc, OpcodeStr, VR128,
Bruno Cardoso Lopesaa02ff12010-05-27 18:17:40 +0000867 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Bruno Cardoso Lopes17227db2010-06-19 01:17:05 +0000868 "2", "_pd", f128mem, memopv2f64, SSEPackedDouble>, TB, OpSize;
Dan Gohman20382522007-07-10 00:05:58 +0000869 }
Dan Gohman20382522007-07-10 00:05:58 +0000870}
871
Bruno Cardoso Lopesd7f9cc42010-06-18 01:12:56 +0000872let isCommutable = 0 in {
873 defm MAX : sse12_fp_binop_rm<0x5F, "max", X86fmax>;
874 defm MIN : sse12_fp_binop_rm<0x5D, "min", X86fmin>;
875}
Bill Wendlingddd35322007-05-02 23:11:52 +0000876
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000877//===----------------------------------------------------------------------===//
Evan Cheng9ab1ac52006-04-14 23:32:40 +0000878// SSE packed FP Instructions
Evan Chengc12e6c42006-03-19 09:38:54 +0000879
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000880// Move Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +0000881let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000882def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000883 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000884let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000885def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000886 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000887 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Evan Chengffcb95b2006-02-21 19:13:53 +0000888
Evan Cheng64d80e32007-07-19 01:14:50 +0000889def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000890 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000891 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000892
Chris Lattnerf77e0372008-01-11 06:59:07 +0000893let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000894def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000895 "movups\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000896let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000897def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000898 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000899 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000900def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000901 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000902 [(store (v4f32 VR128:$src), addr:$dst)]>;
903
904// Intrinsic forms of MOVUPS load and store
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000905let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000906def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000907 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000908 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000909def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000910 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +0000911 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000912
Evan Chenge9083d62008-03-05 08:19:16 +0000913let Constraints = "$src1 = $dst" in {
Dan Gohman32791e02007-06-25 15:44:19 +0000914 let AddedComplexity = 20 in {
915 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000916 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000917 "movlps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000918 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000919 (movlp VR128:$src1,
920 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000921 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +0000922 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000923 "movhps\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +0000924 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000925 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +0000926 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2))))))]>;
Dan Gohman32791e02007-06-25 15:44:19 +0000927 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000928} // Constraints = "$src1 = $dst"
Evan Cheng4fcb9222006-03-28 02:43:26 +0000929
Evan Chengb70ea0b2008-05-10 00:59:18 +0000930
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000931def : Pat<(movlhps VR128:$src1, (bc_v4i32 (v2i64 (X86vzload addr:$src2)))),
Chris Lattner3485b512010-03-08 18:57:56 +0000932 (MOVHPSrm (v4i32 VR128:$src1), addr:$src2)>;
Nate Begeman7cdba6d2010-02-12 01:10:45 +0000933
Evan Cheng64d80e32007-07-19 01:14:50 +0000934def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000935 "movlps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000936 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
Evan Cheng015188f2006-06-15 08:14:54 +0000937 (iPTR 0))), addr:$dst)]>;
Evan Cheng9bbfd4f2006-03-28 07:01:28 +0000938
Evan Cheng664ade72006-04-07 21:20:58 +0000939// v2f64 extract element 1 is always custom lowered to unpack high to low
940// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +0000941def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000942 "movhps\t{$src, $dst|$dst, $src}",
Evan Cheng664ade72006-04-07 21:20:58 +0000943 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +0000944 (unpckh (bc_v2f64 (v4f32 VR128:$src)),
945 (undef)), (iPTR 0))), addr:$dst)]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +0000946
Evan Chenge9083d62008-03-05 08:19:16 +0000947let Constraints = "$src1 = $dst" in {
Evan Chengb7a75a52008-09-26 23:41:32 +0000948let AddedComplexity = 20 in {
Evan Cheng0af934e2009-05-12 20:17:52 +0000949def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst),
950 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000951 "movlhps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000952 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +0000953 (v4f32 (movlhps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2c0dbd02006-03-24 02:58:06 +0000954
Evan Cheng0af934e2009-05-12 20:17:52 +0000955def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst),
956 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000957 "movhlps\t{$src2, $dst|$dst, $src2}",
Evan Cheng4fcb9222006-03-28 02:43:26 +0000958 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +0000959 (v4f32 (movhlps VR128:$src1, VR128:$src2)))]>;
Evan Cheng2dadaea2006-04-19 20:37:34 +0000960} // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +0000961} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +0000962
Nate Begemanec8eee22009-04-29 22:47:44 +0000963let AddedComplexity = 20 in {
Nate Begeman9008ca62009-04-27 18:41:29 +0000964def : Pat<(v4f32 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +0000965 (MOVLHPSrr (v4f32 VR128:$src), (v4f32 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +0000966def : Pat<(v2i64 (movddup VR128:$src, (undef))),
Chris Lattner3485b512010-03-08 18:57:56 +0000967 (MOVLHPSrr (v2i64 VR128:$src), (v2i64 VR128:$src))>;
Nate Begemanec8eee22009-04-29 22:47:44 +0000968}
Evan Cheng0b457f02008-09-25 20:50:48 +0000969
Bill Wendlingddd35322007-05-02 23:11:52 +0000970
971
Dan Gohman20382522007-07-10 00:05:58 +0000972// Arithmetic
973
974/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
Bill Wendlingddd35322007-05-02 23:11:52 +0000975///
Dan Gohman20382522007-07-10 00:05:58 +0000976/// In addition, we also have a special variant of the scalar form here to
977/// represent the associated intrinsic operation. This form is unlike the
978/// plain scalar form, in that it takes an entire vector (instead of a
979/// scalar) and leaves the top elements undefined.
980///
981/// And, we have a special variant form for a full-vector intrinsic form.
982///
983/// These four forms can each have a reg or a mem operand, so there are a
984/// total of eight "instructions".
985///
986multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
987 SDNode OpNode,
988 Intrinsic F32Int,
989 Intrinsic V4F32Int,
990 bit Commutable = 0> {
991 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +0000992 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000993 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +0000994 [(set FR32:$dst, (OpNode FR32:$src))]> {
Bill Wendlingddd35322007-05-02 23:11:52 +0000995 let isCommutable = Commutable;
996 }
997
Dan Gohman20382522007-07-10 00:05:58 +0000998 // Scalar operation, mem.
Evan Cheng400073d2009-12-18 07:40:29 +0000999 def SSm : I<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001000 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Evan Cheng400073d2009-12-18 07:40:29 +00001001 [(set FR32:$dst, (OpNode (load addr:$src)))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001002 Requires<[HasSSE1, OptForSize]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001003
Dan Gohman20382522007-07-10 00:05:58 +00001004 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001005 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001006 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001007 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
1008 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001009 }
1010
Dan Gohman20382522007-07-10 00:05:58 +00001011 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001012 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001013 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001014 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001015
1016 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001017 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001018 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001019 [(set VR128:$dst, (F32Int VR128:$src))]> {
1020 let isCommutable = Commutable;
1021 }
1022
1023 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001024 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001025 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001026 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
1027
1028 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001029 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001030 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001031 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
1032 let isCommutable = Commutable;
1033 }
1034
1035 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001036 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001037 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001038 [(set VR128:$dst, (V4F32Int (memopv4f32 addr:$src)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001039}
1040
Dan Gohman20382522007-07-10 00:05:58 +00001041// Square root.
1042defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
1043 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
1044
1045// Reciprocal approximations. Note that these typically require refinement
1046// in order to obtain suitable precision.
1047defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
1048 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
1049defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
1050 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
1051
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001052/// sse12_fp_pack_logical - SSE 1 & 2 packed FP logical ops
1053///
1054multiclass sse12_fp_pack_logical<bits<8> opc, string OpcodeStr,
1055 SDNode OpNode, int HasPat = 0,
1056 bit Commutable = 1,
1057 list<list<dag>> Pattern = []> {
1058 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst),
1059 (ins VR128:$src1, VR128:$src2),
1060 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1061 !if(HasPat, Pattern[0],
1062 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1,
1063 VR128:$src2)))])>
1064 { let isCommutable = Commutable; }
1065
1066 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
1067 (ins VR128:$src1, VR128:$src2),
1068 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1069 !if(HasPat, Pattern[1],
1070 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1071 (bc_v2i64 (v2f64 VR128:$src2))))])>
1072 { let isCommutable = Commutable; }
1073
1074 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst),
1075 (ins VR128:$src1, f128mem:$src2),
1076 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
1077 !if(HasPat, Pattern[2],
1078 [(set VR128:$dst, (OpNode (bc_v2i64 (v4f32 VR128:$src1)),
1079 (memopv2i64 addr:$src2)))])>;
1080
1081 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1082 (ins VR128:$src1, f128mem:$src2),
1083 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
1084 !if(HasPat, Pattern[3],
1085 [(set VR128:$dst, (OpNode (bc_v2i64 (v2f64 VR128:$src1)),
1086 (memopv2i64 addr:$src2)))])>;
1087}
1088
Bill Wendlingddd35322007-05-02 23:11:52 +00001089// Logical
Evan Chenge9083d62008-03-05 08:19:16 +00001090let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopesf39e0ce2010-05-28 22:47:03 +00001091 defm AND : sse12_fp_pack_logical<0x54, "and", and>;
1092 defm OR : sse12_fp_pack_logical<0x56, "or", or>;
1093 defm XOR : sse12_fp_pack_logical<0x57, "xor", xor>;
1094 defm ANDN : sse12_fp_pack_logical<0x55, "andn", undef /* dummy */, 1, 0, [
1095 // single r+r
1096 [(set VR128:$dst, (v2i64 (and (xor VR128:$src1,
1097 (bc_v2i64 (v4i32 immAllOnesV))),
1098 VR128:$src2)))],
1099 // double r+r
1100 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1101 (bc_v2i64 (v2f64 VR128:$src2))))],
1102 // single r+m
1103 [(set VR128:$dst, (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
1104 (bc_v2i64 (v4i32 immAllOnesV))),
1105 (memopv2i64 addr:$src2))))],
1106 // double r+m
1107 [(set VR128:$dst, (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1108 (memopv2i64 addr:$src2)))]]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001109}
1110
Evan Chenge9083d62008-03-05 08:19:16 +00001111let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001112 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Nate Begemanc2616e42008-05-12 20:34:32 +00001113 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1114 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1115 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
1116 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001117 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Nate Begemanc2616e42008-05-12 20:34:32 +00001118 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1119 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
1120 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001121 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001122
1123 // Accept explicit immediate argument form instead of comparison code.
1124let isAsmParserOnly = 1 in {
1125 def CMPPSrri_alt : PSIi8<0xC2, MRMSrcReg,
1126 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1127 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1128 def CMPPSrmi_alt : PSIi8<0xC2, MRMSrcMem,
1129 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1130 "cmpps\t{$src2, $src, $dst|$dst, $src, $src}", []>;
1131}
Bill Wendlingddd35322007-05-02 23:11:52 +00001132}
Nate Begeman30a0de92008-07-17 16:51:19 +00001133def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), VR128:$src2, imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001134 (CMPPSrri (v4f32 VR128:$src1), (v4f32 VR128:$src2), imm:$cc)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00001135def : Pat<(v4i32 (X86cmpps (v4f32 VR128:$src1), (memop addr:$src2), imm:$cc)),
Chris Lattner3485b512010-03-08 18:57:56 +00001136 (CMPPSrmi (v4f32 VR128:$src1), addr:$src2, imm:$cc)>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001137
1138// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001139let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001140 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
Eric Christopher44b93ff2009-07-31 20:07:27 +00001141 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001142 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001143 VR128:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001144 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001145 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001146 (v4f32 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001147 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001148 (outs VR128:$dst), (ins VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001149 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001150 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001151 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001152 (v4f32 (shufp:$src3
1153 VR128:$src1, (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001154
1155 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001156 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001157 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001158 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001159 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001160 (v4f32 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001161 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001162 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001163 "unpckhps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001164 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001165 (v4f32 (unpckh VR128:$src1,
1166 (memopv4f32 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001167
Eric Christopher44b93ff2009-07-31 20:07:27 +00001168 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001169 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001170 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001171 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001172 (v4f32 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001173 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001174 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001175 "unpcklps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001176 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001177 (unpckl VR128:$src1, (memopv4f32 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001178 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001179} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001180
1181// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00001182def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001183 "movmskps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001184 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Cheng8a0b2da2009-05-28 18:55:28 +00001185def MOVMSKPDrr : PDI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001186 "movmskpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001187 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
1188
Evan Cheng27b7db52008-03-08 00:58:38 +00001189// Prefetch intrinsic.
1190def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src),
1191 "prefetcht0\t$src", [(prefetch addr:$src, imm, (i32 3))]>;
1192def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src),
1193 "prefetcht1\t$src", [(prefetch addr:$src, imm, (i32 2))]>;
1194def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src),
1195 "prefetcht2\t$src", [(prefetch addr:$src, imm, (i32 1))]>;
1196def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src),
1197 "prefetchnta\t$src", [(prefetch addr:$src, imm, (i32 0))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001198
1199// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00001200def MOVNTPSmr_Int : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001201 "movntps\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001202 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
1203
David Greene8939b0d2010-02-16 20:50:18 +00001204let AddedComplexity = 400 in { // Prefer non-temporal versions
1205def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1206 "movntps\t{$src, $dst|$dst, $src}",
1207 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
1208
1209def MOVNTDQ_64mr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
1210 "movntdq\t{$src, $dst|$dst, $src}",
1211 [(alignednontemporalstore (v2f64 VR128:$src), addr:$dst)]>;
1212
David Greene8939b0d2010-02-16 20:50:18 +00001213def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1214 "movnti\t{$src, $dst|$dst, $src}",
1215 [(nontemporalstore (i32 GR32:$src), addr:$dst)]>,
1216 TB, Requires<[HasSSE2]>;
1217
1218def MOVNTI_64mr : RI<0xC3, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1219 "movnti\t{$src, $dst|$dst, $src}",
1220 [(nontemporalstore (i64 GR64:$src), addr:$dst)]>,
1221 TB, Requires<[HasSSE2]>;
1222}
1223
Bill Wendlingddd35322007-05-02 23:11:52 +00001224// Load, store, and memory fence
Dan Gohmanee5673b2010-05-20 01:23:41 +00001225def SFENCE : I<0xAE, MRM_F8, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>,
1226 TB, Requires<[HasSSE1]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001227
1228// MXCSR register
Evan Cheng64d80e32007-07-19 01:14:50 +00001229def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001230 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001231def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001232 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001233
1234// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00001235// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00001236// load of an all-zeros value if folding it would be beneficial.
Chris Lattner28c1d292010-02-05 21:30:49 +00001237// FIXME: Change encoding to pseudo!
Daniel Dunbar7417b762009-08-11 22:17:52 +00001238let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001239 isCodeGenOnly = 1 in {
1240def V_SET0PS : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1241 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
1242def V_SET0PD : PDI<0x57, MRMInitReg, (outs VR128:$dst), (ins), "",
1243 [(set VR128:$dst, (v2f64 immAllZerosV))]>;
1244let ExeDomain = SSEPackedInt in
1245def V_SET0PI : PDI<0xEF, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00001246 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001247}
Bill Wendlingddd35322007-05-02 23:11:52 +00001248
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00001249def : Pat<(v2i64 immAllZerosV), (V_SET0PI)>;
1250def : Pat<(v8i16 immAllZerosV), (V_SET0PI)>;
1251def : Pat<(v16i8 immAllZerosV), (V_SET0PI)>;
Evan Chengc8e3b142008-03-12 07:02:50 +00001252
Dan Gohman874cada2010-02-28 00:17:42 +00001253def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001254 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss))>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001255
Eric Christopher44b93ff2009-07-31 20:07:27 +00001256//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001257// SSE2 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00001258//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001259
Dan Gohman874cada2010-02-28 00:17:42 +00001260// Move Instructions. Register-to-register movsd is not used for FR64
1261// register copies because it's a partial register update; FsMOVAPDrr is
1262// used instead. Register-to-register movsd is not modeled as an INSERT_SUBREG
1263// because INSERT_SUBREG requires that the insert be implementable in terms of
1264// a copy, and just mentioned, we don't use movsd for copies.
1265let Constraints = "$src1 = $dst" in
1266def MOVSDrr : SDI<0x10, MRMSrcReg,
1267 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
1268 "movsd\t{$src2, $dst|$dst, $src2}",
Chris Lattner3d005782010-03-15 05:53:30 +00001269 [(set (v2f64 VR128:$dst),
Dan Gohman874cada2010-02-28 00:17:42 +00001270 (movl VR128:$src1, (scalar_to_vector FR64:$src2)))]>;
1271
1272// Extract the low 64-bit value from one vector and insert it into another.
1273let AddedComplexity = 15 in
1274def : Pat<(v2f64 (movl VR128:$src1, VR128:$src2)),
Chris Lattner3485b512010-03-08 18:57:56 +00001275 (MOVSDrr (v2f64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001276 (EXTRACT_SUBREG (v2f64 VR128:$src2), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001277
1278// Implicitly promote a 64-bit scalar to a vector.
1279def : Pat<(v2f64 (scalar_to_vector FR64:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001280 (INSERT_SUBREG (v2f64 (IMPLICIT_DEF)), FR64:$src, sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001281
1282// Loading from memory automatically zeroing upper bits.
1283let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 20 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001284def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001285 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001286 [(set FR64:$dst, (loadf64 addr:$src))]>;
Dan Gohman874cada2010-02-28 00:17:42 +00001287
1288// MOVSDrm zeros the high parts of the register; represent this
1289// with SUBREG_TO_REG.
1290let AddedComplexity = 20 in {
1291def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector (loadf64 addr:$src))))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001292 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001293def : Pat<(v2f64 (scalar_to_vector (loadf64 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001294 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001295def : Pat<(v2f64 (X86vzmovl (loadv2f64 addr:$src))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001296 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001297def : Pat<(v2f64 (X86vzmovl (bc_v2f64 (loadv4f32 addr:$src)))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001298 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001299def : Pat<(v2f64 (X86vzload addr:$src)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001300 (SUBREG_TO_REG (i64 0), (MOVSDrm addr:$src), sub_sd)>;
Dan Gohman874cada2010-02-28 00:17:42 +00001301}
1302
1303// Store scalar value to memory.
Evan Cheng64d80e32007-07-19 01:14:50 +00001304def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001305 "movsd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001306 [(store FR64:$src, addr:$dst)]>;
1307
Dan Gohman874cada2010-02-28 00:17:42 +00001308// Extract and store.
1309def : Pat<(store (f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
1310 addr:$dst),
1311 (MOVSDmr addr:$dst,
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00001312 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00001313
Bill Wendlingddd35322007-05-02 23:11:52 +00001314// Conversion instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00001315def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001316 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001317 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001318def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001319 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001320 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001321def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001322 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001323 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001324def CVTSD2SSrm : I<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001325 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Evan Cheng400073d2009-12-18 07:40:29 +00001326 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>, XD,
Evan Chengb1f49812009-12-22 17:47:23 +00001327 Requires<[HasSSE2, OptForSize]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001328def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001329 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001330 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001331def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001332 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001333 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1334
Sean Callanan5ab94032009-09-16 01:13:52 +00001335def CVTPD2DQrm : S3DI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1336 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1337def CVTPD2DQrr : S3DI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1338 "cvtpd2dq\t{$src, $dst|$dst, $src}", []>;
1339def CVTDQ2PDrm : S3SI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1340 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1341def CVTDQ2PDrr : S3SI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1342 "cvtdq2pd\t{$src, $dst|$dst, $src}", []>;
1343def CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1344 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1345def CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1346 "cvtps2dq\t{$src, $dst|$dst, $src}", []>;
1347def CVTDQ2PSrr : PSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1348 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1349def CVTDQ2PSrm : PSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1350 "cvtdq2ps\t{$src, $dst|$dst, $src}", []>;
1351def COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
1352 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1353def COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
1354 "comisd\t{$src2, $src1|$src1, $src2}", []>;
1355
Bill Wendlingddd35322007-05-02 23:11:52 +00001356// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001357def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001358 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001359 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1360 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001361def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001362 "cvtss2sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001363 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
Evan Chengb1f49812009-12-22 17:47:23 +00001364 Requires<[HasSSE2, OptForSize]>;
Evan Cheng400073d2009-12-18 07:40:29 +00001365
1366def : Pat<(extloadf32 addr:$src),
Dan Gohman874cada2010-02-28 00:17:42 +00001367 (CVTSS2SDrr (MOVSSrm addr:$src))>,
1368 Requires<[HasSSE2, OptForSpeed]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001369
1370// Match intrinsics which expect XMM operand(s).
Evan Cheng64d80e32007-07-19 01:14:50 +00001371def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001372 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001373 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001374def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001375 "cvtsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001376 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1377 (load addr:$src)))]>;
1378
Dan Gohmand9c2af52010-05-26 18:03:53 +00001379// Match intrinsics which expect MM and XMM operand(s).
Dale Johannesenc7842082007-10-30 22:15:38 +00001380def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1381 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1382 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1383def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1384 "cvtpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001385 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001386 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001387def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1388 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1389 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1390def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1391 "cvttpd2pi\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001392 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
Evan Chengb1938262008-05-23 00:37:07 +00001393 (memop addr:$src)))]>;
Dale Johannesenc7842082007-10-30 22:15:38 +00001394def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1395 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1396 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1397def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1398 "cvtpi2pd\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001399 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
Dale Johannesenc7842082007-10-30 22:15:38 +00001400 (load addr:$src)))]>;
1401
Bill Wendlingddd35322007-05-02 23:11:52 +00001402// Aliases for intrinsics
Evan Cheng64d80e32007-07-19 01:14:50 +00001403def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001404 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001405 [(set GR32:$dst,
1406 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001407def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001408 "cvttsd2si\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001409 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1410 (load addr:$src)))]>;
1411
1412// Comparison instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001413let Constraints = "$src1 = $dst", neverHasSideEffects = 1 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001414 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001415 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001416 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001417let mayLoad = 1 in
Eric Christopher44b93ff2009-07-31 20:07:27 +00001418 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001419 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001420 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001421
1422 // Accept explicit immediate argument form instead of comparison code.
1423let isAsmParserOnly = 1 in {
1424 def CMPSDrr_alt : SDIi8<0xC2, MRMSrcReg,
1425 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, i8imm:$src2),
1426 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1427let mayLoad = 1 in
1428 def CMPSDrm_alt : SDIi8<0xC2, MRMSrcMem,
1429 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, i8imm:$src2),
1430 "cmpsd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1431}
Bill Wendlingddd35322007-05-02 23:11:52 +00001432}
1433
Evan Cheng0488db92007-09-25 01:57:46 +00001434let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001435def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001436 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001437 [(set EFLAGS, (X86cmp FR64:$src1, FR64:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001438def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001439 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001440 [(set EFLAGS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001441} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001442
Bill Wendlingddd35322007-05-02 23:11:52 +00001443// Aliases to match intrinsics which expect XMM operand(s).
Evan Chenge9083d62008-03-05 08:19:16 +00001444let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001445 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001446 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001447 (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001448 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001449 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1450 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001451 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001452 (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001453 (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001454 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001455 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1456 (load addr:$src), imm:$cc))]>;
1457}
1458
Evan Cheng0488db92007-09-25 01:57:46 +00001459let Defs = [EFLAGS] in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001460def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001461 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001462 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1463 VR128:$src2))]>;
Evan Chenge5f62042007-09-29 00:00:36 +00001464def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001465 "ucomisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001466 [(set EFLAGS, (X86ucomi (v2f64 VR128:$src1),
1467 (load addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001468
Evan Cheng64d80e32007-07-19 01:14:50 +00001469def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001470 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001471 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1472 VR128:$src2))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001473def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001474 "comisd\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001475 [(set EFLAGS, (X86comi (v2f64 VR128:$src1),
1476 (load addr:$src2)))]>;
Dan Gohmanb1347092009-01-09 02:27:34 +00001477} // Defs = [EFLAGS]
Evan Cheng0488db92007-09-25 01:57:46 +00001478
Eric Christopher44b93ff2009-07-31 20:07:27 +00001479// Aliases of packed SSE2 instructions for scalar use. These all have names
1480// that start with 'Fs'.
Bill Wendlingddd35322007-05-02 23:11:52 +00001481
1482// Alias instructions that map fld0 to pxor for sse.
Dan Gohman4a0b3e12009-09-21 18:30:38 +00001483let isReMaterializable = 1, isAsCheapAsAMove = 1, isCodeGenOnly = 1,
1484 canFoldAsLoad = 1 in
Chris Lattnerbe1778f2010-02-05 21:34:18 +00001485def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins), "",
1486 [(set FR64:$dst, fpimm0)]>,
Bill Wendlingddd35322007-05-02 23:11:52 +00001487 Requires<[HasSSE2]>, TB, OpSize;
1488
Dan Gohman32791e02007-06-25 15:44:19 +00001489// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001490// disregarded.
Chris Lattnerba7e7562008-01-10 07:59:24 +00001491let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001492def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001493 "movapd\t{$src, $dst|$dst, $src}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001494
Dan Gohman32791e02007-06-25 15:44:19 +00001495// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
Bill Wendlingddd35322007-05-02 23:11:52 +00001496// disregarded.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001497let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001498def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001499 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohmand3006222007-07-27 17:16:43 +00001500 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001501
Eric Christopher44b93ff2009-07-31 20:07:27 +00001502//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00001503// SSE packed FP Instructions
1504
1505// Move Instructions
Chris Lattnerba7e7562008-01-10 07:59:24 +00001506let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001507def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001508 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001509let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001510def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001511 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001512 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001513
Evan Cheng64d80e32007-07-19 01:14:50 +00001514def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001515 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001516 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001517
Chris Lattnerf77e0372008-01-11 06:59:07 +00001518let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001519def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001520 "movupd\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001521let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001522def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001523 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001524 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001525def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001526 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001527 [(store (v2f64 VR128:$src), addr:$dst)]>;
1528
1529// Intrinsic forms of MOVUPD load and store
Evan Cheng64d80e32007-07-19 01:14:50 +00001530def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001531 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001532 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001533def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001534 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001535 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001536
Evan Chenge9083d62008-03-05 08:19:16 +00001537let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001538 let AddedComplexity = 20 in {
1539 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001540 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001541 "movlpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001542 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001543 (v2f64 (movlp VR128:$src1,
1544 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001545 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001546 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001547 "movhpd\t{$src2, $dst|$dst, $src2}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00001548 [(set VR128:$dst,
Nate Begeman0b10b912009-11-07 23:17:15 +00001549 (v2f64 (movlhps VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00001550 (scalar_to_vector (loadf64 addr:$src2)))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001551 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001552} // Constraints = "$src1 = $dst"
Bill Wendlingddd35322007-05-02 23:11:52 +00001553
Evan Cheng64d80e32007-07-19 01:14:50 +00001554def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001555 "movlpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001556 [(store (f64 (vector_extract (v2f64 VR128:$src),
1557 (iPTR 0))), addr:$dst)]>;
1558
1559// v2f64 extract element 1 is always custom lowered to unpack high to low
1560// and extract element 0 so the non-store version isn't too horrible.
Evan Cheng64d80e32007-07-19 01:14:50 +00001561def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001562 "movhpd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001563 [(store (f64 (vector_extract
Nate Begeman9008ca62009-04-27 18:41:29 +00001564 (v2f64 (unpckh VR128:$src, (undef))),
1565 (iPTR 0))), addr:$dst)]>;
Evan Chengd9539472006-04-14 21:59:03 +00001566
Evan Cheng470a6ad2006-02-22 02:26:30 +00001567// SSE2 instructions without OpSize prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001568def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001569 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001570 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1571 TB, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001572def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001573 "cvtdq2ps\t{$src, $dst|$dst, $src}",
1574 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
1575 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001576 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001577
1578// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001579def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001580 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001581 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1582 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001583def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001584 "cvtdq2pd\t{$src, $dst|$dst, $src}",
1585 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
1586 (bitconvert (memopv2i64 addr:$src))))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001587 XS, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001588
Evan Cheng64d80e32007-07-19 01:14:50 +00001589def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Evan Cheng029d9da2008-03-14 07:46:48 +00001590 "cvtps2dq\t{$src, $dst|$dst, $src}",
1591 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001592def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001593 "cvtps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001594 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001595 (memop addr:$src)))]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001596// SSE2 packed instructions with XS prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001597def CVTTPS2DQrr : SSI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1598 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1599def CVTTPS2DQrm : SSI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1600 "cvttps2dq\t{$src, $dst|$dst, $src}", []>;
1601
Evan Cheng64d80e32007-07-19 01:14:50 +00001602def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001603 "cvttps2dq\t{$src, $dst|$dst, $src}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001604 [(set VR128:$dst,
Sean Callanan108934c2009-12-18 00:01:26 +00001605 (int_x86_sse2_cvttps2dq VR128:$src))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001606 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001607def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001608 "cvttps2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001609 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
Evan Chengb1938262008-05-23 00:37:07 +00001610 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001611 XS, Requires<[HasSSE2]>;
Evan Chengd03db7a2006-04-12 05:20:24 +00001612
Evan Cheng470a6ad2006-02-22 02:26:30 +00001613// SSE2 packed instructions with XD prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00001614def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001615 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001616 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1617 XD, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001618def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001619 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001620 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001621 (memop addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001622 XD, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001623
Evan Cheng64d80e32007-07-19 01:14:50 +00001624def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001625 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001626 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Cheng029d9da2008-03-14 07:46:48 +00001627def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst),(ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001628 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001629 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
Evan Chengb1938262008-05-23 00:37:07 +00001630 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001631
1632// SSE2 instructions without OpSize prefix
Sean Callanan108934c2009-12-18 00:01:26 +00001633def CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1634 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1635def CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
1636 "cvtps2pd\t{$src, $dst|$dst, $src}", []>, TB;
1637
Evan Cheng64d80e32007-07-19 01:14:50 +00001638def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001639 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001640 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1641 TB, Requires<[HasSSE2]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001642def Int_CVTPS2PDrm : I<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001643 "cvtps2pd\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001644 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
Chris Lattner15258d52006-10-07 06:17:43 +00001645 (load addr:$src)))]>,
Evan Cheng190717d2006-05-31 19:00:07 +00001646 TB, Requires<[HasSSE2]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001647
Sean Callanan108934c2009-12-18 00:01:26 +00001648def CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
1649 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1650def CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
1651 "cvtpd2ps\t{$src, $dst|$dst, $src}", []>;
1652
1653
Evan Cheng64d80e32007-07-19 01:14:50 +00001654def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001655 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001656 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Mon P Wangbfbbd4d2008-05-28 00:42:27 +00001657def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001658 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Evan Cheng190717d2006-05-31 19:00:07 +00001659 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
Evan Chengb1938262008-05-23 00:37:07 +00001660 (memop addr:$src)))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001661
Evan Chengd2a6d542006-04-12 23:42:44 +00001662// Match intrinsics which expect XMM operand(s).
1663// Aliases for intrinsics
Evan Chenge9083d62008-03-05 08:19:16 +00001664let Constraints = "$src1 = $dst" in {
Evan Chengd2a6d542006-04-12 23:42:44 +00001665def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001666 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001667 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001668 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
Evan Cheng069287d2006-05-16 07:21:53 +00001669 GR32:$src2))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001670def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001671 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001672 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001673 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1674 (loadi32 addr:$src2)))]>;
1675def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001676 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001677 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001678 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1679 VR128:$src2))]>;
1680def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001681 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001682 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001683 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001684 (load addr:$src2)))]>;
Evan Chengd2a6d542006-04-12 23:42:44 +00001685def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001686 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001687 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001688 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1689 VR128:$src2))]>, XS,
1690 Requires<[HasSSE2]>;
1691def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001692 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001693 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Evan Chengd2a6d542006-04-12 23:42:44 +00001694 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
Chris Lattner15258d52006-10-07 06:17:43 +00001695 (load addr:$src2)))]>, XS,
Evan Chengd2a6d542006-04-12 23:42:44 +00001696 Requires<[HasSSE2]>;
1697}
1698
Dan Gohman20382522007-07-10 00:05:58 +00001699// Arithmetic
1700
1701/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
Chris Lattner6f987732006-10-07 21:17:13 +00001702///
Dan Gohman20382522007-07-10 00:05:58 +00001703/// In addition, we also have a special variant of the scalar form here to
1704/// represent the associated intrinsic operation. This form is unlike the
1705/// plain scalar form, in that it takes an entire vector (instead of a
1706/// scalar) and leaves the top elements undefined.
1707///
1708/// And, we have a special variant form for a full-vector intrinsic form.
1709///
1710/// These four forms can each have a reg or a mem operand, so there are a
1711/// total of eight "instructions".
1712///
1713multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1714 SDNode OpNode,
1715 Intrinsic F64Int,
1716 Intrinsic V2F64Int,
1717 bit Commutable = 0> {
1718 // Scalar operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001719 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001720 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001721 [(set FR64:$dst, (OpNode FR64:$src))]> {
Chris Lattner6f987732006-10-07 21:17:13 +00001722 let isCommutable = Commutable;
1723 }
Bill Wendlingddd35322007-05-02 23:11:52 +00001724
Dan Gohman20382522007-07-10 00:05:58 +00001725 // Scalar operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001726 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001727 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001728 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001729
Dan Gohman20382522007-07-10 00:05:58 +00001730 // Vector operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001731 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001732 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001733 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1734 let isCommutable = Commutable;
Bill Wendlingddd35322007-05-02 23:11:52 +00001735 }
1736
Dan Gohman20382522007-07-10 00:05:58 +00001737 // Vector operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001738 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001739 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4106f372007-07-18 20:23:34 +00001740 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohman20382522007-07-10 00:05:58 +00001741
1742 // Intrinsic operation, reg.
Evan Cheng64d80e32007-07-19 01:14:50 +00001743 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001744 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001745 [(set VR128:$dst, (F64Int VR128:$src))]> {
1746 let isCommutable = Commutable;
1747 }
1748
1749 // Intrinsic operation, mem.
Evan Cheng64d80e32007-07-19 01:14:50 +00001750 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001751 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001752 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1753
1754 // Vector intrinsic operation, reg
Evan Cheng64d80e32007-07-19 01:14:50 +00001755 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001756 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman20382522007-07-10 00:05:58 +00001757 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1758 let isCommutable = Commutable;
1759 }
1760
1761 // Vector intrinsic operation, mem
Dan Gohmanf3372d12007-08-02 21:06:40 +00001762 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001763 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Evan Chengb1938262008-05-23 00:37:07 +00001764 [(set VR128:$dst, (V2F64Int (memopv2f64 addr:$src)))]>;
Evan Cheng97ac5fa2006-04-03 23:49:17 +00001765}
Evan Chengffcb95b2006-02-21 19:13:53 +00001766
Dan Gohman20382522007-07-10 00:05:58 +00001767// Square root.
1768defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1769 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1770
1771// There is no f64 version of the reciprocal approximation instructions.
1772
Evan Chenge9083d62008-03-05 08:19:16 +00001773let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001774 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001775 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
1776 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1777 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Nate Begemanc2616e42008-05-12 20:34:32 +00001778 VR128:$src, imm:$cc))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001779 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Cheng029d9da2008-03-14 07:46:48 +00001780 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
1781 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
1782 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00001783 (memop addr:$src), imm:$cc))]>;
Daniel Dunbar79373682010-05-25 18:40:53 +00001784
1785 // Accept explicit immediate argument form instead of comparison code.
1786let isAsmParserOnly = 1 in {
1787 def CMPPDrri_alt : PDIi8<0xC2, MRMSrcReg,
1788 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, i8imm:$src2),
1789 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1790 def CMPPDrmi_alt : PDIi8<0xC2, MRMSrcMem,
1791 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, i8imm:$src2),
1792 "cmppd\t{$src2, $src, $dst|$dst, $src, $src2}", []>;
1793}
Evan Cheng470a6ad2006-02-22 02:26:30 +00001794}
Evan Chenge9d50352008-08-05 22:19:15 +00001795def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), VR128:$src2, imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001796 (CMPPDrri VR128:$src1, VR128:$src2, imm:$cc)>;
Evan Chenge9d50352008-08-05 22:19:15 +00001797def : Pat<(v2i64 (X86cmppd (v2f64 VR128:$src1), (memop addr:$src2), imm:$cc)),
Nate Begeman30a0de92008-07-17 16:51:19 +00001798 (CMPPDrmi VR128:$src1, addr:$src2, imm:$cc)>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001799
1800// Shuffle and unpack instructions
Evan Chenge9083d62008-03-05 08:19:16 +00001801let Constraints = "$src1 = $dst" in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001802 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Cheng029d9da2008-03-14 07:46:48 +00001803 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
1804 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begeman9008ca62009-04-27 18:41:29 +00001805 [(set VR128:$dst,
1806 (v2f64 (shufp:$src3 VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001807 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001808 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00001809 f128mem:$src2, i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001810 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001811 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001812 (v2f64 (shufp:$src3
1813 VR128:$src1, (memopv2f64 addr:$src2))))]>;
Evan Cheng470a6ad2006-02-22 02:26:30 +00001814
Bill Wendlingddd35322007-05-02 23:11:52 +00001815 let AddedComplexity = 10 in {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001816 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001817 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001818 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001819 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001820 (v2f64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001821 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001822 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001823 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001824 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001825 (v2f64 (unpckh VR128:$src1,
1826 (memopv2f64 addr:$src2))))]>;
Evan Cheng4fcb9222006-03-28 02:43:26 +00001827
Eric Christopher44b93ff2009-07-31 20:07:27 +00001828 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00001829 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001830 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001831 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001832 (v2f64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00001833 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00001834 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001835 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00001836 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00001837 (unpckl VR128:$src1, (memopv2f64 addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00001838 } // AddedComplexity
Evan Chenge9083d62008-03-05 08:19:16 +00001839} // Constraints = "$src1 = $dst"
Evan Cheng470a6ad2006-02-22 02:26:30 +00001840
Evan Cheng4b1734f2006-03-31 21:29:33 +00001841
Eric Christopher44b93ff2009-07-31 20:07:27 +00001842//===---------------------------------------------------------------------===//
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001843// SSE integer instructions
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001844let ExeDomain = SSEPackedInt in {
Evan Chengbf156d12006-02-21 19:26:52 +00001845
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001846// Move Instructions
Chris Lattnerf77e0372008-01-11 06:59:07 +00001847let neverHasSideEffects = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001848def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001849 "movdqa\t{$src, $dst|$dst, $src}", []>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001850let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001851def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001852 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001853 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001854let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001855def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001856 "movdqa\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001857 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Dan Gohman15511cf2008-12-03 18:15:48 +00001858let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001859def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001860 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001861 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001862 XS, Requires<[HasSSE2]>;
Chris Lattnerf77e0372008-01-11 06:59:07 +00001863let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001864def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001865 "movdqu\t{$src, $dst|$dst, $src}",
Evan Chengb4162fd2007-07-20 00:27:43 +00001866 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Evan Cheng9ab1ac52006-04-14 23:32:40 +00001867 XS, Requires<[HasSSE2]>;
Evan Cheng24dc1f52006-03-23 07:44:07 +00001868
Dan Gohman4106f372007-07-18 20:23:34 +00001869// Intrinsic forms of MOVDQU load and store
Dan Gohman15511cf2008-12-03 18:15:48 +00001870let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +00001871def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001872 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001873 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1874 XS, Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001875def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001876 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4106f372007-07-18 20:23:34 +00001877 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1878 XS, Requires<[HasSSE2]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001879
Evan Chenge7b8a8b2008-03-05 08:11:27 +00001880let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00001881
Chris Lattner45e123c2006-10-07 19:02:31 +00001882multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1883 bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001884 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001885 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001886 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001887 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1888 let isCommutable = Commutable;
1889 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001890 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001891 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001892 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner8139e282006-10-07 18:39:00 +00001893 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001894 (bitconvert (memopv2i64
Sean Callanan108934c2009-12-18 00:01:26 +00001895 addr:$src2))))]>;
Chris Lattner8139e282006-10-07 18:39:00 +00001896}
Chris Lattner8139e282006-10-07 18:39:00 +00001897
Evan Cheng22b942a2008-05-03 00:52:09 +00001898multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1899 string OpcodeStr,
1900 Intrinsic IntId, Intrinsic IntId2> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001901 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001902 (ins VR128:$src1, VR128:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001903 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1904 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001905 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
1906 (ins VR128:$src1, i128mem:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001907 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1908 [(set VR128:$dst, (IntId VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001909 (bitconvert (memopv2i64 addr:$src2))))]>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001910 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001911 (ins VR128:$src1, i32i8imm:$src2),
Evan Cheng22b942a2008-05-03 00:52:09 +00001912 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
1913 [(set VR128:$dst, (IntId2 VR128:$src1, (i32 imm:$src2)))]>;
1914}
1915
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001916/// PDI_binop_rm - Simple SSE2 binary operator.
1917multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1918 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001919 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001920 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001921 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001922 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1923 let isCommutable = Commutable;
1924 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00001925 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001926 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001927 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001928 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Eric Christopher44b93ff2009-07-31 20:07:27 +00001929 (bitconvert (memopv2i64 addr:$src2)))))]>;
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001930}
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001931
1932/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1933///
1934/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1935/// to collapse (bitconvert VT to VT) into its operand.
1936///
1937multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1938 bit Commutable = 0> {
Eric Christopher44b93ff2009-07-31 20:07:27 +00001939 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001940 (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001941 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001942 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1943 let isCommutable = Commutable;
1944 }
Eric Christopher44b93ff2009-07-31 20:07:27 +00001945 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00001946 (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001947 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00001948 [(set VR128:$dst, (OpNode VR128:$src1,
Sean Callanan108934c2009-12-18 00:01:26 +00001949 (memopv2i64 addr:$src2)))]>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001950}
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001951
Evan Chenge9083d62008-03-05 08:19:16 +00001952} // Constraints = "$src1 = $dst"
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00001953} // ExeDomain = SSEPackedInt
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001954
1955// 128-bit Integer Arithmetic
1956
1957defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1958defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1959defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001960defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001961
Chris Lattner45e123c2006-10-07 19:02:31 +00001962defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1963defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1964defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1965defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001966
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001967defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1968defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1969defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
Chris Lattner70f4f2e2006-10-07 19:34:33 +00001970defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001971
Chris Lattner45e123c2006-10-07 19:02:31 +00001972defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1973defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1974defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1975defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
Evan Cheng49ac1bf2006-04-13 00:43:35 +00001976
Chris Lattner7c47f9a2006-10-07 19:14:49 +00001977defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00001978
Chris Lattner45e123c2006-10-07 19:02:31 +00001979defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1980defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1981defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
Evan Cheng00586942006-04-13 06:11:45 +00001982
Chris Lattner45e123c2006-10-07 19:02:31 +00001983defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
Chris Lattner77337992006-10-07 07:06:17 +00001984
Chris Lattner45e123c2006-10-07 19:02:31 +00001985defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1986defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
Chris Lattner8139e282006-10-07 18:39:00 +00001987
Chris Lattner77337992006-10-07 07:06:17 +00001988
Chris Lattner45e123c2006-10-07 19:02:31 +00001989defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1990defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1991defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1992defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
Bill Wendling3b1259b2009-05-28 02:04:00 +00001993defm PSADBW : PDI_binop_rm_int<0xF6, "psadbw", int_x86_sse2_psad_bw, 1>;
Evan Chengc60bd972006-03-25 09:37:23 +00001994
Chris Lattner77337992006-10-07 07:06:17 +00001995
Evan Cheng22b942a2008-05-03 00:52:09 +00001996defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
1997 int_x86_sse2_psll_w, int_x86_sse2_pslli_w>;
1998defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
1999 int_x86_sse2_psll_d, int_x86_sse2_pslli_d>;
2000defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
2001 int_x86_sse2_psll_q, int_x86_sse2_pslli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002002
Evan Cheng22b942a2008-05-03 00:52:09 +00002003defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
2004 int_x86_sse2_psrl_w, int_x86_sse2_psrli_w>;
2005defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
2006 int_x86_sse2_psrl_d, int_x86_sse2_psrli_d>;
Nate Begeman32097bd2008-05-13 17:52:09 +00002007defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Cheng22b942a2008-05-03 00:52:09 +00002008 int_x86_sse2_psrl_q, int_x86_sse2_psrli_q>;
Chris Lattner77337992006-10-07 07:06:17 +00002009
Evan Cheng22b942a2008-05-03 00:52:09 +00002010defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
2011 int_x86_sse2_psra_w, int_x86_sse2_psrai_w>;
Nate Begemanc9bdb002008-05-13 01:47:52 +00002012defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Cheng22b942a2008-05-03 00:52:09 +00002013 int_x86_sse2_psra_d, int_x86_sse2_psrai_d>;
Chris Lattner77337992006-10-07 07:06:17 +00002014
Chris Lattner6970eda2006-10-07 19:49:05 +00002015// 128-bit logical shifts.
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002016let Constraints = "$src1 = $dst", neverHasSideEffects = 1,
2017 ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002018 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002019 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002020 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002021 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Cheng64d80e32007-07-19 01:14:50 +00002022 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002023 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002024 // PSRADQri doesn't exist in SSE[1-3].
Evan Chengff65e382006-04-04 21:49:39 +00002025}
2026
Chris Lattner6970eda2006-10-07 19:49:05 +00002027let Predicates = [HasSSE2] in {
2028 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002029 (v2i64 (PSLLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002030 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
Evan Cheng89321162009-10-28 06:30:34 +00002031 (v2i64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Bill Wendling5e249b42008-10-02 05:56:52 +00002032 def : Pat<(int_x86_sse2_psll_dq_bs VR128:$src1, imm:$src2),
2033 (v2i64 (PSLLDQri VR128:$src1, imm:$src2))>;
2034 def : Pat<(int_x86_sse2_psrl_dq_bs VR128:$src1, imm:$src2),
2035 (v2i64 (PSRLDQri VR128:$src1, imm:$src2))>;
Evan Cheng68c47cb2007-01-05 07:55:56 +00002036 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
Evan Cheng89321162009-10-28 06:30:34 +00002037 (v2f64 (PSRLDQri VR128:$src1, (BYTE_imm imm:$src2)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002038
2039 // Shift up / down and insert zero's.
2040 def : Pat<(v2i64 (X86vshl VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002041 (v2i64 (PSLLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Evan Chengf26ffe92008-05-29 08:22:04 +00002042 def : Pat<(v2i64 (X86vshr VR128:$src, (i8 imm:$amt))),
Evan Cheng89321162009-10-28 06:30:34 +00002043 (v2i64 (PSRLDQri VR128:$src, (BYTE_imm imm:$amt)))>;
Chris Lattner6970eda2006-10-07 19:49:05 +00002044}
2045
Evan Cheng506d3df2006-03-29 23:07:14 +00002046// Logical
Chris Lattnera7ebe552006-10-07 19:37:30 +00002047defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
2048defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
2049defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
2050
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002051let Constraints = "$src1 = $dst", ExeDomain = SSEPackedInt in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002052 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002053 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002054 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002055 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
2056 VR128:$src2)))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002057
Bill Wendlingddd35322007-05-02 23:11:52 +00002058 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002059 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002060 "pandn\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002061 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002062 (memopv2i64 addr:$src2))))]>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002063}
2064
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002065// SSE2 Integer comparison
Bill Wendlingddd35322007-05-02 23:11:52 +00002066defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
2067defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
2068defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
2069defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
2070defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
2071defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002072
Nate Begeman30a0de92008-07-17 16:51:19 +00002073def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002074 (PCMPEQBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002075def : Pat<(v16i8 (X86pcmpeqb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002076 (PCMPEQBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002077def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002078 (PCMPEQWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002079def : Pat<(v8i16 (X86pcmpeqw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002080 (PCMPEQWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002081def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002082 (PCMPEQDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002083def : Pat<(v4i32 (X86pcmpeqd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002084 (PCMPEQDrm VR128:$src1, addr:$src2)>;
2085
Nate Begeman30a0de92008-07-17 16:51:19 +00002086def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002087 (PCMPGTBrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002088def : Pat<(v16i8 (X86pcmpgtb VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002089 (PCMPGTBrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002090def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002091 (PCMPGTWrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002092def : Pat<(v8i16 (X86pcmpgtw VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002093 (PCMPGTWrm VR128:$src1, addr:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002094def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, VR128:$src2)),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002095 (PCMPGTDrr VR128:$src1, VR128:$src2)>;
Nate Begeman30a0de92008-07-17 16:51:19 +00002096def : Pat<(v4i32 (X86pcmpgtd VR128:$src1, (memop addr:$src2))),
Nate Begeman0d1704b2008-05-12 23:09:43 +00002097 (PCMPGTDrm VR128:$src1, addr:$src2)>;
2098
2099
Evan Cheng506d3df2006-03-29 23:07:14 +00002100// Pack instructions
Chris Lattner45e123c2006-10-07 19:02:31 +00002101defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
2102defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
2103defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
Evan Cheng506d3df2006-03-29 23:07:14 +00002104
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002105let ExeDomain = SSEPackedInt in {
2106
Evan Cheng506d3df2006-03-29 23:07:14 +00002107// Shuffle and unpack instructions
Nate Begemana09008b2009-10-19 02:17:23 +00002108let AddedComplexity = 5 in {
Evan Cheng8703be42006-04-04 19:12:30 +00002109def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002110 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002111 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002112 [(set VR128:$dst, (v4i32 (pshufd:$src2
2113 VR128:$src1, (undef))))]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002114def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002115 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002116 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002117 [(set VR128:$dst, (v4i32 (pshufd:$src2
Evan Chengc3630942009-12-09 21:00:30 +00002118 (bc_v4i32 (memopv2i64 addr:$src1)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002119 (undef))))]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002120}
Evan Cheng506d3df2006-03-29 23:07:14 +00002121
2122// SSE2 with ImmT == Imm8 and XS prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002123def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002124 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002125 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002126 [(set VR128:$dst, (v8i16 (pshufhw:$src2 VR128:$src1,
2127 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002128 XS, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002129def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002130 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002131 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002132 [(set VR128:$dst, (v8i16 (pshufhw:$src2
Eric Christopher44b93ff2009-07-31 20:07:27 +00002133 (bc_v8i16 (memopv2i64 addr:$src1)),
2134 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002135 XS, Requires<[HasSSE2]>;
2136
2137// SSE2 with ImmT == Imm8 and XD prefix.
Evan Cheng8703be42006-04-04 19:12:30 +00002138def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Nate Begeman9008ca62009-04-27 18:41:29 +00002139 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002140 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002141 [(set VR128:$dst, (v8i16 (pshuflw:$src2 VR128:$src1,
2142 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002143 XD, Requires<[HasSSE2]>;
Evan Cheng8703be42006-04-04 19:12:30 +00002144def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Nate Begeman9008ca62009-04-27 18:41:29 +00002145 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002146 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002147 [(set VR128:$dst, (v8i16 (pshuflw:$src2
2148 (bc_v8i16 (memopv2i64 addr:$src1)),
2149 (undef))))]>,
Evan Cheng506d3df2006-03-29 23:07:14 +00002150 XD, Requires<[HasSSE2]>;
2151
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002152// Unpack instructions
2153multiclass sse2_unpack<bits<8> opc, string OpcodeStr, ValueType vt,
2154 PatFrag unp_frag, PatFrag bc_frag> {
2155 def rr : PDI<opc, MRMSrcReg,
2156 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
2157 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2158 [(set VR128:$dst, (vt (unp_frag VR128:$src1, VR128:$src2)))]>;
2159 def rm : PDI<opc, MRMSrcMem,
2160 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
2161 !strconcat(OpcodeStr,"\t{$src2, $dst|$dst, $src2}"),
2162 [(set VR128:$dst, (unp_frag VR128:$src1,
2163 (bc_frag (memopv2i64
2164 addr:$src2))))]>;
2165}
Evan Chengc60bd972006-03-25 09:37:23 +00002166
Evan Chenge9083d62008-03-05 08:19:16 +00002167let Constraints = "$src1 = $dst" in {
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002168 defm PUNPCKLBW : sse2_unpack<0x60, "punpcklbw", v16i8, unpckl, bc_v16i8>;
2169 defm PUNPCKLWD : sse2_unpack<0x61, "punpcklwd", v8i16, unpckl, bc_v8i16>;
2170 defm PUNPCKLDQ : sse2_unpack<0x62, "punpckldq", v4i32, unpckl, bc_v4i32>;
2171
2172 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2173 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002174 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002175 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002176 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002177 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002178 (v2i64 (unpckl VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002179 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002180 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002181 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002182 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002183 (v2i64 (unpckl VR128:$src1,
2184 (memopv2i64 addr:$src2))))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002185
Bruno Cardoso Lopes7f5b0d82010-06-01 17:02:50 +00002186 defm PUNPCKHBW : sse2_unpack<0x68, "punpckhbw", v16i8, unpckh, bc_v16i8>;
2187 defm PUNPCKHWD : sse2_unpack<0x69, "punpckhwd", v8i16, unpckh, bc_v8i16>;
2188 defm PUNPCKHDQ : sse2_unpack<0x6A, "punpckhdq", v4i32, unpckh, bc_v4i32>;
2189
2190 /// FIXME: we could eliminate this and use sse2_unpack instead if tblgen
2191 /// knew to collapse (bitconvert VT to VT) into its operand.
Eric Christopher44b93ff2009-07-31 20:07:27 +00002192 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002193 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002194 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002195 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002196 (v2i64 (unpckh VR128:$src1, VR128:$src2)))]>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00002197 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002198 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002199 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002200 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002201 (v2i64 (unpckh VR128:$src1,
2202 (memopv2i64 addr:$src2))))]>;
Evan Chenga971f6f2006-03-23 01:57:24 +00002203}
Evan Cheng82521dd2006-03-21 07:09:35 +00002204
Evan Chengb067a1e2006-03-31 19:22:53 +00002205// Extract / Insert
Evan Cheng9ab1ac52006-04-14 23:32:40 +00002206def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002207 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002208 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Evan Cheng069287d2006-05-16 07:21:53 +00002209 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begeman14d12ca2008-02-11 04:19:36 +00002210 imm:$src2))]>;
Evan Chenge9083d62008-03-05 08:19:16 +00002211let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002212 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002213 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002214 GR32:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002215 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002216 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002217 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002218 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002219 (outs VR128:$dst), (ins VR128:$src1,
Bill Wendlingddd35322007-05-02 23:11:52 +00002220 i16mem:$src2, i32i8imm:$src3),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002221 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002222 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00002223 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2224 imm:$src3))]>;
Evan Chengb067a1e2006-03-31 19:22:53 +00002225}
2226
Evan Chengc5fb2b12006-03-30 00:33:26 +00002227// Mask creation
Evan Cheng64d80e32007-07-19 01:14:50 +00002228def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002229 "pmovmskb\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002230 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
Evan Chengc5fb2b12006-03-30 00:33:26 +00002231
Evan Chengfcf5e212006-04-11 06:57:30 +00002232// Conditional store
Evan Cheng071a2792007-09-11 19:55:27 +00002233let Uses = [EDI] in
Evan Cheng64d80e32007-07-19 01:14:50 +00002234def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002235 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng071a2792007-09-11 19:55:27 +00002236 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Evan Chengfcf5e212006-04-11 06:57:30 +00002237
Evan Cheng1d768642009-02-10 22:06:28 +00002238let Uses = [RDI] in
2239def MASKMOVDQU64 : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
2240 "maskmovdqu\t{$mask, $src|$src, $mask}",
2241 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, RDI)]>;
2242
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002243} // ExeDomain = SSEPackedInt
2244
Evan Chengecac9cb2006-03-25 06:03:26 +00002245// Non-temporal stores
David Greene8939b0d2010-02-16 20:50:18 +00002246def MOVNTPDmr_Int : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
2247 "movntpd\t{$src, $dst|$dst, $src}",
2248 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002249let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002250def MOVNTDQmr_Int : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2251 "movntdq\t{$src, $dst|$dst, $src}",
2252 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
2253def MOVNTImr_Int : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002254 "movnti\t{$src, $dst|$dst, $src}",
Eric Christopher44b93ff2009-07-31 20:07:27 +00002255 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
Evan Chengfcf5e212006-04-11 06:57:30 +00002256 TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002257
David Greene8939b0d2010-02-16 20:50:18 +00002258let AddedComplexity = 400 in { // Prefer non-temporal versions
2259def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2260 "movntpd\t{$src, $dst|$dst, $src}",
2261 [(alignednontemporalstore(v2f64 VR128:$src), addr:$dst)]>;
2262
Jakob Stoklund Olesen4a2a6e72010-03-25 18:52:04 +00002263let ExeDomain = SSEPackedInt in
David Greene8939b0d2010-02-16 20:50:18 +00002264def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
2265 "movntdq\t{$src, $dst|$dst, $src}",
2266 [(alignednontemporalstore (v4f32 VR128:$src), addr:$dst)]>;
David Greene8939b0d2010-02-16 20:50:18 +00002267}
2268
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002269// Flush cache
Evan Cheng64d80e32007-07-19 01:14:50 +00002270def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002271 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002272 TB, Requires<[HasSSE2]>;
2273
2274// Load, store, and memory fence
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002275def LFENCE : I<0xAE, MRM_E8, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002276 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002277def MFENCE : I<0xAE, MRM_F0, (outs), (ins),
Evan Chengf3e1b1d2006-04-14 07:43:12 +00002278 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengecac9cb2006-03-25 06:03:26 +00002279
Dan Gohman14aaeac2010-05-20 01:35:50 +00002280// Pause. This "instruction" is encoded as "rep; nop", so even though it
Dan Gohmand9c2af52010-05-26 18:03:53 +00002281// was introduced with SSE2, it's backward compatible.
Dan Gohman14aaeac2010-05-20 01:35:50 +00002282def PAUSE : I<0x90, RawFrm, (outs), (ins), "pause", []>, REP;
2283
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002284//TODO: custom lower this so as to never even generate the noop
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002285def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002286 (i8 0)), (NOOP)>;
2287def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2288def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
Chris Lattner6d9f86b2010-02-23 06:54:29 +00002289def : Pat<(membarrier (i8 imm), (i8 imm), (i8 imm), (i8 imm),
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00002290 (i8 1)), (MFENCE)>;
2291
Evan Chengffea91e2006-03-26 09:53:12 +00002292// Alias instructions that map zero vector to pxor / xorp* for sse.
Dan Gohman15511cf2008-12-03 18:15:48 +00002293// We set canFoldAsLoad because this can be converted to a constant-pool
Dan Gohman62c939d2008-12-03 05:21:24 +00002294// load of an all-ones value if folding it would be beneficial.
Daniel Dunbar7417b762009-08-11 22:17:52 +00002295let isReMaterializable = 1, isAsCheapAsAMove = 1, canFoldAsLoad = 1,
Jakob Stoklund Olesen428e1522010-03-30 22:46:55 +00002296 isCodeGenOnly = 1, ExeDomain = SSEPackedInt in
Chris Lattner28c1d292010-02-05 21:30:49 +00002297 // FIXME: Change encoding to pseudo.
2298 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins), "",
Chris Lattner8a594482007-11-25 00:24:49 +00002299 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Evan Cheng386031a2006-03-24 07:29:27 +00002300
Evan Cheng64d80e32007-07-19 01:14:50 +00002301def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002302 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002303 [(set VR128:$dst,
Evan Cheng069287d2006-05-16 07:21:53 +00002304 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002305def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002306 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002307 [(set VR128:$dst,
2308 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
Evan Chengebf01d62006-11-16 23:33:25 +00002309
Evan Cheng64d80e32007-07-19 01:14:50 +00002310def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002311 "movd\t{$src, $dst|$dst, $src}",
Chris Lattnerf3597a12006-12-05 18:45:06 +00002312 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2313
Evan Cheng64d80e32007-07-19 01:14:50 +00002314def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002315 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002316 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002317
Evan Cheng11e15b32006-04-03 20:53:28 +00002318// SSE2 instructions with XS prefix
Evan Cheng64d80e32007-07-19 01:14:50 +00002319def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002320 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002321 [(set VR128:$dst,
2322 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2323 Requires<[HasSSE2]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002324def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002325 "movq\t{$src, $dst|$dst, $src}",
Evan Chengebf01d62006-11-16 23:33:25 +00002326 [(store (i64 (vector_extract (v2i64 VR128:$src),
2327 (iPTR 0))), addr:$dst)]>;
2328
Dan Gohman874cada2010-02-28 00:17:42 +00002329def : Pat<(f64 (vector_extract (v2f64 VR128:$src), (iPTR 0))),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002330 (f64 (EXTRACT_SUBREG (v2f64 VR128:$src), sub_sd))>;
Dan Gohman874cada2010-02-28 00:17:42 +00002331
Evan Cheng64d80e32007-07-19 01:14:50 +00002332def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002333 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng069287d2006-05-16 07:21:53 +00002334 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002335 (iPTR 0)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002336def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002337 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng11e15b32006-04-03 20:53:28 +00002338 [(store (i32 (vector_extract (v4i32 VR128:$src),
Evan Cheng015188f2006-06-15 08:14:54 +00002339 (iPTR 0))), addr:$dst)]>;
Evan Cheng11e15b32006-04-03 20:53:28 +00002340
Evan Cheng64d80e32007-07-19 01:14:50 +00002341def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002342 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002343 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002344def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002345 "movd\t{$src, $dst|$dst, $src}",
Evan Chengc9f09232006-12-14 19:43:11 +00002346 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
Chris Lattnerf3597a12006-12-05 18:45:06 +00002347
Evan Cheng397edef2006-04-11 22:28:25 +00002348// Store / copy lower 64-bits of a XMM register.
Evan Cheng64d80e32007-07-19 01:14:50 +00002349def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002350 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng397edef2006-04-11 22:28:25 +00002351 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2352
Evan Cheng017dcc62006-04-21 01:05:10 +00002353// movd / movq to XMM register zero-extends
Evan Cheng7a831ce2007-12-15 03:00:47 +00002354let AddedComplexity = 15 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002355def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002356 "movd\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002357 [(set VR128:$dst, (v4i32 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002358 (v4i32 (scalar_to_vector GR32:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002359// This is X86-64 only.
2360def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2361 "mov{d|q}\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002362 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng7e2ff772008-05-08 00:57:18 +00002363 (v2i64 (scalar_to_vector GR64:$src)))))]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002364}
2365
2366let AddedComplexity = 20 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00002367def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002368 "movd\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002369 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002370 (v4i32 (X86vzmovl (v4i32 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002371 (loadi32 addr:$src))))))]>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002372
2373def : Pat<(v4i32 (X86vzmovl (loadv4i32 addr:$src))),
2374 (MOVZDI2PDIrm addr:$src)>;
2375def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv4f32 addr:$src)))),
2376 (MOVZDI2PDIrm addr:$src)>;
Duncan Sandsd4b9c172008-06-13 19:07:40 +00002377def : Pat<(v4i32 (X86vzmovl (bc_v4i32 (loadv2i64 addr:$src)))),
2378 (MOVZDI2PDIrm addr:$src)>;
Evan Chengc36c0ab2008-05-22 18:56:56 +00002379
Evan Cheng64d80e32007-07-19 01:14:50 +00002380def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002381 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng7a831ce2007-12-15 03:00:47 +00002382 [(set VR128:$dst,
Evan Chengd880b972008-05-09 21:53:03 +00002383 (v2i64 (X86vzmovl (v2i64 (scalar_to_vector
Evan Cheng7e2ff772008-05-08 00:57:18 +00002384 (loadi64 addr:$src))))))]>, XS,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002385 Requires<[HasSSE2]>;
Evan Cheng48090aa2006-03-21 23:01:21 +00002386
Evan Chengc36c0ab2008-05-22 18:56:56 +00002387def : Pat<(v2i64 (X86vzmovl (loadv2i64 addr:$src))),
2388 (MOVZQI2PQIrm addr:$src)>;
2389def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4f32 addr:$src)))),
2390 (MOVZQI2PQIrm addr:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002391def : Pat<(v2i64 (X86vzload addr:$src)), (MOVZQI2PQIrm addr:$src)>;
Evan Chengb70ea0b2008-05-10 00:59:18 +00002392}
Evan Chengd880b972008-05-09 21:53:03 +00002393
Evan Cheng7a831ce2007-12-15 03:00:47 +00002394// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2395// IA32 document. movq xmm1, xmm2 does clear the high bits.
2396let AddedComplexity = 15 in
2397def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2398 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002399 [(set VR128:$dst, (v2i64 (X86vzmovl (v2i64 VR128:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002400 XS, Requires<[HasSSE2]>;
2401
Evan Cheng8e8de682008-05-20 18:24:47 +00002402let AddedComplexity = 20 in {
Evan Cheng7a831ce2007-12-15 03:00:47 +00002403def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2404 "movq\t{$src, $dst|$dst, $src}",
Evan Chengd880b972008-05-09 21:53:03 +00002405 [(set VR128:$dst, (v2i64 (X86vzmovl
Evan Cheng8e8de682008-05-20 18:24:47 +00002406 (loadv2i64 addr:$src))))]>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002407 XS, Requires<[HasSSE2]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002408
Evan Cheng8e8de682008-05-20 18:24:47 +00002409def : Pat<(v2i64 (X86vzmovl (bc_v2i64 (loadv4i32 addr:$src)))),
2410 (MOVZPQILo2PQIrm addr:$src)>;
2411}
2412
Sean Callanan108934c2009-12-18 00:01:26 +00002413// Instructions for the disassembler
2414// xr = XMM register
2415// xm = mem64
2416
2417def MOVQxrxr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2418 "movq\t{$src, $dst|$dst, $src}", []>, XS;
2419
Eric Christopher44b93ff2009-07-31 20:07:27 +00002420//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002421// SSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002422//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002423
Bill Wendlingddd35322007-05-02 23:11:52 +00002424// Move Instructions
Evan Cheng64d80e32007-07-19 01:14:50 +00002425def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002426 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002427 [(set VR128:$dst, (v4f32 (movshdup
2428 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002429def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002430 "movshdup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002431 [(set VR128:$dst, (movshdup
2432 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002433
Evan Cheng64d80e32007-07-19 01:14:50 +00002434def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002435 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002436 [(set VR128:$dst, (v4f32 (movsldup
2437 VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002438def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002439 "movsldup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002440 [(set VR128:$dst, (movsldup
2441 (memopv4f32 addr:$src), (undef)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002442
Evan Cheng64d80e32007-07-19 01:14:50 +00002443def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002444 "movddup\t{$src, $dst|$dst, $src}",
Nate Begeman9008ca62009-04-27 18:41:29 +00002445 [(set VR128:$dst,(v2f64 (movddup VR128:$src, (undef))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +00002446def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002447 "movddup\t{$src, $dst|$dst, $src}",
Evan Cheng0b457f02008-09-25 20:50:48 +00002448 [(set VR128:$dst,
Nate Begeman9008ca62009-04-27 18:41:29 +00002449 (v2f64 (movddup (scalar_to_vector (loadf64 addr:$src)),
2450 (undef))))]>;
Evan Cheng0b457f02008-09-25 20:50:48 +00002451
Nate Begeman9008ca62009-04-27 18:41:29 +00002452def : Pat<(movddup (bc_v2f64 (v2i64 (scalar_to_vector (loadi64 addr:$src)))),
2453 (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002454 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002455
2456let AddedComplexity = 5 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002457def : Pat<(movddup (memopv2f64 addr:$src), (undef)),
Evan Cheng0b457f02008-09-25 20:50:48 +00002458 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
Nate Begemanec8eee22009-04-29 22:47:44 +00002459def : Pat<(movddup (bc_v4f32 (memopv2f64 addr:$src)), (undef)),
2460 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2461def : Pat<(movddup (memopv2i64 addr:$src), (undef)),
2462 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2463def : Pat<(movddup (bc_v4i32 (memopv2i64 addr:$src)), (undef)),
2464 (MOVDDUPrm addr:$src)>, Requires<[HasSSE3]>;
2465}
Bill Wendlingddd35322007-05-02 23:11:52 +00002466
2467// Arithmetic
Evan Chenge9083d62008-03-05 08:19:16 +00002468let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002469 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002470 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002471 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002472 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2473 VR128:$src2))]>;
2474 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002475 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002476 "addsubps\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002477 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002478 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002479 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Cheng64d80e32007-07-19 01:14:50 +00002480 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002481 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002482 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2483 VR128:$src2))]>;
2484 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Cheng64d80e32007-07-19 01:14:50 +00002485 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002486 "addsubpd\t{$src2, $dst|$dst, $src2}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002487 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
Evan Chengb1938262008-05-23 00:37:07 +00002488 (memop addr:$src2)))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002489}
2490
Evan Cheng64d80e32007-07-19 01:14:50 +00002491def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002492 "lddqu\t{$src, $dst|$dst, $src}",
Bill Wendlingddd35322007-05-02 23:11:52 +00002493 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2494
2495// Horizontal ops
2496class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002497 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002498 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002499 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2500class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002501 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002502 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002503 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (memop addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002504class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002505 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002506 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Bill Wendlingddd35322007-05-02 23:11:52 +00002507 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2508class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Cheng64d80e32007-07-19 01:14:50 +00002509 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohmanb1576f52007-07-31 20:11:57 +00002510 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00002511 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (memopv2f64 addr:$src2))))]>;
Bill Wendlingddd35322007-05-02 23:11:52 +00002512
Evan Chenge9083d62008-03-05 08:19:16 +00002513let Constraints = "$src1 = $dst" in {
Bill Wendlingddd35322007-05-02 23:11:52 +00002514 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2515 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2516 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2517 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2518 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2519 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2520 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2521 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2522}
2523
2524// Thread synchronization
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002525def MONITOR : I<0x01, MRM_C8, (outs), (ins), "monitor",
Bill Wendlingddd35322007-05-02 23:11:52 +00002526 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Chris Lattnereaca5fa2010-02-12 23:54:57 +00002527def MWAIT : I<0x01, MRM_C9, (outs), (ins), "mwait",
Bill Wendlingddd35322007-05-02 23:11:52 +00002528 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2529
2530// vector_shuffle v1, <undef> <1, 1, 3, 3>
2531let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002532def : Pat<(v4i32 (movshdup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002533 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2534let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002535def : Pat<(v4i32 (movshdup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002536 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2537
2538// vector_shuffle v1, <undef> <0, 0, 2, 2>
2539let AddedComplexity = 15 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002540 def : Pat<(v4i32 (movsldup VR128:$src, (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002541 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2542let AddedComplexity = 20 in
Nate Begeman9008ca62009-04-27 18:41:29 +00002543 def : Pat<(v4i32 (movsldup (bc_v4i32 (memopv2i64 addr:$src)), (undef))),
Bill Wendlingddd35322007-05-02 23:11:52 +00002544 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2545
Eric Christopher44b93ff2009-07-31 20:07:27 +00002546//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002547// SSSE3 Instructions
Eric Christopher44b93ff2009-07-31 20:07:27 +00002548//===---------------------------------------------------------------------===//
Bill Wendlingddd35322007-05-02 23:11:52 +00002549
Bill Wendling76d708b2007-08-10 06:22:27 +00002550/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begemanfea2be52008-02-09 23:46:37 +00002551multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2552 Intrinsic IntId64, Intrinsic IntId128> {
2553 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2554 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2555 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002556
Nate Begemanfea2be52008-02-09 23:46:37 +00002557 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2558 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2559 [(set VR64:$dst,
2560 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2561
2562 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2563 (ins VR128:$src),
2564 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2565 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2566 OpSize;
2567
2568 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2569 (ins i128mem:$src),
2570 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2571 [(set VR128:$dst,
2572 (IntId128
2573 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Bill Wendlingddd35322007-05-02 23:11:52 +00002574}
2575
Bill Wendling76d708b2007-08-10 06:22:27 +00002576/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begemanfea2be52008-02-09 23:46:37 +00002577multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2578 Intrinsic IntId64, Intrinsic IntId128> {
2579 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2580 (ins VR64:$src),
2581 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2582 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002583
Nate Begemanfea2be52008-02-09 23:46:37 +00002584 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2585 (ins i64mem:$src),
2586 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2587 [(set VR64:$dst,
2588 (IntId64
2589 (bitconvert (memopv4i16 addr:$src))))]>;
2590
2591 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2592 (ins VR128:$src),
2593 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2594 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2595 OpSize;
2596
2597 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2598 (ins i128mem:$src),
2599 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2600 [(set VR128:$dst,
2601 (IntId128
2602 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002603}
2604
2605/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begemanfea2be52008-02-09 23:46:37 +00002606multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2607 Intrinsic IntId64, Intrinsic IntId128> {
2608 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2609 (ins VR64:$src),
2610 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2611 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002612
Nate Begemanfea2be52008-02-09 23:46:37 +00002613 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2614 (ins i64mem:$src),
2615 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2616 [(set VR64:$dst,
2617 (IntId64
2618 (bitconvert (memopv2i32 addr:$src))))]>;
2619
2620 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2621 (ins VR128:$src),
2622 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2623 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2624 OpSize;
2625
2626 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2627 (ins i128mem:$src),
2628 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2629 [(set VR128:$dst,
2630 (IntId128
2631 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002632}
2633
2634defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2635 int_x86_ssse3_pabs_b,
2636 int_x86_ssse3_pabs_b_128>;
2637defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2638 int_x86_ssse3_pabs_w,
2639 int_x86_ssse3_pabs_w_128>;
2640defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2641 int_x86_ssse3_pabs_d,
2642 int_x86_ssse3_pabs_d_128>;
2643
2644/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
Evan Chenge9083d62008-03-05 08:19:16 +00002645let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002646 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2647 Intrinsic IntId64, Intrinsic IntId128,
2648 bit Commutable = 0> {
2649 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2650 (ins VR64:$src1, VR64:$src2),
2651 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2652 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2653 let isCommutable = Commutable;
2654 }
2655 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2656 (ins VR64:$src1, i64mem:$src2),
2657 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2658 [(set VR64:$dst,
2659 (IntId64 VR64:$src1,
2660 (bitconvert (memopv8i8 addr:$src2))))]>;
2661
2662 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2663 (ins VR128:$src1, VR128:$src2),
2664 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2665 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2666 OpSize {
2667 let isCommutable = Commutable;
2668 }
2669 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2670 (ins VR128:$src1, i128mem:$src2),
2671 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2672 [(set VR128:$dst,
2673 (IntId128 VR128:$src1,
2674 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2675 }
2676}
2677
2678/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
Evan Chenge9083d62008-03-05 08:19:16 +00002679let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002680 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2681 Intrinsic IntId64, Intrinsic IntId128,
2682 bit Commutable = 0> {
2683 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2684 (ins VR64:$src1, VR64:$src2),
2685 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2686 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2687 let isCommutable = Commutable;
2688 }
2689 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2690 (ins VR64:$src1, i64mem:$src2),
2691 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2692 [(set VR64:$dst,
2693 (IntId64 VR64:$src1,
2694 (bitconvert (memopv4i16 addr:$src2))))]>;
2695
2696 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2697 (ins VR128:$src1, VR128:$src2),
2698 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2699 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2700 OpSize {
2701 let isCommutable = Commutable;
2702 }
2703 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2704 (ins VR128:$src1, i128mem:$src2),
2705 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2706 [(set VR128:$dst,
2707 (IntId128 VR128:$src1,
2708 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2709 }
2710}
2711
2712/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
Evan Chenge9083d62008-03-05 08:19:16 +00002713let Constraints = "$src1 = $dst" in {
Bill Wendling76d708b2007-08-10 06:22:27 +00002714 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2715 Intrinsic IntId64, Intrinsic IntId128,
2716 bit Commutable = 0> {
2717 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2718 (ins VR64:$src1, VR64:$src2),
2719 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2720 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2721 let isCommutable = Commutable;
2722 }
2723 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2724 (ins VR64:$src1, i64mem:$src2),
2725 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2726 [(set VR64:$dst,
2727 (IntId64 VR64:$src1,
2728 (bitconvert (memopv2i32 addr:$src2))))]>;
2729
2730 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2731 (ins VR128:$src1, VR128:$src2),
2732 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2733 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2734 OpSize {
2735 let isCommutable = Commutable;
2736 }
2737 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2738 (ins VR128:$src1, i128mem:$src2),
2739 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2740 [(set VR128:$dst,
2741 (IntId128 VR128:$src1,
2742 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2743 }
2744}
2745
Chris Lattner65de1b92010-04-17 07:38:24 +00002746let ImmT = NoImm in { // None of these have i8 immediate fields.
Bill Wendling76d708b2007-08-10 06:22:27 +00002747defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2748 int_x86_ssse3_phadd_w,
Evan Cheng4e444432008-06-16 21:16:24 +00002749 int_x86_ssse3_phadd_w_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002750defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2751 int_x86_ssse3_phadd_d,
Evan Cheng4e444432008-06-16 21:16:24 +00002752 int_x86_ssse3_phadd_d_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002753defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2754 int_x86_ssse3_phadd_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002755 int_x86_ssse3_phadd_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002756defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2757 int_x86_ssse3_phsub_w,
2758 int_x86_ssse3_phsub_w_128>;
2759defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2760 int_x86_ssse3_phsub_d,
2761 int_x86_ssse3_phsub_d_128>;
2762defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2763 int_x86_ssse3_phsub_sw,
2764 int_x86_ssse3_phsub_sw_128>;
2765defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2766 int_x86_ssse3_pmadd_ub_sw,
Evan Cheng4e444432008-06-16 21:16:24 +00002767 int_x86_ssse3_pmadd_ub_sw_128>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002768defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2769 int_x86_ssse3_pmul_hr_sw,
2770 int_x86_ssse3_pmul_hr_sw_128, 1>;
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00002771
Bill Wendling76d708b2007-08-10 06:22:27 +00002772defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2773 int_x86_ssse3_pshuf_b,
2774 int_x86_ssse3_pshuf_b_128>;
2775defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2776 int_x86_ssse3_psign_b,
2777 int_x86_ssse3_psign_b_128>;
2778defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2779 int_x86_ssse3_psign_w,
2780 int_x86_ssse3_psign_w_128>;
Evan Chenged7f56b2009-05-28 18:48:53 +00002781defm PSIGND : SS3I_binop_rm_int_32<0x0A, "psignd",
Bill Wendling76d708b2007-08-10 06:22:27 +00002782 int_x86_ssse3_psign_d,
2783 int_x86_ssse3_psign_d_128>;
Chris Lattner65de1b92010-04-17 07:38:24 +00002784}
Bill Wendling76d708b2007-08-10 06:22:27 +00002785
Eric Christophercff6f852010-04-15 01:40:20 +00002786// palignr patterns.
Evan Chenge9083d62008-03-05 08:19:16 +00002787let Constraints = "$src1 = $dst" in {
Bill Wendlingae9671b2007-08-10 09:00:17 +00002788 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002789 (ins VR64:$src1, VR64:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002790 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002791 []>;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002792 def PALIGNR64rm : SS3AI<0x0F, MRMSrcMem, (outs VR64:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002793 (ins VR64:$src1, i64mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002794 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002795 []>;
Bill Wendling76d708b2007-08-10 06:22:27 +00002796
Bill Wendlingae9671b2007-08-10 09:00:17 +00002797 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002798 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002799 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002800 []>, OpSize;
Dan Gohmanc2ecdc52008-05-28 01:50:19 +00002801 def PALIGNR128rm : SS3AI<0x0F, MRMSrcMem, (outs VR128:$dst),
Sean Callananb9e6b342009-11-20 22:28:42 +00002802 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
Dale Johannesen83e105c2007-10-11 20:58:37 +00002803 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Evan Cheng89321162009-10-28 06:30:34 +00002804 []>, OpSize;
Bill Wendling76d708b2007-08-10 06:22:27 +00002805}
Bill Wendlingddd35322007-05-02 23:11:52 +00002806
Eric Christopher6d972fd2010-04-20 00:59:54 +00002807let AddedComplexity = 5 in {
2808
Eric Christophercff6f852010-04-15 01:40:20 +00002809def : Pat<(v1i64 (palign:$src3 VR64:$src1, VR64:$src2)),
2810 (PALIGNR64rr VR64:$src2, VR64:$src1,
2811 (SHUFFLE_get_palign_imm VR64:$src3))>,
2812 Requires<[HasSSSE3]>;
2813def : Pat<(v2i32 (palign:$src3 VR64:$src1, VR64:$src2)),
2814 (PALIGNR64rr VR64:$src2, VR64:$src1,
2815 (SHUFFLE_get_palign_imm VR64:$src3))>,
2816 Requires<[HasSSSE3]>;
2817def : Pat<(v2f32 (palign:$src3 VR64:$src1, VR64:$src2)),
2818 (PALIGNR64rr VR64:$src2, VR64:$src1,
2819 (SHUFFLE_get_palign_imm VR64:$src3))>,
2820 Requires<[HasSSSE3]>;
2821def : Pat<(v4i16 (palign:$src3 VR64:$src1, VR64:$src2)),
2822 (PALIGNR64rr VR64:$src2, VR64:$src1,
2823 (SHUFFLE_get_palign_imm VR64:$src3))>,
2824 Requires<[HasSSSE3]>;
2825def : Pat<(v8i8 (palign:$src3 VR64:$src1, VR64:$src2)),
2826 (PALIGNR64rr VR64:$src2, VR64:$src1,
2827 (SHUFFLE_get_palign_imm VR64:$src3))>,
2828 Requires<[HasSSSE3]>;
Evan Cheng89321162009-10-28 06:30:34 +00002829
Nate Begemana09008b2009-10-19 02:17:23 +00002830def : Pat<(v4i32 (palign:$src3 VR128:$src1, VR128:$src2)),
2831 (PALIGNR128rr VR128:$src2, VR128:$src1,
2832 (SHUFFLE_get_palign_imm VR128:$src3))>,
2833 Requires<[HasSSSE3]>;
2834def : Pat<(v4f32 (palign:$src3 VR128:$src1, VR128:$src2)),
2835 (PALIGNR128rr VR128:$src2, VR128:$src1,
2836 (SHUFFLE_get_palign_imm VR128:$src3))>,
2837 Requires<[HasSSSE3]>;
2838def : Pat<(v8i16 (palign:$src3 VR128:$src1, VR128:$src2)),
2839 (PALIGNR128rr VR128:$src2, VR128:$src1,
2840 (SHUFFLE_get_palign_imm VR128:$src3))>,
2841 Requires<[HasSSSE3]>;
2842def : Pat<(v16i8 (palign:$src3 VR128:$src1, VR128:$src2)),
2843 (PALIGNR128rr VR128:$src2, VR128:$src1,
2844 (SHUFFLE_get_palign_imm VR128:$src3))>,
2845 Requires<[HasSSSE3]>;
Eric Christopher761411c2009-11-07 08:45:53 +00002846}
Nate Begemana09008b2009-10-19 02:17:23 +00002847
Nate Begemanb9a47b82009-02-23 08:49:38 +00002848def : Pat<(X86pshufb VR128:$src, VR128:$mask),
2849 (PSHUFBrr128 VR128:$src, VR128:$mask)>, Requires<[HasSSSE3]>;
2850def : Pat<(X86pshufb VR128:$src, (bc_v16i8 (memopv2i64 addr:$mask))),
2851 (PSHUFBrm128 VR128:$src, addr:$mask)>, Requires<[HasSSSE3]>;
2852
Eric Christopher44b93ff2009-07-31 20:07:27 +00002853//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002854// Non-Instruction Patterns
Eric Christopher44b93ff2009-07-31 20:07:27 +00002855//===---------------------------------------------------------------------===//
Evan Cheng48090aa2006-03-21 23:01:21 +00002856
Eric Christopher44b93ff2009-07-31 20:07:27 +00002857// extload f32 -> f64. This matches load+fextend because we have a hack in
2858// the isel (PreprocessForFPConvert) that can introduce loads after dag
2859// combine.
Chris Lattnerd43d00c2008-01-24 08:07:48 +00002860// Since these loads aren't folded into the fextend, we have to match it
2861// explicitly here.
2862let Predicates = [HasSSE2] in
2863 def : Pat<(fextend (loadf32 addr:$src)),
2864 (CVTSS2SDrm addr:$src)>;
2865
Evan Cheng2c0dbd02006-03-24 02:58:06 +00002866// bit_convert
Chris Lattner4cc84ed2006-10-07 04:52:09 +00002867let Predicates = [HasSSE2] in {
2868 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2869 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2870 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2871 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2872 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2873 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2874 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2875 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2876 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2877 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2878 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2879 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2880 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2881 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2882 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2883 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2884 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2885 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2886 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2887 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2888 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2889 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2890 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2891 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2892 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2893 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2894 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2895 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2896 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2897 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2898}
Evan Chengb9df0ca2006-03-22 02:53:00 +00002899
Evan Cheng017dcc62006-04-21 01:05:10 +00002900// Move scalar to XMM zero-extended
2901// movd to XMM register zero-extends
Evan Chengf2ea84a2006-10-09 21:42:15 +00002902let AddedComplexity = 15 in {
Evan Cheng017dcc62006-04-21 01:05:10 +00002903// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Evan Chengd880b972008-05-09 21:53:03 +00002904def : Pat<(v2f64 (X86vzmovl (v2f64 (scalar_to_vector FR64:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002905 (MOVSDrr (v2f64 (V_SET0PS)), FR64:$src)>;
Evan Chengd880b972008-05-09 21:53:03 +00002906def : Pat<(v4f32 (X86vzmovl (v4f32 (scalar_to_vector FR32:$src)))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002907 (MOVSSrr (v4f32 (V_SET0PS)), FR32:$src)>;
Evan Cheng23573e52008-05-09 23:37:55 +00002908def : Pat<(v4f32 (X86vzmovl (v4f32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002909 (MOVSSrr (v4f32 (V_SET0PS)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002910 (f32 (EXTRACT_SUBREG (v4f32 VR128:$src), sub_ss)))>;
Evan Cheng331e2bd2008-07-10 01:08:23 +00002911def : Pat<(v4i32 (X86vzmovl (v4i32 VR128:$src))),
Jakob Stoklund Olesend363b4e2010-03-31 00:40:13 +00002912 (MOVSSrr (v4i32 (V_SET0PI)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00002913 (EXTRACT_SUBREG (v4i32 VR128:$src), sub_ss))>;
Evan Cheng017dcc62006-04-21 01:05:10 +00002914}
Evan Chengbc4832b2006-03-24 23:15:12 +00002915
Evan Chengb9df0ca2006-03-22 02:53:00 +00002916// Splat v2f64 / v2i64
Evan Chengfd111b52006-04-19 21:15:24 +00002917let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002918def : Pat<(splat_lo (v2f64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002919 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002920def : Pat<(unpckh (v2f64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002921 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002922def : Pat<(splat_lo (v2i64 VR128:$src), (undef)),
Chris Lattner30da68a2006-06-20 00:25:29 +00002923 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002924def : Pat<(unpckh (v2i64 VR128:$src), (undef)),
Evan Chengf686d9b2006-10-27 21:08:32 +00002925 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengfd111b52006-04-19 21:15:24 +00002926}
Evan Cheng475aecf2006-03-29 03:04:49 +00002927
Evan Chengb7a5c522006-04-18 21:55:35 +00002928// Special unary SHUFPSrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002929def : Pat<(v4f32 (pshufd:$src3 VR128:$src1, (undef))),
2930 (SHUFPSrri VR128:$src1, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00002931 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002932let AddedComplexity = 5 in
2933def : Pat<(v4f32 (pshufd:$src2 VR128:$src1, (undef))),
2934 (PSHUFDri VR128:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
2935 Requires<[HasSSE2]>;
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002936// Special unary SHUFPDrri case.
Nate Begeman9008ca62009-04-27 18:41:29 +00002937def : Pat<(v2i64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002938 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002939 (SHUFFLE_get_shuf_imm VR128:$src3))>,
2940 Requires<[HasSSE2]>;
2941// Special unary SHUFPDrri case.
2942def : Pat<(v2f64 (pshufd:$src3 VR128:$src1, (undef))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002943 (SHUFPDrri VR128:$src1, VR128:$src1,
Nate Begeman9008ca62009-04-27 18:41:29 +00002944 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Dan Gohman7f55fcb2007-08-02 21:17:01 +00002945 Requires<[HasSSE2]>;
Evan Cheng3d60df42006-04-10 22:35:16 +00002946// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Nate Begeman9008ca62009-04-27 18:41:29 +00002947def : Pat<(pshufd:$src2 (bc_v4i32 (memopv4f32 addr:$src1)), (undef)),
2948 (PSHUFDmi addr:$src1, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Cheng7d9061e2006-03-30 19:54:57 +00002949 Requires<[HasSSE2]>;
Evan Chengb7a75a52008-09-26 23:41:32 +00002950
Evan Cheng3d60df42006-04-10 22:35:16 +00002951// Special binary v4i32 shuffle cases with SHUFPS.
Nate Begeman9008ca62009-04-27 18:41:29 +00002952def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (v4i32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002953 (SHUFPSrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002954 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002955 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002956def : Pat<(v4i32 (shufp:$src3 VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002957 (SHUFPSrmi VR128:$src1, addr:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002958 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Chris Lattner30da68a2006-06-20 00:25:29 +00002959 Requires<[HasSSE2]>;
Evan Cheng7a831ce2007-12-15 03:00:47 +00002960// Special binary v2i64 shuffle cases using SHUFPDrri.
Nate Begeman9008ca62009-04-27 18:41:29 +00002961def : Pat<(v2i64 (shufp:$src3 VR128:$src1, VR128:$src2)),
Eric Christopher44b93ff2009-07-31 20:07:27 +00002962 (SHUFPDrri VR128:$src1, VR128:$src2,
Nate Begeman9008ca62009-04-27 18:41:29 +00002963 (SHUFFLE_get_shuf_imm VR128:$src3))>,
Evan Cheng7a831ce2007-12-15 03:00:47 +00002964 Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00002965
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00002966// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00002967let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002968def : Pat<(v4i32 (unpckl_undef:$src2 VR128:$src, (undef))),
2969 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00002970 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002971def : Pat<(v4f32 (unpckl_undef:$src2 VR128:$src, (undef))),
2972 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00002973 Requires<[OptForSpeed, HasSSE2]>;
2974}
Evan Chengfd111b52006-04-19 21:15:24 +00002975let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002976def : Pat<(v4f32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002977 (UNPCKLPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002978def : Pat<(v16i8 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002979 (PUNPCKLBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002980def : Pat<(v8i16 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002981 (PUNPCKLWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002982def : Pat<(v4i32 (unpckl_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002983 (PUNPCKLDQrr VR128:$src, VR128:$src)>;
Evan Chengfd111b52006-04-19 21:15:24 +00002984}
Evan Cheng1d5a8cc2006-04-05 07:20:06 +00002985
Evan Cheng174f8032007-05-17 18:44:37 +00002986// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Evan Chengb7a75a52008-09-26 23:41:32 +00002987let AddedComplexity = 15 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002988def : Pat<(v4i32 (unpckh_undef:$src2 VR128:$src, (undef))),
2989 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00002990 Requires<[OptForSpeed, HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002991def : Pat<(v4f32 (unpckh_undef:$src2 VR128:$src, (undef))),
2992 (PSHUFDri VR128:$src, (SHUFFLE_get_shuf_imm VR128:$src2))>,
Evan Chengb7a75a52008-09-26 23:41:32 +00002993 Requires<[OptForSpeed, HasSSE2]>;
2994}
Evan Cheng174f8032007-05-17 18:44:37 +00002995let AddedComplexity = 10 in {
Nate Begeman9008ca62009-04-27 18:41:29 +00002996def : Pat<(v4f32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002997 (UNPCKHPSrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00002998def : Pat<(v16i8 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00002999 (PUNPCKHBWrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003000def : Pat<(v8i16 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003001 (PUNPCKHWDrr VR128:$src, VR128:$src)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003002def : Pat<(v4i32 (unpckh_undef VR128:$src, (undef))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003003 (PUNPCKHDQrr VR128:$src, VR128:$src)>;
Evan Cheng174f8032007-05-17 18:44:37 +00003004}
3005
Evan Chengb7a75a52008-09-26 23:41:32 +00003006let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003007// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
Nate Begeman0b10b912009-11-07 23:17:15 +00003008def : Pat<(v4i32 (movlhps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003009 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003010
3011// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003012def : Pat<(v4i32 (movhlps VR128:$src1, VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003013 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
Evan Cheng2dadaea2006-04-19 20:37:34 +00003014
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003015// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003016def : Pat<(v4f32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003017 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003018def : Pat<(v4i32 (movhlps_undef VR128:$src1, (undef))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003019 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003020}
Evan Cheng9d09b892006-05-31 00:51:37 +00003021
Evan Cheng6e56e2c2006-11-07 22:14:24 +00003022let AddedComplexity = 20 in {
Evan Cheng2dadaea2006-04-19 20:37:34 +00003023// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003024def : Pat<(v4f32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003025 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003026def : Pat<(v2f64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003027 (MOVLPDrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003028def : Pat<(v4i32 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003029 (MOVLPSrm VR128:$src1, addr:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003030def : Pat<(v2i64 (movlp VR128:$src1, (load addr:$src2))),
Dan Gohmane13709a2010-02-26 01:14:30 +00003031 (MOVLPDrm VR128:$src1, addr:$src2)>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003032}
Evan Cheng64e97692006-04-24 21:58:20 +00003033
Evan Chengcd0baf22008-05-23 21:23:16 +00003034// (store (vector_shuffle (load addr), v2, <4, 5, 2, 3>), addr) using MOVLPS
Nate Begeman9008ca62009-04-27 18:41:29 +00003035def : Pat<(store (v4f32 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003036 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003037def : Pat<(store (v2f64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003038 (MOVLPDmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003039def : Pat<(store (v4i32 (movlp (bc_v4i32 (loadv2i64 addr:$src1)), VR128:$src2)),
3040 addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003041 (MOVLPSmr addr:$src1, VR128:$src2)>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003042def : Pat<(store (v2i64 (movlp (load addr:$src1), VR128:$src2)), addr:$src1),
Dan Gohmane13709a2010-02-26 01:14:30 +00003043 (MOVLPDmr addr:$src1, VR128:$src2)>;
Evan Chengcd0baf22008-05-23 21:23:16 +00003044
Evan Chengf2ea84a2006-10-09 21:42:15 +00003045let AddedComplexity = 15 in {
Evan Cheng64e97692006-04-24 21:58:20 +00003046// Setting the lowest element in the vector.
Nate Begeman9008ca62009-04-27 18:41:29 +00003047def : Pat<(v4i32 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003048 (MOVSSrr (v4i32 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003049 (EXTRACT_SUBREG (v4i32 VR128:$src2), sub_ss))>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003050def : Pat<(v2i64 (movl VR128:$src1, VR128:$src2)),
Dan Gohman874cada2010-02-28 00:17:42 +00003051 (MOVSDrr (v2i64 VR128:$src1),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003052 (EXTRACT_SUBREG (v2i64 VR128:$src2), sub_sd))>;
Evan Chenga7fc6422006-04-24 23:34:56 +00003053
Dan Gohman874cada2010-02-28 00:17:42 +00003054// vector_shuffle v1, v2 <4, 5, 2, 3> using movsd
Nate Begeman9008ca62009-04-27 18:41:29 +00003055def : Pat<(v4f32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003056 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003057 Requires<[HasSSE2]>;
Nate Begeman9008ca62009-04-27 18:41:29 +00003058def : Pat<(v4i32 (movlp VR128:$src1, VR128:$src2)),
Jakob Stoklund Olesen3458e9e2010-05-24 14:48:17 +00003059 (MOVSDrr VR128:$src1, (EXTRACT_SUBREG VR128:$src2, sub_sd))>,
Dan Gohman874cada2010-02-28 00:17:42 +00003060 Requires<[HasSSE2]>;
Evan Chengf2ea84a2006-10-09 21:42:15 +00003061}
Evan Cheng9e062ed2006-05-03 20:32:03 +00003062
Eli Friedman7e2242b2009-06-19 07:00:55 +00003063// vector_shuffle v1, v2 <4, 5, 2, 3> using SHUFPSrri (we prefer movsd, but
3064// fall back to this for SSE1)
3065def : Pat<(v4f32 (movlp:$src3 VR128:$src1, (v4f32 VR128:$src2))),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003066 (SHUFPSrri VR128:$src2, VR128:$src1,
Dan Gohmane13709a2010-02-26 01:14:30 +00003067 (SHUFFLE_get_shuf_imm VR128:$src3))>;
Eli Friedman7e2242b2009-06-19 07:00:55 +00003068
Evan Chenga7fc6422006-04-24 23:34:56 +00003069// Set lowest element and zero upper elements.
Evan Chengd880b972008-05-09 21:53:03 +00003070def : Pat<(v2f64 (X86vzmovl (v2f64 VR128:$src))),
Evan Chengfd17f422008-05-08 22:35:02 +00003071 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
Evan Chengcdfc3c82006-04-17 22:45:49 +00003072
Evan Cheng2c3ae372006-04-12 21:21:57 +00003073// Some special case pandn patterns.
3074def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3075 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003076 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003077def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3078 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003079 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003080def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3081 VR128:$src2)),
Chris Lattner30da68a2006-06-20 00:25:29 +00003082 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
Evan Cheng1b32f222006-03-30 07:33:32 +00003083
Evan Cheng2c3ae372006-04-12 21:21:57 +00003084def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003085 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003086 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003087def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003088 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003089 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng2c3ae372006-04-12 21:21:57 +00003090def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Evan Chengb1938262008-05-23 00:37:07 +00003091 (memop addr:$src2))),
Chris Lattner30da68a2006-06-20 00:25:29 +00003092 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Evan Cheng206ee9d2006-07-07 08:33:52 +00003093
Nate Begemanb348d182007-11-17 03:58:34 +00003094// vector -> vector casts
3095def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3096 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3097def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3098 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
Eli Friedmand0c0fae2008-09-05 23:07:03 +00003099def : Pat<(v2f64 (sint_to_fp (v2i32 VR64:$src))),
3100 (Int_CVTPI2PDrr VR64:$src)>, Requires<[HasSSE2]>;
3101def : Pat<(v2i32 (fp_to_sint (v2f64 VR128:$src))),
3102 (Int_CVTTPD2PIrr VR128:$src)>, Requires<[HasSSE2]>;
Nate Begemanb348d182007-11-17 03:58:34 +00003103
Evan Chengb4162fd2007-07-20 00:27:43 +00003104// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohmand3006222007-07-27 17:16:43 +00003105def : Pat<(alignedloadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003106 (MOVAPSrm addr:$src)>;
Dan Gohmand3006222007-07-27 17:16:43 +00003107def : Pat<(loadv4i32 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003108 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003109def : Pat<(alignedloadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003110 (MOVAPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003111def : Pat<(loadv2i64 addr:$src),
Dan Gohmane13709a2010-02-26 01:14:30 +00003112 (MOVUPSrm addr:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003113
3114def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003115 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003116def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003117 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003118def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003119 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003120def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003121 (MOVAPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003122def : Pat<(store (v2i64 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003123 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003124def : Pat<(store (v4i32 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003125 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003126def : Pat<(store (v8i16 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003127 (MOVUPSmr addr:$dst, VR128:$src)>;
Evan Chengb4162fd2007-07-20 00:27:43 +00003128def : Pat<(store (v16i8 VR128:$src), addr:$dst),
Dan Gohmane13709a2010-02-26 01:14:30 +00003129 (MOVUPSmr addr:$dst, VR128:$src)>;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003130
Nate Begeman63ec90a2008-02-03 07:18:54 +00003131//===----------------------------------------------------------------------===//
3132// SSE4.1 Instructions
3133//===----------------------------------------------------------------------===//
3134
Dale Johannesene397acc2008-10-10 23:51:03 +00003135multiclass sse41_fp_unop_rm<bits<8> opcps, bits<8> opcpd,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003136 string OpcodeStr,
Nate Begeman63ec90a2008-02-03 07:18:54 +00003137 Intrinsic V4F32Int,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003138 Intrinsic V2F64Int> {
Nate Begeman63ec90a2008-02-03 07:18:54 +00003139 // Intrinsic operation, reg.
Nate Begeman63ec90a2008-02-03 07:18:54 +00003140 // Vector intrinsic operation, reg
Eric Christopher44b93ff2009-07-31 20:07:27 +00003141 def PSr_Int : SS4AIi8<opcps, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003142 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003143 !strconcat(OpcodeStr,
3144 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003145 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3146 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003147
3148 // Vector intrinsic operation, mem
Evan Cheng400073d2009-12-18 07:40:29 +00003149 def PSm_Int : Ii8<opcps, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003150 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003151 !strconcat(OpcodeStr,
3152 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003153 [(set VR128:$dst,
3154 (V4F32Int (memopv4f32 addr:$src1),imm:$src2))]>,
Evan Cheng400073d2009-12-18 07:40:29 +00003155 TA, OpSize,
Evan Chengb1f49812009-12-22 17:47:23 +00003156 Requires<[HasSSE41]>;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003157
Nate Begeman63ec90a2008-02-03 07:18:54 +00003158 // Vector intrinsic operation, reg
Evan Cheng172b7942008-03-14 07:39:27 +00003159 def PDr_Int : SS4AIi8<opcpd, MRMSrcReg,
Nate Begeman204e84e2008-02-04 06:00:24 +00003160 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003161 !strconcat(OpcodeStr,
3162 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003163 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3164 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003165
3166 // Vector intrinsic operation, mem
Evan Cheng172b7942008-03-14 07:39:27 +00003167 def PDm_Int : SS4AIi8<opcpd, MRMSrcMem,
Nate Begeman204e84e2008-02-04 06:00:24 +00003168 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begeman63ec90a2008-02-03 07:18:54 +00003169 !strconcat(OpcodeStr,
3170 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Chengb1938262008-05-23 00:37:07 +00003171 [(set VR128:$dst,
3172 (V2F64Int (memopv2f64 addr:$src1),imm:$src2))]>,
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003173 OpSize;
Nate Begeman63ec90a2008-02-03 07:18:54 +00003174}
3175
Dale Johannesene397acc2008-10-10 23:51:03 +00003176let Constraints = "$src1 = $dst" in {
3177multiclass sse41_fp_binop_rm<bits<8> opcss, bits<8> opcsd,
3178 string OpcodeStr,
3179 Intrinsic F32Int,
3180 Intrinsic F64Int> {
3181 // Intrinsic operation, reg.
3182 def SSr_Int : SS4AIi8<opcss, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003183 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003184 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3185 !strconcat(OpcodeStr,
3186 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003187 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003188 (F32Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3189 OpSize;
3190
3191 // Intrinsic operation, mem.
Eric Christopher44b93ff2009-07-31 20:07:27 +00003192 def SSm_Int : SS4AIi8<opcss, MRMSrcMem,
3193 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003194 (ins VR128:$src1, ssmem:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003195 !strconcat(OpcodeStr,
Dale Johannesene397acc2008-10-10 23:51:03 +00003196 "ss\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003197 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003198 (F32Int VR128:$src1, sse_load_f32:$src2, imm:$src3))]>,
3199 OpSize;
3200
3201 // Intrinsic operation, reg.
3202 def SDr_Int : SS4AIi8<opcsd, MRMSrcReg,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003203 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003204 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3205 !strconcat(OpcodeStr,
3206 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003207 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003208 (F64Int VR128:$src1, VR128:$src2, imm:$src3))]>,
3209 OpSize;
3210
3211 // Intrinsic operation, mem.
3212 def SDm_Int : SS4AIi8<opcsd, MRMSrcMem,
Eric Christopher44b93ff2009-07-31 20:07:27 +00003213 (outs VR128:$dst),
Dale Johannesene397acc2008-10-10 23:51:03 +00003214 (ins VR128:$src1, sdmem:$src2, i32i8imm:$src3),
3215 !strconcat(OpcodeStr,
3216 "sd\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003217 [(set VR128:$dst,
Dale Johannesene397acc2008-10-10 23:51:03 +00003218 (F64Int VR128:$src1, sse_load_f64:$src2, imm:$src3))]>,
3219 OpSize;
3220}
3221}
3222
Nate Begeman63ec90a2008-02-03 07:18:54 +00003223// FP round - roundss, roundps, roundsd, roundpd
Dale Johannesene397acc2008-10-10 23:51:03 +00003224defm ROUND : sse41_fp_unop_rm<0x08, 0x09, "round",
3225 int_x86_sse41_round_ps, int_x86_sse41_round_pd>;
3226defm ROUND : sse41_fp_binop_rm<0x0A, 0x0B, "round",
3227 int_x86_sse41_round_ss, int_x86_sse41_round_sd>;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003228
3229// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3230multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3231 Intrinsic IntId128> {
3232 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3233 (ins VR128:$src),
3234 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3235 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3236 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3237 (ins i128mem:$src),
3238 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3239 [(set VR128:$dst,
3240 (IntId128
3241 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3242}
3243
3244defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3245 int_x86_sse41_phminposuw>;
3246
3247/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003248let Constraints = "$src1 = $dst" in {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003249 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3250 Intrinsic IntId128, bit Commutable = 0> {
Nate Begemanfea2be52008-02-09 23:46:37 +00003251 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3252 (ins VR128:$src1, VR128:$src2),
3253 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3254 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3255 OpSize {
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003256 let isCommutable = Commutable;
3257 }
Nate Begemanfea2be52008-02-09 23:46:37 +00003258 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3259 (ins VR128:$src1, i128mem:$src2),
3260 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3261 [(set VR128:$dst,
3262 (IntId128 VR128:$src1,
3263 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begeman2f6f1c02008-02-04 05:34:34 +00003264 }
3265}
3266
3267defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3268 int_x86_sse41_pcmpeqq, 1>;
3269defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3270 int_x86_sse41_packusdw, 0>;
3271defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3272 int_x86_sse41_pminsb, 1>;
3273defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3274 int_x86_sse41_pminsd, 1>;
3275defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3276 int_x86_sse41_pminud, 1>;
3277defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3278 int_x86_sse41_pminuw, 1>;
3279defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3280 int_x86_sse41_pmaxsb, 1>;
3281defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3282 int_x86_sse41_pmaxsd, 1>;
3283defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3284 int_x86_sse41_pmaxud, 1>;
3285defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3286 int_x86_sse41_pmaxuw, 1>;
Nate Begeman204e84e2008-02-04 06:00:24 +00003287
Mon P Wangaf9b9522008-12-18 21:42:19 +00003288defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq", int_x86_sse41_pmuldq, 1>;
3289
Nate Begeman30a0de92008-07-17 16:51:19 +00003290def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, VR128:$src2)),
3291 (PCMPEQQrr VR128:$src1, VR128:$src2)>;
3292def : Pat<(v2i64 (X86pcmpeqq VR128:$src1, (memop addr:$src2))),
3293 (PCMPEQQrm VR128:$src1, addr:$src2)>;
3294
Nate Begeman1426d522008-02-09 01:38:08 +00003295/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003296let Constraints = "$src1 = $dst" in {
Dan Gohman0b924dc2008-05-23 17:49:40 +00003297 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, ValueType OpVT,
3298 SDNode OpNode, Intrinsic IntId128,
3299 bit Commutable = 0> {
Nate Begeman1426d522008-02-09 01:38:08 +00003300 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3301 (ins VR128:$src1, VR128:$src2),
3302 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman0b924dc2008-05-23 17:49:40 +00003303 [(set VR128:$dst, (OpNode (OpVT VR128:$src1),
3304 VR128:$src2))]>, OpSize {
Nate Begeman1426d522008-02-09 01:38:08 +00003305 let isCommutable = Commutable;
3306 }
3307 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3308 (ins VR128:$src1, VR128:$src2),
3309 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3310 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3311 OpSize {
3312 let isCommutable = Commutable;
3313 }
3314 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3315 (ins VR128:$src1, i128mem:$src2),
3316 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3317 [(set VR128:$dst,
Chris Lattner1a7d0872010-02-18 06:33:42 +00003318 (OpVT (OpNode VR128:$src1, (memop addr:$src2))))]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003319 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3320 (ins VR128:$src1, i128mem:$src2),
3321 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3322 [(set VR128:$dst,
Evan Chengb1938262008-05-23 00:37:07 +00003323 (IntId128 VR128:$src1, (memop addr:$src2)))]>,
Nate Begeman1426d522008-02-09 01:38:08 +00003324 OpSize;
3325 }
3326}
Eric Christopher8258d0b2010-03-30 18:49:01 +00003327
3328/// SS48I_binop_rm - Simple SSE41 binary operator.
3329let Constraints = "$src1 = $dst" in {
3330multiclass SS48I_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
3331 ValueType OpVT, bit Commutable = 0> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003332 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003333 (ins VR128:$src1, VR128:$src2),
3334 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3335 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]>,
3336 OpSize {
3337 let isCommutable = Commutable;
3338 }
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003339 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
Eric Christopher8258d0b2010-03-30 18:49:01 +00003340 (ins VR128:$src1, i128mem:$src2),
3341 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3342 [(set VR128:$dst, (OpNode VR128:$src1,
3343 (bc_v4i32 (memopv2i64 addr:$src2))))]>,
3344 OpSize;
3345}
3346}
3347
3348defm PMULLD : SS48I_binop_rm<0x40, "pmulld", mul, v4i32, 1>;
Nate Begeman1426d522008-02-09 01:38:08 +00003349
Evan Cheng172b7942008-03-14 07:39:27 +00003350/// SS41I_binop_rmi_int - SSE 4.1 binary operator with 8-bit immediate
Evan Chenge9083d62008-03-05 08:19:16 +00003351let Constraints = "$src1 = $dst" in {
Nate Begeman204e84e2008-02-04 06:00:24 +00003352 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3353 Intrinsic IntId128, bit Commutable = 0> {
Evan Cheng172b7942008-03-14 07:39:27 +00003354 def rri : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003355 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003356 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003357 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003358 [(set VR128:$dst,
Nate Begemanfea2be52008-02-09 23:46:37 +00003359 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3360 OpSize {
Nate Begeman204e84e2008-02-04 06:00:24 +00003361 let isCommutable = Commutable;
3362 }
Evan Cheng172b7942008-03-14 07:39:27 +00003363 def rmi : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003364 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3365 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003366 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begemanfea2be52008-02-09 23:46:37 +00003367 [(set VR128:$dst,
3368 (IntId128 VR128:$src1,
3369 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3370 OpSize;
Nate Begeman204e84e2008-02-04 06:00:24 +00003371 }
3372}
3373
3374defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3375 int_x86_sse41_blendps, 0>;
3376defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3377 int_x86_sse41_blendpd, 0>;
3378defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3379 int_x86_sse41_pblendw, 0>;
3380defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3381 int_x86_sse41_dpps, 1>;
3382defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3383 int_x86_sse41_dppd, 1>;
3384defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
Eric Christopher419e2232010-04-08 00:52:02 +00003385 int_x86_sse41_mpsadbw, 0>;
Nate Begeman1426d522008-02-09 01:38:08 +00003386
Nate Begemanfea2be52008-02-09 23:46:37 +00003387
Evan Cheng172b7942008-03-14 07:39:27 +00003388/// SS41I_ternary_int - SSE 4.1 ternary operator
Evan Chenge9083d62008-03-05 08:19:16 +00003389let Uses = [XMM0], Constraints = "$src1 = $dst" in {
Nate Begemanab5d56c2008-02-10 18:47:57 +00003390 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3391 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3392 (ins VR128:$src1, VR128:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003393 !strconcat(OpcodeStr,
Nate Begemanab5d56c2008-02-10 18:47:57 +00003394 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3395 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3396 OpSize;
3397
3398 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3399 (ins VR128:$src1, i128mem:$src2),
3400 !strconcat(OpcodeStr,
3401 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3402 [(set VR128:$dst,
3403 (IntId VR128:$src1,
3404 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3405 }
3406}
3407
3408defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3409defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3410defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3411
3412
Nate Begemanfea2be52008-02-09 23:46:37 +00003413multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3414 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3415 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3416 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3417
3418 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3419 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003420 [(set VR128:$dst,
3421 (IntId (bitconvert (v2i64 (scalar_to_vector (loadi64 addr:$src))))))]>,
3422 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003423}
3424
3425defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3426defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3427defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3428defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3429defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3430defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3431
Evan Chengca57f782008-09-24 23:27:55 +00003432// Common patterns involving scalar load.
3433def : Pat<(int_x86_sse41_pmovsxbw (vzmovl_v2i64 addr:$src)),
3434 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3435def : Pat<(int_x86_sse41_pmovsxbw (vzload_v2i64 addr:$src)),
3436 (PMOVSXBWrm addr:$src)>, Requires<[HasSSE41]>;
3437
3438def : Pat<(int_x86_sse41_pmovsxwd (vzmovl_v2i64 addr:$src)),
3439 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3440def : Pat<(int_x86_sse41_pmovsxwd (vzload_v2i64 addr:$src)),
3441 (PMOVSXWDrm addr:$src)>, Requires<[HasSSE41]>;
3442
3443def : Pat<(int_x86_sse41_pmovsxdq (vzmovl_v2i64 addr:$src)),
3444 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3445def : Pat<(int_x86_sse41_pmovsxdq (vzload_v2i64 addr:$src)),
3446 (PMOVSXDQrm addr:$src)>, Requires<[HasSSE41]>;
3447
3448def : Pat<(int_x86_sse41_pmovzxbw (vzmovl_v2i64 addr:$src)),
3449 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3450def : Pat<(int_x86_sse41_pmovzxbw (vzload_v2i64 addr:$src)),
3451 (PMOVZXBWrm addr:$src)>, Requires<[HasSSE41]>;
3452
3453def : Pat<(int_x86_sse41_pmovzxwd (vzmovl_v2i64 addr:$src)),
3454 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3455def : Pat<(int_x86_sse41_pmovzxwd (vzload_v2i64 addr:$src)),
3456 (PMOVZXWDrm addr:$src)>, Requires<[HasSSE41]>;
3457
3458def : Pat<(int_x86_sse41_pmovzxdq (vzmovl_v2i64 addr:$src)),
3459 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3460def : Pat<(int_x86_sse41_pmovzxdq (vzload_v2i64 addr:$src)),
3461 (PMOVZXDQrm addr:$src)>, Requires<[HasSSE41]>;
3462
3463
Nate Begemanfea2be52008-02-09 23:46:37 +00003464multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3465 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3466 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3467 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3468
3469 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3470 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003471 [(set VR128:$dst,
3472 (IntId (bitconvert (v4i32 (scalar_to_vector (loadi32 addr:$src))))))]>,
3473 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003474}
3475
3476defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3477defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3478defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3479defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3480
Evan Chengca57f782008-09-24 23:27:55 +00003481// Common patterns involving scalar load
3482def : Pat<(int_x86_sse41_pmovsxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003483 (PMOVSXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003484def : Pat<(int_x86_sse41_pmovsxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003485 (PMOVSXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003486
3487def : Pat<(int_x86_sse41_pmovzxbd (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003488 (PMOVZXBDrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003489def : Pat<(int_x86_sse41_pmovzxwq (vzmovl_v4i32 addr:$src)),
Evan Cheng89d4a282008-09-25 00:49:51 +00003490 (PMOVZXWQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003491
3492
Nate Begemanfea2be52008-02-09 23:46:37 +00003493multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3494 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3495 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3496 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3497
Evan Chengca57f782008-09-24 23:27:55 +00003498 // Expecting a i16 load any extended to i32 value.
Nate Begemanfea2be52008-02-09 23:46:37 +00003499 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3500 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
Evan Chengca57f782008-09-24 23:27:55 +00003501 [(set VR128:$dst, (IntId (bitconvert
3502 (v4i32 (scalar_to_vector (loadi16_anyext addr:$src))))))]>,
3503 OpSize;
Nate Begemanfea2be52008-02-09 23:46:37 +00003504}
3505
3506defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
Eli Friedman9d47b8d2009-06-06 05:55:37 +00003507defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovzxbq", int_x86_sse41_pmovzxbq>;
Nate Begemanfea2be52008-02-09 23:46:37 +00003508
Evan Chengca57f782008-09-24 23:27:55 +00003509// Common patterns involving scalar load
3510def : Pat<(int_x86_sse41_pmovsxbq
3511 (bitconvert (v4i32 (X86vzmovl
3512 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003513 (PMOVSXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003514
3515def : Pat<(int_x86_sse41_pmovzxbq
3516 (bitconvert (v4i32 (X86vzmovl
3517 (v4i32 (scalar_to_vector (loadi32 addr:$src))))))),
Evan Cheng89d4a282008-09-25 00:49:51 +00003518 (PMOVZXBQrm addr:$src)>, Requires<[HasSSE41]>;
Evan Chengca57f782008-09-24 23:27:55 +00003519
Nate Begemanfea2be52008-02-09 23:46:37 +00003520
Nate Begeman14d12ca2008-02-11 04:19:36 +00003521/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3522multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003523 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003524 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003525 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003526 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003527 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3528 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003529 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003530 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003531 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003532 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003533 []>, OpSize;
3534// FIXME:
3535// There's an AssertZext in the way of writing the store pattern
3536// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begemanfea2be52008-02-09 23:46:37 +00003537}
3538
Nate Begeman14d12ca2008-02-11 04:19:36 +00003539defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003540
Nate Begeman14d12ca2008-02-11 04:19:36 +00003541
3542/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3543multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003544 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003545 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003546 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003547 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3548 []>, OpSize;
3549// FIXME:
3550// There's an AssertZext in the way of writing the store pattern
3551// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3552}
3553
3554defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3555
3556
3557/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3558multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003559 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003560 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003561 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003562 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3563 [(set GR32:$dst,
3564 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003565 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003566 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003567 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003568 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3569 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3570 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003571}
3572
Nate Begeman14d12ca2008-02-11 04:19:36 +00003573defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman1426d522008-02-09 01:38:08 +00003574
Nate Begeman14d12ca2008-02-11 04:19:36 +00003575
Evan Cheng62a3f152008-03-24 21:52:23 +00003576/// SS41I_extractf32 - SSE 4.1 extract 32 bits fp value to int reg or memory
3577/// destination
Nate Begeman14d12ca2008-02-11 04:19:36 +00003578multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Evan Cheng7aae8762008-03-26 08:11:49 +00003579 def rr : SS4AIi8<opc, MRMDestReg, (outs GR32:$dst),
Nate Begemanfea2be52008-02-09 23:46:37 +00003580 (ins VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003581 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003582 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Dan Gohman171c11e2008-04-16 02:32:24 +00003583 [(set GR32:$dst,
3584 (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2))]>,
Evan Cheng62a3f152008-03-24 21:52:23 +00003585 OpSize;
Eric Christopher44b93ff2009-07-31 20:07:27 +00003586 def mr : SS4AIi8<opc, MRMDestMem, (outs),
Nate Begemanfea2be52008-02-09 23:46:37 +00003587 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003588 !strconcat(OpcodeStr,
Nate Begemanfea2be52008-02-09 23:46:37 +00003589 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Evan Cheng62a3f152008-03-24 21:52:23 +00003590 [(store (extractelt (bc_v4i32 (v4f32 VR128:$src1)), imm:$src2),
Nate Begemanfea2be52008-02-09 23:46:37 +00003591 addr:$dst)]>, OpSize;
Nate Begeman1426d522008-02-09 01:38:08 +00003592}
3593
Nate Begeman14d12ca2008-02-11 04:19:36 +00003594defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begemanfea2be52008-02-09 23:46:37 +00003595
Dan Gohmand9ced092008-08-08 18:30:21 +00003596// Also match an EXTRACTPS store when the store is done as f32 instead of i32.
3597def : Pat<(store (f32 (bitconvert (extractelt (bc_v4i32 (v4f32 VR128:$src1)),
3598 imm:$src2))),
3599 addr:$dst),
3600 (EXTRACTPSmr addr:$dst, VR128:$src1, imm:$src2)>,
3601 Requires<[HasSSE41]>;
3602
Evan Chenge9083d62008-03-05 08:19:16 +00003603let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003604 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003605 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003606 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003607 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003608 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003609 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003610 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003611 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003612 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3613 !strconcat(OpcodeStr,
3614 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003615 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003616 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3617 imm:$src3))]>, OpSize;
3618 }
3619}
3620
3621defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3622
Evan Chenge9083d62008-03-05 08:19:16 +00003623let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003624 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
Evan Cheng172b7942008-03-14 07:39:27 +00003625 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003626 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003627 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003628 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003629 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003630 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3631 OpSize;
Evan Cheng172b7942008-03-14 07:39:27 +00003632 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003633 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3634 !strconcat(OpcodeStr,
3635 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003636 [(set VR128:$dst,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003637 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3638 imm:$src3)))]>, OpSize;
3639 }
3640}
3641
3642defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3643
Eric Christopher1e5cdea2009-07-23 02:22:41 +00003644// insertps has a few different modes, there's the first two here below which
3645// are optimized inserts that won't zero arbitrary elements in the destination
3646// vector. The next one matches the intrinsic and could zero arbitrary elements
3647// in the target vector.
Evan Chenge9083d62008-03-05 08:19:16 +00003648let Constraints = "$src1 = $dst" in {
Nate Begeman14d12ca2008-02-11 04:19:36 +00003649 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
Eric Christopherfbd66872009-07-24 00:33:09 +00003650 def rr : SS4AIi8<opc, MRMSrcReg, (outs VR128:$dst),
3651 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003652 !strconcat(OpcodeStr,
Nate Begeman14d12ca2008-02-11 04:19:36 +00003653 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003654 [(set VR128:$dst,
3655 (X86insrtps VR128:$src1, VR128:$src2, imm:$src3))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003656 OpSize;
Eric Christopherfbd66872009-07-24 00:33:09 +00003657 def rm : SS4AIi8<opc, MRMSrcMem, (outs VR128:$dst),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003658 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3659 !strconcat(OpcodeStr,
3660 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Eric Christopher44b93ff2009-07-31 20:07:27 +00003661 [(set VR128:$dst,
Eric Christopherfbd66872009-07-24 00:33:09 +00003662 (X86insrtps VR128:$src1,
3663 (v4f32 (scalar_to_vector (loadf32 addr:$src2))),
Nate Begeman14d12ca2008-02-11 04:19:36 +00003664 imm:$src3))]>, OpSize;
3665 }
3666}
3667
Evan Cheng7aae8762008-03-26 08:11:49 +00003668defm INSERTPS : SS41I_insertf32<0x21, "insertps">;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003669
Eric Christopherfbd66872009-07-24 00:33:09 +00003670def : Pat<(int_x86_sse41_insertps VR128:$src1, VR128:$src2, imm:$src3),
3671 (INSERTPSrr VR128:$src1, VR128:$src2, imm:$src3)>;
3672
Eric Christopher71c67532009-07-29 00:28:05 +00003673// ptest instruction we'll lower to this in X86ISelLowering primarily from
3674// the intel intrinsic that corresponds to this.
Nate Begemanbc4efb82008-03-16 21:14:46 +00003675let Defs = [EFLAGS] in {
3676def PTESTrr : SS48I<0x17, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003677 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003678 [(set EFLAGS, (X86ptest VR128:$src1, VR128:$src2))]>,
3679 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003680def PTESTrm : SS48I<0x17, MRMSrcMem, (outs), (ins VR128:$src1, i128mem:$src2),
Eric Christopher71c67532009-07-29 00:28:05 +00003681 "ptest \t{$src2, $src1|$src1, $src2}",
Chris Lattnerd486d772010-03-28 05:07:17 +00003682 [(set EFLAGS, (X86ptest VR128:$src1, (load addr:$src2)))]>,
3683 OpSize;
Nate Begemanbc4efb82008-03-16 21:14:46 +00003684}
3685
3686def MOVNTDQArm : SS48I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
3687 "movntdqa\t{$src, $dst|$dst, $src}",
Kevin Enderby40fe18f2010-02-10 00:10:31 +00003688 [(set VR128:$dst, (int_x86_sse41_movntdqa addr:$src))]>,
3689 OpSize;
Nate Begeman30a0de92008-07-17 16:51:19 +00003690
Eric Christopherb120ab42009-08-18 22:50:32 +00003691
3692//===----------------------------------------------------------------------===//
3693// SSE4.2 Instructions
3694//===----------------------------------------------------------------------===//
3695
Nate Begeman30a0de92008-07-17 16:51:19 +00003696/// SS42I_binop_rm_int - Simple SSE 4.2 binary operator
3697let Constraints = "$src1 = $dst" in {
3698 multiclass SS42I_binop_rm_int<bits<8> opc, string OpcodeStr,
3699 Intrinsic IntId128, bit Commutable = 0> {
3700 def rr : SS428I<opc, MRMSrcReg, (outs VR128:$dst),
3701 (ins VR128:$src1, VR128:$src2),
3702 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3703 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3704 OpSize {
3705 let isCommutable = Commutable;
3706 }
3707 def rm : SS428I<opc, MRMSrcMem, (outs VR128:$dst),
3708 (ins VR128:$src1, i128mem:$src2),
3709 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3710 [(set VR128:$dst,
3711 (IntId128 VR128:$src1,
3712 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3713 }
3714}
3715
Nate Begemane99b2552008-07-17 17:04:58 +00003716defm PCMPGTQ : SS42I_binop_rm_int<0x37, "pcmpgtq", int_x86_sse42_pcmpgtq>;
Nate Begeman30a0de92008-07-17 16:51:19 +00003717
3718def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, VR128:$src2)),
3719 (PCMPGTQrr VR128:$src1, VR128:$src2)>;
3720def : Pat<(v2i64 (X86pcmpgtq VR128:$src1, (memop addr:$src2))),
3721 (PCMPGTQrm VR128:$src1, addr:$src2)>;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003722
3723// crc intrinsic instruction
3724// This set of instructions are only rm, the only difference is the size
3725// of r and m.
3726let Constraints = "$src1 = $dst" in {
Eric Christopher027c2b12009-08-10 21:48:58 +00003727 def CRC32m8 : SS42FI<0xF0, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003728 (ins GR32:$src1, i8mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003729 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003730 [(set GR32:$dst,
3731 (int_x86_sse42_crc32_8 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003732 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003733 def CRC32r8 : SS42FI<0xF0, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003734 (ins GR32:$src1, GR8:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003735 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003736 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003737 (int_x86_sse42_crc32_8 GR32:$src1, GR8:$src2))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003738 def CRC32m16 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003739 (ins GR32:$src1, i16mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003740 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003741 [(set GR32:$dst,
3742 (int_x86_sse42_crc32_16 GR32:$src1,
3743 (load addr:$src2)))]>,
3744 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003745 def CRC32r16 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003746 (ins GR32:$src1, GR16:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003747 "crc32{w} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003748 [(set GR32:$dst,
Eric Christopher027c2b12009-08-10 21:48:58 +00003749 (int_x86_sse42_crc32_16 GR32:$src1, GR16:$src2))]>,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003750 OpSize;
Eric Christopher027c2b12009-08-10 21:48:58 +00003751 def CRC32m32 : SS42FI<0xF1, MRMSrcMem, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003752 (ins GR32:$src1, i32mem:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003753 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003754 [(set GR32:$dst,
3755 (int_x86_sse42_crc32_32 GR32:$src1,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003756 (load addr:$src2)))]>;
Eric Christopher027c2b12009-08-10 21:48:58 +00003757 def CRC32r32 : SS42FI<0xF1, MRMSrcReg, (outs GR32:$dst),
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003758 (ins GR32:$src1, GR32:$src2),
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003759 "crc32{l} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003760 [(set GR32:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003761 (int_x86_sse42_crc32_32 GR32:$src1, GR32:$src2))]>;
3762 def CRC64m8 : SS42FI<0xF0, MRMSrcMem, (outs GR64:$dst),
3763 (ins GR64:$src1, i8mem:$src2),
3764 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003765 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003766 (int_x86_sse42_crc64_8 GR64:$src1,
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003767 (load addr:$src2)))]>,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003768 REX_W;
3769 def CRC64r8 : SS42FI<0xF0, MRMSrcReg, (outs GR64:$dst),
3770 (ins GR64:$src1, GR8:$src2),
3771 "crc32{b} \t{$src2, $src1|$src1, $src2}",
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003772 [(set GR64:$dst,
Kevin Enderbyb46b03b2010-03-19 20:04:42 +00003773 (int_x86_sse42_crc64_8 GR64:$src1, GR8:$src2))]>,
3774 REX_W;
3775 def CRC64m64 : SS42FI<0xF1, MRMSrcMem, (outs GR64:$dst),
3776 (ins GR64:$src1, i64mem:$src2),
3777 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3778 [(set GR64:$dst,
3779 (int_x86_sse42_crc64_64 GR64:$src1,
3780 (load addr:$src2)))]>,
3781 REX_W;
3782 def CRC64r64 : SS42FI<0xF1, MRMSrcReg, (outs GR64:$dst),
3783 (ins GR64:$src1, GR64:$src2),
3784 "crc32{q} \t{$src2, $src1|$src1, $src2}",
3785 [(set GR64:$dst,
3786 (int_x86_sse42_crc64_64 GR64:$src1, GR64:$src2))]>,
3787 REX_W;
Eric Christopherb4dc13c2009-08-08 21:55:08 +00003788}
Eric Christopherb120ab42009-08-18 22:50:32 +00003789
3790// String/text processing instructions.
Dan Gohman533297b2009-10-29 18:10:34 +00003791let Defs = [EFLAGS], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003792def PCMPISTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003793 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3794 "#PCMPISTRM128rr PSEUDO!",
3795 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, VR128:$src2,
3796 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003797def PCMPISTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003798 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3799 "#PCMPISTRM128rm PSEUDO!",
3800 [(set VR128:$dst, (int_x86_sse42_pcmpistrm128 VR128:$src1, (load addr:$src2),
3801 imm:$src3))]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003802}
3803
3804let Defs = [XMM0, EFLAGS] in {
3805def PCMPISTRM128rr : SS42AI<0x62, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003806 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3807 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003808def PCMPISTRM128rm : SS42AI<0x62, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003809 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3810 "pcmpistrm\t{$src3, $src2, $src1|$src1, $src2, $src3}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003811}
3812
Sean Callanan108934c2009-12-18 00:01:26 +00003813let Defs = [EFLAGS], Uses = [EAX, EDX], usesCustomInserter = 1 in {
Eric Christopherb120ab42009-08-18 22:50:32 +00003814def PCMPESTRM128REG : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003815 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3816 "#PCMPESTRM128rr PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003817 [(set VR128:$dst,
3818 (int_x86_sse42_pcmpestrm128
Sean Callanan108934c2009-12-18 00:01:26 +00003819 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5))]>, OpSize;
3820
Eric Christopherb120ab42009-08-18 22:50:32 +00003821def PCMPESTRM128MEM : SS42AI<0, Pseudo, (outs VR128:$dst),
Sean Callanan108934c2009-12-18 00:01:26 +00003822 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3823 "#PCMPESTRM128rm PSEUDO!",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003824 [(set VR128:$dst, (int_x86_sse42_pcmpestrm128
3825 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5))]>,
Sean Callanan108934c2009-12-18 00:01:26 +00003826 OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003827}
3828
3829let Defs = [XMM0, EFLAGS], Uses = [EAX, EDX] in {
Sean Callanan47234e62009-08-20 18:24:27 +00003830def PCMPESTRM128rr : SS42AI<0x60, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003831 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3832 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Sean Callanan47234e62009-08-20 18:24:27 +00003833def PCMPESTRM128rm : SS42AI<0x60, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003834 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3835 "pcmpestrm\t{$src5, $src3, $src1|$src1, $src3, $src5}", []>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003836}
3837
3838let Defs = [ECX, EFLAGS] in {
3839 multiclass SS42AI_pcmpistri<Intrinsic IntId128> {
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003840 def rr : SS42AI<0x63, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003841 (ins VR128:$src1, VR128:$src2, i8imm:$src3),
3842 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3843 [(set ECX, (IntId128 VR128:$src1, VR128:$src2, imm:$src3)),
3844 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003845 def rm : SS42AI<0x63, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003846 (ins VR128:$src1, i128mem:$src2, i8imm:$src3),
3847 "pcmpistri\t{$src3, $src2, $src1|$src1, $src2, $src3}",
3848 [(set ECX, (IntId128 VR128:$src1, (load addr:$src2), imm:$src3)),
3849 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003850 }
3851}
3852
3853defm PCMPISTRI : SS42AI_pcmpistri<int_x86_sse42_pcmpistri128>;
3854defm PCMPISTRIA : SS42AI_pcmpistri<int_x86_sse42_pcmpistria128>;
3855defm PCMPISTRIC : SS42AI_pcmpistri<int_x86_sse42_pcmpistric128>;
3856defm PCMPISTRIO : SS42AI_pcmpistri<int_x86_sse42_pcmpistrio128>;
3857defm PCMPISTRIS : SS42AI_pcmpistri<int_x86_sse42_pcmpistris128>;
3858defm PCMPISTRIZ : SS42AI_pcmpistri<int_x86_sse42_pcmpistriz128>;
3859
3860let Defs = [ECX, EFLAGS] in {
3861let Uses = [EAX, EDX] in {
3862 multiclass SS42AI_pcmpestri<Intrinsic IntId128> {
3863 def rr : SS42AI<0x61, MRMSrcReg, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003864 (ins VR128:$src1, VR128:$src3, i8imm:$src5),
3865 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
3866 [(set ECX, (IntId128 VR128:$src1, EAX, VR128:$src3, EDX, imm:$src5)),
3867 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003868 def rm : SS42AI<0x61, MRMSrcMem, (outs),
Sean Callanan108934c2009-12-18 00:01:26 +00003869 (ins VR128:$src1, i128mem:$src3, i8imm:$src5),
3870 "pcmpestri\t{$src5, $src3, $src1|$src1, $src3, $src5}",
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003871 [(set ECX,
Sean Callanan108934c2009-12-18 00:01:26 +00003872 (IntId128 VR128:$src1, EAX, (load addr:$src3), EDX, imm:$src5)),
3873 (implicit EFLAGS)]>, OpSize;
Eric Christopherb120ab42009-08-18 22:50:32 +00003874 }
3875}
3876}
3877
3878defm PCMPESTRI : SS42AI_pcmpestri<int_x86_sse42_pcmpestri128>;
3879defm PCMPESTRIA : SS42AI_pcmpestri<int_x86_sse42_pcmpestria128>;
3880defm PCMPESTRIC : SS42AI_pcmpestri<int_x86_sse42_pcmpestric128>;
3881defm PCMPESTRIO : SS42AI_pcmpestri<int_x86_sse42_pcmpestrio128>;
3882defm PCMPESTRIS : SS42AI_pcmpestri<int_x86_sse42_pcmpestris128>;
3883defm PCMPESTRIZ : SS42AI_pcmpestri<int_x86_sse42_pcmpestriz128>;
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003884
3885//===----------------------------------------------------------------------===//
3886// AES-NI Instructions
3887//===----------------------------------------------------------------------===//
3888
3889let Constraints = "$src1 = $dst" in {
3890 multiclass AESI_binop_rm_int<bits<8> opc, string OpcodeStr,
3891 Intrinsic IntId128, bit Commutable = 0> {
3892 def rr : AES8I<opc, MRMSrcReg, (outs VR128:$dst),
3893 (ins VR128:$src1, VR128:$src2),
3894 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3895 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3896 OpSize {
3897 let isCommutable = Commutable;
3898 }
3899 def rm : AES8I<opc, MRMSrcMem, (outs VR128:$dst),
3900 (ins VR128:$src1, i128mem:$src2),
3901 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3902 [(set VR128:$dst,
3903 (IntId128 VR128:$src1,
3904 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
3905 }
3906}
3907
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003908defm AESENC : AESI_binop_rm_int<0xDC, "aesenc",
3909 int_x86_aesni_aesenc>;
3910defm AESENCLAST : AESI_binop_rm_int<0xDD, "aesenclast",
3911 int_x86_aesni_aesenclast>;
3912defm AESDEC : AESI_binop_rm_int<0xDE, "aesdec",
3913 int_x86_aesni_aesdec>;
3914defm AESDECLAST : AESI_binop_rm_int<0xDF, "aesdeclast",
3915 int_x86_aesni_aesdeclast>;
3916
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003917def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, VR128:$src2)),
3918 (AESENCrr VR128:$src1, VR128:$src2)>;
3919def : Pat<(v2i64 (int_x86_aesni_aesenc VR128:$src1, (memop addr:$src2))),
3920 (AESENCrm VR128:$src1, addr:$src2)>;
3921def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, VR128:$src2)),
3922 (AESENCLASTrr VR128:$src1, VR128:$src2)>;
3923def : Pat<(v2i64 (int_x86_aesni_aesenclast VR128:$src1, (memop addr:$src2))),
3924 (AESENCLASTrm VR128:$src1, addr:$src2)>;
3925def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, VR128:$src2)),
3926 (AESDECrr VR128:$src1, VR128:$src2)>;
3927def : Pat<(v2i64 (int_x86_aesni_aesdec VR128:$src1, (memop addr:$src2))),
3928 (AESDECrm VR128:$src1, addr:$src2)>;
3929def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, VR128:$src2)),
3930 (AESDECLASTrr VR128:$src1, VR128:$src2)>;
3931def : Pat<(v2i64 (int_x86_aesni_aesdeclast VR128:$src1, (memop addr:$src2))),
3932 (AESDECLASTrm VR128:$src1, addr:$src2)>;
3933
Eric Christopherb3500fd2010-04-02 23:48:33 +00003934def AESIMCrr : AES8I<0xDB, MRMSrcReg, (outs VR128:$dst),
3935 (ins VR128:$src1),
3936 "aesimc\t{$src1, $dst|$dst, $src1}",
3937 [(set VR128:$dst,
3938 (int_x86_aesni_aesimc VR128:$src1))]>,
3939 OpSize;
3940
3941def AESIMCrm : AES8I<0xDB, MRMSrcMem, (outs VR128:$dst),
3942 (ins i128mem:$src1),
3943 "aesimc\t{$src1, $dst|$dst, $src1}",
3944 [(set VR128:$dst,
3945 (int_x86_aesni_aesimc (bitconvert (memopv2i64 addr:$src1))))]>,
3946 OpSize;
3947
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003948def AESKEYGENASSIST128rr : AESAI<0xDF, MRMSrcReg, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003949 (ins VR128:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003950 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3951 [(set VR128:$dst,
3952 (int_x86_aesni_aeskeygenassist VR128:$src1, imm:$src2))]>,
3953 OpSize;
3954def AESKEYGENASSIST128rm : AESAI<0xDF, MRMSrcMem, (outs VR128:$dst),
Eric Christopher7e2f5aa2010-05-25 17:33:22 +00003955 (ins i128mem:$src1, i8imm:$src2),
Eric Christopher6d1cd1c2010-04-02 21:54:27 +00003956 "aeskeygenassist\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3957 [(set VR128:$dst,
3958 (int_x86_aesni_aeskeygenassist (bitconvert (memopv2i64 addr:$src1)),
3959 imm:$src2))]>,
3960 OpSize;