blob: e50716b2c206718f0c11abe4f23b663540c6afc3 [file] [log] [blame]
Arnold Schwaighofer373e8652007-10-12 21:30:57 +00001//====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86 SSE instruction set, defining the instructions,
11// and properties of the instructions which are needed for code generation,
12// machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
16
17//===----------------------------------------------------------------------===//
18// SSE specific DAG Nodes.
19//===----------------------------------------------------------------------===//
20
21def SDTX86FPShiftOp : SDTypeProfile<1, 2, [ SDTCisSameAs<0, 1>,
22 SDTCisFP<0>, SDTCisInt<2> ]>;
23
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024def X86fmin : SDNode<"X86ISD::FMIN", SDTFPBinOp>;
25def X86fmax : SDNode<"X86ISD::FMAX", SDTFPBinOp>;
26def X86fand : SDNode<"X86ISD::FAND", SDTFPBinOp,
27 [SDNPCommutative, SDNPAssociative]>;
28def X86for : SDNode<"X86ISD::FOR", SDTFPBinOp,
29 [SDNPCommutative, SDNPAssociative]>;
30def X86fxor : SDNode<"X86ISD::FXOR", SDTFPBinOp,
31 [SDNPCommutative, SDNPAssociative]>;
32def X86frsqrt : SDNode<"X86ISD::FRSQRT", SDTFPUnaryOp>;
33def X86frcp : SDNode<"X86ISD::FRCP", SDTFPUnaryOp>;
34def X86fsrl : SDNode<"X86ISD::FSRL", SDTX86FPShiftOp>;
Evan Chengf37bf452007-10-01 18:12:48 +000035def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
Evan Cheng621216e2007-09-29 00:00:36 +000036def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037def X86s2vec : SDNode<"X86ISD::S2VEC", SDTypeProfile<1, 1, []>, []>;
Nate Begemand77e59e2008-02-11 04:19:36 +000038def X86pextrb : SDNode<"X86ISD::PEXTRB",
39 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
40def X86pextrw : SDNode<"X86ISD::PEXTRW",
41 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
42def X86pinsrb : SDNode<"X86ISD::PINSRB",
43 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
44 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
45def X86pinsrw : SDNode<"X86ISD::PINSRW",
46 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
47 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
48def X86insrtps : SDNode<"X86ISD::INSERTPS",
49 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
50 SDTCisVT<2, f32>, SDTCisPtrTy<3>]>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051
52//===----------------------------------------------------------------------===//
53// SSE 'Special' Instructions
54//===----------------------------------------------------------------------===//
55
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000056let isImplicitDef = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +000057def IMPLICIT_DEF_VR128 : I<0, Pseudo, (outs VR128:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 "#IMPLICIT_DEF $dst",
59 [(set VR128:$dst, (v4f32 (undef)))]>,
60 Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000061def IMPLICIT_DEF_FR32 : I<0, Pseudo, (outs FR32:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062 "#IMPLICIT_DEF $dst",
Dale Johannesene0e0fd02007-09-23 14:52:20 +000063 [(set FR32:$dst, (undef))]>, Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000064def IMPLICIT_DEF_FR64 : I<0, Pseudo, (outs FR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065 "#IMPLICIT_DEF $dst",
66 [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000067}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068
69//===----------------------------------------------------------------------===//
70// SSE Complex Patterns
71//===----------------------------------------------------------------------===//
72
73// These are 'extloads' from a scalar to the low element of a vector, zeroing
74// the top elements. These are used for the SSE 'ss' and 'sd' instruction
75// forms.
76def sse_load_f32 : ComplexPattern<v4f32, 4, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000077 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078def sse_load_f64 : ComplexPattern<v2f64, 4, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000079 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080
81def ssmem : Operand<v4f32> {
82 let PrintMethod = "printf32mem";
83 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
84}
85def sdmem : Operand<v2f64> {
86 let PrintMethod = "printf64mem";
87 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
88}
89
90//===----------------------------------------------------------------------===//
91// SSE pattern fragments
92//===----------------------------------------------------------------------===//
93
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
95def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
96def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
97def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
98
Dan Gohman11821702007-07-27 17:16:43 +000099// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +0000100def alignedstore : PatFrag<(ops node:$val, node:$ptr),
101 (st node:$val, node:$ptr), [{
102 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
103 return !ST->isTruncatingStore() &&
104 ST->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000105 ST->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000106 return false;
107}]>;
108
Dan Gohman11821702007-07-27 17:16:43 +0000109// Like 'load', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +0000110def alignedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
111 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
112 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
113 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000114 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000115 return false;
116}]>;
117
Dan Gohman11821702007-07-27 17:16:43 +0000118def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
119def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000120def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
121def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
122def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
123def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
124
125// Like 'load', but uses special alignment checks suitable for use in
126// memory operands in most SSE instructions, which are required to
127// be naturally aligned on some targets but not on others.
128// FIXME: Actually implement support for targets that don't require the
129// alignment. This probably wants a subtarget predicate.
130def memop : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
131 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
132 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
133 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000134 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000135 return false;
136}]>;
137
Dan Gohman11821702007-07-27 17:16:43 +0000138def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
139def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000140def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
141def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
142def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
143def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000144def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000145
Bill Wendling3b15d722007-08-11 09:52:53 +0000146// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
147// 16-byte boundary.
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000148// FIXME: 8 byte alignment for mmx reads is not required
Bill Wendling3b15d722007-08-11 09:52:53 +0000149def memop64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
150 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
151 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
152 LD->getAddressingMode() == ISD::UNINDEXED &&
153 LD->getAlignment() >= 8;
154 return false;
155}]>;
156
157def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
Bill Wendling3b15d722007-08-11 09:52:53 +0000158def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
159def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
160def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
161
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
163def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
164def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
165def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
166def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
167def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
168
169def fp32imm0 : PatLeaf<(f32 fpimm), [{
170 return N->isExactlyValue(+0.0);
171}]>;
172
173def PSxLDQ_imm : SDNodeXForm<imm, [{
174 // Transformation function: imm >> 3
175 return getI32Imm(N->getValue() >> 3);
176}]>;
177
178// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
179// SHUFP* etc. imm.
180def SHUFFLE_get_shuf_imm : SDNodeXForm<build_vector, [{
181 return getI8Imm(X86::getShuffleSHUFImmediate(N));
182}]>;
183
184// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
185// PSHUFHW imm.
186def SHUFFLE_get_pshufhw_imm : SDNodeXForm<build_vector, [{
187 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
188}]>;
189
190// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
191// PSHUFLW imm.
192def SHUFFLE_get_pshuflw_imm : SDNodeXForm<build_vector, [{
193 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
194}]>;
195
196def SSE_splat_mask : PatLeaf<(build_vector), [{
197 return X86::isSplatMask(N);
198}], SHUFFLE_get_shuf_imm>;
199
200def SSE_splat_lo_mask : PatLeaf<(build_vector), [{
201 return X86::isSplatLoMask(N);
202}]>;
203
204def MOVHLPS_shuffle_mask : PatLeaf<(build_vector), [{
205 return X86::isMOVHLPSMask(N);
206}]>;
207
208def MOVHLPS_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
209 return X86::isMOVHLPS_v_undef_Mask(N);
210}]>;
211
212def MOVHP_shuffle_mask : PatLeaf<(build_vector), [{
213 return X86::isMOVHPMask(N);
214}]>;
215
216def MOVLP_shuffle_mask : PatLeaf<(build_vector), [{
217 return X86::isMOVLPMask(N);
218}]>;
219
220def MOVL_shuffle_mask : PatLeaf<(build_vector), [{
221 return X86::isMOVLMask(N);
222}]>;
223
224def MOVSHDUP_shuffle_mask : PatLeaf<(build_vector), [{
225 return X86::isMOVSHDUPMask(N);
226}]>;
227
228def MOVSLDUP_shuffle_mask : PatLeaf<(build_vector), [{
229 return X86::isMOVSLDUPMask(N);
230}]>;
231
232def UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
233 return X86::isUNPCKLMask(N);
234}]>;
235
236def UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
237 return X86::isUNPCKHMask(N);
238}]>;
239
240def UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
241 return X86::isUNPCKL_v_undef_Mask(N);
242}]>;
243
244def UNPCKH_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
245 return X86::isUNPCKH_v_undef_Mask(N);
246}]>;
247
248def PSHUFD_shuffle_mask : PatLeaf<(build_vector), [{
249 return X86::isPSHUFDMask(N);
250}], SHUFFLE_get_shuf_imm>;
251
252def PSHUFHW_shuffle_mask : PatLeaf<(build_vector), [{
253 return X86::isPSHUFHWMask(N);
254}], SHUFFLE_get_pshufhw_imm>;
255
256def PSHUFLW_shuffle_mask : PatLeaf<(build_vector), [{
257 return X86::isPSHUFLWMask(N);
258}], SHUFFLE_get_pshuflw_imm>;
259
260def SHUFP_unary_shuffle_mask : PatLeaf<(build_vector), [{
261 return X86::isPSHUFDMask(N);
262}], SHUFFLE_get_shuf_imm>;
263
264def SHUFP_shuffle_mask : PatLeaf<(build_vector), [{
265 return X86::isSHUFPMask(N);
266}], SHUFFLE_get_shuf_imm>;
267
268def PSHUFD_binary_shuffle_mask : PatLeaf<(build_vector), [{
269 return X86::isSHUFPMask(N);
270}], SHUFFLE_get_shuf_imm>;
271
272//===----------------------------------------------------------------------===//
273// SSE scalar FP Instructions
274//===----------------------------------------------------------------------===//
275
276// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
277// scheduler into a branch sequence.
Evan Cheng950aac02007-09-25 01:57:46 +0000278// These are expanded by the scheduler.
279let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000281 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 "#CMOV_FR32 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000283 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
284 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000286 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 "#CMOV_FR64 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000288 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
289 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000291 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "#CMOV_V4F32 PSEUDO!",
293 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000294 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
295 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000297 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298 "#CMOV_V2F64 PSEUDO!",
299 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000300 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
301 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000303 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 "#CMOV_V2I64 PSEUDO!",
305 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000306 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng950aac02007-09-25 01:57:46 +0000307 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308}
309
310//===----------------------------------------------------------------------===//
311// SSE1 Instructions
312//===----------------------------------------------------------------------===//
313
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000315let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000316def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000317 "movss\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000318let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000319def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000320 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000322def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000323 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324 [(store FR32:$src, addr:$dst)]>;
325
326// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000327def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000328 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000330def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000331 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000333def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000334 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000336def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000337 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
339
340// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000341def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000342 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000344def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000345 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 [(set GR32:$dst, (int_x86_sse_cvtss2si
347 (load addr:$src)))]>;
348
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000349// Match intrinisics which expect MM and XMM operand(s).
350def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
351 "cvtps2pi\t{$src, $dst|$dst, $src}",
352 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
353def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
354 "cvtps2pi\t{$src, $dst|$dst, $src}",
355 [(set VR64:$dst, (int_x86_sse_cvtps2pi
356 (load addr:$src)))]>;
357def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
358 "cvttps2pi\t{$src, $dst|$dst, $src}",
359 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
360def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
361 "cvttps2pi\t{$src, $dst|$dst, $src}",
362 [(set VR64:$dst, (int_x86_sse_cvttps2pi
363 (load addr:$src)))]>;
364let isTwoAddress = 1 in {
365 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
366 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
367 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
368 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
369 VR64:$src2))]>;
370 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
371 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
372 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
373 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
374 (load addr:$src2)))]>;
375}
376
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000378def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000379 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 [(set GR32:$dst,
381 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000382def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000383 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384 [(set GR32:$dst,
385 (int_x86_sse_cvttss2si(load addr:$src)))]>;
386
387let isTwoAddress = 1 in {
388 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000389 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000390 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
392 GR32:$src2))]>;
393 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000394 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000395 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
397 (loadi32 addr:$src2)))]>;
398}
399
400// Comparison instructions
401let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000402let neverHasSideEffects = 1 in
Chris Lattnera9f545f2007-12-16 20:12:41 +0000403 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000404 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000405 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000406let neverHasSideEffects = 1, mayLoad = 1 in
Chris Lattnera9f545f2007-12-16 20:12:41 +0000407 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000408 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410}
411
Evan Cheng55687072007-09-14 21:48:26 +0000412let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000413def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000414 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000415 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000416def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000417 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000418 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000419 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000420} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421
422// Aliases to match intrinsics which expect XMM operand(s).
423let isTwoAddress = 1 in {
Chris Lattnera9f545f2007-12-16 20:12:41 +0000424 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000425 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000426 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
428 VR128:$src, imm:$cc))]>;
Chris Lattnera9f545f2007-12-16 20:12:41 +0000429 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000430 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000431 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
433 (load addr:$src), imm:$cc))]>;
434}
435
Evan Cheng55687072007-09-14 21:48:26 +0000436let Defs = [EFLAGS] in {
Evan Cheng621216e2007-09-29 00:00:36 +0000437def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000438 (ins VR128:$src1, VR128:$src2),
439 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000440 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000441 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000442def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000443 (ins VR128:$src1, f128mem:$src2),
444 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000445 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000446 (implicit EFLAGS)]>;
447
Evan Cheng621216e2007-09-29 00:00:36 +0000448def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000449 (ins VR128:$src1, VR128:$src2),
450 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000451 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000452 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000453def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000454 (ins VR128:$src1, f128mem:$src2),
455 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000456 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000457 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000458} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459
460// Aliases of packed SSE1 instructions for scalar use. These all have names that
461// start with 'Fs'.
462
463// Alias instructions that map fld0 to pxor for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000464let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000465def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000466 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467 Requires<[HasSSE1]>, TB, OpSize;
468
469// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
470// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000471let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000472def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000473 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
475// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
476// disregarded.
Chris Lattner1a1932c2008-01-06 23:38:27 +0000477let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000478def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000479 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000480 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481
482// Alias bitwise logical operations using SSE logical ops on packed FP values.
483let isTwoAddress = 1 in {
484let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000485 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000488 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000489 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000491 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000492 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
494}
495
Evan Chengb783fa32007-07-19 01:14:50 +0000496def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000497 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000499 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000500def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000503 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000504def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000507 (memopfsf32 addr:$src2)))]>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000508let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000510 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000511 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000512
513let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000515 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000516 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000518}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
520/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
521///
522/// In addition, we also have a special variant of the scalar form here to
523/// represent the associated intrinsic operation. This form is unlike the
524/// plain scalar form, in that it takes an entire vector (instead of a scalar)
525/// and leaves the top elements undefined.
526///
527/// These three forms can each be reg+reg or reg+mem, so there are a total of
528/// six "instructions".
529///
530let isTwoAddress = 1 in {
531multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
532 SDNode OpNode, Intrinsic F32Int,
533 bit Commutable = 0> {
534 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000535 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000536 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
538 let isCommutable = Commutable;
539 }
540
541 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000542 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000543 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
545
546 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000547 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000548 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
550 let isCommutable = Commutable;
551 }
552
553 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000554 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000555 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000556 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557
558 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000559 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000560 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
562 let isCommutable = Commutable;
563 }
564
565 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000566 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000567 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 [(set VR128:$dst, (F32Int VR128:$src1,
569 sse_load_f32:$src2))]>;
570}
571}
572
573// Arithmetic instructions
574defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
575defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
576defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
577defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
578
579/// sse1_fp_binop_rm - Other SSE1 binops
580///
581/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
582/// instructions for a full-vector intrinsic form. Operations that map
583/// onto C operators don't use this form since they just use the plain
584/// vector form instead of having a separate vector intrinsic form.
585///
586/// This provides a total of eight "instructions".
587///
588let isTwoAddress = 1 in {
589multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
590 SDNode OpNode,
591 Intrinsic F32Int,
592 Intrinsic V4F32Int,
593 bit Commutable = 0> {
594
595 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000596 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000597 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
599 let isCommutable = Commutable;
600 }
601
602 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000603 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000604 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
606
607 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000608 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000609 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
611 let isCommutable = Commutable;
612 }
613
614 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000615 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000616 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000617 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618
619 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000620 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000621 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
623 let isCommutable = Commutable;
624 }
625
626 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000627 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000628 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 [(set VR128:$dst, (F32Int VR128:$src1,
630 sse_load_f32:$src2))]>;
631
632 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000633 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000634 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
636 let isCommutable = Commutable;
637 }
638
639 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +0000640 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000641 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642 [(set VR128:$dst, (V4F32Int VR128:$src1, (load addr:$src2)))]>;
643}
644}
645
646defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
647 int_x86_sse_max_ss, int_x86_sse_max_ps>;
648defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
649 int_x86_sse_min_ss, int_x86_sse_min_ps>;
650
651//===----------------------------------------------------------------------===//
652// SSE packed FP Instructions
653
654// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000655let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000656def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000657 "movaps\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000658let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000659def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000660 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000661 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662
Evan Chengb783fa32007-07-19 01:14:50 +0000663def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000664 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000665 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000667let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000668def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000669 "movups\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000670let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000671def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000672 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000673 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000674def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000675 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000676 [(store (v4f32 VR128:$src), addr:$dst)]>;
677
678// Intrinsic forms of MOVUPS load and store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000679let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000680def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000681 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000682 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000683def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000685 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686
687let isTwoAddress = 1 in {
688 let AddedComplexity = 20 in {
689 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000690 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "movlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 [(set VR128:$dst,
693 (v4f32 (vector_shuffle VR128:$src1,
694 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
695 MOVLP_shuffle_mask)))]>;
696 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000697 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000698 "movhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699 [(set VR128:$dst,
700 (v4f32 (vector_shuffle VR128:$src1,
701 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
702 MOVHP_shuffle_mask)))]>;
703 } // AddedComplexity
704} // isTwoAddress
705
Evan Chengb783fa32007-07-19 01:14:50 +0000706def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000707 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
709 (iPTR 0))), addr:$dst)]>;
710
711// v2f64 extract element 1 is always custom lowered to unpack high to low
712// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000713def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000714 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715 [(store (f64 (vector_extract
716 (v2f64 (vector_shuffle
717 (bc_v2f64 (v4f32 VR128:$src)), (undef),
718 UNPCKH_shuffle_mask)), (iPTR 0))),
719 addr:$dst)]>;
720
721let isTwoAddress = 1 in {
722let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000723def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000724 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 [(set VR128:$dst,
726 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
727 MOVHP_shuffle_mask)))]>;
728
Evan Chengb783fa32007-07-19 01:14:50 +0000729def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000730 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000731 [(set VR128:$dst,
732 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
733 MOVHLPS_shuffle_mask)))]>;
734} // AddedComplexity
735} // isTwoAddress
736
737
738
739// Arithmetic
740
741/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
742///
743/// In addition, we also have a special variant of the scalar form here to
744/// represent the associated intrinsic operation. This form is unlike the
745/// plain scalar form, in that it takes an entire vector (instead of a
746/// scalar) and leaves the top elements undefined.
747///
748/// And, we have a special variant form for a full-vector intrinsic form.
749///
750/// These four forms can each have a reg or a mem operand, so there are a
751/// total of eight "instructions".
752///
753multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
754 SDNode OpNode,
755 Intrinsic F32Int,
756 Intrinsic V4F32Int,
757 bit Commutable = 0> {
758 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000759 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000760 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 [(set FR32:$dst, (OpNode FR32:$src))]> {
762 let isCommutable = Commutable;
763 }
764
765 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000766 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
769
770 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000771 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000772 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
774 let isCommutable = Commutable;
775 }
776
777 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000778 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000779 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000780 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781
782 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000783 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(set VR128:$dst, (F32Int VR128:$src))]> {
786 let isCommutable = Commutable;
787 }
788
789 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000790 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000791 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000792 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
793
794 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000795 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000796 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
798 let isCommutable = Commutable;
799 }
800
801 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000802 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000803 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000804 [(set VR128:$dst, (V4F32Int (load addr:$src)))]>;
805}
806
807// Square root.
808defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
809 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
810
811// Reciprocal approximations. Note that these typically require refinement
812// in order to obtain suitable precision.
813defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
814 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
815defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
816 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
817
818// Logical
819let isTwoAddress = 1 in {
820 let isCommutable = 1 in {
821 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000822 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000823 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 [(set VR128:$dst, (v2i64
825 (and VR128:$src1, VR128:$src2)))]>;
826 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000827 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000828 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000829 [(set VR128:$dst, (v2i64
830 (or VR128:$src1, VR128:$src2)))]>;
831 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000832 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000833 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834 [(set VR128:$dst, (v2i64
835 (xor VR128:$src1, VR128:$src2)))]>;
836 }
837
838 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000839 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000840 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000841 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
842 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000843 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000844 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000845 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000846 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
847 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000849 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000850 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000851 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
852 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853 def ANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000854 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000855 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856 [(set VR128:$dst,
857 (v2i64 (and (xor VR128:$src1,
858 (bc_v2i64 (v4i32 immAllOnesV))),
859 VR128:$src2)))]>;
860 def ANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000861 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000862 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000863 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000864 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000866 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867}
868
869let isTwoAddress = 1 in {
870 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000871 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000872 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
874 VR128:$src, imm:$cc))]>;
875 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000876 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000877 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
879 (load addr:$src), imm:$cc))]>;
880}
881
882// Shuffle and unpack instructions
883let isTwoAddress = 1 in {
884 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
885 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000886 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000887 VR128:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000888 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889 [(set VR128:$dst,
890 (v4f32 (vector_shuffle
891 VR128:$src1, VR128:$src2,
892 SHUFP_shuffle_mask:$src3)))]>;
893 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000894 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895 f128mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000896 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897 [(set VR128:$dst,
898 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000899 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000900 SHUFP_shuffle_mask:$src3)))]>;
901
902 let AddedComplexity = 10 in {
903 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000904 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000905 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906 [(set VR128:$dst,
907 (v4f32 (vector_shuffle
908 VR128:$src1, VR128:$src2,
909 UNPCKH_shuffle_mask)))]>;
910 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000911 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000912 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913 [(set VR128:$dst,
914 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000915 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000916 UNPCKH_shuffle_mask)))]>;
917
918 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000919 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000920 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921 [(set VR128:$dst,
922 (v4f32 (vector_shuffle
923 VR128:$src1, VR128:$src2,
924 UNPCKL_shuffle_mask)))]>;
925 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000926 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000927 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000928 [(set VR128:$dst,
929 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000930 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000931 UNPCKL_shuffle_mask)))]>;
932 } // AddedComplexity
933} // isTwoAddress
934
935// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000936def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000939def MOVMSKPDrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
942
943// Prefetching loads.
944// TODO: no intrinsics for these?
Dan Gohman91888f02007-07-31 20:11:57 +0000945def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src), "prefetcht0\t$src", []>;
946def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src), "prefetcht1\t$src", []>;
947def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src), "prefetcht2\t$src", []>;
948def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src), "prefetchnta\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949
950// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000951def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000952 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
954
955// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +0000956def SFENCE : PSI<0xAE, MRM7m, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957
958// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000959def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000960 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000961def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000962 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963
964// Alias instructions that map zero vector to pxor / xorp* for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000965let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000966def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000967 "xorps\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000968 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000969
970// FR32 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +0000971def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000972 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973 [(set VR128:$dst,
974 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000975def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000976 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977 [(set VR128:$dst,
978 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
979
980// FIXME: may not be able to eliminate this movss with coalescing the src and
981// dest register classes are different. We really want to write this pattern
982// like this:
983// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
984// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +0000985def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000986 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000987 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
988 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000989def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000990 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991 [(store (f32 (vector_extract (v4f32 VR128:$src),
992 (iPTR 0))), addr:$dst)]>;
993
994
995// Move to lower bits of a VR128, leaving upper bits alone.
996// Three operand (but two address) aliases.
997let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000998let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000999 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001000 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001001 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001002
1003 let AddedComplexity = 15 in
1004 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001005 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001006 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007 [(set VR128:$dst,
1008 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
1009 MOVL_shuffle_mask)))]>;
1010}
1011
1012// Move to lower bits of a VR128 and zeroing upper bits.
1013// Loading from memory automatically zeroing upper bits.
1014let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00001015def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001016 "movss\t{$src, $dst|$dst, $src}",
Chris Lattnere6aa3862007-11-25 00:24:49 +00001017 [(set VR128:$dst, (v4f32 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018 (v4f32 (scalar_to_vector (loadf32 addr:$src))),
1019 MOVL_shuffle_mask)))]>;
1020
1021
1022//===----------------------------------------------------------------------===//
1023// SSE2 Instructions
1024//===----------------------------------------------------------------------===//
1025
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001027let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001028def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001029 "movsd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001030let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001031def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001032 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001034def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001035 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001036 [(store FR64:$src, addr:$dst)]>;
1037
1038// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001039def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001042def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001043 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001045def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001046 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001048def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001049 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001051def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001052 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001054def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001055 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1057
1058// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001059def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001060 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1062 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001063def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001064 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1066 Requires<[HasSSE2]>;
1067
1068// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +00001069def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001070 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001072def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001073 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1075 (load addr:$src)))]>;
1076
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001077// Match intrinisics which expect MM and XMM operand(s).
1078def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1079 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1080 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1081def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1082 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1083 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
1084 (load addr:$src)))]>;
1085def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1086 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1087 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1088def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1089 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1090 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
1091 (load addr:$src)))]>;
1092def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1093 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1094 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1095def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1096 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1097 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1098 (load addr:$src)))]>;
1099
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +00001101def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001102 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001103 [(set GR32:$dst,
1104 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001105def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001106 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001107 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1108 (load addr:$src)))]>;
1109
1110// Comparison instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001111let isTwoAddress = 1, neverHasSideEffects = 1 in {
Evan Cheng653c7ac2007-12-20 19:57:09 +00001112 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001113 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001114 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001115let mayLoad = 1 in
Evan Cheng653c7ac2007-12-20 19:57:09 +00001116 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001117 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001118 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119}
1120
Evan Cheng950aac02007-09-25 01:57:46 +00001121let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001122def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001123 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001124 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001125def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001127 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001128 (implicit EFLAGS)]>;
1129}
1130
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131// Aliases to match intrinsics which expect XMM operand(s).
1132let isTwoAddress = 1 in {
Evan Cheng653c7ac2007-12-20 19:57:09 +00001133 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001134 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1137 VR128:$src, imm:$cc))]>;
Evan Cheng653c7ac2007-12-20 19:57:09 +00001138 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001139 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001140 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1142 (load addr:$src), imm:$cc))]>;
1143}
1144
Evan Cheng950aac02007-09-25 01:57:46 +00001145let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001146def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001147 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001148 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1149 (implicit EFLAGS)]>;
1150def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001151 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001152 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1153 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154
Evan Chengb783fa32007-07-19 01:14:50 +00001155def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001156 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001157 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1158 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001159def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001160 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001161 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001162 (implicit EFLAGS)]>;
1163} // Defs = EFLAGS]
1164
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001165// Aliases of packed SSE2 instructions for scalar use. These all have names that
1166// start with 'Fs'.
1167
1168// Alias instructions that map fld0 to pxor for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001169let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001170def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001171 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001172 Requires<[HasSSE2]>, TB, OpSize;
1173
1174// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1175// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001176let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001177def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001178 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001179
1180// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1181// disregarded.
Chris Lattner1a1932c2008-01-06 23:38:27 +00001182let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001183def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001184 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001185 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001186
1187// Alias bitwise logical operations using SSE logical ops on packed FP values.
1188let isTwoAddress = 1 in {
1189let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +00001190 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001191 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001193 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001194 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001196 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001197 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001198 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1199}
1200
Evan Chengb783fa32007-07-19 01:14:50 +00001201def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001202 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001203 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001204 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001205def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001206 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001207 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001208 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001209def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001210 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001211 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001212 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001213
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001214let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001215def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001216 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001217 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001218let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001219def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001220 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001221 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001223}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001224
1225/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1226///
1227/// In addition, we also have a special variant of the scalar form here to
1228/// represent the associated intrinsic operation. This form is unlike the
1229/// plain scalar form, in that it takes an entire vector (instead of a scalar)
1230/// and leaves the top elements undefined.
1231///
1232/// These three forms can each be reg+reg or reg+mem, so there are a total of
1233/// six "instructions".
1234///
1235let isTwoAddress = 1 in {
1236multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1237 SDNode OpNode, Intrinsic F64Int,
1238 bit Commutable = 0> {
1239 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001240 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001241 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001242 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1243 let isCommutable = Commutable;
1244 }
1245
1246 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001247 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001248 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001249 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1250
1251 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001252 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001253 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001254 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1255 let isCommutable = Commutable;
1256 }
1257
1258 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001259 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001260 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001261 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001262
1263 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001264 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001265 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1267 let isCommutable = Commutable;
1268 }
1269
1270 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001271 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001272 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001273 [(set VR128:$dst, (F64Int VR128:$src1,
1274 sse_load_f64:$src2))]>;
1275}
1276}
1277
1278// Arithmetic instructions
1279defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1280defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1281defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1282defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1283
1284/// sse2_fp_binop_rm - Other SSE2 binops
1285///
1286/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1287/// instructions for a full-vector intrinsic form. Operations that map
1288/// onto C operators don't use this form since they just use the plain
1289/// vector form instead of having a separate vector intrinsic form.
1290///
1291/// This provides a total of eight "instructions".
1292///
1293let isTwoAddress = 1 in {
1294multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1295 SDNode OpNode,
1296 Intrinsic F64Int,
1297 Intrinsic V2F64Int,
1298 bit Commutable = 0> {
1299
1300 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001301 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001302 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001303 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1304 let isCommutable = Commutable;
1305 }
1306
1307 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001308 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001309 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1311
1312 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001313 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001314 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001315 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1316 let isCommutable = Commutable;
1317 }
1318
1319 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001320 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001321 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001322 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001323
1324 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001325 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001326 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001327 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1328 let isCommutable = Commutable;
1329 }
1330
1331 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001332 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001333 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001334 [(set VR128:$dst, (F64Int VR128:$src1,
1335 sse_load_f64:$src2))]>;
1336
1337 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001338 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001339 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001340 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1341 let isCommutable = Commutable;
1342 }
1343
1344 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +00001345 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001346 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001347 [(set VR128:$dst, (V2F64Int VR128:$src1, (load addr:$src2)))]>;
1348}
1349}
1350
1351defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1352 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1353defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1354 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1355
1356//===----------------------------------------------------------------------===//
1357// SSE packed FP Instructions
1358
1359// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001360let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001361def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001362 "movapd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001363let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001364def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001365 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001366 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001367
Evan Chengb783fa32007-07-19 01:14:50 +00001368def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001369 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001370 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001371
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001372let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001373def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001374 "movupd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001375let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001376def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001377 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001378 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001379def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001380 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001381 [(store (v2f64 VR128:$src), addr:$dst)]>;
1382
1383// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001384def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001385 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001386 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001387def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001388 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001389 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001390
1391let isTwoAddress = 1 in {
1392 let AddedComplexity = 20 in {
1393 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001394 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001395 "movlpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001396 [(set VR128:$dst,
1397 (v2f64 (vector_shuffle VR128:$src1,
1398 (scalar_to_vector (loadf64 addr:$src2)),
1399 MOVLP_shuffle_mask)))]>;
1400 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001401 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001402 "movhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001403 [(set VR128:$dst,
1404 (v2f64 (vector_shuffle VR128:$src1,
1405 (scalar_to_vector (loadf64 addr:$src2)),
1406 MOVHP_shuffle_mask)))]>;
1407 } // AddedComplexity
1408} // isTwoAddress
1409
Evan Chengb783fa32007-07-19 01:14:50 +00001410def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001411 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001412 [(store (f64 (vector_extract (v2f64 VR128:$src),
1413 (iPTR 0))), addr:$dst)]>;
1414
1415// v2f64 extract element 1 is always custom lowered to unpack high to low
1416// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001417def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001418 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001419 [(store (f64 (vector_extract
1420 (v2f64 (vector_shuffle VR128:$src, (undef),
1421 UNPCKH_shuffle_mask)), (iPTR 0))),
1422 addr:$dst)]>;
1423
1424// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001425def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001426 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001427 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1428 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001429def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001430 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001431 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
Dan Gohman4a4f1512007-07-18 20:23:34 +00001432 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001433 TB, Requires<[HasSSE2]>;
1434
1435// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001436def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001437 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001438 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1439 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001440def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001441 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
Dan Gohman4a4f1512007-07-18 20:23:34 +00001443 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001444 XS, Requires<[HasSSE2]>;
1445
Evan Chengb783fa32007-07-19 01:14:50 +00001446def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001447 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001448 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001449def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001450 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001451 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1452 (load addr:$src)))]>;
1453// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001454def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001455 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001456 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1457 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001458def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001459 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001460 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1461 (load addr:$src)))]>,
1462 XS, Requires<[HasSSE2]>;
1463
1464// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001465def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001466 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001467 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1468 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001469def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001470 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001471 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1472 (load addr:$src)))]>,
1473 XD, Requires<[HasSSE2]>;
1474
Evan Chengb783fa32007-07-19 01:14:50 +00001475def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001476 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001477 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001478def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001479 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001480 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1481 (load addr:$src)))]>;
1482
1483// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001484def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001485 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001486 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1487 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001488def Int_CVTPS2PDrm : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001489 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1491 (load addr:$src)))]>,
1492 TB, Requires<[HasSSE2]>;
1493
Evan Chengb783fa32007-07-19 01:14:50 +00001494def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001495 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001496 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001497def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001498 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001499 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1500 (load addr:$src)))]>;
1501
1502// Match intrinsics which expect XMM operand(s).
1503// Aliases for intrinsics
1504let isTwoAddress = 1 in {
1505def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001506 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001507 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001508 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1509 GR32:$src2))]>;
1510def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001511 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001512 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001513 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1514 (loadi32 addr:$src2)))]>;
1515def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001516 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001517 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001518 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1519 VR128:$src2))]>;
1520def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001521 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001522 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001523 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1524 (load addr:$src2)))]>;
1525def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001526 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001527 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001528 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1529 VR128:$src2))]>, XS,
1530 Requires<[HasSSE2]>;
1531def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001532 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001533 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001534 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1535 (load addr:$src2)))]>, XS,
1536 Requires<[HasSSE2]>;
1537}
1538
1539// Arithmetic
1540
1541/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1542///
1543/// In addition, we also have a special variant of the scalar form here to
1544/// represent the associated intrinsic operation. This form is unlike the
1545/// plain scalar form, in that it takes an entire vector (instead of a
1546/// scalar) and leaves the top elements undefined.
1547///
1548/// And, we have a special variant form for a full-vector intrinsic form.
1549///
1550/// These four forms can each have a reg or a mem operand, so there are a
1551/// total of eight "instructions".
1552///
1553multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1554 SDNode OpNode,
1555 Intrinsic F64Int,
1556 Intrinsic V2F64Int,
1557 bit Commutable = 0> {
1558 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001559 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001560 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001561 [(set FR64:$dst, (OpNode FR64:$src))]> {
1562 let isCommutable = Commutable;
1563 }
1564
1565 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001566 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001567 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001568 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1569
1570 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001571 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001572 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001573 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1574 let isCommutable = Commutable;
1575 }
1576
1577 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001578 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001579 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001580 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001581
1582 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001583 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001584 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001585 [(set VR128:$dst, (F64Int VR128:$src))]> {
1586 let isCommutable = Commutable;
1587 }
1588
1589 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001590 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001591 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001592 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1593
1594 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001595 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001596 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001597 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1598 let isCommutable = Commutable;
1599 }
1600
1601 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001602 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001603 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001604 [(set VR128:$dst, (V2F64Int (load addr:$src)))]>;
1605}
1606
1607// Square root.
1608defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1609 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1610
1611// There is no f64 version of the reciprocal approximation instructions.
1612
1613// Logical
1614let isTwoAddress = 1 in {
1615 let isCommutable = 1 in {
1616 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001617 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001618 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001619 [(set VR128:$dst,
1620 (and (bc_v2i64 (v2f64 VR128:$src1)),
1621 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1622 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001623 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001624 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001625 [(set VR128:$dst,
1626 (or (bc_v2i64 (v2f64 VR128:$src1)),
1627 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1628 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001629 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001630 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001631 [(set VR128:$dst,
1632 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1633 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1634 }
1635
1636 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001637 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001638 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001639 [(set VR128:$dst,
1640 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001641 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001642 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001643 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001644 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001645 [(set VR128:$dst,
1646 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001647 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001648 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001649 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001650 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001651 [(set VR128:$dst,
1652 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001653 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001654 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001655 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001656 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001657 [(set VR128:$dst,
1658 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1659 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1660 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001661 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001662 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001663 [(set VR128:$dst,
1664 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001665 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001666}
1667
1668let isTwoAddress = 1 in {
1669 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001670 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001671 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001672 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1673 VR128:$src, imm:$cc))]>;
1674 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001675 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001676 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001677 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1678 (load addr:$src), imm:$cc))]>;
1679}
1680
1681// Shuffle and unpack instructions
1682let isTwoAddress = 1 in {
1683 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001684 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001685 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686 [(set VR128:$dst, (v2f64 (vector_shuffle
1687 VR128:$src1, VR128:$src2,
1688 SHUFP_shuffle_mask:$src3)))]>;
1689 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001690 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001691 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001692 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001693 [(set VR128:$dst,
1694 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001695 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001696 SHUFP_shuffle_mask:$src3)))]>;
1697
1698 let AddedComplexity = 10 in {
1699 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001700 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001701 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001702 [(set VR128:$dst,
1703 (v2f64 (vector_shuffle
1704 VR128:$src1, VR128:$src2,
1705 UNPCKH_shuffle_mask)))]>;
1706 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001707 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001708 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001709 [(set VR128:$dst,
1710 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001711 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001712 UNPCKH_shuffle_mask)))]>;
1713
1714 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001715 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001716 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001717 [(set VR128:$dst,
1718 (v2f64 (vector_shuffle
1719 VR128:$src1, VR128:$src2,
1720 UNPCKL_shuffle_mask)))]>;
1721 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001722 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001723 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001724 [(set VR128:$dst,
1725 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001726 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001727 UNPCKL_shuffle_mask)))]>;
1728 } // AddedComplexity
1729} // isTwoAddress
1730
1731
1732//===----------------------------------------------------------------------===//
1733// SSE integer instructions
1734
1735// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001736let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001737def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001738 "movdqa\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001739let isSimpleLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001740def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001741 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001742 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001743let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001744def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001745 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001746 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001747let isSimpleLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001748def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001749 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001750 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001751 XS, Requires<[HasSSE2]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001752let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001753def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001754 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001755 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001756 XS, Requires<[HasSSE2]>;
1757
Dan Gohman4a4f1512007-07-18 20:23:34 +00001758// Intrinsic forms of MOVDQU load and store
Chris Lattner1a1932c2008-01-06 23:38:27 +00001759let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001760def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001761 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001762 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1763 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001764def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001765 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001766 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1767 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001768
1769let isTwoAddress = 1 in {
1770
1771multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1772 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001773 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001774 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001775 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1776 let isCommutable = Commutable;
1777 }
Evan Chengb783fa32007-07-19 01:14:50 +00001778 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001779 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001780 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001781 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001782}
1783
1784multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1785 string OpcodeStr, Intrinsic IntId> {
Evan Chengb783fa32007-07-19 01:14:50 +00001786 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001787 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001788 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001789 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001790 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001791 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001792 (bitconvert (memopv2i64 addr:$src2))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001793 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001794 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001795 [(set VR128:$dst, (IntId VR128:$src1,
1796 (scalar_to_vector (i32 imm:$src2))))]>;
1797}
1798
1799
1800/// PDI_binop_rm - Simple SSE2 binary operator.
1801multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1802 ValueType OpVT, bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001803 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001804 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001805 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1806 let isCommutable = Commutable;
1807 }
Evan Chengb783fa32007-07-19 01:14:50 +00001808 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001809 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001810 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001811 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001812}
1813
1814/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1815///
1816/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1817/// to collapse (bitconvert VT to VT) into its operand.
1818///
1819multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1820 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001821 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001822 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001823 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1824 let isCommutable = Commutable;
1825 }
Evan Chengb783fa32007-07-19 01:14:50 +00001826 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001827 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001828 [(set VR128:$dst, (OpNode VR128:$src1,(memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001829}
1830
1831} // isTwoAddress
1832
1833// 128-bit Integer Arithmetic
1834
1835defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1836defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1837defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1838defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1839
1840defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1841defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1842defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1843defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1844
1845defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1846defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1847defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1848defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1849
1850defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1851defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1852defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1853defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1854
1855defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1856
1857defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1858defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1859defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1860
1861defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1862
1863defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1864defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1865
1866
1867defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1868defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1869defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1870defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1871defm PSADBW : PDI_binop_rm_int<0xE0, "psadbw", int_x86_sse2_psad_bw, 1>;
1872
1873
1874defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw", int_x86_sse2_psll_w>;
1875defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld", int_x86_sse2_psll_d>;
1876defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq", int_x86_sse2_psll_q>;
1877
1878defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw", int_x86_sse2_psrl_w>;
1879defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld", int_x86_sse2_psrl_d>;
1880defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq", int_x86_sse2_psrl_q>;
1881
1882defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw", int_x86_sse2_psra_w>;
1883defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad", int_x86_sse2_psra_d>;
1884// PSRAQ doesn't exist in SSE[1-3].
1885
1886// 128-bit logical shifts.
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001887let isTwoAddress = 1, neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001888 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001889 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001890 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001891 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001892 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001893 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001894 // PSRADQri doesn't exist in SSE[1-3].
1895}
1896
1897let Predicates = [HasSSE2] in {
1898 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1899 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1900 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1901 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1902 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1903 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1904}
1905
1906// Logical
1907defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1908defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1909defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1910
1911let isTwoAddress = 1 in {
1912 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001913 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001914 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001915 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1916 VR128:$src2)))]>;
1917
1918 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001919 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001920 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7dc19012007-08-02 21:17:01 +00001922 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001923}
1924
1925// SSE2 Integer comparison
1926defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
1927defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
1928defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
1929defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
1930defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
1931defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
1932
1933// Pack instructions
1934defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
1935defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
1936defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
1937
1938// Shuffle and unpack instructions
1939def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001940 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001941 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001942 [(set VR128:$dst, (v4i32 (vector_shuffle
1943 VR128:$src1, (undef),
1944 PSHUFD_shuffle_mask:$src2)))]>;
1945def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001946 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001947 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001948 [(set VR128:$dst, (v4i32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001949 (bc_v4i32(memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001950 (undef),
1951 PSHUFD_shuffle_mask:$src2)))]>;
1952
1953// SSE2 with ImmT == Imm8 and XS prefix.
1954def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001955 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001956 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001957 [(set VR128:$dst, (v8i16 (vector_shuffle
1958 VR128:$src1, (undef),
1959 PSHUFHW_shuffle_mask:$src2)))]>,
1960 XS, Requires<[HasSSE2]>;
1961def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001962 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001963 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001964 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001965 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001966 (undef),
1967 PSHUFHW_shuffle_mask:$src2)))]>,
1968 XS, Requires<[HasSSE2]>;
1969
1970// SSE2 with ImmT == Imm8 and XD prefix.
1971def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001972 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001973 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001974 [(set VR128:$dst, (v8i16 (vector_shuffle
1975 VR128:$src1, (undef),
1976 PSHUFLW_shuffle_mask:$src2)))]>,
1977 XD, Requires<[HasSSE2]>;
1978def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001979 (outs VR128:$dst), (ins i128mem:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001980 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001981 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001982 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001983 (undef),
1984 PSHUFLW_shuffle_mask:$src2)))]>,
1985 XD, Requires<[HasSSE2]>;
1986
1987
1988let isTwoAddress = 1 in {
1989 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001990 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001991 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001992 [(set VR128:$dst,
1993 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1994 UNPCKL_shuffle_mask)))]>;
1995 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001996 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001997 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001998 [(set VR128:$dst,
1999 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002000 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002001 UNPCKL_shuffle_mask)))]>;
2002 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002003 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002004 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002005 [(set VR128:$dst,
2006 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
2007 UNPCKL_shuffle_mask)))]>;
2008 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002009 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002010 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002011 [(set VR128:$dst,
2012 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002013 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002014 UNPCKL_shuffle_mask)))]>;
2015 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002016 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002017 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002018 [(set VR128:$dst,
2019 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2020 UNPCKL_shuffle_mask)))]>;
2021 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002022 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002023 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002024 [(set VR128:$dst,
2025 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002026 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002027 UNPCKL_shuffle_mask)))]>;
2028 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002029 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002030 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002031 [(set VR128:$dst,
2032 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2033 UNPCKL_shuffle_mask)))]>;
2034 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002035 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002036 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002037 [(set VR128:$dst,
2038 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002039 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002040 UNPCKL_shuffle_mask)))]>;
2041
2042 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002043 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002044 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002045 [(set VR128:$dst,
2046 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
2047 UNPCKH_shuffle_mask)))]>;
2048 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002049 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002050 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002051 [(set VR128:$dst,
2052 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002053 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002054 UNPCKH_shuffle_mask)))]>;
2055 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002056 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002057 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002058 [(set VR128:$dst,
2059 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
2060 UNPCKH_shuffle_mask)))]>;
2061 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002062 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002063 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002064 [(set VR128:$dst,
2065 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002066 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002067 UNPCKH_shuffle_mask)))]>;
2068 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002069 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002070 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002071 [(set VR128:$dst,
2072 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2073 UNPCKH_shuffle_mask)))]>;
2074 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002075 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002076 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002077 [(set VR128:$dst,
2078 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002079 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002080 UNPCKH_shuffle_mask)))]>;
2081 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002082 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002083 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002084 [(set VR128:$dst,
2085 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2086 UNPCKH_shuffle_mask)))]>;
2087 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002088 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002089 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002090 [(set VR128:$dst,
2091 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002092 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002093 UNPCKH_shuffle_mask)))]>;
2094}
2095
2096// Extract / Insert
2097def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002098 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002099 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002100 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begemand77e59e2008-02-11 04:19:36 +00002101 imm:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002102let isTwoAddress = 1 in {
2103 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002104 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002105 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002106 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002107 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002108 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002109 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002110 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002111 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002112 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begemand77e59e2008-02-11 04:19:36 +00002113 [(set VR128:$dst,
2114 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2115 imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002116}
2117
2118// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00002119def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002120 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002121 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2122
2123// Conditional store
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002124let Uses = [EDI] in
Evan Chengb783fa32007-07-19 01:14:50 +00002125def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00002126 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002127 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002128
2129// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00002130def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002131 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002132 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002133def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002134 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002135 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002136def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002137 "movnti\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002138 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2139 TB, Requires<[HasSSE2]>;
2140
2141// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002142def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002143 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002144 TB, Requires<[HasSSE2]>;
2145
2146// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +00002147def LFENCE : I<0xAE, MRM5m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002148 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002149def MFENCE : I<0xAE, MRM6m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002150 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2151
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002152// Alias instructions that map zero vector to pxor / xorp* for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +00002153let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002154 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002155 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +00002156 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002157
2158// FR64 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +00002159def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002160 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002161 [(set VR128:$dst,
2162 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002163def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002164 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002165 [(set VR128:$dst,
2166 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2167
Evan Chengb783fa32007-07-19 01:14:50 +00002168def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002169 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002170 [(set VR128:$dst,
2171 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002172def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002173 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002174 [(set VR128:$dst,
2175 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2176
Evan Chengb783fa32007-07-19 01:14:50 +00002177def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002178 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002179 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2180
Evan Chengb783fa32007-07-19 01:14:50 +00002181def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002182 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002183 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2184
2185// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002186def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002187 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002188 [(set VR128:$dst,
2189 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2190 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002191def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002192 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002193 [(store (i64 (vector_extract (v2i64 VR128:$src),
2194 (iPTR 0))), addr:$dst)]>;
2195
2196// FIXME: may not be able to eliminate this movss with coalescing the src and
2197// dest register classes are different. We really want to write this pattern
2198// like this:
2199// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2200// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +00002201def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002202 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002203 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2204 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002205def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002206 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002207 [(store (f64 (vector_extract (v2f64 VR128:$src),
2208 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002209def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002210 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002211 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2212 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002213def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002214 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002215 [(store (i32 (vector_extract (v4i32 VR128:$src),
2216 (iPTR 0))), addr:$dst)]>;
2217
Evan Chengb783fa32007-07-19 01:14:50 +00002218def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002219 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002220 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002221def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002222 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002223 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2224
2225
2226// Move to lower bits of a VR128, leaving upper bits alone.
2227// Three operand (but two address) aliases.
2228let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00002229 let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002230 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002231 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002232 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002233
2234 let AddedComplexity = 15 in
2235 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002236 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002237 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002238 [(set VR128:$dst,
2239 (v2f64 (vector_shuffle VR128:$src1, VR128:$src2,
2240 MOVL_shuffle_mask)))]>;
2241}
2242
2243// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002244def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002245 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002246 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2247
2248// Move to lower bits of a VR128 and zeroing upper bits.
2249// Loading from memory automatically zeroing upper bits.
2250let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002251 def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002252 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002253 [(set VR128:$dst,
Chris Lattnere6aa3862007-11-25 00:24:49 +00002254 (v2f64 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002255 (v2f64 (scalar_to_vector
2256 (loadf64 addr:$src))),
2257 MOVL_shuffle_mask)))]>;
2258
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002259// movd / movq to XMM register zero-extends
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002260let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002261def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002262 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002263 [(set VR128:$dst,
2264 (v4i32 (vector_shuffle immAllZerosV,
2265 (v4i32 (scalar_to_vector GR32:$src)),
2266 MOVL_shuffle_mask)))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002267// This is X86-64 only.
2268def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2269 "mov{d|q}\t{$src, $dst|$dst, $src}",
2270 [(set VR128:$dst,
2271 (v2i64 (vector_shuffle immAllZerosV_bc,
2272 (v2i64 (scalar_to_vector GR64:$src)),
2273 MOVL_shuffle_mask)))]>;
2274}
2275
2276let AddedComplexity = 20 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002277def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002278 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002279 [(set VR128:$dst,
2280 (v4i32 (vector_shuffle immAllZerosV,
2281 (v4i32 (scalar_to_vector (loadi32 addr:$src))),
2282 MOVL_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002283def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002284 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002285 [(set VR128:$dst,
2286 (v2i64 (vector_shuffle immAllZerosV_bc,
2287 (v2i64 (scalar_to_vector (loadi64 addr:$src))),
2288 MOVL_shuffle_mask)))]>, XS,
2289 Requires<[HasSSE2]>;
2290}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002291
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002292// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2293// IA32 document. movq xmm1, xmm2 does clear the high bits.
2294let AddedComplexity = 15 in
2295def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2296 "movq\t{$src, $dst|$dst, $src}",
2297 [(set VR128:$dst, (v2i64 (vector_shuffle immAllZerosV_bc,
2298 VR128:$src,
2299 MOVL_shuffle_mask)))]>,
2300 XS, Requires<[HasSSE2]>;
2301
2302let AddedComplexity = 20 in
2303def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2304 "movq\t{$src, $dst|$dst, $src}",
2305 [(set VR128:$dst, (v2i64 (vector_shuffle immAllZerosV_bc,
2306 (memopv2i64 addr:$src),
2307 MOVL_shuffle_mask)))]>,
2308 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002309
2310//===----------------------------------------------------------------------===//
2311// SSE3 Instructions
2312//===----------------------------------------------------------------------===//
2313
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002314// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002315def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002316 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002317 [(set VR128:$dst, (v4f32 (vector_shuffle
2318 VR128:$src, (undef),
2319 MOVSHDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002320def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002321 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002322 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002323 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002324 MOVSHDUP_shuffle_mask)))]>;
2325
Evan Chengb783fa32007-07-19 01:14:50 +00002326def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002327 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002328 [(set VR128:$dst, (v4f32 (vector_shuffle
2329 VR128:$src, (undef),
2330 MOVSLDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002331def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002332 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002333 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002334 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002335 MOVSLDUP_shuffle_mask)))]>;
2336
Evan Chengb783fa32007-07-19 01:14:50 +00002337def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002338 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002339 [(set VR128:$dst, (v2f64 (vector_shuffle
2340 VR128:$src, (undef),
2341 SSE_splat_lo_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002342def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002343 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002344 [(set VR128:$dst,
2345 (v2f64 (vector_shuffle
2346 (scalar_to_vector (loadf64 addr:$src)),
2347 (undef),
2348 SSE_splat_lo_mask)))]>;
2349
2350// Arithmetic
2351let isTwoAddress = 1 in {
2352 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002353 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002354 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002355 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2356 VR128:$src2))]>;
2357 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002358 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002359 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002360 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2361 (load addr:$src2)))]>;
2362 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002363 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002364 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002365 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2366 VR128:$src2))]>;
2367 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002368 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002369 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002370 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2371 (load addr:$src2)))]>;
2372}
2373
Evan Chengb783fa32007-07-19 01:14:50 +00002374def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002375 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002376 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2377
2378// Horizontal ops
2379class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002380 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002381 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002382 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2383class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002384 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002385 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002386 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (load addr:$src2))))]>;
2387class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002388 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002389 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002390 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2391class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002392 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002393 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002394 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (load addr:$src2))))]>;
2395
2396let isTwoAddress = 1 in {
2397 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2398 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2399 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2400 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2401 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2402 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2403 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2404 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2405}
2406
2407// Thread synchronization
Evan Chengb783fa32007-07-19 01:14:50 +00002408def MONITOR : I<0xC8, RawFrm, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002409 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002410def MWAIT : I<0xC9, RawFrm, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002411 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2412
2413// vector_shuffle v1, <undef> <1, 1, 3, 3>
2414let AddedComplexity = 15 in
2415def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2416 MOVSHDUP_shuffle_mask)),
2417 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2418let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002419def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002420 MOVSHDUP_shuffle_mask)),
2421 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2422
2423// vector_shuffle v1, <undef> <0, 0, 2, 2>
2424let AddedComplexity = 15 in
2425 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2426 MOVSLDUP_shuffle_mask)),
2427 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2428let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002429 def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002430 MOVSLDUP_shuffle_mask)),
2431 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2432
2433//===----------------------------------------------------------------------===//
2434// SSSE3 Instructions
2435//===----------------------------------------------------------------------===//
2436
Bill Wendling3b15d722007-08-11 09:52:53 +00002437// SSSE3 Instruction Templates:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002438//
Bill Wendling98680292007-08-10 06:22:27 +00002439// SS38I - SSSE3 instructions with T8 prefix.
2440// SS3AI - SSSE3 instructions with TA prefix.
Bill Wendling3b15d722007-08-11 09:52:53 +00002441//
2442// Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
2443// uses the MMX registers. We put those instructions here because they better
2444// fit into the SSSE3 instruction category rather than the MMX category.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002445
Evan Chengb783fa32007-07-19 01:14:50 +00002446class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
2447 list<dag> pattern>
Bill Wendling98680292007-08-10 06:22:27 +00002448 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002449class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
2450 list<dag> pattern>
Bill Wendling98680292007-08-10 06:22:27 +00002451 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002452
Bill Wendling98680292007-08-10 06:22:27 +00002453/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002454multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2455 Intrinsic IntId64, Intrinsic IntId128> {
2456 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2457 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2458 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002459
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002460 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2461 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2462 [(set VR64:$dst,
2463 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2464
2465 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2466 (ins VR128:$src),
2467 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2468 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2469 OpSize;
2470
2471 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2472 (ins i128mem:$src),
2473 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2474 [(set VR128:$dst,
2475 (IntId128
2476 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002477}
2478
Bill Wendling98680292007-08-10 06:22:27 +00002479/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002480multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2481 Intrinsic IntId64, Intrinsic IntId128> {
2482 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2483 (ins VR64:$src),
2484 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2485 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002486
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002487 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2488 (ins i64mem:$src),
2489 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2490 [(set VR64:$dst,
2491 (IntId64
2492 (bitconvert (memopv4i16 addr:$src))))]>;
2493
2494 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2495 (ins VR128:$src),
2496 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2497 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2498 OpSize;
2499
2500 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2501 (ins i128mem:$src),
2502 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2503 [(set VR128:$dst,
2504 (IntId128
2505 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002506}
2507
2508/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002509multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2510 Intrinsic IntId64, Intrinsic IntId128> {
2511 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2512 (ins VR64:$src),
2513 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2514 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002515
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002516 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2517 (ins i64mem:$src),
2518 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2519 [(set VR64:$dst,
2520 (IntId64
2521 (bitconvert (memopv2i32 addr:$src))))]>;
2522
2523 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2524 (ins VR128:$src),
2525 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2526 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2527 OpSize;
2528
2529 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2530 (ins i128mem:$src),
2531 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2532 [(set VR128:$dst,
2533 (IntId128
2534 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002535}
2536
2537defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2538 int_x86_ssse3_pabs_b,
2539 int_x86_ssse3_pabs_b_128>;
2540defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2541 int_x86_ssse3_pabs_w,
2542 int_x86_ssse3_pabs_w_128>;
2543defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2544 int_x86_ssse3_pabs_d,
2545 int_x86_ssse3_pabs_d_128>;
2546
2547/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2548let isTwoAddress = 1 in {
2549 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2550 Intrinsic IntId64, Intrinsic IntId128,
2551 bit Commutable = 0> {
2552 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2553 (ins VR64:$src1, VR64:$src2),
2554 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2555 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2556 let isCommutable = Commutable;
2557 }
2558 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2559 (ins VR64:$src1, i64mem:$src2),
2560 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2561 [(set VR64:$dst,
2562 (IntId64 VR64:$src1,
2563 (bitconvert (memopv8i8 addr:$src2))))]>;
2564
2565 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2566 (ins VR128:$src1, VR128:$src2),
2567 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2568 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2569 OpSize {
2570 let isCommutable = Commutable;
2571 }
2572 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2573 (ins VR128:$src1, i128mem:$src2),
2574 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2575 [(set VR128:$dst,
2576 (IntId128 VR128:$src1,
2577 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2578 }
2579}
2580
2581/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2582let isTwoAddress = 1 in {
2583 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2584 Intrinsic IntId64, Intrinsic IntId128,
2585 bit Commutable = 0> {
2586 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2587 (ins VR64:$src1, VR64:$src2),
2588 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2589 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2590 let isCommutable = Commutable;
2591 }
2592 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2593 (ins VR64:$src1, i64mem:$src2),
2594 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2595 [(set VR64:$dst,
2596 (IntId64 VR64:$src1,
2597 (bitconvert (memopv4i16 addr:$src2))))]>;
2598
2599 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2600 (ins VR128:$src1, VR128:$src2),
2601 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2602 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2603 OpSize {
2604 let isCommutable = Commutable;
2605 }
2606 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2607 (ins VR128:$src1, i128mem:$src2),
2608 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2609 [(set VR128:$dst,
2610 (IntId128 VR128:$src1,
2611 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2612 }
2613}
2614
2615/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2616let isTwoAddress = 1 in {
2617 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2618 Intrinsic IntId64, Intrinsic IntId128,
2619 bit Commutable = 0> {
2620 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2621 (ins VR64:$src1, VR64:$src2),
2622 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2623 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2624 let isCommutable = Commutable;
2625 }
2626 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2627 (ins VR64:$src1, i64mem:$src2),
2628 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2629 [(set VR64:$dst,
2630 (IntId64 VR64:$src1,
2631 (bitconvert (memopv2i32 addr:$src2))))]>;
2632
2633 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2634 (ins VR128:$src1, VR128:$src2),
2635 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2636 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2637 OpSize {
2638 let isCommutable = Commutable;
2639 }
2640 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2641 (ins VR128:$src1, i128mem:$src2),
2642 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2643 [(set VR128:$dst,
2644 (IntId128 VR128:$src1,
2645 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2646 }
2647}
2648
2649defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2650 int_x86_ssse3_phadd_w,
2651 int_x86_ssse3_phadd_w_128, 1>;
2652defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2653 int_x86_ssse3_phadd_d,
2654 int_x86_ssse3_phadd_d_128, 1>;
2655defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2656 int_x86_ssse3_phadd_sw,
2657 int_x86_ssse3_phadd_sw_128, 1>;
2658defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2659 int_x86_ssse3_phsub_w,
2660 int_x86_ssse3_phsub_w_128>;
2661defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2662 int_x86_ssse3_phsub_d,
2663 int_x86_ssse3_phsub_d_128>;
2664defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2665 int_x86_ssse3_phsub_sw,
2666 int_x86_ssse3_phsub_sw_128>;
2667defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2668 int_x86_ssse3_pmadd_ub_sw,
2669 int_x86_ssse3_pmadd_ub_sw_128, 1>;
2670defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2671 int_x86_ssse3_pmul_hr_sw,
2672 int_x86_ssse3_pmul_hr_sw_128, 1>;
2673defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2674 int_x86_ssse3_pshuf_b,
2675 int_x86_ssse3_pshuf_b_128>;
2676defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2677 int_x86_ssse3_psign_b,
2678 int_x86_ssse3_psign_b_128>;
2679defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2680 int_x86_ssse3_psign_w,
2681 int_x86_ssse3_psign_w_128>;
2682defm PSIGND : SS3I_binop_rm_int_32<0x09, "psignd",
2683 int_x86_ssse3_psign_d,
2684 int_x86_ssse3_psign_d_128>;
2685
2686let isTwoAddress = 1 in {
Bill Wendling1dc817c2007-08-10 09:00:17 +00002687 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2688 (ins VR64:$src1, VR64:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002689 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002690 [(set VR64:$dst,
2691 (int_x86_ssse3_palign_r
2692 VR64:$src1, VR64:$src2,
2693 imm:$src3))]>;
2694 def PALIGNR64rm : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2695 (ins VR64:$src1, i64mem:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002696 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002697 [(set VR64:$dst,
2698 (int_x86_ssse3_palign_r
2699 VR64:$src1,
2700 (bitconvert (memopv2i32 addr:$src2)),
2701 imm:$src3))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002702
Bill Wendling1dc817c2007-08-10 09:00:17 +00002703 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2704 (ins VR128:$src1, VR128:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002705 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002706 [(set VR128:$dst,
2707 (int_x86_ssse3_palign_r_128
2708 VR128:$src1, VR128:$src2,
2709 imm:$src3))]>, OpSize;
2710 def PALIGNR128rm : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2711 (ins VR128:$src1, i128mem:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002712 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002713 [(set VR128:$dst,
2714 (int_x86_ssse3_palign_r_128
2715 VR128:$src1,
2716 (bitconvert (memopv4i32 addr:$src2)),
2717 imm:$src3))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002718}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002719
2720//===----------------------------------------------------------------------===//
2721// Non-Instruction Patterns
2722//===----------------------------------------------------------------------===//
2723
2724// 128-bit vector undef's.
Bill Wendling1dc817c2007-08-10 09:00:17 +00002725def : Pat<(v4f32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002726def : Pat<(v2f64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2727def : Pat<(v16i8 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2728def : Pat<(v8i16 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2729def : Pat<(v4i32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2730def : Pat<(v2i64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2731
Chris Lattnerdec9cb52008-01-24 08:07:48 +00002732// extload f32 -> f64. This matches load+fextend because we have a hack in
2733// the isel (PreprocessForFPConvert) that can introduce loads after dag combine.
2734// Since these loads aren't folded into the fextend, we have to match it
2735// explicitly here.
2736let Predicates = [HasSSE2] in
2737 def : Pat<(fextend (loadf32 addr:$src)),
2738 (CVTSS2SDrm addr:$src)>;
2739
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002740// Scalar to v8i16 / v16i8. The source may be a GR32, but only the lower 8 or
2741// 16-bits matter.
2742def : Pat<(v8i16 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2743 Requires<[HasSSE2]>;
2744def : Pat<(v16i8 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2745 Requires<[HasSSE2]>;
2746
2747// bit_convert
2748let Predicates = [HasSSE2] in {
2749 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2750 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2751 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2752 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2753 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2754 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2755 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2756 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2757 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2758 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2759 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2760 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2761 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2762 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2763 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2764 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2765 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2766 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2767 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2768 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2769 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2770 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2771 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2772 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2773 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2774 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2775 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2776 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2777 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2778 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2779}
2780
2781// Move scalar to XMM zero-extended
2782// movd to XMM register zero-extends
2783let AddedComplexity = 15 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002784// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Chris Lattnere6aa3862007-11-25 00:24:49 +00002785def : Pat<(v2f64 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002786 (v2f64 (scalar_to_vector FR64:$src)), MOVL_shuffle_mask)),
2787 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
Chris Lattnere6aa3862007-11-25 00:24:49 +00002788def : Pat<(v4f32 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002789 (v4f32 (scalar_to_vector FR32:$src)), MOVL_shuffle_mask)),
2790 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE2]>;
2791}
2792
2793// Splat v2f64 / v2i64
2794let AddedComplexity = 10 in {
2795def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2796 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2797def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2798 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2799def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2800 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2801def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2802 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2803}
2804
2805// Splat v4f32
2806def : Pat<(vector_shuffle (v4f32 VR128:$src), (undef), SSE_splat_mask:$sm),
2807 (SHUFPSrri VR128:$src, VR128:$src, SSE_splat_mask:$sm)>,
2808 Requires<[HasSSE1]>;
2809
2810// Special unary SHUFPSrri case.
2811// FIXME: when we want non two-address code, then we should use PSHUFD?
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002812def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2813 SHUFP_unary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002814 (SHUFPSrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2815 Requires<[HasSSE1]>;
Dan Gohman7dc19012007-08-02 21:17:01 +00002816// Special unary SHUFPDrri case.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002817def : Pat<(v2f64 (vector_shuffle VR128:$src1, (undef),
2818 SHUFP_unary_shuffle_mask:$sm)),
Dan Gohman7dc19012007-08-02 21:17:01 +00002819 (SHUFPDrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2820 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002821// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Dan Gohman4a4f1512007-07-18 20:23:34 +00002822def : Pat<(vector_shuffle (memopv4f32 addr:$src1), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002823 SHUFP_unary_shuffle_mask:$sm),
2824 (PSHUFDmi addr:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2825 Requires<[HasSSE2]>;
2826// Special binary v4i32 shuffle cases with SHUFPS.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002827def : Pat<(v4i32 (vector_shuffle VR128:$src1, (v4i32 VR128:$src2),
2828 PSHUFD_binary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002829 (SHUFPSrri VR128:$src1, VR128:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2830 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002831def : Pat<(v4i32 (vector_shuffle VR128:$src1,
2832 (bc_v4i32 (memopv2i64 addr:$src2)), PSHUFD_binary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002833 (SHUFPSrmi VR128:$src1, addr:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2834 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002835// Special binary v2i64 shuffle cases using SHUFPDrri.
2836def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2837 SHUFP_shuffle_mask:$sm)),
2838 (SHUFPDrri VR128:$src1, VR128:$src2, SHUFP_shuffle_mask:$sm)>,
2839 Requires<[HasSSE2]>;
2840// Special unary SHUFPDrri case.
2841def : Pat<(v2i64 (vector_shuffle VR128:$src1, (undef),
2842 SHUFP_unary_shuffle_mask:$sm)),
2843 (SHUFPDrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2844 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002845
2846// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2847let AddedComplexity = 10 in {
2848def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2849 UNPCKL_v_undef_shuffle_mask)),
2850 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2851def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2852 UNPCKL_v_undef_shuffle_mask)),
2853 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2854def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2855 UNPCKL_v_undef_shuffle_mask)),
2856 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2857def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2858 UNPCKL_v_undef_shuffle_mask)),
2859 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2860}
2861
2862// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2863let AddedComplexity = 10 in {
2864def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2865 UNPCKH_v_undef_shuffle_mask)),
2866 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2867def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2868 UNPCKH_v_undef_shuffle_mask)),
2869 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2870def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2871 UNPCKH_v_undef_shuffle_mask)),
2872 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2873def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2874 UNPCKH_v_undef_shuffle_mask)),
2875 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2876}
2877
2878let AddedComplexity = 15 in {
2879// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2880def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2881 MOVHP_shuffle_mask)),
2882 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2883
2884// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2885def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2886 MOVHLPS_shuffle_mask)),
2887 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2888
2889// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2890def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2891 MOVHLPS_v_undef_shuffle_mask)),
2892 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2893def : Pat<(v4i32 (vector_shuffle VR128:$src1, (undef),
2894 MOVHLPS_v_undef_shuffle_mask)),
2895 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2896}
2897
2898let AddedComplexity = 20 in {
2899// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2900// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Dan Gohman4a4f1512007-07-18 20:23:34 +00002901def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002902 MOVLP_shuffle_mask)),
2903 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002904def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002905 MOVLP_shuffle_mask)),
2906 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002907def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002908 MOVHP_shuffle_mask)),
2909 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002910def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002911 MOVHP_shuffle_mask)),
2912 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2913
Dan Gohman4a4f1512007-07-18 20:23:34 +00002914def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002915 MOVLP_shuffle_mask)),
2916 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002917def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002918 MOVLP_shuffle_mask)),
2919 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002920def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002921 MOVHP_shuffle_mask)),
2922 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002923def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002924 MOVLP_shuffle_mask)),
2925 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2926}
2927
2928let AddedComplexity = 15 in {
2929// Setting the lowest element in the vector.
2930def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2931 MOVL_shuffle_mask)),
2932 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2933def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2934 MOVL_shuffle_mask)),
2935 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2936
2937// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
2938def : Pat<(v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
2939 MOVLP_shuffle_mask)),
2940 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2941def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2942 MOVLP_shuffle_mask)),
2943 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2944}
2945
2946// Set lowest element and zero upper elements.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002947let AddedComplexity = 15 in
2948def : Pat<(v2f64 (vector_shuffle immAllZerosV_bc, VR128:$src,
2949 MOVL_shuffle_mask)),
2950 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
2951
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002952
2953// FIXME: Temporary workaround since 2-wide shuffle is broken.
2954def : Pat<(int_x86_sse2_movs_d VR128:$src1, VR128:$src2),
2955 (v2f64 (MOVLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2956def : Pat<(int_x86_sse2_loadh_pd VR128:$src1, addr:$src2),
2957 (v2f64 (MOVHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2958def : Pat<(int_x86_sse2_loadl_pd VR128:$src1, addr:$src2),
2959 (v2f64 (MOVLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2960def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, VR128:$src2, imm:$src3),
2961 (v2f64 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$src3))>,
2962 Requires<[HasSSE2]>;
2963def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, (load addr:$src2), imm:$src3),
2964 (v2f64 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$src3))>,
2965 Requires<[HasSSE2]>;
2966def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, VR128:$src2),
2967 (v2f64 (UNPCKHPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2968def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, (load addr:$src2)),
2969 (v2f64 (UNPCKHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2970def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, VR128:$src2),
2971 (v2f64 (UNPCKLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2972def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, (load addr:$src2)),
2973 (v2f64 (UNPCKLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2974def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, VR128:$src2),
2975 (v2i64 (PUNPCKHQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2976def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, (load addr:$src2)),
2977 (v2i64 (PUNPCKHQDQrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2978def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, VR128:$src2),
2979 (v2i64 (PUNPCKLQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2980def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, (load addr:$src2)),
2981 (PUNPCKLQDQrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2982
2983// Some special case pandn patterns.
2984def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2985 VR128:$src2)),
2986 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2987def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2988 VR128:$src2)),
2989 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2990def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2991 VR128:$src2)),
2992 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2993
2994def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00002995 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002996 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2997def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00002998 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002999 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3000def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00003001 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003002 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3003
Nate Begeman78246ca2007-11-17 03:58:34 +00003004// vector -> vector casts
3005def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3006 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3007def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3008 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3009
Evan Cheng51a49b22007-07-20 00:27:43 +00003010// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00003011def : Pat<(alignedloadv4i32 addr:$src),
3012 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
3013def : Pat<(loadv4i32 addr:$src),
3014 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00003015def : Pat<(alignedloadv2i64 addr:$src),
3016 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
3017def : Pat<(loadv2i64 addr:$src),
3018 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
3019
3020def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3021 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3022def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3023 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3024def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3025 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3026def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3027 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3028def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3029 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3030def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3031 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3032def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3033 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3034def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3035 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begemanb2975562008-02-03 07:18:54 +00003036
3037//===----------------------------------------------------------------------===//
3038// SSE4.1 Instructions
3039//===----------------------------------------------------------------------===//
3040
3041// SSE4.1 Instruction Templates:
3042//
Nate Begemaneb3f5432008-02-04 05:34:34 +00003043// SS48I - SSE 4.1 instructions with T8 prefix.
Nate Begemanb2975562008-02-03 07:18:54 +00003044// SS41AI - SSE 4.1 instructions with TA prefix.
3045//
Nate Begemaneb3f5432008-02-04 05:34:34 +00003046class SS48I<bits<8> o, Format F, dag outs, dag ins, string asm,
3047 list<dag> pattern>
Nate Begemanb2975562008-02-03 07:18:54 +00003048 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSE41]>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003049class SS4AI<bits<8> o, Format F, dag outs, dag ins, string asm,
3050 list<dag> pattern>
Nate Begemanb2975562008-02-03 07:18:54 +00003051 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSE41]>;
3052
3053
3054multiclass sse41_fp_unop_rm<bits<8> opcss, bits<8> opcps,
3055 bits<8> opcsd, bits<8> opcpd,
3056 string OpcodeStr,
3057 Intrinsic F32Int,
3058 Intrinsic V4F32Int,
3059 Intrinsic F64Int,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003060 Intrinsic V2F64Int> {
Nate Begemanb2975562008-02-03 07:18:54 +00003061 // Intrinsic operation, reg.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003062 def SSr_Int : SS4AI<opcss, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003063 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003064 !strconcat(OpcodeStr,
3065 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003066 [(set VR128:$dst, (F32Int VR128:$src1, imm:$src2))]>,
3067 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003068
3069 // Intrinsic operation, mem.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003070 def SSm_Int : SS4AI<opcss, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003071 (outs VR128:$dst), (ins ssmem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003072 !strconcat(OpcodeStr,
3073 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003074 [(set VR128:$dst, (F32Int sse_load_f32:$src1, imm:$src2))]>,
3075 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003076
3077 // Vector intrinsic operation, reg
Nate Begemaneb3f5432008-02-04 05:34:34 +00003078 def PSr_Int : SS4AI<opcps, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003079 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003080 !strconcat(OpcodeStr,
3081 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003082 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3083 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003084
3085 // Vector intrinsic operation, mem
Nate Begemaneb3f5432008-02-04 05:34:34 +00003086 def PSm_Int : SS4AI<opcps, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003087 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003088 !strconcat(OpcodeStr,
3089 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003090 [(set VR128:$dst, (V4F32Int (load addr:$src1),imm:$src2))]>,
3091 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003092
3093 // Intrinsic operation, reg.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003094 def SDr_Int : SS4AI<opcsd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003095 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003096 !strconcat(OpcodeStr,
3097 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003098 [(set VR128:$dst, (F64Int VR128:$src1, imm:$src2))]>,
3099 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003100
3101 // Intrinsic operation, mem.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003102 def SDm_Int : SS4AI<opcsd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003103 (outs VR128:$dst), (ins sdmem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003104 !strconcat(OpcodeStr,
3105 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003106 [(set VR128:$dst, (F64Int sse_load_f64:$src1, imm:$src2))]>,
3107 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003108
3109 // Vector intrinsic operation, reg
Nate Begemaneb3f5432008-02-04 05:34:34 +00003110 def PDr_Int : SS4AI<opcpd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003111 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003112 !strconcat(OpcodeStr,
3113 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003114 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3115 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003116
3117 // Vector intrinsic operation, mem
Nate Begemaneb3f5432008-02-04 05:34:34 +00003118 def PDm_Int : SS4AI<opcpd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003119 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003120 !strconcat(OpcodeStr,
3121 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003122 [(set VR128:$dst, (V2F64Int (load addr:$src1),imm:$src2))]>,
3123 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003124}
3125
3126// FP round - roundss, roundps, roundsd, roundpd
3127defm ROUND : sse41_fp_unop_rm<0x0A, 0x08, 0x0B, 0x09, "round",
3128 int_x86_sse41_round_ss, int_x86_sse41_round_ps,
3129 int_x86_sse41_round_sd, int_x86_sse41_round_pd>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003130
3131// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3132multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3133 Intrinsic IntId128> {
3134 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3135 (ins VR128:$src),
3136 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3137 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3138 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3139 (ins i128mem:$src),
3140 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3141 [(set VR128:$dst,
3142 (IntId128
3143 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3144}
3145
3146defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3147 int_x86_sse41_phminposuw>;
3148
3149/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3150let isTwoAddress = 1 in {
3151 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3152 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003153 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3154 (ins VR128:$src1, VR128:$src2),
3155 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3156 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3157 OpSize {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003158 let isCommutable = Commutable;
3159 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003160 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3161 (ins VR128:$src1, i128mem:$src2),
3162 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3163 [(set VR128:$dst,
3164 (IntId128 VR128:$src1,
3165 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003166 }
3167}
3168
3169defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3170 int_x86_sse41_pcmpeqq, 1>;
3171defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3172 int_x86_sse41_packusdw, 0>;
3173defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3174 int_x86_sse41_pminsb, 1>;
3175defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3176 int_x86_sse41_pminsd, 1>;
3177defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3178 int_x86_sse41_pminud, 1>;
3179defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3180 int_x86_sse41_pminuw, 1>;
3181defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3182 int_x86_sse41_pmaxsb, 1>;
3183defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3184 int_x86_sse41_pmaxsd, 1>;
3185defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3186 int_x86_sse41_pmaxud, 1>;
3187defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3188 int_x86_sse41_pmaxuw, 1>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003189defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq",
3190 int_x86_sse41_pmuldq, 1>;
Nate Begeman72d802a2008-02-04 06:00:24 +00003191
Nate Begeman58057962008-02-09 01:38:08 +00003192
3193/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3194let isTwoAddress = 1 in {
3195 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, SDNode OpNode,
3196 Intrinsic IntId128, bit Commutable = 0> {
3197 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3198 (ins VR128:$src1, VR128:$src2),
3199 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3200 [(set VR128:$dst, (OpNode (v4i32 VR128:$src1),
3201 VR128:$src2))]>, OpSize {
3202 let isCommutable = Commutable;
3203 }
3204 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3205 (ins VR128:$src1, VR128:$src2),
3206 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3207 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3208 OpSize {
3209 let isCommutable = Commutable;
3210 }
3211 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3212 (ins VR128:$src1, i128mem:$src2),
3213 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3214 [(set VR128:$dst,
3215 (OpNode VR128:$src1, (memopv4i32 addr:$src2)))]>, OpSize;
3216 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3217 (ins VR128:$src1, i128mem:$src2),
3218 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3219 [(set VR128:$dst,
3220 (IntId128 VR128:$src1, (memopv4i32 addr:$src2)))]>,
3221 OpSize;
3222 }
3223}
3224defm PMULLD : SS41I_binop_patint<0x40, "pmulld", mul,
3225 int_x86_sse41_pmulld, 1>;
3226
3227
Nate Begeman72d802a2008-02-04 06:00:24 +00003228/// SS41I_binop_rmi_int - SSE 4.1 binary operator with immediate
3229let isTwoAddress = 1 in {
3230 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3231 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003232 def rri : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3233 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3234 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003235 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003236 [(set VR128:$dst,
3237 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3238 OpSize {
Nate Begeman72d802a2008-02-04 06:00:24 +00003239 let isCommutable = Commutable;
3240 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003241 def rmi : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3242 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3243 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003244 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003245 [(set VR128:$dst,
3246 (IntId128 VR128:$src1,
3247 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3248 OpSize;
Nate Begeman72d802a2008-02-04 06:00:24 +00003249 }
3250}
3251
3252defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3253 int_x86_sse41_blendps, 0>;
3254defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3255 int_x86_sse41_blendpd, 0>;
3256defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3257 int_x86_sse41_pblendw, 0>;
3258defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3259 int_x86_sse41_dpps, 1>;
3260defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3261 int_x86_sse41_dppd, 1>;
3262defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3263 int_x86_sse41_mpsadbw, 0>;
Nate Begeman58057962008-02-09 01:38:08 +00003264
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003265
Nate Begemanb4e9a042008-02-10 18:47:57 +00003266/// SS41I_binop_rmi_int - SSE 4.1 binary operator with immediate
Nate Begemand77e59e2008-02-11 04:19:36 +00003267let Uses = [XMM0], isTwoAddress = 1 in {
Nate Begemanb4e9a042008-02-10 18:47:57 +00003268 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3269 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3270 (ins VR128:$src1, VR128:$src2),
3271 !strconcat(OpcodeStr,
3272 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3273 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3274 OpSize;
3275
3276 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3277 (ins VR128:$src1, i128mem:$src2),
3278 !strconcat(OpcodeStr,
3279 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3280 [(set VR128:$dst,
3281 (IntId VR128:$src1,
3282 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3283 }
3284}
3285
3286defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3287defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3288defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3289
3290
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003291multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3292 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3293 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3294 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3295
3296 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3297 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3298 [(set VR128:$dst,
3299 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3300}
3301
3302defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3303defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3304defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3305defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3306defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3307defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3308
3309multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3310 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3311 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3312 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3313
3314 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3315 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3316 [(set VR128:$dst,
3317 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3318}
3319
3320defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3321defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3322defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3323defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3324
3325multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3326 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3327 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3328 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3329
3330 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3331 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3332 [(set VR128:$dst,
3333 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3334}
3335
3336defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3337defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovsxbq", int_x86_sse41_pmovzxbq>;
3338
3339
Nate Begemand77e59e2008-02-11 04:19:36 +00003340/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3341multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003342 def rr : SS4AI<opc, MRMSrcReg, (outs GR32:$dst),
3343 (ins VR128:$src1, i32i8imm:$src2),
3344 !strconcat(OpcodeStr,
3345 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003346 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3347 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003348 def mr : SS4AI<opc, MRMDestMem, (outs),
3349 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3350 !strconcat(OpcodeStr,
3351 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003352 []>, OpSize;
3353// FIXME:
3354// There's an AssertZext in the way of writing the store pattern
3355// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003356}
3357
Nate Begemand77e59e2008-02-11 04:19:36 +00003358defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003359
Nate Begemand77e59e2008-02-11 04:19:36 +00003360
3361/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3362multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3363 def mr : SS4AI<opc, MRMDestMem, (outs),
3364 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3365 !strconcat(OpcodeStr,
3366 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3367 []>, OpSize;
3368// FIXME:
3369// There's an AssertZext in the way of writing the store pattern
3370// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3371}
3372
3373defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3374
3375
3376/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3377multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003378 def rr : SS4AI<opc, MRMSrcReg, (outs GR32:$dst),
3379 (ins VR128:$src1, i32i8imm:$src2),
3380 !strconcat(OpcodeStr,
3381 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3382 [(set GR32:$dst,
3383 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3384 def mr : SS4AI<opc, MRMDestMem, (outs),
3385 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3386 !strconcat(OpcodeStr,
3387 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3388 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3389 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003390}
3391
Nate Begemand77e59e2008-02-11 04:19:36 +00003392defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman58057962008-02-09 01:38:08 +00003393
Nate Begemand77e59e2008-02-11 04:19:36 +00003394
3395/// SS41I_extractf32 - SSE 4.1 extract 32 bits to fp reg or memory destination
3396multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003397 def rr : SS4AI<opc, MRMSrcReg, (outs FR32:$dst),
3398 (ins VR128:$src1, i32i8imm:$src2),
3399 !strconcat(OpcodeStr,
3400 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3401 [(set FR32:$dst,
3402 (extractelt (v4f32 VR128:$src1), imm:$src2))]>, OpSize;
3403 def mr : SS4AI<opc, MRMDestMem, (outs),
3404 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3405 !strconcat(OpcodeStr,
3406 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3407 [(store (extractelt (v4f32 VR128:$src1), imm:$src2),
3408 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003409}
3410
Nate Begemand77e59e2008-02-11 04:19:36 +00003411defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003412
Nate Begemand77e59e2008-02-11 04:19:36 +00003413let isTwoAddress = 1 in {
3414 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3415 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3416 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3417 !strconcat(OpcodeStr,
3418 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3419 [(set VR128:$dst,
3420 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3421 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3422 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3423 !strconcat(OpcodeStr,
3424 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3425 [(set VR128:$dst,
3426 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3427 imm:$src3))]>, OpSize;
3428 }
3429}
3430
3431defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3432
3433let isTwoAddress = 1 in {
3434 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3435 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3436 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3437 !strconcat(OpcodeStr,
3438 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3439 [(set VR128:$dst,
3440 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3441 OpSize;
3442 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3443 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3444 !strconcat(OpcodeStr,
3445 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3446 [(set VR128:$dst,
3447 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3448 imm:$src3)))]>, OpSize;
3449 }
3450}
3451
3452defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3453
3454let isTwoAddress = 1 in {
3455 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3456 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3457 (ins VR128:$src1, FR32:$src2, i32i8imm:$src3),
3458 !strconcat(OpcodeStr,
3459 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3460 [(set VR128:$dst,
3461 (X86insrtps VR128:$src1, FR32:$src2, imm:$src3))]>, OpSize;
3462 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3463 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3464 !strconcat(OpcodeStr,
3465 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3466 [(set VR128:$dst,
3467 (X86insrtps VR128:$src1, (loadf32 addr:$src2),
3468 imm:$src3))]>, OpSize;
3469 }
3470}
3471
3472defm INSERTPS : SS41I_insertf32<0x31, "insertps">;