blob: 63065c95cf09b9eff063e36d7830b6b71e67f2aa [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//====- X86InstrSSE.td - Describe the X86 Instruction Set -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Evan Cheng and is distributed under the University
6// of Illinois Open Source License. See LICENSE.TXT for details.
7//
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>;
35def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest,
36 [SDNPHasChain, SDNPOutFlag]>;
37def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest,
38 [SDNPHasChain, SDNPOutFlag]>;
39def X86s2vec : SDNode<"X86ISD::S2VEC", SDTypeProfile<1, 1, []>, []>;
40def X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
41def X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
42
43//===----------------------------------------------------------------------===//
44// SSE 'Special' Instructions
45//===----------------------------------------------------------------------===//
46
Evan Chengb783fa32007-07-19 01:14:50 +000047def IMPLICIT_DEF_VR128 : I<0, Pseudo, (outs VR128:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048 "#IMPLICIT_DEF $dst",
49 [(set VR128:$dst, (v4f32 (undef)))]>,
50 Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000051def IMPLICIT_DEF_FR32 : I<0, Pseudo, (outs FR32:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 "#IMPLICIT_DEF $dst",
53 [(set FR32:$dst, (undef))]>, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +000054def IMPLICIT_DEF_FR64 : I<0, Pseudo, (outs FR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055 "#IMPLICIT_DEF $dst",
56 [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
57
58//===----------------------------------------------------------------------===//
59// SSE Complex Patterns
60//===----------------------------------------------------------------------===//
61
62// These are 'extloads' from a scalar to the low element of a vector, zeroing
63// the top elements. These are used for the SSE 'ss' and 'sd' instruction
64// forms.
65def sse_load_f32 : ComplexPattern<v4f32, 4, "SelectScalarSSELoad", [],
66 [SDNPHasChain]>;
67def sse_load_f64 : ComplexPattern<v2f64, 4, "SelectScalarSSELoad", [],
68 [SDNPHasChain]>;
69
70def ssmem : Operand<v4f32> {
71 let PrintMethod = "printf32mem";
72 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
73}
74def sdmem : Operand<v2f64> {
75 let PrintMethod = "printf64mem";
76 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
77}
78
79//===----------------------------------------------------------------------===//
80// SSE pattern fragments
81//===----------------------------------------------------------------------===//
82
Dan Gohmanf17a25c2007-07-18 16:29:46 +000083def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
84def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
85def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
86def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
87
Dan Gohman11821702007-07-27 17:16:43 +000088// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +000089def alignedstore : PatFrag<(ops node:$val, node:$ptr),
90 (st node:$val, node:$ptr), [{
91 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
92 return !ST->isTruncatingStore() &&
93 ST->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +000094 ST->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +000095 return false;
96}]>;
97
Dan Gohman11821702007-07-27 17:16:43 +000098// Like 'load', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +000099def alignedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
100 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
101 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
102 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000103 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000104 return false;
105}]>;
106
Dan Gohman11821702007-07-27 17:16:43 +0000107def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
108def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000109def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
110def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
111def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
112def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
113
114// Like 'load', but uses special alignment checks suitable for use in
115// memory operands in most SSE instructions, which are required to
116// be naturally aligned on some targets but not on others.
117// FIXME: Actually implement support for targets that don't require the
118// alignment. This probably wants a subtarget predicate.
119def memop : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
120 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
121 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
122 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000123 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000124 return false;
125}]>;
126
Dan Gohman11821702007-07-27 17:16:43 +0000127def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
128def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000129def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
130def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
131def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
132def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
133
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
135def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
136def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
137def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
138def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
139def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
140
141def fp32imm0 : PatLeaf<(f32 fpimm), [{
142 return N->isExactlyValue(+0.0);
143}]>;
144
145def PSxLDQ_imm : SDNodeXForm<imm, [{
146 // Transformation function: imm >> 3
147 return getI32Imm(N->getValue() >> 3);
148}]>;
149
150// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
151// SHUFP* etc. imm.
152def SHUFFLE_get_shuf_imm : SDNodeXForm<build_vector, [{
153 return getI8Imm(X86::getShuffleSHUFImmediate(N));
154}]>;
155
156// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
157// PSHUFHW imm.
158def SHUFFLE_get_pshufhw_imm : SDNodeXForm<build_vector, [{
159 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
160}]>;
161
162// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
163// PSHUFLW imm.
164def SHUFFLE_get_pshuflw_imm : SDNodeXForm<build_vector, [{
165 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
166}]>;
167
168def SSE_splat_mask : PatLeaf<(build_vector), [{
169 return X86::isSplatMask(N);
170}], SHUFFLE_get_shuf_imm>;
171
172def SSE_splat_lo_mask : PatLeaf<(build_vector), [{
173 return X86::isSplatLoMask(N);
174}]>;
175
176def MOVHLPS_shuffle_mask : PatLeaf<(build_vector), [{
177 return X86::isMOVHLPSMask(N);
178}]>;
179
180def MOVHLPS_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
181 return X86::isMOVHLPS_v_undef_Mask(N);
182}]>;
183
184def MOVHP_shuffle_mask : PatLeaf<(build_vector), [{
185 return X86::isMOVHPMask(N);
186}]>;
187
188def MOVLP_shuffle_mask : PatLeaf<(build_vector), [{
189 return X86::isMOVLPMask(N);
190}]>;
191
192def MOVL_shuffle_mask : PatLeaf<(build_vector), [{
193 return X86::isMOVLMask(N);
194}]>;
195
196def MOVSHDUP_shuffle_mask : PatLeaf<(build_vector), [{
197 return X86::isMOVSHDUPMask(N);
198}]>;
199
200def MOVSLDUP_shuffle_mask : PatLeaf<(build_vector), [{
201 return X86::isMOVSLDUPMask(N);
202}]>;
203
204def UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
205 return X86::isUNPCKLMask(N);
206}]>;
207
208def UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
209 return X86::isUNPCKHMask(N);
210}]>;
211
212def UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
213 return X86::isUNPCKL_v_undef_Mask(N);
214}]>;
215
216def UNPCKH_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
217 return X86::isUNPCKH_v_undef_Mask(N);
218}]>;
219
220def PSHUFD_shuffle_mask : PatLeaf<(build_vector), [{
221 return X86::isPSHUFDMask(N);
222}], SHUFFLE_get_shuf_imm>;
223
224def PSHUFHW_shuffle_mask : PatLeaf<(build_vector), [{
225 return X86::isPSHUFHWMask(N);
226}], SHUFFLE_get_pshufhw_imm>;
227
228def PSHUFLW_shuffle_mask : PatLeaf<(build_vector), [{
229 return X86::isPSHUFLWMask(N);
230}], SHUFFLE_get_pshuflw_imm>;
231
232def SHUFP_unary_shuffle_mask : PatLeaf<(build_vector), [{
233 return X86::isPSHUFDMask(N);
234}], SHUFFLE_get_shuf_imm>;
235
236def SHUFP_shuffle_mask : PatLeaf<(build_vector), [{
237 return X86::isSHUFPMask(N);
238}], SHUFFLE_get_shuf_imm>;
239
240def PSHUFD_binary_shuffle_mask : PatLeaf<(build_vector), [{
241 return X86::isSHUFPMask(N);
242}], SHUFFLE_get_shuf_imm>;
243
244//===----------------------------------------------------------------------===//
245// SSE scalar FP Instructions
246//===----------------------------------------------------------------------===//
247
248// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
249// scheduler into a branch sequence.
250let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
251 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000252 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253 "#CMOV_FR32 PSEUDO!",
254 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond))]>;
255 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000256 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 "#CMOV_FR64 PSEUDO!",
258 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond))]>;
259 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000260 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 "#CMOV_V4F32 PSEUDO!",
262 [(set VR128:$dst,
263 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
264 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000265 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 "#CMOV_V2F64 PSEUDO!",
267 [(set VR128:$dst,
268 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
269 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000270 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271 "#CMOV_V2I64 PSEUDO!",
272 [(set VR128:$dst,
273 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond)))]>;
274}
275
276//===----------------------------------------------------------------------===//
277// SSE1 Instructions
278//===----------------------------------------------------------------------===//
279
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000281def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000282 "movss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanca9f99d2007-08-02 14:27:55 +0000283let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000284def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000285 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000287def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000288 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 [(store FR32:$src, addr:$dst)]>;
290
291// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000292def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000293 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000295def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000296 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 [(set GR32:$dst, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000298def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000299 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000301def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000302 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
304
305// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000306def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000307 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000309def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000310 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 [(set GR32:$dst, (int_x86_sse_cvtss2si
312 (load addr:$src)))]>;
313
314// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000315def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000316 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 [(set GR32:$dst,
318 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000319def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000320 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321 [(set GR32:$dst,
322 (int_x86_sse_cvttss2si(load addr:$src)))]>;
323
324let isTwoAddress = 1 in {
325 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000326 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
329 GR32:$src2))]>;
330 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000331 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000332 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
334 (loadi32 addr:$src2)))]>;
335}
336
337// Comparison instructions
338let isTwoAddress = 1 in {
339 def CMPSSrr : SSI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000340 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 def CMPSSrm : SSI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000343 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345}
346
Evan Chengb783fa32007-07-19 01:14:50 +0000347def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000348 "ucomiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 [(X86cmp FR32:$src1, FR32:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000350def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000351 "ucomiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 [(X86cmp FR32:$src1, (loadf32 addr:$src2))]>;
353
354// Aliases to match intrinsics which expect XMM operand(s).
355let isTwoAddress = 1 in {
356 def Int_CMPSSrr : SSI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000357 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000358 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
360 VR128:$src, imm:$cc))]>;
361 def Int_CMPSSrm : SSI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000362 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000363 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
365 (load addr:$src), imm:$cc))]>;
366}
367
Evan Chengb783fa32007-07-19 01:14:50 +0000368def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000369 "ucomiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000371def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000372 "ucomiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2))]>;
374
Evan Chengb783fa32007-07-19 01:14:50 +0000375def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000376 "comiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377 [(X86comi (v4f32 VR128:$src1), VR128:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000378def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000379 "comiss\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 [(X86comi (v4f32 VR128:$src1), (load addr:$src2))]>;
381
382// Aliases of packed SSE1 instructions for scalar use. These all have names that
383// start with 'Fs'.
384
385// Alias instructions that map fld0 to pxor for sse.
Evan Chengb783fa32007-07-19 01:14:50 +0000386def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000387 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388 Requires<[HasSSE1]>, TB, OpSize;
389
390// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
391// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +0000392def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394
395// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
396// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +0000397def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000398 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000399 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400
401// Alias bitwise logical operations using SSE logical ops on packed FP values.
402let isTwoAddress = 1 in {
403let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000404 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000405 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000407 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000408 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000410 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000411 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000412 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
413}
414
Evan Chengb783fa32007-07-19 01:14:50 +0000415def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000416 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000418 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000419def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000420 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000422 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000423def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000426 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427
428def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000429 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000430 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000432 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000433 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434}
435
436/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
437///
438/// In addition, we also have a special variant of the scalar form here to
439/// represent the associated intrinsic operation. This form is unlike the
440/// plain scalar form, in that it takes an entire vector (instead of a scalar)
441/// and leaves the top elements undefined.
442///
443/// These three forms can each be reg+reg or reg+mem, so there are a total of
444/// six "instructions".
445///
446let isTwoAddress = 1 in {
447multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
448 SDNode OpNode, Intrinsic F32Int,
449 bit Commutable = 0> {
450 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000451 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000452 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
454 let isCommutable = Commutable;
455 }
456
457 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000458 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
461
462 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000463 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000464 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
466 let isCommutable = Commutable;
467 }
468
469 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000470 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000471 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000472 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
474 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000475 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000476 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
478 let isCommutable = Commutable;
479 }
480
481 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000482 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000483 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484 [(set VR128:$dst, (F32Int VR128:$src1,
485 sse_load_f32:$src2))]>;
486}
487}
488
489// Arithmetic instructions
490defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
491defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
492defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
493defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
494
495/// sse1_fp_binop_rm - Other SSE1 binops
496///
497/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
498/// instructions for a full-vector intrinsic form. Operations that map
499/// onto C operators don't use this form since they just use the plain
500/// vector form instead of having a separate vector intrinsic form.
501///
502/// This provides a total of eight "instructions".
503///
504let isTwoAddress = 1 in {
505multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
506 SDNode OpNode,
507 Intrinsic F32Int,
508 Intrinsic V4F32Int,
509 bit Commutable = 0> {
510
511 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000512 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000513 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
515 let isCommutable = Commutable;
516 }
517
518 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000519 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000520 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
522
523 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000524 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000525 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
527 let isCommutable = Commutable;
528 }
529
530 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000531 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000532 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000533 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
535 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000536 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000537 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000538 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
539 let isCommutable = Commutable;
540 }
541
542 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000543 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000544 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 [(set VR128:$dst, (F32Int VR128:$src1,
546 sse_load_f32:$src2))]>;
547
548 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000549 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000550 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
552 let isCommutable = Commutable;
553 }
554
555 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +0000556 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000557 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558 [(set VR128:$dst, (V4F32Int VR128:$src1, (load addr:$src2)))]>;
559}
560}
561
562defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
563 int_x86_sse_max_ss, int_x86_sse_max_ps>;
564defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
565 int_x86_sse_min_ss, int_x86_sse_min_ps>;
566
567//===----------------------------------------------------------------------===//
568// SSE packed FP Instructions
569
570// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000571def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000572 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanca9f99d2007-08-02 14:27:55 +0000573let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000574def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000575 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000576 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577
Evan Chengb783fa32007-07-19 01:14:50 +0000578def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000579 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000580 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581
Evan Chengb783fa32007-07-19 01:14:50 +0000582def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000583 "movups\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000584def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000585 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000586 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000587def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000588 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000589 [(store (v4f32 VR128:$src), addr:$dst)]>;
590
591// Intrinsic forms of MOVUPS load and store
Evan Chengb783fa32007-07-19 01:14:50 +0000592def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000593 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000594 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000595def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000596 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000597 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598
599let isTwoAddress = 1 in {
600 let AddedComplexity = 20 in {
601 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000602 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000603 "movlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604 [(set VR128:$dst,
605 (v4f32 (vector_shuffle VR128:$src1,
606 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
607 MOVLP_shuffle_mask)))]>;
608 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000609 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000610 "movhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 [(set VR128:$dst,
612 (v4f32 (vector_shuffle VR128:$src1,
613 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
614 MOVHP_shuffle_mask)))]>;
615 } // AddedComplexity
616} // isTwoAddress
617
Evan Chengb783fa32007-07-19 01:14:50 +0000618def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000619 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
621 (iPTR 0))), addr:$dst)]>;
622
623// v2f64 extract element 1 is always custom lowered to unpack high to low
624// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000625def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000626 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 [(store (f64 (vector_extract
628 (v2f64 (vector_shuffle
629 (bc_v2f64 (v4f32 VR128:$src)), (undef),
630 UNPCKH_shuffle_mask)), (iPTR 0))),
631 addr:$dst)]>;
632
633let isTwoAddress = 1 in {
634let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000635def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000636 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000637 [(set VR128:$dst,
638 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
639 MOVHP_shuffle_mask)))]>;
640
Evan Chengb783fa32007-07-19 01:14:50 +0000641def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000642 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 [(set VR128:$dst,
644 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
645 MOVHLPS_shuffle_mask)))]>;
646} // AddedComplexity
647} // isTwoAddress
648
649
650
651// Arithmetic
652
653/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
654///
655/// In addition, we also have a special variant of the scalar form here to
656/// represent the associated intrinsic operation. This form is unlike the
657/// plain scalar form, in that it takes an entire vector (instead of a
658/// scalar) and leaves the top elements undefined.
659///
660/// And, we have a special variant form for a full-vector intrinsic form.
661///
662/// These four forms can each have a reg or a mem operand, so there are a
663/// total of eight "instructions".
664///
665multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
666 SDNode OpNode,
667 Intrinsic F32Int,
668 Intrinsic V4F32Int,
669 bit Commutable = 0> {
670 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000671 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000672 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 [(set FR32:$dst, (OpNode FR32:$src))]> {
674 let isCommutable = Commutable;
675 }
676
677 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000678 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000679 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
681
682 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000683 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
686 let isCommutable = Commutable;
687 }
688
689 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000690 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000692 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693
694 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000695 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000696 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697 [(set VR128:$dst, (F32Int VR128:$src))]> {
698 let isCommutable = Commutable;
699 }
700
701 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000702 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000703 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
705
706 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000707 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000708 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
710 let isCommutable = Commutable;
711 }
712
713 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000714 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000715 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 [(set VR128:$dst, (V4F32Int (load addr:$src)))]>;
717}
718
719// Square root.
720defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
721 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
722
723// Reciprocal approximations. Note that these typically require refinement
724// in order to obtain suitable precision.
725defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
726 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
727defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
728 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
729
730// Logical
731let isTwoAddress = 1 in {
732 let isCommutable = 1 in {
733 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000734 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000735 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 [(set VR128:$dst, (v2i64
737 (and VR128:$src1, VR128:$src2)))]>;
738 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000739 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000740 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741 [(set VR128:$dst, (v2i64
742 (or VR128:$src1, VR128:$src2)))]>;
743 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000744 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000745 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 [(set VR128:$dst, (v2i64
747 (xor VR128:$src1, VR128:$src2)))]>;
748 }
749
750 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000751 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000752 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000753 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
754 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000756 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000757 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000758 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
759 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000761 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000762 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000763 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
764 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000765 def ANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000766 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000767 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 [(set VR128:$dst,
769 (v2i64 (and (xor VR128:$src1,
770 (bc_v2i64 (v4i32 immAllOnesV))),
771 VR128:$src2)))]>;
772 def ANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000773 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000774 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000775 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000776 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000778 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779}
780
781let isTwoAddress = 1 in {
782 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000783 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000784 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
786 VR128:$src, imm:$cc))]>;
787 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000788 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000789 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
791 (load addr:$src), imm:$cc))]>;
792}
793
794// Shuffle and unpack instructions
795let isTwoAddress = 1 in {
796 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
797 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000798 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 VR128:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000800 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 [(set VR128:$dst,
802 (v4f32 (vector_shuffle
803 VR128:$src1, VR128:$src2,
804 SHUFP_shuffle_mask:$src3)))]>;
805 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000806 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000807 f128mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000808 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 [(set VR128:$dst,
810 (v4f32 (vector_shuffle
811 VR128:$src1, (load addr:$src2),
812 SHUFP_shuffle_mask:$src3)))]>;
813
814 let AddedComplexity = 10 in {
815 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000816 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000817 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 [(set VR128:$dst,
819 (v4f32 (vector_shuffle
820 VR128:$src1, VR128:$src2,
821 UNPCKH_shuffle_mask)))]>;
822 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000823 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000824 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000825 [(set VR128:$dst,
826 (v4f32 (vector_shuffle
827 VR128:$src1, (load addr:$src2),
828 UNPCKH_shuffle_mask)))]>;
829
830 def UNPCKLPSrr : PSI<0x14, 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 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(set VR128:$dst,
834 (v4f32 (vector_shuffle
835 VR128:$src1, VR128:$src2,
836 UNPCKL_shuffle_mask)))]>;
837 def UNPCKLPSrm : PSI<0x14, 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 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840 [(set VR128:$dst,
841 (v4f32 (vector_shuffle
842 VR128:$src1, (load addr:$src2),
843 UNPCKL_shuffle_mask)))]>;
844 } // AddedComplexity
845} // isTwoAddress
846
847// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000848def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000849 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000851def MOVMSKPDrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000852 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
854
855// Prefetching loads.
856// TODO: no intrinsics for these?
Dan Gohman91888f02007-07-31 20:11:57 +0000857def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src), "prefetcht0\t$src", []>;
858def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src), "prefetcht1\t$src", []>;
859def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src), "prefetcht2\t$src", []>;
860def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src), "prefetchnta\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861
862// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000863def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000864 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
866
867// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +0000868def SFENCE : PSI<0xAE, MRM7m, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869
870// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000871def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000872 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000873def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000874 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875
876// Alias instructions that map zero vector to pxor / xorp* for sse.
877// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
878let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000879def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000880 "xorps\t$dst, $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
882
883// FR32 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +0000884def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000885 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000886 [(set VR128:$dst,
887 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000888def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000889 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000890 [(set VR128:$dst,
891 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
892
893// FIXME: may not be able to eliminate this movss with coalescing the src and
894// dest register classes are different. We really want to write this pattern
895// like this:
896// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
897// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +0000898def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000899 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000900 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
901 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000902def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000903 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000904 [(store (f32 (vector_extract (v4f32 VR128:$src),
905 (iPTR 0))), addr:$dst)]>;
906
907
908// Move to lower bits of a VR128, leaving upper bits alone.
909// Three operand (but two address) aliases.
910let isTwoAddress = 1 in {
911 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000912 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000913 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914
915 let AddedComplexity = 15 in
916 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000917 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000918 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000919 [(set VR128:$dst,
920 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
921 MOVL_shuffle_mask)))]>;
922}
923
924// Move to lower bits of a VR128 and zeroing upper bits.
925// Loading from memory automatically zeroing upper bits.
926let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +0000927def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000928 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000929 [(set VR128:$dst, (v4f32 (vector_shuffle immAllZerosV,
930 (v4f32 (scalar_to_vector (loadf32 addr:$src))),
931 MOVL_shuffle_mask)))]>;
932
933
934//===----------------------------------------------------------------------===//
935// SSE2 Instructions
936//===----------------------------------------------------------------------===//
937
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000939def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000940 "movsd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanca9f99d2007-08-02 14:27:55 +0000941let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000942def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000943 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000944 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000945def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000946 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000947 [(store FR64:$src, addr:$dst)]>;
948
949// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000950def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000951 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000952 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000953def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000956def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000957 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000958 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000959def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000960 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000962def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000963 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000964 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000965def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000966 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
968
969// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +0000970def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000971 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
973 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000974def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000975 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
977 Requires<[HasSSE2]>;
978
979// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000980def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000981 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000982 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000983def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000984 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
986 (load addr:$src)))]>;
987
988// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000989def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000990 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991 [(set GR32:$dst,
992 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000993def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000994 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
996 (load addr:$src)))]>;
997
998// Comparison instructions
999let isTwoAddress = 1 in {
1000 def CMPSDrr : SDI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001001 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001002 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003 def CMPSDrm : SDI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001004 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001005 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006}
1007
Evan Chengb783fa32007-07-19 01:14:50 +00001008def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001009 "ucomisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001010 [(X86cmp FR64:$src1, FR64:$src2)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001011def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001012 "ucomisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013 [(X86cmp FR64:$src1, (loadf64 addr:$src2))]>;
1014
1015// Aliases to match intrinsics which expect XMM operand(s).
1016let isTwoAddress = 1 in {
1017 def Int_CMPSDrr : SDI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001018 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001019 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1021 VR128:$src, imm:$cc))]>;
1022 def Int_CMPSDrm : SDI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001023 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001024 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001025 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1026 (load addr:$src), imm:$cc))]>;
1027}
1028
Evan Chengb783fa32007-07-19 01:14:50 +00001029def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001030 "ucomisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001032def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001033 "ucomisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2))]>;
1035
Evan Chengb783fa32007-07-19 01:14:50 +00001036def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001037 "comisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001039def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "comisd\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 [(X86comi (v2f64 VR128:$src1), (load addr:$src2))]>;
1042
1043// Aliases of packed SSE2 instructions for scalar use. These all have names that
1044// start with 'Fs'.
1045
1046// Alias instructions that map fld0 to pxor for sse.
Evan Chengb783fa32007-07-19 01:14:50 +00001047def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001048 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049 Requires<[HasSSE2]>, TB, OpSize;
1050
1051// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1052// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +00001053def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001054 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055
1056// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1057// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +00001058def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001059 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001060 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001061
1062// Alias bitwise logical operations using SSE logical ops on packed FP values.
1063let isTwoAddress = 1 in {
1064let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +00001065 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001066 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001068 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001069 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001071 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001072 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001073 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1074}
1075
Evan Chengb783fa32007-07-19 01:14:50 +00001076def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001077 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001079 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001080def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001081 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001083 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001084def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001085 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001086 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001087 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088
1089def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001090 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001091 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001093 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001094 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095}
1096
1097/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1098///
1099/// In addition, we also have a special variant of the scalar form here to
1100/// represent the associated intrinsic operation. This form is unlike the
1101/// plain scalar form, in that it takes an entire vector (instead of a scalar)
1102/// and leaves the top elements undefined.
1103///
1104/// These three forms can each be reg+reg or reg+mem, so there are a total of
1105/// six "instructions".
1106///
1107let isTwoAddress = 1 in {
1108multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1109 SDNode OpNode, Intrinsic F64Int,
1110 bit Commutable = 0> {
1111 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001112 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001113 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1115 let isCommutable = Commutable;
1116 }
1117
1118 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001119 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001120 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1122
1123 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001124 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001125 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1127 let isCommutable = Commutable;
1128 }
1129
1130 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001131 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001132 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001133 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001134
1135 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001136 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001137 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1139 let isCommutable = Commutable;
1140 }
1141
1142 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001143 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001144 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001145 [(set VR128:$dst, (F64Int VR128:$src1,
1146 sse_load_f64:$src2))]>;
1147}
1148}
1149
1150// Arithmetic instructions
1151defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1152defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1153defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1154defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1155
1156/// sse2_fp_binop_rm - Other SSE2 binops
1157///
1158/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1159/// instructions for a full-vector intrinsic form. Operations that map
1160/// onto C operators don't use this form since they just use the plain
1161/// vector form instead of having a separate vector intrinsic form.
1162///
1163/// This provides a total of eight "instructions".
1164///
1165let isTwoAddress = 1 in {
1166multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1167 SDNode OpNode,
1168 Intrinsic F64Int,
1169 Intrinsic V2F64Int,
1170 bit Commutable = 0> {
1171
1172 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001173 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001174 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001175 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1176 let isCommutable = Commutable;
1177 }
1178
1179 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001180 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001181 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1183
1184 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001185 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001186 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1188 let isCommutable = Commutable;
1189 }
1190
1191 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001192 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001194 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001195
1196 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001197 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001198 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001199 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1200 let isCommutable = Commutable;
1201 }
1202
1203 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001204 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001205 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001206 [(set VR128:$dst, (F64Int VR128:$src1,
1207 sse_load_f64:$src2))]>;
1208
1209 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001210 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001211 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001212 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1213 let isCommutable = Commutable;
1214 }
1215
1216 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +00001217 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001218 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001219 [(set VR128:$dst, (V2F64Int VR128:$src1, (load addr:$src2)))]>;
1220}
1221}
1222
1223defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1224 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1225defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1226 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1227
1228//===----------------------------------------------------------------------===//
1229// SSE packed FP Instructions
1230
1231// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001232def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001233 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanca9f99d2007-08-02 14:27:55 +00001234let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001235def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001236 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001237 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001238
Evan Chengb783fa32007-07-19 01:14:50 +00001239def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001240 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001241 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001242
Evan Chengb783fa32007-07-19 01:14:50 +00001243def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001244 "movupd\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001245def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001246 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001247 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001248def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001249 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001250 [(store (v2f64 VR128:$src), addr:$dst)]>;
1251
1252// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001253def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001254 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001255 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001256def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001257 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001258 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001259
1260let isTwoAddress = 1 in {
1261 let AddedComplexity = 20 in {
1262 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001263 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001264 "movlpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265 [(set VR128:$dst,
1266 (v2f64 (vector_shuffle VR128:$src1,
1267 (scalar_to_vector (loadf64 addr:$src2)),
1268 MOVLP_shuffle_mask)))]>;
1269 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001270 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001271 "movhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001272 [(set VR128:$dst,
1273 (v2f64 (vector_shuffle VR128:$src1,
1274 (scalar_to_vector (loadf64 addr:$src2)),
1275 MOVHP_shuffle_mask)))]>;
1276 } // AddedComplexity
1277} // isTwoAddress
1278
Evan Chengb783fa32007-07-19 01:14:50 +00001279def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281 [(store (f64 (vector_extract (v2f64 VR128:$src),
1282 (iPTR 0))), addr:$dst)]>;
1283
1284// v2f64 extract element 1 is always custom lowered to unpack high to low
1285// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001286def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001287 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001288 [(store (f64 (vector_extract
1289 (v2f64 (vector_shuffle VR128:$src, (undef),
1290 UNPCKH_shuffle_mask)), (iPTR 0))),
1291 addr:$dst)]>;
1292
1293// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001294def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001295 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001296 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1297 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001298def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001299 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
Dan Gohman4a4f1512007-07-18 20:23:34 +00001301 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001302 TB, Requires<[HasSSE2]>;
1303
1304// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001305def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001306 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001307 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1308 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001309def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001310 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001311 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
Dan Gohman4a4f1512007-07-18 20:23:34 +00001312 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313 XS, Requires<[HasSSE2]>;
1314
Evan Chengb783fa32007-07-19 01:14:50 +00001315def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001316 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001318def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001319 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001320 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1321 (load addr:$src)))]>;
1322// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001323def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001324 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1326 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001327def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001328 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1330 (load addr:$src)))]>,
1331 XS, Requires<[HasSSE2]>;
1332
1333// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001334def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001335 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001336 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1337 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001338def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001339 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001340 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1341 (load addr:$src)))]>,
1342 XD, Requires<[HasSSE2]>;
1343
Evan Chengb783fa32007-07-19 01:14:50 +00001344def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001345 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001346 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001347def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001348 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1350 (load addr:$src)))]>;
1351
1352// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001353def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001354 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001355 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1356 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001357def Int_CVTPS2PDrm : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001358 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1360 (load addr:$src)))]>,
1361 TB, Requires<[HasSSE2]>;
1362
Evan Chengb783fa32007-07-19 01:14:50 +00001363def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001364 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001365 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001366def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001367 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001368 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1369 (load addr:$src)))]>;
1370
1371// Match intrinsics which expect XMM operand(s).
1372// Aliases for intrinsics
1373let isTwoAddress = 1 in {
1374def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001375 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001376 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001377 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1378 GR32:$src2))]>;
1379def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001380 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001381 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001382 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1383 (loadi32 addr:$src2)))]>;
1384def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001385 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001386 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001387 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1388 VR128:$src2))]>;
1389def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001390 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001391 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001392 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1393 (load addr:$src2)))]>;
1394def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001395 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001396 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001397 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1398 VR128:$src2))]>, XS,
1399 Requires<[HasSSE2]>;
1400def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001401 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001402 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001403 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1404 (load addr:$src2)))]>, XS,
1405 Requires<[HasSSE2]>;
1406}
1407
1408// Arithmetic
1409
1410/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1411///
1412/// In addition, we also have a special variant of the scalar form here to
1413/// represent the associated intrinsic operation. This form is unlike the
1414/// plain scalar form, in that it takes an entire vector (instead of a
1415/// scalar) and leaves the top elements undefined.
1416///
1417/// And, we have a special variant form for a full-vector intrinsic form.
1418///
1419/// These four forms can each have a reg or a mem operand, so there are a
1420/// total of eight "instructions".
1421///
1422multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1423 SDNode OpNode,
1424 Intrinsic F64Int,
1425 Intrinsic V2F64Int,
1426 bit Commutable = 0> {
1427 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001428 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001429 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001430 [(set FR64:$dst, (OpNode FR64:$src))]> {
1431 let isCommutable = Commutable;
1432 }
1433
1434 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001435 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001436 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001437 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1438
1439 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001440 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001441 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1443 let isCommutable = Commutable;
1444 }
1445
1446 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001447 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001448 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001449 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001450
1451 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001452 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001453 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001454 [(set VR128:$dst, (F64Int VR128:$src))]> {
1455 let isCommutable = Commutable;
1456 }
1457
1458 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001459 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001460 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001461 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1462
1463 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001464 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001465 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001466 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1467 let isCommutable = Commutable;
1468 }
1469
1470 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001471 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001472 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001473 [(set VR128:$dst, (V2F64Int (load addr:$src)))]>;
1474}
1475
1476// Square root.
1477defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1478 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1479
1480// There is no f64 version of the reciprocal approximation instructions.
1481
1482// Logical
1483let isTwoAddress = 1 in {
1484 let isCommutable = 1 in {
1485 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001486 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001487 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001488 [(set VR128:$dst,
1489 (and (bc_v2i64 (v2f64 VR128:$src1)),
1490 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1491 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001492 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001493 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001494 [(set VR128:$dst,
1495 (or (bc_v2i64 (v2f64 VR128:$src1)),
1496 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1497 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001498 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001499 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001500 [(set VR128:$dst,
1501 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1502 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1503 }
1504
1505 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001506 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001507 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001508 [(set VR128:$dst,
1509 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001510 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001511 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001512 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001513 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001514 [(set VR128:$dst,
1515 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001516 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001517 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001518 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001519 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520 [(set VR128:$dst,
1521 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001522 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001523 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001524 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001525 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001526 [(set VR128:$dst,
1527 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1528 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1529 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001530 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001531 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001532 [(set VR128:$dst,
1533 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001534 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001535}
1536
1537let isTwoAddress = 1 in {
1538 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001539 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001540 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001541 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1542 VR128:$src, imm:$cc))]>;
1543 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001544 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001545 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001546 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1547 (load addr:$src), imm:$cc))]>;
1548}
1549
1550// Shuffle and unpack instructions
1551let isTwoAddress = 1 in {
1552 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001553 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001554 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001555 [(set VR128:$dst, (v2f64 (vector_shuffle
1556 VR128:$src1, VR128:$src2,
1557 SHUFP_shuffle_mask:$src3)))]>;
1558 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001559 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001560 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001561 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001562 [(set VR128:$dst,
1563 (v2f64 (vector_shuffle
1564 VR128:$src1, (load addr:$src2),
1565 SHUFP_shuffle_mask:$src3)))]>;
1566
1567 let AddedComplexity = 10 in {
1568 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001569 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001570 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001571 [(set VR128:$dst,
1572 (v2f64 (vector_shuffle
1573 VR128:$src1, VR128:$src2,
1574 UNPCKH_shuffle_mask)))]>;
1575 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001576 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001577 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001578 [(set VR128:$dst,
1579 (v2f64 (vector_shuffle
1580 VR128:$src1, (load addr:$src2),
1581 UNPCKH_shuffle_mask)))]>;
1582
1583 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001584 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001585 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001586 [(set VR128:$dst,
1587 (v2f64 (vector_shuffle
1588 VR128:$src1, VR128:$src2,
1589 UNPCKL_shuffle_mask)))]>;
1590 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001591 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001592 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001593 [(set VR128:$dst,
1594 (v2f64 (vector_shuffle
1595 VR128:$src1, (load addr:$src2),
1596 UNPCKL_shuffle_mask)))]>;
1597 } // AddedComplexity
1598} // isTwoAddress
1599
1600
1601//===----------------------------------------------------------------------===//
1602// SSE integer instructions
1603
1604// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001605def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001606 "movdqa\t{$src, $dst|$dst, $src}", []>;
Evan Chengb783fa32007-07-19 01:14:50 +00001607def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001608 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001609 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001610def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001611 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001612 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001613def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001614 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001615 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001616 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001617def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001618 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001619 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001620 XS, Requires<[HasSSE2]>;
1621
Dan Gohman4a4f1512007-07-18 20:23:34 +00001622// Intrinsic forms of MOVDQU load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001623def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001624 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001625 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1626 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001627def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001628 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001629 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1630 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001631
1632let isTwoAddress = 1 in {
1633
1634multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1635 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001636 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001637 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001638 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1639 let isCommutable = Commutable;
1640 }
Evan Chengb783fa32007-07-19 01:14:50 +00001641 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001642 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001643 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001644 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001645}
1646
1647multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1648 string OpcodeStr, Intrinsic IntId> {
Evan Chengb783fa32007-07-19 01:14:50 +00001649 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001650 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001651 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001652 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001653 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001654 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001655 (bitconvert (memopv2i64 addr:$src2))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001656 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001657 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001658 [(set VR128:$dst, (IntId VR128:$src1,
1659 (scalar_to_vector (i32 imm:$src2))))]>;
1660}
1661
1662
1663/// PDI_binop_rm - Simple SSE2 binary operator.
1664multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1665 ValueType OpVT, bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001666 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001667 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001668 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1669 let isCommutable = Commutable;
1670 }
Evan Chengb783fa32007-07-19 01:14:50 +00001671 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001672 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001673 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001674 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001675}
1676
1677/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1678///
1679/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1680/// to collapse (bitconvert VT to VT) into its operand.
1681///
1682multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1683 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001684 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001685 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1687 let isCommutable = Commutable;
1688 }
Evan Chengb783fa32007-07-19 01:14:50 +00001689 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001690 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001691 [(set VR128:$dst, (OpNode VR128:$src1,(memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001692}
1693
1694} // isTwoAddress
1695
1696// 128-bit Integer Arithmetic
1697
1698defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1699defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1700defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1701defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1702
1703defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1704defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1705defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1706defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1707
1708defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1709defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1710defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1711defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1712
1713defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1714defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1715defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1716defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1717
1718defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1719
1720defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1721defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1722defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1723
1724defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1725
1726defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1727defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1728
1729
1730defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1731defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1732defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1733defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1734defm PSADBW : PDI_binop_rm_int<0xE0, "psadbw", int_x86_sse2_psad_bw, 1>;
1735
1736
1737defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw", int_x86_sse2_psll_w>;
1738defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld", int_x86_sse2_psll_d>;
1739defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq", int_x86_sse2_psll_q>;
1740
1741defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw", int_x86_sse2_psrl_w>;
1742defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld", int_x86_sse2_psrl_d>;
1743defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq", int_x86_sse2_psrl_q>;
1744
1745defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw", int_x86_sse2_psra_w>;
1746defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad", int_x86_sse2_psra_d>;
1747// PSRAQ doesn't exist in SSE[1-3].
1748
1749// 128-bit logical shifts.
1750let isTwoAddress = 1 in {
1751 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001752 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001753 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001755 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001756 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001757 // PSRADQri doesn't exist in SSE[1-3].
1758}
1759
1760let Predicates = [HasSSE2] in {
1761 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1762 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1763 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1764 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1765 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1766 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1767}
1768
1769// Logical
1770defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1771defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1772defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1773
1774let isTwoAddress = 1 in {
1775 def PANDNrr : PDI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001776 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001777 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1779 VR128:$src2)))]>;
1780
1781 def PANDNrm : PDI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001782 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001783 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001784 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1785 (load addr:$src2))))]>;
1786}
1787
1788// SSE2 Integer comparison
1789defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
1790defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
1791defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
1792defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
1793defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
1794defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
1795
1796// Pack instructions
1797defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
1798defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
1799defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
1800
1801// Shuffle and unpack instructions
1802def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001803 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001804 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001805 [(set VR128:$dst, (v4i32 (vector_shuffle
1806 VR128:$src1, (undef),
1807 PSHUFD_shuffle_mask:$src2)))]>;
1808def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001809 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001810 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001811 [(set VR128:$dst, (v4i32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001812 (bc_v4i32(memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001813 (undef),
1814 PSHUFD_shuffle_mask:$src2)))]>;
1815
1816// SSE2 with ImmT == Imm8 and XS prefix.
1817def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001818 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001819 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001820 [(set VR128:$dst, (v8i16 (vector_shuffle
1821 VR128:$src1, (undef),
1822 PSHUFHW_shuffle_mask:$src2)))]>,
1823 XS, Requires<[HasSSE2]>;
1824def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001825 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001826 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001827 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001828 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001829 (undef),
1830 PSHUFHW_shuffle_mask:$src2)))]>,
1831 XS, Requires<[HasSSE2]>;
1832
1833// SSE2 with ImmT == Imm8 and XD prefix.
1834def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001835 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001836 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001837 [(set VR128:$dst, (v8i16 (vector_shuffle
1838 VR128:$src1, (undef),
1839 PSHUFLW_shuffle_mask:$src2)))]>,
1840 XD, Requires<[HasSSE2]>;
1841def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001842 (outs VR128:$dst), (ins i128mem:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001843 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001844 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001845 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001846 (undef),
1847 PSHUFLW_shuffle_mask:$src2)))]>,
1848 XD, Requires<[HasSSE2]>;
1849
1850
1851let isTwoAddress = 1 in {
1852 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001853 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001854 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001855 [(set VR128:$dst,
1856 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1857 UNPCKL_shuffle_mask)))]>;
1858 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001859 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001860 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001861 [(set VR128:$dst,
1862 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001863 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001864 UNPCKL_shuffle_mask)))]>;
1865 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001866 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001867 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001868 [(set VR128:$dst,
1869 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
1870 UNPCKL_shuffle_mask)))]>;
1871 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001872 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001873 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001874 [(set VR128:$dst,
1875 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001876 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001877 UNPCKL_shuffle_mask)))]>;
1878 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001879 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001880 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001881 [(set VR128:$dst,
1882 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
1883 UNPCKL_shuffle_mask)))]>;
1884 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001885 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001886 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001887 [(set VR128:$dst,
1888 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001889 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001890 UNPCKL_shuffle_mask)))]>;
1891 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001892 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001893 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001894 [(set VR128:$dst,
1895 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
1896 UNPCKL_shuffle_mask)))]>;
1897 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001898 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001899 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001900 [(set VR128:$dst,
1901 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001902 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001903 UNPCKL_shuffle_mask)))]>;
1904
1905 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001906 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001907 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001908 [(set VR128:$dst,
1909 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1910 UNPCKH_shuffle_mask)))]>;
1911 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001912 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001913 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914 [(set VR128:$dst,
1915 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001916 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001917 UNPCKH_shuffle_mask)))]>;
1918 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001919 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001920 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001921 [(set VR128:$dst,
1922 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
1923 UNPCKH_shuffle_mask)))]>;
1924 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001925 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001926 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001927 [(set VR128:$dst,
1928 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001929 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001930 UNPCKH_shuffle_mask)))]>;
1931 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001932 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001933 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001934 [(set VR128:$dst,
1935 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
1936 UNPCKH_shuffle_mask)))]>;
1937 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001938 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001939 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001940 [(set VR128:$dst,
1941 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001942 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001943 UNPCKH_shuffle_mask)))]>;
1944 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001945 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001946 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001947 [(set VR128:$dst,
1948 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
1949 UNPCKH_shuffle_mask)))]>;
1950 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001951 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001952 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001953 [(set VR128:$dst,
1954 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001955 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001956 UNPCKH_shuffle_mask)))]>;
1957}
1958
1959// Extract / Insert
1960def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001961 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001962 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001963 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
1964 (iPTR imm:$src2)))]>;
1965let isTwoAddress = 1 in {
1966 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001967 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001968 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001969 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001970 [(set VR128:$dst,
1971 (v8i16 (X86pinsrw (v8i16 VR128:$src1),
1972 GR32:$src2, (iPTR imm:$src3))))]>;
1973 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001974 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001975 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001976 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001977 [(set VR128:$dst,
1978 (v8i16 (X86pinsrw (v8i16 VR128:$src1),
1979 (i32 (anyext (loadi16 addr:$src2))),
1980 (iPTR imm:$src3))))]>;
1981}
1982
1983// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00001984def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001985 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001986 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
1987
1988// Conditional store
Evan Chengb783fa32007-07-19 01:14:50 +00001989def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00001990 "maskmovdqu\t{$mask, $src|$src, $mask}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001991 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>,
1992 Imp<[EDI],[]>;
1993
1994// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00001995def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001996 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001997 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001998def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001999 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002000 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002001def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002002 "movnti\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002003 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2004 TB, Requires<[HasSSE2]>;
2005
2006// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002007def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002008 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002009 TB, Requires<[HasSSE2]>;
2010
2011// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +00002012def LFENCE : I<0xAE, MRM5m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002013 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002014def MFENCE : I<0xAE, MRM6m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002015 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2016
2017
2018// Alias instructions that map zero vector to pxor / xorp* for sse.
2019// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2020let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002021 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002022 "pcmpeqd\t$dst, $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002023 [(set VR128:$dst, (v2f64 immAllOnesV))]>;
2024
2025// FR64 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +00002026def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002027 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002028 [(set VR128:$dst,
2029 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002030def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002031 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002032 [(set VR128:$dst,
2033 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2034
Evan Chengb783fa32007-07-19 01:14:50 +00002035def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002036 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002037 [(set VR128:$dst,
2038 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002039def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002040 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002041 [(set VR128:$dst,
2042 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2043
Evan Chengb783fa32007-07-19 01:14:50 +00002044def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002045 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002046 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2047
Evan Chengb783fa32007-07-19 01:14:50 +00002048def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002049 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002050 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2051
2052// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002053def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002054 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002055 [(set VR128:$dst,
2056 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2057 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002058def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002059 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002060 [(store (i64 (vector_extract (v2i64 VR128:$src),
2061 (iPTR 0))), addr:$dst)]>;
2062
2063// FIXME: may not be able to eliminate this movss with coalescing the src and
2064// dest register classes are different. We really want to write this pattern
2065// like this:
2066// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2067// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +00002068def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002069 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002070 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2071 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002072def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002073 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002074 [(store (f64 (vector_extract (v2f64 VR128:$src),
2075 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002076def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002077 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002078 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2079 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002080def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002081 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002082 [(store (i32 (vector_extract (v4i32 VR128:$src),
2083 (iPTR 0))), addr:$dst)]>;
2084
Evan Chengb783fa32007-07-19 01:14:50 +00002085def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002086 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002087 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002088def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002089 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002090 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2091
2092
2093// Move to lower bits of a VR128, leaving upper bits alone.
2094// Three operand (but two address) aliases.
2095let isTwoAddress = 1 in {
2096 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002097 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002098 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002099
2100 let AddedComplexity = 15 in
2101 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002102 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002103 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002104 [(set VR128:$dst,
2105 (v2f64 (vector_shuffle VR128:$src1, VR128:$src2,
2106 MOVL_shuffle_mask)))]>;
2107}
2108
2109// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002110def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002111 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002112 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2113
2114// Move to lower bits of a VR128 and zeroing upper bits.
2115// Loading from memory automatically zeroing upper bits.
2116let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002117 def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002118 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002119 [(set VR128:$dst,
2120 (v2f64 (vector_shuffle immAllZerosV,
2121 (v2f64 (scalar_to_vector
2122 (loadf64 addr:$src))),
2123 MOVL_shuffle_mask)))]>;
2124
2125let AddedComplexity = 15 in
2126// movd / movq to XMM register zero-extends
Evan Chengb783fa32007-07-19 01:14:50 +00002127def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002128 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002129 [(set VR128:$dst,
2130 (v4i32 (vector_shuffle immAllZerosV,
2131 (v4i32 (scalar_to_vector GR32:$src)),
2132 MOVL_shuffle_mask)))]>;
2133let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002134def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002135 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002136 [(set VR128:$dst,
2137 (v4i32 (vector_shuffle immAllZerosV,
2138 (v4i32 (scalar_to_vector (loadi32 addr:$src))),
2139 MOVL_shuffle_mask)))]>;
2140
2141// Moving from XMM to XMM but still clear upper 64 bits.
2142let AddedComplexity = 15 in
Evan Chengb783fa32007-07-19 01:14:50 +00002143def MOVZQI2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002144 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002145 [(set VR128:$dst, (int_x86_sse2_movl_dq VR128:$src))]>,
2146 XS, Requires<[HasSSE2]>;
2147let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002148def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002149 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002150 [(set VR128:$dst, (int_x86_sse2_movl_dq
Dan Gohman4a4f1512007-07-18 20:23:34 +00002151 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002152 XS, Requires<[HasSSE2]>;
2153
2154
2155//===----------------------------------------------------------------------===//
2156// SSE3 Instructions
2157//===----------------------------------------------------------------------===//
2158
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002159// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002160def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002161 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002162 [(set VR128:$dst, (v4f32 (vector_shuffle
2163 VR128:$src, (undef),
2164 MOVSHDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002165def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002166 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002167 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002168 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002169 MOVSHDUP_shuffle_mask)))]>;
2170
Evan Chengb783fa32007-07-19 01:14:50 +00002171def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002172 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002173 [(set VR128:$dst, (v4f32 (vector_shuffle
2174 VR128:$src, (undef),
2175 MOVSLDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002176def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002177 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002178 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002179 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002180 MOVSLDUP_shuffle_mask)))]>;
2181
Evan Chengb783fa32007-07-19 01:14:50 +00002182def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002183 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002184 [(set VR128:$dst, (v2f64 (vector_shuffle
2185 VR128:$src, (undef),
2186 SSE_splat_lo_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002187def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002188 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002189 [(set VR128:$dst,
2190 (v2f64 (vector_shuffle
2191 (scalar_to_vector (loadf64 addr:$src)),
2192 (undef),
2193 SSE_splat_lo_mask)))]>;
2194
2195// Arithmetic
2196let isTwoAddress = 1 in {
2197 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002198 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002199 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002200 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2201 VR128:$src2))]>;
2202 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002203 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002204 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002205 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2206 (load addr:$src2)))]>;
2207 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002208 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002209 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002210 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2211 VR128:$src2))]>;
2212 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002213 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002214 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002215 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2216 (load addr:$src2)))]>;
2217}
2218
Evan Chengb783fa32007-07-19 01:14:50 +00002219def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002220 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002221 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2222
2223// Horizontal ops
2224class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002225 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002226 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002227 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2228class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002229 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002230 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002231 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (load addr:$src2))))]>;
2232class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002233 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002234 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002235 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2236class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002237 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002238 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002239 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (load addr:$src2))))]>;
2240
2241let isTwoAddress = 1 in {
2242 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2243 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2244 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2245 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2246 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2247 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2248 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2249 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2250}
2251
2252// Thread synchronization
Evan Chengb783fa32007-07-19 01:14:50 +00002253def MONITOR : I<0xC8, RawFrm, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002254 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002255def MWAIT : I<0xC9, RawFrm, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002256 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2257
2258// vector_shuffle v1, <undef> <1, 1, 3, 3>
2259let AddedComplexity = 15 in
2260def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2261 MOVSHDUP_shuffle_mask)),
2262 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2263let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002264def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002265 MOVSHDUP_shuffle_mask)),
2266 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2267
2268// vector_shuffle v1, <undef> <0, 0, 2, 2>
2269let AddedComplexity = 15 in
2270 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2271 MOVSLDUP_shuffle_mask)),
2272 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2273let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002274 def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002275 MOVSLDUP_shuffle_mask)),
2276 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2277
2278//===----------------------------------------------------------------------===//
2279// SSSE3 Instructions
2280//===----------------------------------------------------------------------===//
2281
2282// SSE3 Instruction Templates:
2283//
2284// SS38I - SSSE3 instructions with T8 and OpSize prefixes.
2285// SS3AI - SSSE3 instructions with TA and OpSize prefixes.
2286
Evan Chengb783fa32007-07-19 01:14:50 +00002287class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
2288 list<dag> pattern>
2289 : I<o, F, outs, ins, asm, pattern>, T8, OpSize, Requires<[HasSSSE3]>;
2290class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
2291 list<dag> pattern>
2292 : I<o, F, outs, ins, asm, pattern>, TA, OpSize, Requires<[HasSSSE3]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002293
2294/// SS3I_binop_rm_int - Simple SSSE3 binary operatr whose type is v2i64.
2295let isTwoAddress = 1 in {
2296 multiclass SS3I_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
2297 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00002298 def rr : SS38I<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002299 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002300 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
2301 let isCommutable = Commutable;
2302 }
Evan Chengb783fa32007-07-19 01:14:50 +00002303 def rm : SS38I<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002304 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002305 [(set VR128:$dst,
2306 (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002307 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002308 }
2309}
2310
2311defm PMULHRSW128 : SS3I_binop_rm_int<0x0B, "pmulhrsw",
2312 int_x86_ssse3_pmulhrsw_128, 1>;
2313
2314//===----------------------------------------------------------------------===//
2315// Non-Instruction Patterns
2316//===----------------------------------------------------------------------===//
2317
2318// 128-bit vector undef's.
2319def : Pat<(v2f64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2320def : Pat<(v16i8 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2321def : Pat<(v8i16 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2322def : Pat<(v4i32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2323def : Pat<(v2i64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2324
2325// 128-bit vector all zero's.
2326def : Pat<(v16i8 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2327def : Pat<(v8i16 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2328def : Pat<(v4i32 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2329def : Pat<(v2i64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2330def : Pat<(v2f64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2331
2332// 128-bit vector all one's.
2333def : Pat<(v16i8 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2334def : Pat<(v8i16 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2335def : Pat<(v4i32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2336def : Pat<(v2i64 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2337def : Pat<(v4f32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE1]>;
2338
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002339
2340// Scalar to v8i16 / v16i8. The source may be a GR32, but only the lower 8 or
2341// 16-bits matter.
2342def : Pat<(v8i16 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2343 Requires<[HasSSE2]>;
2344def : Pat<(v16i8 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2345 Requires<[HasSSE2]>;
2346
2347// bit_convert
2348let Predicates = [HasSSE2] in {
2349 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2350 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2351 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2352 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2353 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2354 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2355 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2356 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2357 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2358 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2359 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2360 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2361 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2362 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2363 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2364 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2365 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2366 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2367 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2368 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2369 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2370 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2371 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2372 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2373 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2374 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2375 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2376 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2377 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2378 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2379}
2380
2381// Move scalar to XMM zero-extended
2382// movd to XMM register zero-extends
2383let AddedComplexity = 15 in {
2384def : Pat<(v8i16 (vector_shuffle immAllZerosV,
2385 (v8i16 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2386 (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2387def : Pat<(v16i8 (vector_shuffle immAllZerosV,
2388 (v16i8 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2389 (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2390// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2391def : Pat<(v2f64 (vector_shuffle immAllZerosV,
2392 (v2f64 (scalar_to_vector FR64:$src)), MOVL_shuffle_mask)),
2393 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
2394def : Pat<(v4f32 (vector_shuffle immAllZerosV,
2395 (v4f32 (scalar_to_vector FR32:$src)), MOVL_shuffle_mask)),
2396 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE2]>;
2397}
2398
2399// Splat v2f64 / v2i64
2400let AddedComplexity = 10 in {
2401def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2402 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2403def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2404 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2405def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2406 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2407def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2408 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2409}
2410
2411// Splat v4f32
2412def : Pat<(vector_shuffle (v4f32 VR128:$src), (undef), SSE_splat_mask:$sm),
2413 (SHUFPSrri VR128:$src, VR128:$src, SSE_splat_mask:$sm)>,
2414 Requires<[HasSSE1]>;
2415
2416// Special unary SHUFPSrri case.
2417// FIXME: when we want non two-address code, then we should use PSHUFD?
2418def : Pat<(vector_shuffle (v4f32 VR128:$src1), (undef),
2419 SHUFP_unary_shuffle_mask:$sm),
2420 (SHUFPSrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2421 Requires<[HasSSE1]>;
2422// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Dan Gohman4a4f1512007-07-18 20:23:34 +00002423def : Pat<(vector_shuffle (memopv4f32 addr:$src1), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002424 SHUFP_unary_shuffle_mask:$sm),
2425 (PSHUFDmi addr:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2426 Requires<[HasSSE2]>;
2427// Special binary v4i32 shuffle cases with SHUFPS.
2428def : Pat<(vector_shuffle (v4i32 VR128:$src1), (v4i32 VR128:$src2),
2429 PSHUFD_binary_shuffle_mask:$sm),
2430 (SHUFPSrri VR128:$src1, VR128:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2431 Requires<[HasSSE2]>;
2432def : Pat<(vector_shuffle (v4i32 VR128:$src1),
Dan Gohman4a4f1512007-07-18 20:23:34 +00002433 (bc_v4i32 (memopv2i64 addr:$src2)), PSHUFD_binary_shuffle_mask:$sm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002434 (SHUFPSrmi VR128:$src1, addr:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2435 Requires<[HasSSE2]>;
2436
2437// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2438let AddedComplexity = 10 in {
2439def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2440 UNPCKL_v_undef_shuffle_mask)),
2441 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2442def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2443 UNPCKL_v_undef_shuffle_mask)),
2444 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2445def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2446 UNPCKL_v_undef_shuffle_mask)),
2447 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2448def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2449 UNPCKL_v_undef_shuffle_mask)),
2450 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2451}
2452
2453// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2454let AddedComplexity = 10 in {
2455def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2456 UNPCKH_v_undef_shuffle_mask)),
2457 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2458def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2459 UNPCKH_v_undef_shuffle_mask)),
2460 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2461def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2462 UNPCKH_v_undef_shuffle_mask)),
2463 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2464def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2465 UNPCKH_v_undef_shuffle_mask)),
2466 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2467}
2468
2469let AddedComplexity = 15 in {
2470// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2471def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2472 MOVHP_shuffle_mask)),
2473 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2474
2475// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2476def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2477 MOVHLPS_shuffle_mask)),
2478 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2479
2480// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2481def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2482 MOVHLPS_v_undef_shuffle_mask)),
2483 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2484def : Pat<(v4i32 (vector_shuffle VR128:$src1, (undef),
2485 MOVHLPS_v_undef_shuffle_mask)),
2486 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2487}
2488
2489let AddedComplexity = 20 in {
2490// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2491// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Dan Gohman4a4f1512007-07-18 20:23:34 +00002492def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002493 MOVLP_shuffle_mask)),
2494 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002495def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002496 MOVLP_shuffle_mask)),
2497 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002498def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002499 MOVHP_shuffle_mask)),
2500 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002501def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002502 MOVHP_shuffle_mask)),
2503 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2504
Dan Gohman4a4f1512007-07-18 20:23:34 +00002505def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002506 MOVLP_shuffle_mask)),
2507 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002508def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002509 MOVLP_shuffle_mask)),
2510 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002511def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002512 MOVHP_shuffle_mask)),
2513 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002514def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002515 MOVLP_shuffle_mask)),
2516 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2517}
2518
2519let AddedComplexity = 15 in {
2520// Setting the lowest element in the vector.
2521def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2522 MOVL_shuffle_mask)),
2523 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2524def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2525 MOVL_shuffle_mask)),
2526 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2527
2528// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
2529def : Pat<(v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
2530 MOVLP_shuffle_mask)),
2531 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2532def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2533 MOVLP_shuffle_mask)),
2534 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2535}
2536
2537// Set lowest element and zero upper elements.
2538let AddedComplexity = 20 in
2539def : Pat<(bc_v2i64 (vector_shuffle immAllZerosV,
2540 (v2f64 (scalar_to_vector (loadf64 addr:$src))),
2541 MOVL_shuffle_mask)),
2542 (MOVZQI2PQIrm addr:$src)>, Requires<[HasSSE2]>;
2543
2544// FIXME: Temporary workaround since 2-wide shuffle is broken.
2545def : Pat<(int_x86_sse2_movs_d VR128:$src1, VR128:$src2),
2546 (v2f64 (MOVLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2547def : Pat<(int_x86_sse2_loadh_pd VR128:$src1, addr:$src2),
2548 (v2f64 (MOVHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2549def : Pat<(int_x86_sse2_loadl_pd VR128:$src1, addr:$src2),
2550 (v2f64 (MOVLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2551def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, VR128:$src2, imm:$src3),
2552 (v2f64 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$src3))>,
2553 Requires<[HasSSE2]>;
2554def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, (load addr:$src2), imm:$src3),
2555 (v2f64 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$src3))>,
2556 Requires<[HasSSE2]>;
2557def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, VR128:$src2),
2558 (v2f64 (UNPCKHPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2559def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, (load addr:$src2)),
2560 (v2f64 (UNPCKHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2561def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, VR128:$src2),
2562 (v2f64 (UNPCKLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2563def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, (load addr:$src2)),
2564 (v2f64 (UNPCKLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2565def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, VR128:$src2),
2566 (v2i64 (PUNPCKHQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2567def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, (load addr:$src2)),
2568 (v2i64 (PUNPCKHQDQrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2569def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, VR128:$src2),
2570 (v2i64 (PUNPCKLQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2571def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, (load addr:$src2)),
2572 (PUNPCKLQDQrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2573
2574// Some special case pandn patterns.
2575def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2576 VR128:$src2)),
2577 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2578def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2579 VR128:$src2)),
2580 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2581def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2582 VR128:$src2)),
2583 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2584
2585def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2586 (load addr:$src2))),
2587 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2588def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2589 (load addr:$src2))),
2590 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2591def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2592 (load addr:$src2))),
2593 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2594
Evan Cheng51a49b22007-07-20 00:27:43 +00002595// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00002596def : Pat<(alignedloadv4i32 addr:$src),
2597 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
2598def : Pat<(loadv4i32 addr:$src),
2599 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00002600def : Pat<(alignedloadv2i64 addr:$src),
2601 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
2602def : Pat<(loadv2i64 addr:$src),
2603 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
2604
2605def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
2606 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2607def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
2608 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2609def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
2610 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2611def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
2612 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2613def : Pat<(store (v2i64 VR128:$src), addr:$dst),
2614 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2615def : Pat<(store (v4i32 VR128:$src), addr:$dst),
2616 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2617def : Pat<(store (v8i16 VR128:$src), addr:$dst),
2618 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2619def : Pat<(store (v16i8 VR128:$src), addr:$dst),
2620 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
Evan Cheng86ab7d32007-07-31 08:04:03 +00002621
2622// (vextract (v4i32 bc (v4f32 s2v (f32 load $addr))), 0) -> (i32 load $addr)
2623def : Pat<(vector_extract
2624 (bc_v4i32 (v4f32 (scalar_to_vector (loadf32 addr:$src)))), (iPTR 0)),
Evan Cheng43a09ac2007-08-01 21:42:24 +00002625 (MOV32rm addr:$src)>, Requires<[HasSSE2]>;
Evan Cheng86ab7d32007-07-31 08:04:03 +00002626def : Pat<(vector_extract
2627 (bc_v2i64 (v2f64 (scalar_to_vector (loadf64 addr:$src)))), (iPTR 0)),
Evan Cheng43a09ac2007-08-01 21:42:24 +00002628 (MOV64rm addr:$src)>, Requires<[HasSSE2, In64BitMode]>;