blob: 35b575b9d86b189c01d56c5fe3fe309f96f29d38 [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>;
Nate Begemand77e59e2008-02-11 04:19:36 +000037def X86pextrb : SDNode<"X86ISD::PEXTRB",
38 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
39def X86pextrw : SDNode<"X86ISD::PEXTRW",
40 SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisPtrTy<2>]>>;
41def X86pinsrb : SDNode<"X86ISD::PINSRB",
42 SDTypeProfile<1, 3, [SDTCisVT<0, v16i8>, SDTCisSameAs<0,1>,
43 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
44def X86pinsrw : SDNode<"X86ISD::PINSRW",
45 SDTypeProfile<1, 3, [SDTCisVT<0, v8i16>, SDTCisSameAs<0,1>,
46 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
47def X86insrtps : SDNode<"X86ISD::INSERTPS",
48 SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisSameAs<0,1>,
49 SDTCisVT<2, f32>, SDTCisPtrTy<3>]>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
51//===----------------------------------------------------------------------===//
52// SSE 'Special' Instructions
53//===----------------------------------------------------------------------===//
54
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000055let isImplicitDef = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +000056def IMPLICIT_DEF_VR128 : I<0, Pseudo, (outs VR128:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 "#IMPLICIT_DEF $dst",
58 [(set VR128:$dst, (v4f32 (undef)))]>,
59 Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000060def IMPLICIT_DEF_FR32 : I<0, Pseudo, (outs FR32:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 "#IMPLICIT_DEF $dst",
Dale Johannesene0e0fd02007-09-23 14:52:20 +000062 [(set FR32:$dst, (undef))]>, Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000063def IMPLICIT_DEF_FR64 : I<0, Pseudo, (outs FR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 "#IMPLICIT_DEF $dst",
65 [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000066}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067
68//===----------------------------------------------------------------------===//
69// SSE Complex Patterns
70//===----------------------------------------------------------------------===//
71
72// These are 'extloads' from a scalar to the low element of a vector, zeroing
73// the top elements. These are used for the SSE 'ss' and 'sd' instruction
74// forms.
75def sse_load_f32 : ComplexPattern<v4f32, 4, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000076 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077def sse_load_f64 : ComplexPattern<v2f64, 4, "SelectScalarSSELoad", [],
Chris Lattnerc90ee9c2008-01-10 07:59:24 +000078 [SDNPHasChain, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079
80def ssmem : Operand<v4f32> {
81 let PrintMethod = "printf32mem";
82 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
83}
84def sdmem : Operand<v2f64> {
85 let PrintMethod = "printf64mem";
86 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
87}
88
89//===----------------------------------------------------------------------===//
90// SSE pattern fragments
91//===----------------------------------------------------------------------===//
92
Dan Gohmanf17a25c2007-07-18 16:29:46 +000093def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
94def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
95def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
96def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
97
Dan Gohman11821702007-07-27 17:16:43 +000098// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +000099def alignedstore : PatFrag<(ops node:$val, node:$ptr),
100 (st node:$val, node:$ptr), [{
101 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
102 return !ST->isTruncatingStore() &&
103 ST->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000104 ST->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000105 return false;
106}]>;
107
Dan Gohman11821702007-07-27 17:16:43 +0000108// Like 'load', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +0000109def alignedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
110 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
111 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
112 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000113 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000114 return false;
115}]>;
116
Dan Gohman11821702007-07-27 17:16:43 +0000117def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
118def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000119def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
120def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
121def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
122def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
123
124// Like 'load', but uses special alignment checks suitable for use in
125// memory operands in most SSE instructions, which are required to
126// be naturally aligned on some targets but not on others.
127// FIXME: Actually implement support for targets that don't require the
128// alignment. This probably wants a subtarget predicate.
129def memop : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
130 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
131 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
132 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000133 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000134 return false;
135}]>;
136
Dan Gohman11821702007-07-27 17:16:43 +0000137def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
138def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000139def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
140def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
141def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
142def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000143def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000144
Bill Wendling3b15d722007-08-11 09:52:53 +0000145// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
146// 16-byte boundary.
Nate Begeman9a58b8a2008-02-09 23:46:37 +0000147// FIXME: 8 byte alignment for mmx reads is not required
Bill Wendling3b15d722007-08-11 09:52:53 +0000148def memop64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
149 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
150 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
151 LD->getAddressingMode() == ISD::UNINDEXED &&
152 LD->getAlignment() >= 8;
153 return false;
154}]>;
155
156def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
Bill Wendling3b15d722007-08-11 09:52:53 +0000157def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
158def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
159def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
160
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
162def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
163def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
164def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
165def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
166def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
167
168def fp32imm0 : PatLeaf<(f32 fpimm), [{
169 return N->isExactlyValue(+0.0);
170}]>;
171
172def PSxLDQ_imm : SDNodeXForm<imm, [{
173 // Transformation function: imm >> 3
174 return getI32Imm(N->getValue() >> 3);
175}]>;
176
177// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
178// SHUFP* etc. imm.
179def SHUFFLE_get_shuf_imm : SDNodeXForm<build_vector, [{
180 return getI8Imm(X86::getShuffleSHUFImmediate(N));
181}]>;
182
183// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
184// PSHUFHW imm.
185def SHUFFLE_get_pshufhw_imm : SDNodeXForm<build_vector, [{
186 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
187}]>;
188
189// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
190// PSHUFLW imm.
191def SHUFFLE_get_pshuflw_imm : SDNodeXForm<build_vector, [{
192 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
193}]>;
194
195def SSE_splat_mask : PatLeaf<(build_vector), [{
196 return X86::isSplatMask(N);
197}], SHUFFLE_get_shuf_imm>;
198
199def SSE_splat_lo_mask : PatLeaf<(build_vector), [{
200 return X86::isSplatLoMask(N);
201}]>;
202
203def MOVHLPS_shuffle_mask : PatLeaf<(build_vector), [{
204 return X86::isMOVHLPSMask(N);
205}]>;
206
207def MOVHLPS_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
208 return X86::isMOVHLPS_v_undef_Mask(N);
209}]>;
210
211def MOVHP_shuffle_mask : PatLeaf<(build_vector), [{
212 return X86::isMOVHPMask(N);
213}]>;
214
215def MOVLP_shuffle_mask : PatLeaf<(build_vector), [{
216 return X86::isMOVLPMask(N);
217}]>;
218
219def MOVL_shuffle_mask : PatLeaf<(build_vector), [{
220 return X86::isMOVLMask(N);
221}]>;
222
223def MOVSHDUP_shuffle_mask : PatLeaf<(build_vector), [{
224 return X86::isMOVSHDUPMask(N);
225}]>;
226
227def MOVSLDUP_shuffle_mask : PatLeaf<(build_vector), [{
228 return X86::isMOVSLDUPMask(N);
229}]>;
230
231def UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
232 return X86::isUNPCKLMask(N);
233}]>;
234
235def UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
236 return X86::isUNPCKHMask(N);
237}]>;
238
239def UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
240 return X86::isUNPCKL_v_undef_Mask(N);
241}]>;
242
243def UNPCKH_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
244 return X86::isUNPCKH_v_undef_Mask(N);
245}]>;
246
247def PSHUFD_shuffle_mask : PatLeaf<(build_vector), [{
248 return X86::isPSHUFDMask(N);
249}], SHUFFLE_get_shuf_imm>;
250
251def PSHUFHW_shuffle_mask : PatLeaf<(build_vector), [{
252 return X86::isPSHUFHWMask(N);
253}], SHUFFLE_get_pshufhw_imm>;
254
255def PSHUFLW_shuffle_mask : PatLeaf<(build_vector), [{
256 return X86::isPSHUFLWMask(N);
257}], SHUFFLE_get_pshuflw_imm>;
258
259def SHUFP_unary_shuffle_mask : PatLeaf<(build_vector), [{
260 return X86::isPSHUFDMask(N);
261}], SHUFFLE_get_shuf_imm>;
262
263def SHUFP_shuffle_mask : PatLeaf<(build_vector), [{
264 return X86::isSHUFPMask(N);
265}], SHUFFLE_get_shuf_imm>;
266
267def PSHUFD_binary_shuffle_mask : PatLeaf<(build_vector), [{
268 return X86::isSHUFPMask(N);
269}], SHUFFLE_get_shuf_imm>;
270
271//===----------------------------------------------------------------------===//
272// SSE scalar FP Instructions
273//===----------------------------------------------------------------------===//
274
275// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
276// scheduler into a branch sequence.
Evan Cheng950aac02007-09-25 01:57:46 +0000277// These are expanded by the scheduler.
278let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000280 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281 "#CMOV_FR32 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000282 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
283 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000285 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286 "#CMOV_FR64 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000287 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
288 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000290 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 "#CMOV_V4F32 PSEUDO!",
292 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000293 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
294 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000296 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 "#CMOV_V2F64 PSEUDO!",
298 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000299 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
300 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000302 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 "#CMOV_V2I64 PSEUDO!",
304 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000305 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng950aac02007-09-25 01:57:46 +0000306 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307}
308
309//===----------------------------------------------------------------------===//
310// SSE1 Instructions
311//===----------------------------------------------------------------------===//
312
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000314let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000315def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000316 "movss\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000317let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000318def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000319 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000321def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000322 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(store FR32:$src, addr:$dst)]>;
324
325// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000326def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000332def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000333 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000335def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000336 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
338
339// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000340def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000343def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 [(set GR32:$dst, (int_x86_sse_cvtss2si
346 (load addr:$src)))]>;
347
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000348// Match intrinisics which expect MM and XMM operand(s).
349def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
350 "cvtps2pi\t{$src, $dst|$dst, $src}",
351 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
352def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
353 "cvtps2pi\t{$src, $dst|$dst, $src}",
354 [(set VR64:$dst, (int_x86_sse_cvtps2pi
355 (load addr:$src)))]>;
356def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
357 "cvttps2pi\t{$src, $dst|$dst, $src}",
358 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
359def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
360 "cvttps2pi\t{$src, $dst|$dst, $src}",
361 [(set VR64:$dst, (int_x86_sse_cvttps2pi
362 (load addr:$src)))]>;
363let isTwoAddress = 1 in {
364 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
365 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
366 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
367 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
368 VR64:$src2))]>;
369 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
370 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
371 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
372 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
373 (load addr:$src2)))]>;
374}
375
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000377def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000378 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 [(set GR32:$dst,
380 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000381def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000382 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383 [(set GR32:$dst,
384 (int_x86_sse_cvttss2si(load addr:$src)))]>;
385
386let isTwoAddress = 1 in {
387 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000388 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000389 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
391 GR32:$src2))]>;
392 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000393 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000394 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
396 (loadi32 addr:$src2)))]>;
397}
398
399// Comparison instructions
400let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000401let neverHasSideEffects = 1 in
Chris Lattnera9f545f2007-12-16 20:12:41 +0000402 def CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000403 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000404 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000405let neverHasSideEffects = 1, mayLoad = 1 in
Chris Lattnera9f545f2007-12-16 20:12:41 +0000406 def CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000407 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000408 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409}
410
Evan Cheng55687072007-09-14 21:48:26 +0000411let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000412def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000413 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000414 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000415def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000416 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000417 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000418 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000419} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420
421// Aliases to match intrinsics which expect XMM operand(s).
422let isTwoAddress = 1 in {
Chris Lattnera9f545f2007-12-16 20:12:41 +0000423 def Int_CMPSSrr : SSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000424 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000425 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
427 VR128:$src, imm:$cc))]>;
Chris Lattnera9f545f2007-12-16 20:12:41 +0000428 def Int_CMPSSrm : SSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000429 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
432 (load addr:$src), imm:$cc))]>;
433}
434
Evan Cheng55687072007-09-14 21:48:26 +0000435let Defs = [EFLAGS] in {
Evan Cheng621216e2007-09-29 00:00:36 +0000436def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000437 (ins VR128:$src1, VR128:$src2),
438 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000439 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000440 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000441def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000442 (ins VR128:$src1, f128mem:$src2),
443 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000444 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000445 (implicit EFLAGS)]>;
446
Evan Cheng621216e2007-09-29 00:00:36 +0000447def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000448 (ins VR128:$src1, VR128:$src2),
449 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000450 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000451 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000452def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000453 (ins VR128:$src1, f128mem:$src2),
454 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000455 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000456 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000457} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458
459// Aliases of packed SSE1 instructions for scalar use. These all have names that
460// start with 'Fs'.
461
462// Alias instructions that map fld0 to pxor for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000463let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000464def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000465 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466 Requires<[HasSSE1]>, TB, OpSize;
467
468// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
469// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000470let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000471def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000472 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
474// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
475// disregarded.
Chris Lattner1a1932c2008-01-06 23:38:27 +0000476let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000477def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000478 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000479 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480
481// Alias bitwise logical operations using SSE logical ops on packed FP values.
482let isTwoAddress = 1 in {
483let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000484 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000485 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000487 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000488 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000490 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000491 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
493}
494
Evan Chengb783fa32007-07-19 01:14:50 +0000495def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000496 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000498 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000499def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000500 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000501 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000502 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000503def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000504 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000506 (memopfsf32 addr:$src2)))]>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000507let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000509 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000510 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000511
512let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000514 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000515 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000517}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
519/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
520///
521/// In addition, we also have a special variant of the scalar form here to
522/// represent the associated intrinsic operation. This form is unlike the
523/// plain scalar form, in that it takes an entire vector (instead of a scalar)
524/// and leaves the top elements undefined.
525///
526/// These three forms can each be reg+reg or reg+mem, so there are a total of
527/// six "instructions".
528///
529let isTwoAddress = 1 in {
530multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
531 SDNode OpNode, Intrinsic F32Int,
532 bit Commutable = 0> {
533 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000534 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000535 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
537 let isCommutable = Commutable;
538 }
539
540 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000541 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000542 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
544
545 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000546 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000547 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
549 let isCommutable = Commutable;
550 }
551
552 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000553 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000554 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000555 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
557 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000558 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000559 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000560 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
561 let isCommutable = Commutable;
562 }
563
564 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000565 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000566 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567 [(set VR128:$dst, (F32Int VR128:$src1,
568 sse_load_f32:$src2))]>;
569}
570}
571
572// Arithmetic instructions
573defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
574defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
575defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
576defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
577
578/// sse1_fp_binop_rm - Other SSE1 binops
579///
580/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
581/// instructions for a full-vector intrinsic form. Operations that map
582/// onto C operators don't use this form since they just use the plain
583/// vector form instead of having a separate vector intrinsic form.
584///
585/// This provides a total of eight "instructions".
586///
587let isTwoAddress = 1 in {
588multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
589 SDNode OpNode,
590 Intrinsic F32Int,
591 Intrinsic V4F32Int,
592 bit Commutable = 0> {
593
594 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000595 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000596 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
598 let isCommutable = Commutable;
599 }
600
601 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000602 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000603 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
605
606 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000607 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000608 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
610 let isCommutable = Commutable;
611 }
612
613 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000614 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000615 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000616 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000619 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000620 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
622 let isCommutable = Commutable;
623 }
624
625 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000626 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000627 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628 [(set VR128:$dst, (F32Int VR128:$src1,
629 sse_load_f32:$src2))]>;
630
631 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000632 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000633 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
635 let isCommutable = Commutable;
636 }
637
638 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +0000639 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000640 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000641 [(set VR128:$dst, (V4F32Int VR128:$src1, (load addr:$src2)))]>;
642}
643}
644
645defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
646 int_x86_sse_max_ss, int_x86_sse_max_ps>;
647defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
648 int_x86_sse_min_ss, int_x86_sse_min_ps>;
649
650//===----------------------------------------------------------------------===//
651// SSE packed FP Instructions
652
653// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000654let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000655def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000656 "movaps\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000657let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000658def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000659 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000660 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661
Evan Chengb783fa32007-07-19 01:14:50 +0000662def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000663 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000664 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000666let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000667def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000668 "movups\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +0000669let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000670def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000671 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000672 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000673def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000674 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000675 [(store (v4f32 VR128:$src), addr:$dst)]>;
676
677// Intrinsic forms of MOVUPS load and store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000678let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000679def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000680 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000681 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000682def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000683 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000684 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685
686let isTwoAddress = 1 in {
687 let AddedComplexity = 20 in {
688 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000689 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000690 "movlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691 [(set VR128:$dst,
692 (v4f32 (vector_shuffle VR128:$src1,
693 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
694 MOVLP_shuffle_mask)))]>;
695 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000696 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000697 "movhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(set VR128:$dst,
699 (v4f32 (vector_shuffle VR128:$src1,
700 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
701 MOVHP_shuffle_mask)))]>;
702 } // AddedComplexity
703} // isTwoAddress
704
Evan Chengb783fa32007-07-19 01:14:50 +0000705def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000706 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
708 (iPTR 0))), addr:$dst)]>;
709
710// v2f64 extract element 1 is always custom lowered to unpack high to low
711// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000712def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000713 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 [(store (f64 (vector_extract
715 (v2f64 (vector_shuffle
716 (bc_v2f64 (v4f32 VR128:$src)), (undef),
717 UNPCKH_shuffle_mask)), (iPTR 0))),
718 addr:$dst)]>;
719
720let isTwoAddress = 1 in {
721let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000722def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000723 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 [(set VR128:$dst,
725 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
726 MOVHP_shuffle_mask)))]>;
727
Evan Chengb783fa32007-07-19 01:14:50 +0000728def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000729 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730 [(set VR128:$dst,
731 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
732 MOVHLPS_shuffle_mask)))]>;
733} // AddedComplexity
734} // isTwoAddress
735
736
737
738// Arithmetic
739
740/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
741///
742/// In addition, we also have a special variant of the scalar form here to
743/// represent the associated intrinsic operation. This form is unlike the
744/// plain scalar form, in that it takes an entire vector (instead of a
745/// scalar) and leaves the top elements undefined.
746///
747/// And, we have a special variant form for a full-vector intrinsic form.
748///
749/// These four forms can each have a reg or a mem operand, so there are a
750/// total of eight "instructions".
751///
752multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
753 SDNode OpNode,
754 Intrinsic F32Int,
755 Intrinsic V4F32Int,
756 bit Commutable = 0> {
757 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000758 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000759 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 [(set FR32:$dst, (OpNode FR32:$src))]> {
761 let isCommutable = Commutable;
762 }
763
764 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000765 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000766 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
768
769 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000770 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000771 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
773 let isCommutable = Commutable;
774 }
775
776 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000777 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000778 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000779 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000780
781 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000782 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000783 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784 [(set VR128:$dst, (F32Int VR128:$src))]> {
785 let isCommutable = Commutable;
786 }
787
788 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000789 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000790 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
792
793 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000794 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000795 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
797 let isCommutable = Commutable;
798 }
799
800 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000801 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000802 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 [(set VR128:$dst, (V4F32Int (load addr:$src)))]>;
804}
805
806// Square root.
807defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
808 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
809
810// Reciprocal approximations. Note that these typically require refinement
811// in order to obtain suitable precision.
812defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
813 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
814defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
815 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
816
817// Logical
818let isTwoAddress = 1 in {
819 let isCommutable = 1 in {
820 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000821 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000822 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000823 [(set VR128:$dst, (v2i64
824 (and VR128:$src1, VR128:$src2)))]>;
825 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000826 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000827 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828 [(set VR128:$dst, (v2i64
829 (or VR128:$src1, VR128:$src2)))]>;
830 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000831 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000832 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(set VR128:$dst, (v2i64
834 (xor VR128:$src1, VR128:$src2)))]>;
835 }
836
837 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000838 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000839 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000840 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
841 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000843 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000844 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000845 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
846 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000847 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000848 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000849 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000850 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
851 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000852 def ANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000853 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000854 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 [(set VR128:$dst,
856 (v2i64 (and (xor VR128:$src1,
857 (bc_v2i64 (v4i32 immAllOnesV))),
858 VR128:$src2)))]>;
859 def ANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000860 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000861 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000863 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000865 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000866}
867
868let isTwoAddress = 1 in {
869 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000870 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000871 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000872 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
873 VR128:$src, imm:$cc))]>;
874 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000875 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000876 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
878 (load addr:$src), imm:$cc))]>;
879}
880
881// Shuffle and unpack instructions
882let isTwoAddress = 1 in {
883 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
884 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000885 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886 VR128:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000887 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888 [(set VR128:$dst,
889 (v4f32 (vector_shuffle
890 VR128:$src1, VR128:$src2,
891 SHUFP_shuffle_mask:$src3)))]>;
892 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000893 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000894 f128mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000895 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000896 [(set VR128:$dst,
897 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000898 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899 SHUFP_shuffle_mask:$src3)))]>;
900
901 let AddedComplexity = 10 in {
902 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000903 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000904 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000905 [(set VR128:$dst,
906 (v4f32 (vector_shuffle
907 VR128:$src1, VR128:$src2,
908 UNPCKH_shuffle_mask)))]>;
909 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000910 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000911 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912 [(set VR128:$dst,
913 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000914 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915 UNPCKH_shuffle_mask)))]>;
916
917 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000918 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000919 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000920 [(set VR128:$dst,
921 (v4f32 (vector_shuffle
922 VR128:$src1, VR128:$src2,
923 UNPCKL_shuffle_mask)))]>;
924 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000925 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000926 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000927 [(set VR128:$dst,
928 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000929 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 UNPCKL_shuffle_mask)))]>;
931 } // AddedComplexity
932} // isTwoAddress
933
934// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000935def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000936 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000938def MOVMSKPDrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000939 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000940 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
941
942// Prefetching loads.
943// TODO: no intrinsics for these?
Dan Gohman91888f02007-07-31 20:11:57 +0000944def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src), "prefetcht0\t$src", []>;
945def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src), "prefetcht1\t$src", []>;
946def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src), "prefetcht2\t$src", []>;
947def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src), "prefetchnta\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948
949// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000950def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000951 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
953
954// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +0000955def SFENCE : PSI<0xAE, MRM7m, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000956
957// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000958def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000959 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000960def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000961 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962
963// Alias instructions that map zero vector to pxor / xorp* for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000964let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000965def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000966 "xorps\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000967 [(set VR128:$dst, (v4i32 immAllZerosV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000968
969// FR32 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +0000970def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972 [(set VR128:$dst,
973 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000974def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000975 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976 [(set VR128:$dst,
977 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
978
979// FIXME: may not be able to eliminate this movss with coalescing the src and
980// dest register classes are different. We really want to write this pattern
981// like this:
982// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
983// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +0000984def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000985 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
987 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000988def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000989 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000990 [(store (f32 (vector_extract (v4f32 VR128:$src),
991 (iPTR 0))), addr:$dst)]>;
992
993
994// Move to lower bits of a VR128, leaving upper bits alone.
995// Three operand (but two address) aliases.
996let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +0000997let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000998 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000999 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001000 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001001
1002 let AddedComplexity = 15 in
1003 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001004 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001005 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006 [(set VR128:$dst,
1007 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
1008 MOVL_shuffle_mask)))]>;
1009}
1010
1011// Move to lower bits of a VR128 and zeroing upper bits.
1012// Loading from memory automatically zeroing upper bits.
1013let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00001014def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001015 "movss\t{$src, $dst|$dst, $src}",
Chris Lattnere6aa3862007-11-25 00:24:49 +00001016 [(set VR128:$dst, (v4f32 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001017 (v4f32 (scalar_to_vector (loadf32 addr:$src))),
1018 MOVL_shuffle_mask)))]>;
1019
1020
1021//===----------------------------------------------------------------------===//
1022// SSE2 Instructions
1023//===----------------------------------------------------------------------===//
1024
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001025// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001026let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001027def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001028 "movsd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001029let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001030def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001031 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001032 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001033def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001034 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001035 [(store FR64:$src, addr:$dst)]>;
1036
1037// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001038def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001039 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001041def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001042 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001043 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001044def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001045 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001046 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001047def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001048 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001050def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001051 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001053def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001054 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1056
1057// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001058def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001059 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1061 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001062def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001063 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001064 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1065 Requires<[HasSSE2]>;
1066
1067// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +00001068def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001069 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001071def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001072 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1074 (load addr:$src)))]>;
1075
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001076// Match intrinisics which expect MM and XMM operand(s).
1077def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1078 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1079 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1080def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1081 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1082 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
1083 (load addr:$src)))]>;
1084def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1085 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1086 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1087def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1088 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1089 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
1090 (load addr:$src)))]>;
1091def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1092 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1093 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1094def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1095 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1096 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1097 (load addr:$src)))]>;
1098
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +00001100def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001102 [(set GR32:$dst,
1103 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001104def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001105 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1107 (load addr:$src)))]>;
1108
1109// Comparison instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001110let isTwoAddress = 1, neverHasSideEffects = 1 in {
Evan Cheng653c7ac2007-12-20 19:57:09 +00001111 def CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001112 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001113 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001114let mayLoad = 1 in
Evan Cheng653c7ac2007-12-20 19:57:09 +00001115 def CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001116 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001117 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118}
1119
Evan Cheng950aac02007-09-25 01:57:46 +00001120let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001121def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001122 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001123 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001124def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001125 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001126 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001127 (implicit EFLAGS)]>;
1128}
1129
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130// Aliases to match intrinsics which expect XMM operand(s).
1131let isTwoAddress = 1 in {
Evan Cheng653c7ac2007-12-20 19:57:09 +00001132 def Int_CMPSDrr : SDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001133 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001134 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001135 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1136 VR128:$src, imm:$cc))]>;
Evan Cheng653c7ac2007-12-20 19:57:09 +00001137 def Int_CMPSDrm : SDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001138 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001139 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1141 (load addr:$src), imm:$cc))]>;
1142}
1143
Evan Cheng950aac02007-09-25 01:57:46 +00001144let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001145def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001146 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001147 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1148 (implicit EFLAGS)]>;
1149def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001150 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001151 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1152 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153
Evan Chengb783fa32007-07-19 01:14:50 +00001154def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001155 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001156 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1157 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001158def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001159 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001160 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001161 (implicit EFLAGS)]>;
1162} // Defs = EFLAGS]
1163
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001164// Aliases of packed SSE2 instructions for scalar use. These all have names that
1165// start with 'Fs'.
1166
1167// Alias instructions that map fld0 to pxor for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +00001168let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001169def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001170 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 Requires<[HasSSE2]>, TB, OpSize;
1172
1173// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1174// disregarded.
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001175let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001176def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001177 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001178
1179// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1180// disregarded.
Chris Lattner1a1932c2008-01-06 23:38:27 +00001181let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001182def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001183 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001184 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185
1186// Alias bitwise logical operations using SSE logical ops on packed FP values.
1187let isTwoAddress = 1 in {
1188let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +00001189 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001190 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001191 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001192 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001194 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001195 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001196 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001197 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1198}
1199
Evan Chengb783fa32007-07-19 01:14:50 +00001200def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001201 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001202 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001203 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001204def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001205 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001207 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001208def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001209 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001211 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001213let neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001214def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001215 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001216 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001217let mayLoad = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001219 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001220 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001221}
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001222}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001223
1224/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1225///
1226/// In addition, we also have a special variant of the scalar form here to
1227/// represent the associated intrinsic operation. This form is unlike the
1228/// plain scalar form, in that it takes an entire vector (instead of a scalar)
1229/// and leaves the top elements undefined.
1230///
1231/// These three forms can each be reg+reg or reg+mem, so there are a total of
1232/// six "instructions".
1233///
1234let isTwoAddress = 1 in {
1235multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1236 SDNode OpNode, Intrinsic F64Int,
1237 bit Commutable = 0> {
1238 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001239 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001240 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001241 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1242 let isCommutable = Commutable;
1243 }
1244
1245 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001246 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001247 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001248 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1249
1250 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001251 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001252 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1254 let isCommutable = Commutable;
1255 }
1256
1257 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001258 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001259 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001260 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001261
1262 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001263 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001264 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1266 let isCommutable = Commutable;
1267 }
1268
1269 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001270 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272 [(set VR128:$dst, (F64Int VR128:$src1,
1273 sse_load_f64:$src2))]>;
1274}
1275}
1276
1277// Arithmetic instructions
1278defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1279defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1280defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1281defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1282
1283/// sse2_fp_binop_rm - Other SSE2 binops
1284///
1285/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1286/// instructions for a full-vector intrinsic form. Operations that map
1287/// onto C operators don't use this form since they just use the plain
1288/// vector form instead of having a separate vector intrinsic form.
1289///
1290/// This provides a total of eight "instructions".
1291///
1292let isTwoAddress = 1 in {
1293multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1294 SDNode OpNode,
1295 Intrinsic F64Int,
1296 Intrinsic V2F64Int,
1297 bit Commutable = 0> {
1298
1299 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001300 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001301 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001302 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1303 let isCommutable = Commutable;
1304 }
1305
1306 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001307 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001308 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001309 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1310
1311 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001312 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001313 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001314 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1315 let isCommutable = Commutable;
1316 }
1317
1318 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001319 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001320 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001321 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001322
1323 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001324 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001325 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001326 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1327 let isCommutable = Commutable;
1328 }
1329
1330 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001331 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001332 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001333 [(set VR128:$dst, (F64Int VR128:$src1,
1334 sse_load_f64:$src2))]>;
1335
1336 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001337 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001338 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001339 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1340 let isCommutable = Commutable;
1341 }
1342
1343 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +00001344 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001345 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001346 [(set VR128:$dst, (V2F64Int VR128:$src1, (load addr:$src2)))]>;
1347}
1348}
1349
1350defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1351 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1352defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1353 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1354
1355//===----------------------------------------------------------------------===//
1356// SSE packed FP Instructions
1357
1358// Move Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +00001359let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001360def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001361 "movapd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001362let isSimpleLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001363def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001364 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001365 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001366
Evan Chengb783fa32007-07-19 01:14:50 +00001367def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001368 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001369 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001370
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001371let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001372def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001373 "movupd\t{$src, $dst|$dst, $src}", []>;
Chris Lattner1a1932c2008-01-06 23:38:27 +00001374let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001375def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001376 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001377 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001378def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001379 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001380 [(store (v2f64 VR128:$src), addr:$dst)]>;
1381
1382// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001383def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001384 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001385 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001386def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001387 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001388 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001389
1390let isTwoAddress = 1 in {
1391 let AddedComplexity = 20 in {
1392 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001393 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001394 "movlpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001395 [(set VR128:$dst,
1396 (v2f64 (vector_shuffle VR128:$src1,
1397 (scalar_to_vector (loadf64 addr:$src2)),
1398 MOVLP_shuffle_mask)))]>;
1399 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001400 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001401 "movhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001402 [(set VR128:$dst,
1403 (v2f64 (vector_shuffle VR128:$src1,
1404 (scalar_to_vector (loadf64 addr:$src2)),
1405 MOVHP_shuffle_mask)))]>;
1406 } // AddedComplexity
1407} // isTwoAddress
1408
Evan Chengb783fa32007-07-19 01:14:50 +00001409def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001410 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001411 [(store (f64 (vector_extract (v2f64 VR128:$src),
1412 (iPTR 0))), addr:$dst)]>;
1413
1414// v2f64 extract element 1 is always custom lowered to unpack high to low
1415// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001416def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001417 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001418 [(store (f64 (vector_extract
1419 (v2f64 (vector_shuffle VR128:$src, (undef),
1420 UNPCKH_shuffle_mask)), (iPTR 0))),
1421 addr:$dst)]>;
1422
1423// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001424def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001425 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001426 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1427 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001428def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001429 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001430 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
Dan Gohman4a4f1512007-07-18 20:23:34 +00001431 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001432 TB, Requires<[HasSSE2]>;
1433
1434// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001435def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001436 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001437 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1438 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001439def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001440 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001441 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
Dan Gohman4a4f1512007-07-18 20:23:34 +00001442 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001443 XS, Requires<[HasSSE2]>;
1444
Evan Chengb783fa32007-07-19 01:14:50 +00001445def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001446 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001447 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001448def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001449 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001450 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1451 (load addr:$src)))]>;
1452// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001453def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001454 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001455 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1456 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001457def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001458 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001459 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1460 (load addr:$src)))]>,
1461 XS, Requires<[HasSSE2]>;
1462
1463// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001464def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001465 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001466 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1467 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001468def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001469 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001470 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1471 (load addr:$src)))]>,
1472 XD, Requires<[HasSSE2]>;
1473
Evan Chengb783fa32007-07-19 01:14:50 +00001474def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001475 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001476 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001477def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001478 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001479 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1480 (load addr:$src)))]>;
1481
1482// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001483def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001484 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001485 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1486 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001487def Int_CVTPS2PDrm : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001488 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001489 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1490 (load addr:$src)))]>,
1491 TB, Requires<[HasSSE2]>;
1492
Evan Chengb783fa32007-07-19 01:14:50 +00001493def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001494 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001495 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001496def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001497 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001498 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1499 (load addr:$src)))]>;
1500
1501// Match intrinsics which expect XMM operand(s).
1502// Aliases for intrinsics
1503let isTwoAddress = 1 in {
1504def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001505 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001506 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001507 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1508 GR32:$src2))]>;
1509def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001510 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001511 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001512 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1513 (loadi32 addr:$src2)))]>;
1514def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001515 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001516 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001517 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1518 VR128:$src2))]>;
1519def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001520 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001521 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001522 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1523 (load addr:$src2)))]>;
1524def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001525 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001526 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001527 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1528 VR128:$src2))]>, XS,
1529 Requires<[HasSSE2]>;
1530def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001531 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001532 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1534 (load addr:$src2)))]>, XS,
1535 Requires<[HasSSE2]>;
1536}
1537
1538// Arithmetic
1539
1540/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1541///
1542/// In addition, we also have a special variant of the scalar form here to
1543/// represent the associated intrinsic operation. This form is unlike the
1544/// plain scalar form, in that it takes an entire vector (instead of a
1545/// scalar) and leaves the top elements undefined.
1546///
1547/// And, we have a special variant form for a full-vector intrinsic form.
1548///
1549/// These four forms can each have a reg or a mem operand, so there are a
1550/// total of eight "instructions".
1551///
1552multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1553 SDNode OpNode,
1554 Intrinsic F64Int,
1555 Intrinsic V2F64Int,
1556 bit Commutable = 0> {
1557 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001558 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001559 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001560 [(set FR64:$dst, (OpNode FR64:$src))]> {
1561 let isCommutable = Commutable;
1562 }
1563
1564 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001565 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001566 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001567 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1568
1569 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001570 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001571 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001572 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1573 let isCommutable = Commutable;
1574 }
1575
1576 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001577 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001578 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001579 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001580
1581 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001582 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001583 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001584 [(set VR128:$dst, (F64Int VR128:$src))]> {
1585 let isCommutable = Commutable;
1586 }
1587
1588 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001589 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001590 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001591 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1592
1593 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001594 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001595 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001596 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1597 let isCommutable = Commutable;
1598 }
1599
1600 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001601 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001602 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001603 [(set VR128:$dst, (V2F64Int (load addr:$src)))]>;
1604}
1605
1606// Square root.
1607defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1608 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1609
1610// There is no f64 version of the reciprocal approximation instructions.
1611
1612// Logical
1613let isTwoAddress = 1 in {
1614 let isCommutable = 1 in {
1615 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001616 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001617 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001618 [(set VR128:$dst,
1619 (and (bc_v2i64 (v2f64 VR128:$src1)),
1620 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1621 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001622 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001623 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001624 [(set VR128:$dst,
1625 (or (bc_v2i64 (v2f64 VR128:$src1)),
1626 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1627 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001628 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001629 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001630 [(set VR128:$dst,
1631 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1632 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1633 }
1634
1635 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001636 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001637 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001638 [(set VR128:$dst,
1639 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001640 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001641 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001642 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001643 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001644 [(set VR128:$dst,
1645 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001646 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001647 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001648 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001649 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001650 [(set VR128:$dst,
1651 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001652 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001653 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001654 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001655 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001656 [(set VR128:$dst,
1657 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1658 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1659 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001660 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001661 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001662 [(set VR128:$dst,
1663 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001664 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001665}
1666
1667let isTwoAddress = 1 in {
1668 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001669 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001670 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001671 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1672 VR128:$src, imm:$cc))]>;
1673 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001674 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001675 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001676 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1677 (load addr:$src), imm:$cc))]>;
1678}
1679
1680// Shuffle and unpack instructions
1681let isTwoAddress = 1 in {
1682 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001683 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001684 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001685 [(set VR128:$dst, (v2f64 (vector_shuffle
1686 VR128:$src1, VR128:$src2,
1687 SHUFP_shuffle_mask:$src3)))]>;
1688 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001689 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001690 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001691 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001692 [(set VR128:$dst,
1693 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001694 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001695 SHUFP_shuffle_mask:$src3)))]>;
1696
1697 let AddedComplexity = 10 in {
1698 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001699 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001700 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001701 [(set VR128:$dst,
1702 (v2f64 (vector_shuffle
1703 VR128:$src1, VR128:$src2,
1704 UNPCKH_shuffle_mask)))]>;
1705 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001706 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001707 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001708 [(set VR128:$dst,
1709 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001710 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001711 UNPCKH_shuffle_mask)))]>;
1712
1713 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001714 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001715 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001716 [(set VR128:$dst,
1717 (v2f64 (vector_shuffle
1718 VR128:$src1, VR128:$src2,
1719 UNPCKL_shuffle_mask)))]>;
1720 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001721 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001722 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001723 [(set VR128:$dst,
1724 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001725 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001726 UNPCKL_shuffle_mask)))]>;
1727 } // AddedComplexity
1728} // isTwoAddress
1729
1730
1731//===----------------------------------------------------------------------===//
1732// SSE integer instructions
1733
1734// Move Instructions
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001735let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001736def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001737 "movdqa\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001738let isSimpleLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001739def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001740 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001741 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001742let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001743def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001744 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001745 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001746let isSimpleLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001747def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001748 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001749 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001750 XS, Requires<[HasSSE2]>;
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001751let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001752def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001753 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001754 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001755 XS, Requires<[HasSSE2]>;
1756
Dan Gohman4a4f1512007-07-18 20:23:34 +00001757// Intrinsic forms of MOVDQU load and store
Chris Lattner1a1932c2008-01-06 23:38:27 +00001758let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001759def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001760 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001761 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1762 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001763def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001764 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001765 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1766 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001767
Evan Cheng88004752008-03-05 08:11:27 +00001768let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001769
1770multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1771 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001772 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001773 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001774 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1775 let isCommutable = Commutable;
1776 }
Evan Chengb783fa32007-07-19 01:14:50 +00001777 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001778 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001779 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001780 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001781}
1782
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001783/// PDI_binop_rm - Simple SSE2 binary operator.
1784multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1785 ValueType OpVT, bit Commutable = 0> {
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, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1789 let isCommutable = Commutable;
1790 }
Evan Chengb783fa32007-07-19 01:14:50 +00001791 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001792 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001793 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001794 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001795}
1796
1797/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1798///
1799/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1800/// to collapse (bitconvert VT to VT) into its operand.
1801///
1802multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1803 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001804 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001805 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001806 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1807 let isCommutable = Commutable;
1808 }
Evan Chengb783fa32007-07-19 01:14:50 +00001809 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001810 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001811 [(set VR128:$dst, (OpNode VR128:$src1,(memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001812}
1813
1814} // isTwoAddress
1815
1816// 128-bit Integer Arithmetic
1817
1818defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1819defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1820defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1821defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1822
1823defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1824defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1825defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1826defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1827
1828defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1829defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1830defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1831defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1832
1833defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1834defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1835defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1836defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1837
1838defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1839
1840defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1841defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1842defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1843
1844defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1845
1846defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1847defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1848
1849
1850defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1851defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1852defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1853defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1854defm PSADBW : PDI_binop_rm_int<0xE0, "psadbw", int_x86_sse2_psad_bw, 1>;
1855
1856
Evan Chengd1045a62008-02-18 23:04:32 +00001857defm PSLLW : PDI_binop_rm_int<0xF1, "psllw", int_x86_sse2_psll_w>;
1858defm PSLLD : PDI_binop_rm_int<0xF2, "pslld", int_x86_sse2_psll_d>;
1859defm PSLLQ : PDI_binop_rm_int<0xF3, "psllq", int_x86_sse2_psll_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001860
Evan Chengd1045a62008-02-18 23:04:32 +00001861defm PSRLW : PDI_binop_rm_int<0xD1, "psrlw", int_x86_sse2_psrl_w>;
1862defm PSRLD : PDI_binop_rm_int<0xD2, "psrld", int_x86_sse2_psrl_d>;
1863defm PSRLQ : PDI_binop_rm_int<0xD3, "psrlq", int_x86_sse2_psrl_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864
Evan Chengd1045a62008-02-18 23:04:32 +00001865defm PSRAW : PDI_binop_rm_int<0xE1, "psraw", int_x86_sse2_psra_w>;
1866defm PSRAD : PDI_binop_rm_int<0xE2, "psrad", int_x86_sse2_psra_d>;
1867
1868// Some immediate variants need to match a bit_convert.
Evan Cheng88004752008-03-05 08:11:27 +00001869let Constraints = "$src1 = $dst" in {
Evan Chengd1045a62008-02-18 23:04:32 +00001870def PSLLWri : PDIi8<0x71, MRM6r, (outs VR128:$dst),
1871 (ins VR128:$src1, i32i8imm:$src2),
1872 "psllw\t{$src2, $dst|$dst, $src2}",
1873 [(set VR128:$dst, (int_x86_sse2_psll_w VR128:$src1,
1874 (bc_v8i16 (v4i32 (scalar_to_vector (i32 imm:$src2))))))]>;
1875def PSLLDri : PDIi8<0x72, MRM6r, (outs VR128:$dst),
1876 (ins VR128:$src1, i32i8imm:$src2),
1877 "pslld\t{$src2, $dst|$dst, $src2}",
1878 [(set VR128:$dst, (int_x86_sse2_psll_d VR128:$src1,
1879 (scalar_to_vector (i32 imm:$src2))))]>;
1880def PSLLQri : PDIi8<0x73, MRM6r, (outs VR128:$dst),
1881 (ins VR128:$src1, i32i8imm:$src2),
1882 "psllq\t{$src2, $dst|$dst, $src2}",
1883 [(set VR128:$dst, (int_x86_sse2_psll_q VR128:$src1,
1884 (bc_v2i64 (v4i32 (scalar_to_vector (i32 imm:$src2))))))]>;
1885
1886def PSRLWri : PDIi8<0x71, MRM2r, (outs VR128:$dst),
1887 (ins VR128:$src1, i32i8imm:$src2),
1888 "psrlw\t{$src2, $dst|$dst, $src2}",
1889 [(set VR128:$dst, (int_x86_sse2_psrl_w VR128:$src1,
1890 (bc_v8i16 (v4i32 (scalar_to_vector (i32 imm:$src2))))))]>;
1891def PSRLDri : PDIi8<0x72, MRM2r, (outs VR128:$dst),
1892 (ins VR128:$src1, i32i8imm:$src2),
1893 "psrld\t{$src2, $dst|$dst, $src2}",
1894 [(set VR128:$dst, (int_x86_sse2_psrl_d VR128:$src1,
1895 (scalar_to_vector (i32 imm:$src2))))]>;
1896def PSRLQri : PDIi8<0x73, MRM2r, (outs VR128:$dst),
1897 (ins VR128:$src1, i32i8imm:$src2),
1898 "psrlq\t{$src2, $dst|$dst, $src2}",
1899 [(set VR128:$dst, (int_x86_sse2_psrl_q VR128:$src1,
1900 (bc_v2i64 (v4i32 (scalar_to_vector (i32 imm:$src2))))))]>;
1901
1902def PSRAWri : PDIi8<0x71, MRM4r, (outs VR128:$dst),
1903 (ins VR128:$src1, i32i8imm:$src2),
1904 "psraw\t{$src2, $dst|$dst, $src2}",
1905 [(set VR128:$dst, (int_x86_sse2_psra_w VR128:$src1,
1906 (bc_v8i16 (v4i32 (scalar_to_vector (i32 imm:$src2))))))]>;
1907def PSRADri : PDIi8<0x72, MRM4r, (outs VR128:$dst),
1908 (ins VR128:$src1, i32i8imm:$src2),
1909 "psrad\t{$src2, $dst|$dst, $src2}",
1910 [(set VR128:$dst, (int_x86_sse2_psra_d VR128:$src1,
1911 (scalar_to_vector (i32 imm:$src2))))]>;
Evan Cheng88004752008-03-05 08:11:27 +00001912}
Evan Chengd1045a62008-02-18 23:04:32 +00001913
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914// PSRAQ doesn't exist in SSE[1-3].
1915
1916// 128-bit logical shifts.
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00001917let isTwoAddress = 1, neverHasSideEffects = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001918 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001919 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001920 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001922 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001923 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001924 // PSRADQri doesn't exist in SSE[1-3].
1925}
1926
1927let Predicates = [HasSSE2] in {
1928 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1929 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1930 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1931 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1932 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1933 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1934}
1935
1936// Logical
1937defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1938defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1939defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1940
1941let isTwoAddress = 1 in {
1942 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001943 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001944 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001945 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1946 VR128:$src2)))]>;
1947
1948 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001949 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001950 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001951 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7dc19012007-08-02 21:17:01 +00001952 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001953}
1954
1955// SSE2 Integer comparison
1956defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
1957defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
1958defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
1959defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
1960defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
1961defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
1962
1963// Pack instructions
1964defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
1965defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
1966defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
1967
1968// Shuffle and unpack instructions
1969def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001970 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001971 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001972 [(set VR128:$dst, (v4i32 (vector_shuffle
1973 VR128:$src1, (undef),
1974 PSHUFD_shuffle_mask:$src2)))]>;
1975def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001976 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001977 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001978 [(set VR128:$dst, (v4i32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001979 (bc_v4i32(memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001980 (undef),
1981 PSHUFD_shuffle_mask:$src2)))]>;
1982
1983// SSE2 with ImmT == Imm8 and XS prefix.
1984def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001985 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001986 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001987 [(set VR128:$dst, (v8i16 (vector_shuffle
1988 VR128:$src1, (undef),
1989 PSHUFHW_shuffle_mask:$src2)))]>,
1990 XS, Requires<[HasSSE2]>;
1991def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001992 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001993 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001994 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001995 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001996 (undef),
1997 PSHUFHW_shuffle_mask:$src2)))]>,
1998 XS, Requires<[HasSSE2]>;
1999
2000// SSE2 with ImmT == Imm8 and XD prefix.
2001def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002002 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002003 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002004 [(set VR128:$dst, (v8i16 (vector_shuffle
2005 VR128:$src1, (undef),
2006 PSHUFLW_shuffle_mask:$src2)))]>,
2007 XD, Requires<[HasSSE2]>;
2008def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002009 (outs VR128:$dst), (ins i128mem:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002010 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002011 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002012 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002013 (undef),
2014 PSHUFLW_shuffle_mask:$src2)))]>,
2015 XD, Requires<[HasSSE2]>;
2016
2017
2018let isTwoAddress = 1 in {
2019 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002020 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002021 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002022 [(set VR128:$dst,
2023 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
2024 UNPCKL_shuffle_mask)))]>;
2025 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002026 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002027 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002028 [(set VR128:$dst,
2029 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002030 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002031 UNPCKL_shuffle_mask)))]>;
2032 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002033 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002034 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002035 [(set VR128:$dst,
2036 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
2037 UNPCKL_shuffle_mask)))]>;
2038 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002039 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002040 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002041 [(set VR128:$dst,
2042 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002043 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002044 UNPCKL_shuffle_mask)))]>;
2045 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002046 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002047 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002048 [(set VR128:$dst,
2049 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2050 UNPCKL_shuffle_mask)))]>;
2051 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002052 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002053 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002054 [(set VR128:$dst,
2055 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002056 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002057 UNPCKL_shuffle_mask)))]>;
2058 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002059 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002060 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002061 [(set VR128:$dst,
2062 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2063 UNPCKL_shuffle_mask)))]>;
2064 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002065 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002066 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002067 [(set VR128:$dst,
2068 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002069 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002070 UNPCKL_shuffle_mask)))]>;
2071
2072 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002073 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002074 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002075 [(set VR128:$dst,
2076 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
2077 UNPCKH_shuffle_mask)))]>;
2078 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002079 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002080 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002081 [(set VR128:$dst,
2082 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002083 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002084 UNPCKH_shuffle_mask)))]>;
2085 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002086 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002087 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002088 [(set VR128:$dst,
2089 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
2090 UNPCKH_shuffle_mask)))]>;
2091 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002092 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002093 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002094 [(set VR128:$dst,
2095 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002096 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002097 UNPCKH_shuffle_mask)))]>;
2098 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002099 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002100 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002101 [(set VR128:$dst,
2102 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2103 UNPCKH_shuffle_mask)))]>;
2104 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002105 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002106 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002107 [(set VR128:$dst,
2108 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002109 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002110 UNPCKH_shuffle_mask)))]>;
2111 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002112 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002113 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002114 [(set VR128:$dst,
2115 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2116 UNPCKH_shuffle_mask)))]>;
2117 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002118 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002119 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002120 [(set VR128:$dst,
2121 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002122 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002123 UNPCKH_shuffle_mask)))]>;
2124}
2125
2126// Extract / Insert
2127def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002128 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002129 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002130 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
Nate Begemand77e59e2008-02-11 04:19:36 +00002131 imm:$src2))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002132let isTwoAddress = 1 in {
2133 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002134 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002135 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002136 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002137 [(set VR128:$dst,
Nate Begemand77e59e2008-02-11 04:19:36 +00002138 (X86pinsrw VR128:$src1, GR32:$src2, imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002139 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002140 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002141 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002142 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Nate Begemand77e59e2008-02-11 04:19:36 +00002143 [(set VR128:$dst,
2144 (X86pinsrw VR128:$src1, (extloadi16 addr:$src2),
2145 imm:$src3))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002146}
2147
2148// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00002149def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002150 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002151 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2152
2153// Conditional store
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002154let Uses = [EDI] in
Evan Chengb783fa32007-07-19 01:14:50 +00002155def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00002156 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002157 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002158
2159// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00002160def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002161 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002162 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002163def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002164 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002165 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002166def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002167 "movnti\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002168 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2169 TB, Requires<[HasSSE2]>;
2170
2171// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002172def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002173 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002174 TB, Requires<[HasSSE2]>;
2175
2176// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +00002177def LFENCE : I<0xAE, MRM5m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002178 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002179def MFENCE : I<0xAE, MRM6m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002180 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2181
Andrew Lenharth785610d2008-02-16 01:24:58 +00002182//TODO: custom lower this so as to never even generate the noop
2183def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
2184 (i8 0)), (NOOP)>;
2185def : Pat<(membarrier (i8 0), (i8 0), (i8 0), (i8 1), (i8 1)), (SFENCE)>;
2186def : Pat<(membarrier (i8 1), (i8 0), (i8 0), (i8 0), (i8 1)), (LFENCE)>;
2187def : Pat<(membarrier (i8 imm:$ll), (i8 imm:$ls), (i8 imm:$sl), (i8 imm:$ss),
2188 (i8 1)), (MFENCE)>;
2189
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002190// Alias instructions that map zero vector to pxor / xorp* for sse.
Chris Lattner17dab4a2008-01-10 05:45:39 +00002191let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002192 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002193 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +00002194 [(set VR128:$dst, (v4i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002195
2196// FR64 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +00002197def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002198 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002199 [(set VR128:$dst,
2200 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002201def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002202 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002203 [(set VR128:$dst,
2204 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2205
Evan Chengb783fa32007-07-19 01:14:50 +00002206def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002207 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002208 [(set VR128:$dst,
2209 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002210def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002211 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002212 [(set VR128:$dst,
2213 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2214
Evan Chengb783fa32007-07-19 01:14:50 +00002215def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002216 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002217 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2218
Evan Chengb783fa32007-07-19 01:14:50 +00002219def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002220 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002221 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2222
2223// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002224def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002225 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002226 [(set VR128:$dst,
2227 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2228 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002229def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002230 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002231 [(store (i64 (vector_extract (v2i64 VR128:$src),
2232 (iPTR 0))), addr:$dst)]>;
2233
2234// FIXME: may not be able to eliminate this movss with coalescing the src and
2235// dest register classes are different. We really want to write this pattern
2236// like this:
2237// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2238// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +00002239def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002240 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002241 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2242 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002243def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002244 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002245 [(store (f64 (vector_extract (v2f64 VR128:$src),
2246 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002247def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002248 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002249 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2250 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002251def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002252 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002253 [(store (i32 (vector_extract (v4i32 VR128:$src),
2254 (iPTR 0))), addr:$dst)]>;
2255
Evan Chengb783fa32007-07-19 01:14:50 +00002256def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002257 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002258 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002259def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002260 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002261 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2262
2263
2264// Move to lower bits of a VR128, leaving upper bits alone.
2265// Three operand (but two address) aliases.
2266let isTwoAddress = 1 in {
Chris Lattnerd1a9eb62008-01-11 06:59:07 +00002267 let neverHasSideEffects = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002268 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002269 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002270 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002271
2272 let AddedComplexity = 15 in
2273 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002274 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002275 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002276 [(set VR128:$dst,
2277 (v2f64 (vector_shuffle VR128:$src1, VR128:$src2,
2278 MOVL_shuffle_mask)))]>;
2279}
2280
2281// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002282def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002283 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002284 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2285
2286// Move to lower bits of a VR128 and zeroing upper bits.
2287// Loading from memory automatically zeroing upper bits.
2288let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002289 def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002290 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002291 [(set VR128:$dst,
Chris Lattnere6aa3862007-11-25 00:24:49 +00002292 (v2f64 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002293 (v2f64 (scalar_to_vector
2294 (loadf64 addr:$src))),
2295 MOVL_shuffle_mask)))]>;
2296
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002297// movd / movq to XMM register zero-extends
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002298let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002299def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002300 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002301 [(set VR128:$dst,
2302 (v4i32 (vector_shuffle immAllZerosV,
2303 (v4i32 (scalar_to_vector GR32:$src)),
2304 MOVL_shuffle_mask)))]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002305// This is X86-64 only.
2306def MOVZQI2PQIrr : RPDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR64:$src),
2307 "mov{d|q}\t{$src, $dst|$dst, $src}",
2308 [(set VR128:$dst,
2309 (v2i64 (vector_shuffle immAllZerosV_bc,
2310 (v2i64 (scalar_to_vector GR64:$src)),
2311 MOVL_shuffle_mask)))]>;
2312}
2313
2314let AddedComplexity = 20 in {
Evan Chengb783fa32007-07-19 01:14:50 +00002315def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002316 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002317 [(set VR128:$dst,
2318 (v4i32 (vector_shuffle immAllZerosV,
2319 (v4i32 (scalar_to_vector (loadi32 addr:$src))),
2320 MOVL_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002321def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002322 "movq\t{$src, $dst|$dst, $src}",
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002323 [(set VR128:$dst,
2324 (v2i64 (vector_shuffle immAllZerosV_bc,
2325 (v2i64 (scalar_to_vector (loadi64 addr:$src))),
2326 MOVL_shuffle_mask)))]>, XS,
2327 Requires<[HasSSE2]>;
2328}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002329
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002330// Moving from XMM to XMM and clear upper 64 bits. Note, there is a bug in
2331// IA32 document. movq xmm1, xmm2 does clear the high bits.
2332let AddedComplexity = 15 in
2333def MOVZPQILo2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
2334 "movq\t{$src, $dst|$dst, $src}",
2335 [(set VR128:$dst, (v2i64 (vector_shuffle immAllZerosV_bc,
2336 VR128:$src,
2337 MOVL_shuffle_mask)))]>,
2338 XS, Requires<[HasSSE2]>;
2339
2340let AddedComplexity = 20 in
2341def MOVZPQILo2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
2342 "movq\t{$src, $dst|$dst, $src}",
2343 [(set VR128:$dst, (v2i64 (vector_shuffle immAllZerosV_bc,
2344 (memopv2i64 addr:$src),
2345 MOVL_shuffle_mask)))]>,
2346 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002347
2348//===----------------------------------------------------------------------===//
2349// SSE3 Instructions
2350//===----------------------------------------------------------------------===//
2351
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002352// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002353def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002354 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002355 [(set VR128:$dst, (v4f32 (vector_shuffle
2356 VR128:$src, (undef),
2357 MOVSHDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002358def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002359 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002360 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002361 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002362 MOVSHDUP_shuffle_mask)))]>;
2363
Evan Chengb783fa32007-07-19 01:14:50 +00002364def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002365 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002366 [(set VR128:$dst, (v4f32 (vector_shuffle
2367 VR128:$src, (undef),
2368 MOVSLDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002369def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002370 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002371 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002372 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002373 MOVSLDUP_shuffle_mask)))]>;
2374
Evan Chengb783fa32007-07-19 01:14:50 +00002375def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002376 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002377 [(set VR128:$dst, (v2f64 (vector_shuffle
2378 VR128:$src, (undef),
2379 SSE_splat_lo_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002380def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002381 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002382 [(set VR128:$dst,
2383 (v2f64 (vector_shuffle
2384 (scalar_to_vector (loadf64 addr:$src)),
2385 (undef),
2386 SSE_splat_lo_mask)))]>;
2387
2388// Arithmetic
2389let isTwoAddress = 1 in {
2390 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002391 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002392 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002393 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2394 VR128:$src2))]>;
2395 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002396 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002397 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002398 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2399 (load addr:$src2)))]>;
2400 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002401 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002402 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002403 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2404 VR128:$src2))]>;
2405 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002406 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002407 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002408 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2409 (load addr:$src2)))]>;
2410}
2411
Evan Chengb783fa32007-07-19 01:14:50 +00002412def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002413 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002414 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2415
2416// Horizontal ops
2417class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002418 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002419 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002420 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2421class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002422 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002423 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002424 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (load addr:$src2))))]>;
2425class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002426 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002427 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002428 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2429class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002430 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002431 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002432 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (load addr:$src2))))]>;
2433
2434let isTwoAddress = 1 in {
2435 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2436 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2437 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2438 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2439 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2440 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2441 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2442 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2443}
2444
2445// Thread synchronization
Evan Chengb783fa32007-07-19 01:14:50 +00002446def MONITOR : I<0xC8, RawFrm, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002447 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002448def MWAIT : I<0xC9, RawFrm, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002449 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2450
2451// vector_shuffle v1, <undef> <1, 1, 3, 3>
2452let AddedComplexity = 15 in
2453def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2454 MOVSHDUP_shuffle_mask)),
2455 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2456let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002457def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002458 MOVSHDUP_shuffle_mask)),
2459 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2460
2461// vector_shuffle v1, <undef> <0, 0, 2, 2>
2462let AddedComplexity = 15 in
2463 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2464 MOVSLDUP_shuffle_mask)),
2465 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2466let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002467 def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002468 MOVSLDUP_shuffle_mask)),
2469 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2470
2471//===----------------------------------------------------------------------===//
2472// SSSE3 Instructions
2473//===----------------------------------------------------------------------===//
2474
Bill Wendling98680292007-08-10 06:22:27 +00002475/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002476multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2477 Intrinsic IntId64, Intrinsic IntId128> {
2478 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2479 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2480 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002481
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002482 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2483 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2484 [(set VR64:$dst,
2485 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2486
2487 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2488 (ins VR128:$src),
2489 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2490 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2491 OpSize;
2492
2493 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2494 (ins i128mem:$src),
2495 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2496 [(set VR128:$dst,
2497 (IntId128
2498 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002499}
2500
Bill Wendling98680292007-08-10 06:22:27 +00002501/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002502multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2503 Intrinsic IntId64, Intrinsic IntId128> {
2504 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2505 (ins VR64:$src),
2506 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2507 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002508
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002509 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2510 (ins i64mem:$src),
2511 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2512 [(set VR64:$dst,
2513 (IntId64
2514 (bitconvert (memopv4i16 addr:$src))))]>;
2515
2516 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2517 (ins VR128:$src),
2518 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2519 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2520 OpSize;
2521
2522 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2523 (ins i128mem:$src),
2524 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2525 [(set VR128:$dst,
2526 (IntId128
2527 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002528}
2529
2530/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002531multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2532 Intrinsic IntId64, Intrinsic IntId128> {
2533 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2534 (ins VR64:$src),
2535 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2536 [(set VR64:$dst, (IntId64 VR64:$src))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002537
Nate Begeman9a58b8a2008-02-09 23:46:37 +00002538 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2539 (ins i64mem:$src),
2540 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2541 [(set VR64:$dst,
2542 (IntId64
2543 (bitconvert (memopv2i32 addr:$src))))]>;
2544
2545 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2546 (ins VR128:$src),
2547 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2548 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2549 OpSize;
2550
2551 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2552 (ins i128mem:$src),
2553 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2554 [(set VR128:$dst,
2555 (IntId128
2556 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002557}
2558
2559defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2560 int_x86_ssse3_pabs_b,
2561 int_x86_ssse3_pabs_b_128>;
2562defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2563 int_x86_ssse3_pabs_w,
2564 int_x86_ssse3_pabs_w_128>;
2565defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2566 int_x86_ssse3_pabs_d,
2567 int_x86_ssse3_pabs_d_128>;
2568
2569/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2570let isTwoAddress = 1 in {
2571 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2572 Intrinsic IntId64, Intrinsic IntId128,
2573 bit Commutable = 0> {
2574 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2575 (ins VR64:$src1, VR64:$src2),
2576 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2577 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2578 let isCommutable = Commutable;
2579 }
2580 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2581 (ins VR64:$src1, i64mem:$src2),
2582 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2583 [(set VR64:$dst,
2584 (IntId64 VR64:$src1,
2585 (bitconvert (memopv8i8 addr:$src2))))]>;
2586
2587 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2588 (ins VR128:$src1, VR128:$src2),
2589 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2590 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2591 OpSize {
2592 let isCommutable = Commutable;
2593 }
2594 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2595 (ins VR128:$src1, i128mem:$src2),
2596 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2597 [(set VR128:$dst,
2598 (IntId128 VR128:$src1,
2599 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2600 }
2601}
2602
2603/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2604let isTwoAddress = 1 in {
2605 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2606 Intrinsic IntId64, Intrinsic IntId128,
2607 bit Commutable = 0> {
2608 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2609 (ins VR64:$src1, VR64:$src2),
2610 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2611 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2612 let isCommutable = Commutable;
2613 }
2614 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2615 (ins VR64:$src1, i64mem:$src2),
2616 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2617 [(set VR64:$dst,
2618 (IntId64 VR64:$src1,
2619 (bitconvert (memopv4i16 addr:$src2))))]>;
2620
2621 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2622 (ins VR128:$src1, VR128:$src2),
2623 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2624 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2625 OpSize {
2626 let isCommutable = Commutable;
2627 }
2628 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2629 (ins VR128:$src1, i128mem:$src2),
2630 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2631 [(set VR128:$dst,
2632 (IntId128 VR128:$src1,
2633 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2634 }
2635}
2636
2637/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2638let isTwoAddress = 1 in {
2639 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2640 Intrinsic IntId64, Intrinsic IntId128,
2641 bit Commutable = 0> {
2642 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2643 (ins VR64:$src1, VR64:$src2),
2644 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2645 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2646 let isCommutable = Commutable;
2647 }
2648 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2649 (ins VR64:$src1, i64mem:$src2),
2650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2651 [(set VR64:$dst,
2652 (IntId64 VR64:$src1,
2653 (bitconvert (memopv2i32 addr:$src2))))]>;
2654
2655 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2656 (ins VR128:$src1, VR128:$src2),
2657 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2658 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2659 OpSize {
2660 let isCommutable = Commutable;
2661 }
2662 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2663 (ins VR128:$src1, i128mem:$src2),
2664 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2665 [(set VR128:$dst,
2666 (IntId128 VR128:$src1,
2667 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2668 }
2669}
2670
2671defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2672 int_x86_ssse3_phadd_w,
2673 int_x86_ssse3_phadd_w_128, 1>;
2674defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2675 int_x86_ssse3_phadd_d,
2676 int_x86_ssse3_phadd_d_128, 1>;
2677defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2678 int_x86_ssse3_phadd_sw,
2679 int_x86_ssse3_phadd_sw_128, 1>;
2680defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2681 int_x86_ssse3_phsub_w,
2682 int_x86_ssse3_phsub_w_128>;
2683defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2684 int_x86_ssse3_phsub_d,
2685 int_x86_ssse3_phsub_d_128>;
2686defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2687 int_x86_ssse3_phsub_sw,
2688 int_x86_ssse3_phsub_sw_128>;
2689defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2690 int_x86_ssse3_pmadd_ub_sw,
2691 int_x86_ssse3_pmadd_ub_sw_128, 1>;
2692defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2693 int_x86_ssse3_pmul_hr_sw,
2694 int_x86_ssse3_pmul_hr_sw_128, 1>;
2695defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2696 int_x86_ssse3_pshuf_b,
2697 int_x86_ssse3_pshuf_b_128>;
2698defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2699 int_x86_ssse3_psign_b,
2700 int_x86_ssse3_psign_b_128>;
2701defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2702 int_x86_ssse3_psign_w,
2703 int_x86_ssse3_psign_w_128>;
2704defm PSIGND : SS3I_binop_rm_int_32<0x09, "psignd",
2705 int_x86_ssse3_psign_d,
2706 int_x86_ssse3_psign_d_128>;
2707
2708let isTwoAddress = 1 in {
Bill Wendling1dc817c2007-08-10 09:00:17 +00002709 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2710 (ins VR64:$src1, VR64:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002711 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002712 [(set VR64:$dst,
2713 (int_x86_ssse3_palign_r
2714 VR64:$src1, VR64:$src2,
2715 imm:$src3))]>;
2716 def PALIGNR64rm : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2717 (ins VR64:$src1, i64mem:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002718 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002719 [(set VR64:$dst,
2720 (int_x86_ssse3_palign_r
2721 VR64:$src1,
2722 (bitconvert (memopv2i32 addr:$src2)),
2723 imm:$src3))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002724
Bill Wendling1dc817c2007-08-10 09:00:17 +00002725 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2726 (ins VR128:$src1, VR128:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002727 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002728 [(set VR128:$dst,
2729 (int_x86_ssse3_palign_r_128
2730 VR128:$src1, VR128:$src2,
2731 imm:$src3))]>, OpSize;
2732 def PALIGNR128rm : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2733 (ins VR128:$src1, i128mem:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002734 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002735 [(set VR128:$dst,
2736 (int_x86_ssse3_palign_r_128
2737 VR128:$src1,
2738 (bitconvert (memopv4i32 addr:$src2)),
2739 imm:$src3))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002740}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002741
2742//===----------------------------------------------------------------------===//
2743// Non-Instruction Patterns
2744//===----------------------------------------------------------------------===//
2745
2746// 128-bit vector undef's.
Bill Wendling1dc817c2007-08-10 09:00:17 +00002747def : Pat<(v4f32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002748def : Pat<(v2f64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2749def : Pat<(v16i8 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2750def : Pat<(v8i16 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2751def : Pat<(v4i32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2752def : Pat<(v2i64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2753
Chris Lattnerdec9cb52008-01-24 08:07:48 +00002754// extload f32 -> f64. This matches load+fextend because we have a hack in
2755// the isel (PreprocessForFPConvert) that can introduce loads after dag combine.
2756// Since these loads aren't folded into the fextend, we have to match it
2757// explicitly here.
2758let Predicates = [HasSSE2] in
2759 def : Pat<(fextend (loadf32 addr:$src)),
2760 (CVTSS2SDrm addr:$src)>;
2761
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002762// bit_convert
2763let Predicates = [HasSSE2] in {
2764 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2765 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2766 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2767 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2768 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2769 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2770 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2771 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2772 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2773 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2774 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2775 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2776 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2777 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2778 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2779 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2780 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2781 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2782 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2783 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2784 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2785 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2786 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2787 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2788 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2789 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2790 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2791 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2792 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2793 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2794}
2795
2796// Move scalar to XMM zero-extended
2797// movd to XMM register zero-extends
2798let AddedComplexity = 15 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002799// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
Chris Lattnere6aa3862007-11-25 00:24:49 +00002800def : Pat<(v2f64 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002801 (v2f64 (scalar_to_vector FR64:$src)), MOVL_shuffle_mask)),
2802 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
Chris Lattnere6aa3862007-11-25 00:24:49 +00002803def : Pat<(v4f32 (vector_shuffle immAllZerosV_bc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002804 (v4f32 (scalar_to_vector FR32:$src)), MOVL_shuffle_mask)),
2805 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE2]>;
2806}
2807
2808// Splat v2f64 / v2i64
2809let AddedComplexity = 10 in {
2810def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2811 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2812def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2813 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2814def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2815 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2816def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2817 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2818}
2819
2820// Splat v4f32
2821def : Pat<(vector_shuffle (v4f32 VR128:$src), (undef), SSE_splat_mask:$sm),
2822 (SHUFPSrri VR128:$src, VR128:$src, SSE_splat_mask:$sm)>,
2823 Requires<[HasSSE1]>;
2824
2825// Special unary SHUFPSrri case.
2826// FIXME: when we want non two-address code, then we should use PSHUFD?
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002827def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2828 SHUFP_unary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002829 (SHUFPSrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2830 Requires<[HasSSE1]>;
Dan Gohman7dc19012007-08-02 21:17:01 +00002831// Special unary SHUFPDrri case.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002832def : Pat<(v2f64 (vector_shuffle VR128:$src1, (undef),
2833 SHUFP_unary_shuffle_mask:$sm)),
Dan Gohman7dc19012007-08-02 21:17:01 +00002834 (SHUFPDrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2835 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002836// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Dan Gohman4a4f1512007-07-18 20:23:34 +00002837def : Pat<(vector_shuffle (memopv4f32 addr:$src1), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002838 SHUFP_unary_shuffle_mask:$sm),
2839 (PSHUFDmi addr:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2840 Requires<[HasSSE2]>;
2841// Special binary v4i32 shuffle cases with SHUFPS.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002842def : Pat<(v4i32 (vector_shuffle VR128:$src1, (v4i32 VR128:$src2),
2843 PSHUFD_binary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002844 (SHUFPSrri VR128:$src1, VR128:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2845 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002846def : Pat<(v4i32 (vector_shuffle VR128:$src1,
2847 (bc_v4i32 (memopv2i64 addr:$src2)), PSHUFD_binary_shuffle_mask:$sm)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002848 (SHUFPSrmi VR128:$src1, addr:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2849 Requires<[HasSSE2]>;
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002850// Special binary v2i64 shuffle cases using SHUFPDrri.
2851def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2852 SHUFP_shuffle_mask:$sm)),
2853 (SHUFPDrri VR128:$src1, VR128:$src2, SHUFP_shuffle_mask:$sm)>,
2854 Requires<[HasSSE2]>;
2855// Special unary SHUFPDrri case.
2856def : Pat<(v2i64 (vector_shuffle VR128:$src1, (undef),
2857 SHUFP_unary_shuffle_mask:$sm)),
2858 (SHUFPDrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2859 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002860
2861// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2862let AddedComplexity = 10 in {
2863def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2864 UNPCKL_v_undef_shuffle_mask)),
2865 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2866def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2867 UNPCKL_v_undef_shuffle_mask)),
2868 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2869def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2870 UNPCKL_v_undef_shuffle_mask)),
2871 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2872def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2873 UNPCKL_v_undef_shuffle_mask)),
2874 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2875}
2876
2877// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2878let AddedComplexity = 10 in {
2879def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2880 UNPCKH_v_undef_shuffle_mask)),
2881 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2882def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2883 UNPCKH_v_undef_shuffle_mask)),
2884 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2885def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2886 UNPCKH_v_undef_shuffle_mask)),
2887 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2888def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2889 UNPCKH_v_undef_shuffle_mask)),
2890 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2891}
2892
2893let AddedComplexity = 15 in {
2894// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2895def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2896 MOVHP_shuffle_mask)),
2897 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2898
2899// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2900def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2901 MOVHLPS_shuffle_mask)),
2902 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2903
2904// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2905def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2906 MOVHLPS_v_undef_shuffle_mask)),
2907 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2908def : Pat<(v4i32 (vector_shuffle VR128:$src1, (undef),
2909 MOVHLPS_v_undef_shuffle_mask)),
2910 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2911}
2912
2913let AddedComplexity = 20 in {
2914// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2915// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Dan Gohman4a4f1512007-07-18 20:23:34 +00002916def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002917 MOVLP_shuffle_mask)),
2918 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002919def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002920 MOVLP_shuffle_mask)),
2921 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002922def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002923 MOVHP_shuffle_mask)),
2924 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002925def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002926 MOVHP_shuffle_mask)),
2927 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2928
Dan Gohman4a4f1512007-07-18 20:23:34 +00002929def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002930 MOVLP_shuffle_mask)),
2931 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002932def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002933 MOVLP_shuffle_mask)),
2934 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002935def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002936 MOVHP_shuffle_mask)),
2937 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002938def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002939 MOVLP_shuffle_mask)),
2940 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2941}
2942
2943let AddedComplexity = 15 in {
2944// Setting the lowest element in the vector.
2945def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2946 MOVL_shuffle_mask)),
2947 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2948def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2949 MOVL_shuffle_mask)),
2950 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2951
2952// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
2953def : Pat<(v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
2954 MOVLP_shuffle_mask)),
2955 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2956def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2957 MOVLP_shuffle_mask)),
2958 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2959}
2960
2961// Set lowest element and zero upper elements.
Evan Cheng15e8f5a2007-12-15 03:00:47 +00002962let AddedComplexity = 15 in
2963def : Pat<(v2f64 (vector_shuffle immAllZerosV_bc, VR128:$src,
2964 MOVL_shuffle_mask)),
2965 (MOVZPQILo2PQIrr VR128:$src)>, Requires<[HasSSE2]>;
2966
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002967
2968// FIXME: Temporary workaround since 2-wide shuffle is broken.
2969def : Pat<(int_x86_sse2_movs_d VR128:$src1, VR128:$src2),
2970 (v2f64 (MOVLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2971def : Pat<(int_x86_sse2_loadh_pd VR128:$src1, addr:$src2),
2972 (v2f64 (MOVHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2973def : Pat<(int_x86_sse2_loadl_pd VR128:$src1, addr:$src2),
2974 (v2f64 (MOVLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2975def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, VR128:$src2, imm:$src3),
2976 (v2f64 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$src3))>,
2977 Requires<[HasSSE2]>;
2978def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, (load addr:$src2), imm:$src3),
2979 (v2f64 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$src3))>,
2980 Requires<[HasSSE2]>;
2981def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, VR128:$src2),
2982 (v2f64 (UNPCKHPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2983def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, (load addr:$src2)),
2984 (v2f64 (UNPCKHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2985def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, VR128:$src2),
2986 (v2f64 (UNPCKLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2987def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, (load addr:$src2)),
2988 (v2f64 (UNPCKLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2989def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, VR128:$src2),
2990 (v2i64 (PUNPCKHQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2991def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, (load addr:$src2)),
2992 (v2i64 (PUNPCKHQDQrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2993def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, VR128:$src2),
2994 (v2i64 (PUNPCKLQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2995def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, (load addr:$src2)),
2996 (PUNPCKLQDQrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2997
2998// Some special case pandn patterns.
2999def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
3000 VR128:$src2)),
3001 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3002def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
3003 VR128:$src2)),
3004 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3005def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
3006 VR128:$src2)),
3007 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
3008
3009def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00003010 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003011 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3012def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00003013 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003014 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3015def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00003016 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003017 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
3018
Nate Begeman78246ca2007-11-17 03:58:34 +00003019// vector -> vector casts
3020def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
3021 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
3022def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
3023 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
3024
Evan Cheng51a49b22007-07-20 00:27:43 +00003025// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00003026def : Pat<(alignedloadv4i32 addr:$src),
3027 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
3028def : Pat<(loadv4i32 addr:$src),
3029 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00003030def : Pat<(alignedloadv2i64 addr:$src),
3031 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
3032def : Pat<(loadv2i64 addr:$src),
3033 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
3034
3035def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
3036 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3037def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
3038 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3039def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
3040 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3041def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
3042 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3043def : Pat<(store (v2i64 VR128:$src), addr:$dst),
3044 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3045def : Pat<(store (v4i32 VR128:$src), addr:$dst),
3046 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3047def : Pat<(store (v8i16 VR128:$src), addr:$dst),
3048 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3049def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3050 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
Nate Begemanb2975562008-02-03 07:18:54 +00003051
3052//===----------------------------------------------------------------------===//
3053// SSE4.1 Instructions
3054//===----------------------------------------------------------------------===//
3055
Nate Begemanb2975562008-02-03 07:18:54 +00003056multiclass sse41_fp_unop_rm<bits<8> opcss, bits<8> opcps,
3057 bits<8> opcsd, bits<8> opcpd,
3058 string OpcodeStr,
3059 Intrinsic F32Int,
3060 Intrinsic V4F32Int,
3061 Intrinsic F64Int,
Nate Begemaneb3f5432008-02-04 05:34:34 +00003062 Intrinsic V2F64Int> {
Nate Begemanb2975562008-02-03 07:18:54 +00003063 // Intrinsic operation, reg.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003064 def SSr_Int : SS4AI<opcss, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003065 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003066 !strconcat(OpcodeStr,
3067 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003068 [(set VR128:$dst, (F32Int VR128:$src1, imm:$src2))]>,
3069 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003070
3071 // Intrinsic operation, mem.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003072 def SSm_Int : SS4AI<opcss, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003073 (outs VR128:$dst), (ins ssmem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003074 !strconcat(OpcodeStr,
3075 "ss\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003076 [(set VR128:$dst, (F32Int sse_load_f32:$src1, imm:$src2))]>,
3077 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003078
3079 // Vector intrinsic operation, reg
Nate Begemaneb3f5432008-02-04 05:34:34 +00003080 def PSr_Int : SS4AI<opcps, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003081 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003082 !strconcat(OpcodeStr,
3083 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003084 [(set VR128:$dst, (V4F32Int VR128:$src1, imm:$src2))]>,
3085 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003086
3087 // Vector intrinsic operation, mem
Nate Begemaneb3f5432008-02-04 05:34:34 +00003088 def PSm_Int : SS4AI<opcps, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003089 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003090 !strconcat(OpcodeStr,
3091 "ps\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003092 [(set VR128:$dst, (V4F32Int (load addr:$src1),imm:$src2))]>,
3093 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003094
3095 // Intrinsic operation, reg.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003096 def SDr_Int : SS4AI<opcsd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003097 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003098 !strconcat(OpcodeStr,
3099 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003100 [(set VR128:$dst, (F64Int VR128:$src1, imm:$src2))]>,
3101 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003102
3103 // Intrinsic operation, mem.
Nate Begemaneb3f5432008-02-04 05:34:34 +00003104 def SDm_Int : SS4AI<opcsd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003105 (outs VR128:$dst), (ins sdmem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003106 !strconcat(OpcodeStr,
3107 "sd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003108 [(set VR128:$dst, (F64Int sse_load_f64:$src1, imm:$src2))]>,
3109 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003110
3111 // Vector intrinsic operation, reg
Nate Begemaneb3f5432008-02-04 05:34:34 +00003112 def PDr_Int : SS4AI<opcpd, MRMSrcReg,
Nate Begeman72d802a2008-02-04 06:00:24 +00003113 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003114 !strconcat(OpcodeStr,
3115 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003116 [(set VR128:$dst, (V2F64Int VR128:$src1, imm:$src2))]>,
3117 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003118
3119 // Vector intrinsic operation, mem
Nate Begemaneb3f5432008-02-04 05:34:34 +00003120 def PDm_Int : SS4AI<opcpd, MRMSrcMem,
Nate Begeman72d802a2008-02-04 06:00:24 +00003121 (outs VR128:$dst), (ins f128mem:$src1, i32i8imm:$src2),
Nate Begemanb2975562008-02-03 07:18:54 +00003122 !strconcat(OpcodeStr,
3123 "pd\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemaneb3f5432008-02-04 05:34:34 +00003124 [(set VR128:$dst, (V2F64Int (load addr:$src1),imm:$src2))]>,
3125 OpSize;
Nate Begemanb2975562008-02-03 07:18:54 +00003126}
3127
3128// FP round - roundss, roundps, roundsd, roundpd
3129defm ROUND : sse41_fp_unop_rm<0x0A, 0x08, 0x0B, 0x09, "round",
3130 int_x86_sse41_round_ss, int_x86_sse41_round_ps,
3131 int_x86_sse41_round_sd, int_x86_sse41_round_pd>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003132
3133// SS41I_unop_rm_int_v16 - SSE 4.1 unary operator whose type is v8i16.
3134multiclass SS41I_unop_rm_int_v16<bits<8> opc, string OpcodeStr,
3135 Intrinsic IntId128> {
3136 def rr128 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3137 (ins VR128:$src),
3138 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3139 [(set VR128:$dst, (IntId128 VR128:$src))]>, OpSize;
3140 def rm128 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3141 (ins i128mem:$src),
3142 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3143 [(set VR128:$dst,
3144 (IntId128
3145 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
3146}
3147
3148defm PHMINPOSUW : SS41I_unop_rm_int_v16 <0x41, "phminposuw",
3149 int_x86_sse41_phminposuw>;
3150
3151/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3152let isTwoAddress = 1 in {
3153 multiclass SS41I_binop_rm_int<bits<8> opc, string OpcodeStr,
3154 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003155 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3156 (ins VR128:$src1, VR128:$src2),
3157 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3158 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3159 OpSize {
Nate Begemaneb3f5432008-02-04 05:34:34 +00003160 let isCommutable = Commutable;
3161 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003162 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3163 (ins VR128:$src1, i128mem:$src2),
3164 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3165 [(set VR128:$dst,
3166 (IntId128 VR128:$src1,
3167 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003168 }
3169}
3170
3171defm PCMPEQQ : SS41I_binop_rm_int<0x29, "pcmpeqq",
3172 int_x86_sse41_pcmpeqq, 1>;
3173defm PACKUSDW : SS41I_binop_rm_int<0x2B, "packusdw",
3174 int_x86_sse41_packusdw, 0>;
3175defm PMINSB : SS41I_binop_rm_int<0x38, "pminsb",
3176 int_x86_sse41_pminsb, 1>;
3177defm PMINSD : SS41I_binop_rm_int<0x39, "pminsd",
3178 int_x86_sse41_pminsd, 1>;
3179defm PMINUD : SS41I_binop_rm_int<0x3B, "pminud",
3180 int_x86_sse41_pminud, 1>;
3181defm PMINUW : SS41I_binop_rm_int<0x3A, "pminuw",
3182 int_x86_sse41_pminuw, 1>;
3183defm PMAXSB : SS41I_binop_rm_int<0x3C, "pmaxsb",
3184 int_x86_sse41_pmaxsb, 1>;
3185defm PMAXSD : SS41I_binop_rm_int<0x3D, "pmaxsd",
3186 int_x86_sse41_pmaxsd, 1>;
3187defm PMAXUD : SS41I_binop_rm_int<0x3F, "pmaxud",
3188 int_x86_sse41_pmaxud, 1>;
3189defm PMAXUW : SS41I_binop_rm_int<0x3E, "pmaxuw",
3190 int_x86_sse41_pmaxuw, 1>;
Nate Begemaneb3f5432008-02-04 05:34:34 +00003191defm PMULDQ : SS41I_binop_rm_int<0x28, "pmuldq",
3192 int_x86_sse41_pmuldq, 1>;
Nate Begeman72d802a2008-02-04 06:00:24 +00003193
Nate Begeman58057962008-02-09 01:38:08 +00003194
3195/// SS41I_binop_rm_int - Simple SSE 4.1 binary operator
3196let isTwoAddress = 1 in {
3197 multiclass SS41I_binop_patint<bits<8> opc, string OpcodeStr, SDNode OpNode,
3198 Intrinsic IntId128, bit Commutable = 0> {
3199 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3200 (ins VR128:$src1, VR128:$src2),
3201 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3202 [(set VR128:$dst, (OpNode (v4i32 VR128:$src1),
3203 VR128:$src2))]>, OpSize {
3204 let isCommutable = Commutable;
3205 }
3206 def rr_int : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3207 (ins VR128:$src1, VR128:$src2),
3208 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3209 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
3210 OpSize {
3211 let isCommutable = Commutable;
3212 }
3213 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3214 (ins VR128:$src1, i128mem:$src2),
3215 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3216 [(set VR128:$dst,
3217 (OpNode VR128:$src1, (memopv4i32 addr:$src2)))]>, OpSize;
3218 def rm_int : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3219 (ins VR128:$src1, i128mem:$src2),
3220 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
3221 [(set VR128:$dst,
3222 (IntId128 VR128:$src1, (memopv4i32 addr:$src2)))]>,
3223 OpSize;
3224 }
3225}
3226defm PMULLD : SS41I_binop_patint<0x40, "pmulld", mul,
3227 int_x86_sse41_pmulld, 1>;
3228
3229
Nate Begeman72d802a2008-02-04 06:00:24 +00003230/// SS41I_binop_rmi_int - SSE 4.1 binary operator with immediate
3231let isTwoAddress = 1 in {
3232 multiclass SS41I_binop_rmi_int<bits<8> opc, string OpcodeStr,
3233 Intrinsic IntId128, bit Commutable = 0> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003234 def rri : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3235 (ins VR128:$src1, VR128:$src2, i32i8imm:$src3),
3236 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003237 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003238 [(set VR128:$dst,
3239 (IntId128 VR128:$src1, VR128:$src2, imm:$src3))]>,
3240 OpSize {
Nate Begeman72d802a2008-02-04 06:00:24 +00003241 let isCommutable = Commutable;
3242 }
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003243 def rmi : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3244 (ins VR128:$src1, i128mem:$src2, i32i8imm:$src3),
3245 !strconcat(OpcodeStr,
Nate Begemanb4e9a042008-02-10 18:47:57 +00003246 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003247 [(set VR128:$dst,
3248 (IntId128 VR128:$src1,
3249 (bitconvert (memopv16i8 addr:$src2)), imm:$src3))]>,
3250 OpSize;
Nate Begeman72d802a2008-02-04 06:00:24 +00003251 }
3252}
3253
3254defm BLENDPS : SS41I_binop_rmi_int<0x0C, "blendps",
3255 int_x86_sse41_blendps, 0>;
3256defm BLENDPD : SS41I_binop_rmi_int<0x0D, "blendpd",
3257 int_x86_sse41_blendpd, 0>;
3258defm PBLENDW : SS41I_binop_rmi_int<0x0E, "pblendw",
3259 int_x86_sse41_pblendw, 0>;
3260defm DPPS : SS41I_binop_rmi_int<0x40, "dpps",
3261 int_x86_sse41_dpps, 1>;
3262defm DPPD : SS41I_binop_rmi_int<0x41, "dppd",
3263 int_x86_sse41_dppd, 1>;
3264defm MPSADBW : SS41I_binop_rmi_int<0x42, "mpsadbw",
3265 int_x86_sse41_mpsadbw, 0>;
Nate Begeman58057962008-02-09 01:38:08 +00003266
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003267
Nate Begemanb4e9a042008-02-10 18:47:57 +00003268/// SS41I_binop_rmi_int - SSE 4.1 binary operator with immediate
Nate Begemand77e59e2008-02-11 04:19:36 +00003269let Uses = [XMM0], isTwoAddress = 1 in {
Nate Begemanb4e9a042008-02-10 18:47:57 +00003270 multiclass SS41I_ternary_int<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3271 def rr0 : SS48I<opc, MRMSrcReg, (outs VR128:$dst),
3272 (ins VR128:$src1, VR128:$src2),
3273 !strconcat(OpcodeStr,
3274 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3275 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2, XMM0))]>,
3276 OpSize;
3277
3278 def rm0 : SS48I<opc, MRMSrcMem, (outs VR128:$dst),
3279 (ins VR128:$src1, i128mem:$src2),
3280 !strconcat(OpcodeStr,
3281 "\t{%xmm0, $src2, $dst|$dst, $src2, %xmm0}"),
3282 [(set VR128:$dst,
3283 (IntId VR128:$src1,
3284 (bitconvert (memopv16i8 addr:$src2)), XMM0))]>, OpSize;
3285 }
3286}
3287
3288defm BLENDVPD : SS41I_ternary_int<0x15, "blendvpd", int_x86_sse41_blendvpd>;
3289defm BLENDVPS : SS41I_ternary_int<0x14, "blendvps", int_x86_sse41_blendvps>;
3290defm PBLENDVB : SS41I_ternary_int<0x10, "pblendvb", int_x86_sse41_pblendvb>;
3291
3292
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003293multiclass SS41I_binop_rm_int8<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3294 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3295 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3296 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3297
3298 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
3299 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3300 [(set VR128:$dst,
3301 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3302}
3303
3304defm PMOVSXBW : SS41I_binop_rm_int8<0x20, "pmovsxbw", int_x86_sse41_pmovsxbw>;
3305defm PMOVSXWD : SS41I_binop_rm_int8<0x23, "pmovsxwd", int_x86_sse41_pmovsxwd>;
3306defm PMOVSXDQ : SS41I_binop_rm_int8<0x25, "pmovsxdq", int_x86_sse41_pmovsxdq>;
3307defm PMOVZXBW : SS41I_binop_rm_int8<0x30, "pmovzxbw", int_x86_sse41_pmovzxbw>;
3308defm PMOVZXWD : SS41I_binop_rm_int8<0x33, "pmovzxwd", int_x86_sse41_pmovzxwd>;
3309defm PMOVZXDQ : SS41I_binop_rm_int8<0x35, "pmovzxdq", int_x86_sse41_pmovzxdq>;
3310
3311multiclass SS41I_binop_rm_int4<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3312 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3313 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3314 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3315
3316 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
3317 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3318 [(set VR128:$dst,
3319 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3320}
3321
3322defm PMOVSXBD : SS41I_binop_rm_int4<0x21, "pmovsxbd", int_x86_sse41_pmovsxbd>;
3323defm PMOVSXWQ : SS41I_binop_rm_int4<0x24, "pmovsxwq", int_x86_sse41_pmovsxwq>;
3324defm PMOVZXBD : SS41I_binop_rm_int4<0x31, "pmovzxbd", int_x86_sse41_pmovzxbd>;
3325defm PMOVZXWQ : SS41I_binop_rm_int4<0x34, "pmovzxwq", int_x86_sse41_pmovzxwq>;
3326
3327multiclass SS41I_binop_rm_int2<bits<8> opc, string OpcodeStr, Intrinsic IntId> {
3328 def rr : SS48I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
3329 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3330 [(set VR128:$dst, (IntId VR128:$src))]>, OpSize;
3331
3332 def rm : SS48I<opc, MRMSrcMem, (outs VR128:$dst), (ins i16mem:$src),
3333 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
3334 [(set VR128:$dst,
3335 (IntId (bitconvert (v4i32 (load addr:$src)))))]>, OpSize;
3336}
3337
3338defm PMOVSXBQ : SS41I_binop_rm_int2<0x22, "pmovsxbq", int_x86_sse41_pmovsxbq>;
3339defm PMOVZXBQ : SS41I_binop_rm_int2<0x32, "pmovsxbq", int_x86_sse41_pmovzxbq>;
3340
3341
Nate Begemand77e59e2008-02-11 04:19:36 +00003342/// SS41I_binop_ext8 - SSE 4.1 extract 8 bits to 32 bit reg or 8 bit mem
3343multiclass SS41I_extract8<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003344 def rr : SS4AI<opc, MRMSrcReg, (outs GR32:$dst),
3345 (ins VR128:$src1, i32i8imm:$src2),
3346 !strconcat(OpcodeStr,
3347 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003348 [(set GR32:$dst, (X86pextrb (v16i8 VR128:$src1), imm:$src2))]>,
3349 OpSize;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003350 def mr : SS4AI<opc, MRMDestMem, (outs),
3351 (ins i8mem:$dst, VR128:$src1, i32i8imm:$src2),
3352 !strconcat(OpcodeStr,
3353 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Nate Begemand77e59e2008-02-11 04:19:36 +00003354 []>, OpSize;
3355// FIXME:
3356// There's an AssertZext in the way of writing the store pattern
3357// (store (i8 (trunc (X86pextrb (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003358}
3359
Nate Begemand77e59e2008-02-11 04:19:36 +00003360defm PEXTRB : SS41I_extract8<0x14, "pextrb">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003361
Nate Begemand77e59e2008-02-11 04:19:36 +00003362
3363/// SS41I_extract16 - SSE 4.1 extract 16 bits to memory destination
3364multiclass SS41I_extract16<bits<8> opc, string OpcodeStr> {
3365 def mr : SS4AI<opc, MRMDestMem, (outs),
3366 (ins i16mem:$dst, VR128:$src1, i32i8imm:$src2),
3367 !strconcat(OpcodeStr,
3368 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3369 []>, OpSize;
3370// FIXME:
3371// There's an AssertZext in the way of writing the store pattern
3372// (store (i16 (trunc (X86pextrw (v16i8 VR128:$src1), imm:$src2))), addr:$dst)
3373}
3374
3375defm PEXTRW : SS41I_extract16<0x15, "pextrw">;
3376
3377
3378/// SS41I_extract32 - SSE 4.1 extract 32 bits to int reg or memory destination
3379multiclass SS41I_extract32<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003380 def rr : SS4AI<opc, MRMSrcReg, (outs GR32:$dst),
3381 (ins VR128:$src1, i32i8imm:$src2),
3382 !strconcat(OpcodeStr,
3383 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3384 [(set GR32:$dst,
3385 (extractelt (v4i32 VR128:$src1), imm:$src2))]>, OpSize;
3386 def mr : SS4AI<opc, MRMDestMem, (outs),
3387 (ins i32mem:$dst, VR128:$src1, i32i8imm:$src2),
3388 !strconcat(OpcodeStr,
3389 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3390 [(store (extractelt (v4i32 VR128:$src1), imm:$src2),
3391 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003392}
3393
Nate Begemand77e59e2008-02-11 04:19:36 +00003394defm PEXTRD : SS41I_extract32<0x16, "pextrd">;
Nate Begeman58057962008-02-09 01:38:08 +00003395
Nate Begemand77e59e2008-02-11 04:19:36 +00003396
3397/// SS41I_extractf32 - SSE 4.1 extract 32 bits to fp reg or memory destination
3398multiclass SS41I_extractf32<bits<8> opc, string OpcodeStr> {
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003399 def rr : SS4AI<opc, MRMSrcReg, (outs FR32:$dst),
3400 (ins VR128:$src1, i32i8imm:$src2),
3401 !strconcat(OpcodeStr,
3402 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3403 [(set FR32:$dst,
3404 (extractelt (v4f32 VR128:$src1), imm:$src2))]>, OpSize;
3405 def mr : SS4AI<opc, MRMDestMem, (outs),
3406 (ins f32mem:$dst, VR128:$src1, i32i8imm:$src2),
3407 !strconcat(OpcodeStr,
3408 "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
3409 [(store (extractelt (v4f32 VR128:$src1), imm:$src2),
3410 addr:$dst)]>, OpSize;
Nate Begeman58057962008-02-09 01:38:08 +00003411}
3412
Nate Begemand77e59e2008-02-11 04:19:36 +00003413defm EXTRACTPS : SS41I_extractf32<0x17, "extractps">;
Nate Begeman9a58b8a2008-02-09 23:46:37 +00003414
Nate Begemand77e59e2008-02-11 04:19:36 +00003415let isTwoAddress = 1 in {
3416 multiclass SS41I_insert8<bits<8> opc, string OpcodeStr> {
3417 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3418 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3419 !strconcat(OpcodeStr,
3420 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3421 [(set VR128:$dst,
3422 (X86pinsrb VR128:$src1, GR32:$src2, imm:$src3))]>, OpSize;
3423 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3424 (ins VR128:$src1, i8mem:$src2, i32i8imm:$src3),
3425 !strconcat(OpcodeStr,
3426 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3427 [(set VR128:$dst,
3428 (X86pinsrb VR128:$src1, (extloadi8 addr:$src2),
3429 imm:$src3))]>, OpSize;
3430 }
3431}
3432
3433defm PINSRB : SS41I_insert8<0x20, "pinsrb">;
3434
3435let isTwoAddress = 1 in {
3436 multiclass SS41I_insert32<bits<8> opc, string OpcodeStr> {
3437 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3438 (ins VR128:$src1, GR32:$src2, i32i8imm:$src3),
3439 !strconcat(OpcodeStr,
3440 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3441 [(set VR128:$dst,
3442 (v4i32 (insertelt VR128:$src1, GR32:$src2, imm:$src3)))]>,
3443 OpSize;
3444 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3445 (ins VR128:$src1, i32mem:$src2, i32i8imm:$src3),
3446 !strconcat(OpcodeStr,
3447 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3448 [(set VR128:$dst,
3449 (v4i32 (insertelt VR128:$src1, (loadi32 addr:$src2),
3450 imm:$src3)))]>, OpSize;
3451 }
3452}
3453
3454defm PINSRD : SS41I_insert32<0x22, "pinsrd">;
3455
3456let isTwoAddress = 1 in {
3457 multiclass SS41I_insertf32<bits<8> opc, string OpcodeStr> {
3458 def rr : SS4AI<opc, MRMSrcReg, (outs VR128:$dst),
3459 (ins VR128:$src1, FR32:$src2, i32i8imm:$src3),
3460 !strconcat(OpcodeStr,
3461 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3462 [(set VR128:$dst,
3463 (X86insrtps VR128:$src1, FR32:$src2, imm:$src3))]>, OpSize;
3464 def rm : SS4AI<opc, MRMSrcMem, (outs VR128:$dst),
3465 (ins VR128:$src1, f32mem:$src2, i32i8imm:$src3),
3466 !strconcat(OpcodeStr,
3467 "\t{$src3, $src2, $dst|$dst, $src2, $src3}"),
3468 [(set VR128:$dst,
3469 (X86insrtps VR128:$src1, (loadf32 addr:$src2),
3470 imm:$src3))]>, OpSize;
3471 }
3472}
3473
3474defm INSERTPS : SS41I_insertf32<0x31, "insertps">;