blob: 2c86e8d1c335d4620814c7c51ad5307c9c575c51 [file] [log] [blame]
Arnold Schwaighofer373e8652007-10-12 21:30:57 +00001//====- X86InstrSSE.td - Describe the X86 Instruction Set --*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
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>;
Evan Chengf37bf452007-10-01 18:12:48 +000035def X86comi : SDNode<"X86ISD::COMI", SDTX86CmpTest>;
Evan Cheng621216e2007-09-29 00:00:36 +000036def X86ucomi : SDNode<"X86ISD::UCOMI", SDTX86CmpTest>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037def X86s2vec : SDNode<"X86ISD::S2VEC", SDTypeProfile<1, 1, []>, []>;
38def X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
39def X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
40
41//===----------------------------------------------------------------------===//
42// SSE 'Special' Instructions
43//===----------------------------------------------------------------------===//
44
Evan Chengb783fa32007-07-19 01:14:50 +000045def IMPLICIT_DEF_VR128 : I<0, Pseudo, (outs VR128:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 "#IMPLICIT_DEF $dst",
47 [(set VR128:$dst, (v4f32 (undef)))]>,
48 Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000049def IMPLICIT_DEF_FR32 : I<0, Pseudo, (outs FR32:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 "#IMPLICIT_DEF $dst",
Dale Johannesene0e0fd02007-09-23 14:52:20 +000051 [(set FR32:$dst, (undef))]>, Requires<[HasSSE1]>;
Evan Chengb783fa32007-07-19 01:14:50 +000052def IMPLICIT_DEF_FR64 : I<0, Pseudo, (outs FR64:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053 "#IMPLICIT_DEF $dst",
54 [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
55
56//===----------------------------------------------------------------------===//
57// SSE Complex Patterns
58//===----------------------------------------------------------------------===//
59
60// These are 'extloads' from a scalar to the low element of a vector, zeroing
61// the top elements. These are used for the SSE 'ss' and 'sd' instruction
62// forms.
63def sse_load_f32 : ComplexPattern<v4f32, 4, "SelectScalarSSELoad", [],
64 [SDNPHasChain]>;
65def sse_load_f64 : ComplexPattern<v2f64, 4, "SelectScalarSSELoad", [],
66 [SDNPHasChain]>;
67
68def ssmem : Operand<v4f32> {
69 let PrintMethod = "printf32mem";
70 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
71}
72def sdmem : Operand<v2f64> {
73 let PrintMethod = "printf64mem";
74 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc, i32imm);
75}
76
77//===----------------------------------------------------------------------===//
78// SSE pattern fragments
79//===----------------------------------------------------------------------===//
80
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081def loadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (load node:$ptr))>;
82def loadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (load node:$ptr))>;
83def loadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (load node:$ptr))>;
84def loadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (load node:$ptr))>;
85
Dan Gohman11821702007-07-27 17:16:43 +000086// Like 'store', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +000087def alignedstore : PatFrag<(ops node:$val, node:$ptr),
88 (st node:$val, node:$ptr), [{
89 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
90 return !ST->isTruncatingStore() &&
91 ST->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +000092 ST->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +000093 return false;
94}]>;
95
Dan Gohman11821702007-07-27 17:16:43 +000096// Like 'load', but always requires vector alignment.
Dan Gohman4a4f1512007-07-18 20:23:34 +000097def alignedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
98 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
99 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
100 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000101 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000102 return false;
103}]>;
104
Dan Gohman11821702007-07-27 17:16:43 +0000105def alignedloadfsf32 : PatFrag<(ops node:$ptr), (f32 (alignedload node:$ptr))>;
106def alignedloadfsf64 : PatFrag<(ops node:$ptr), (f64 (alignedload node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000107def alignedloadv4f32 : PatFrag<(ops node:$ptr), (v4f32 (alignedload node:$ptr))>;
108def alignedloadv2f64 : PatFrag<(ops node:$ptr), (v2f64 (alignedload node:$ptr))>;
109def alignedloadv4i32 : PatFrag<(ops node:$ptr), (v4i32 (alignedload node:$ptr))>;
110def alignedloadv2i64 : PatFrag<(ops node:$ptr), (v2i64 (alignedload node:$ptr))>;
111
112// Like 'load', but uses special alignment checks suitable for use in
113// memory operands in most SSE instructions, which are required to
114// be naturally aligned on some targets but not on others.
115// FIXME: Actually implement support for targets that don't require the
116// alignment. This probably wants a subtarget predicate.
117def memop : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
118 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
119 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
120 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman11821702007-07-27 17:16:43 +0000121 LD->getAlignment() >= 16;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000122 return false;
123}]>;
124
Dan Gohman11821702007-07-27 17:16:43 +0000125def memopfsf32 : PatFrag<(ops node:$ptr), (f32 (memop node:$ptr))>;
126def memopfsf64 : PatFrag<(ops node:$ptr), (f64 (memop node:$ptr))>;
Dan Gohman4a4f1512007-07-18 20:23:34 +0000127def memopv4f32 : PatFrag<(ops node:$ptr), (v4f32 (memop node:$ptr))>;
128def memopv2f64 : PatFrag<(ops node:$ptr), (v2f64 (memop node:$ptr))>;
129def memopv4i32 : PatFrag<(ops node:$ptr), (v4i32 (memop node:$ptr))>;
130def memopv2i64 : PatFrag<(ops node:$ptr), (v2i64 (memop node:$ptr))>;
131
Bill Wendling3b15d722007-08-11 09:52:53 +0000132// SSSE3 uses MMX registers for some instructions. They aren't aligned on a
133// 16-byte boundary.
134def memop64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
135 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
136 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
137 LD->getAddressingMode() == ISD::UNINDEXED &&
138 LD->getAlignment() >= 8;
139 return false;
140}]>;
141
142def memopv8i8 : PatFrag<(ops node:$ptr), (v8i8 (memop64 node:$ptr))>;
143def memopv16i8 : PatFrag<(ops node:$ptr), (v16i8 (memop64 node:$ptr))>;
144def memopv4i16 : PatFrag<(ops node:$ptr), (v4i16 (memop64 node:$ptr))>;
145def memopv8i16 : PatFrag<(ops node:$ptr), (v8i16 (memop64 node:$ptr))>;
146def memopv2i32 : PatFrag<(ops node:$ptr), (v2i32 (memop64 node:$ptr))>;
147
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148def bc_v4f32 : PatFrag<(ops node:$in), (v4f32 (bitconvert node:$in))>;
149def bc_v2f64 : PatFrag<(ops node:$in), (v2f64 (bitconvert node:$in))>;
150def bc_v16i8 : PatFrag<(ops node:$in), (v16i8 (bitconvert node:$in))>;
151def bc_v8i16 : PatFrag<(ops node:$in), (v8i16 (bitconvert node:$in))>;
152def bc_v4i32 : PatFrag<(ops node:$in), (v4i32 (bitconvert node:$in))>;
153def bc_v2i64 : PatFrag<(ops node:$in), (v2i64 (bitconvert node:$in))>;
154
155def fp32imm0 : PatLeaf<(f32 fpimm), [{
156 return N->isExactlyValue(+0.0);
157}]>;
158
159def PSxLDQ_imm : SDNodeXForm<imm, [{
160 // Transformation function: imm >> 3
161 return getI32Imm(N->getValue() >> 3);
162}]>;
163
164// SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to PSHUF*,
165// SHUFP* etc. imm.
166def SHUFFLE_get_shuf_imm : SDNodeXForm<build_vector, [{
167 return getI8Imm(X86::getShuffleSHUFImmediate(N));
168}]>;
169
170// SHUFFLE_get_pshufhw_imm xform function: convert vector_shuffle mask to
171// PSHUFHW imm.
172def SHUFFLE_get_pshufhw_imm : SDNodeXForm<build_vector, [{
173 return getI8Imm(X86::getShufflePSHUFHWImmediate(N));
174}]>;
175
176// SHUFFLE_get_pshuflw_imm xform function: convert vector_shuffle mask to
177// PSHUFLW imm.
178def SHUFFLE_get_pshuflw_imm : SDNodeXForm<build_vector, [{
179 return getI8Imm(X86::getShufflePSHUFLWImmediate(N));
180}]>;
181
182def SSE_splat_mask : PatLeaf<(build_vector), [{
183 return X86::isSplatMask(N);
184}], SHUFFLE_get_shuf_imm>;
185
186def SSE_splat_lo_mask : PatLeaf<(build_vector), [{
187 return X86::isSplatLoMask(N);
188}]>;
189
190def MOVHLPS_shuffle_mask : PatLeaf<(build_vector), [{
191 return X86::isMOVHLPSMask(N);
192}]>;
193
194def MOVHLPS_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
195 return X86::isMOVHLPS_v_undef_Mask(N);
196}]>;
197
198def MOVHP_shuffle_mask : PatLeaf<(build_vector), [{
199 return X86::isMOVHPMask(N);
200}]>;
201
202def MOVLP_shuffle_mask : PatLeaf<(build_vector), [{
203 return X86::isMOVLPMask(N);
204}]>;
205
206def MOVL_shuffle_mask : PatLeaf<(build_vector), [{
207 return X86::isMOVLMask(N);
208}]>;
209
210def MOVSHDUP_shuffle_mask : PatLeaf<(build_vector), [{
211 return X86::isMOVSHDUPMask(N);
212}]>;
213
214def MOVSLDUP_shuffle_mask : PatLeaf<(build_vector), [{
215 return X86::isMOVSLDUPMask(N);
216}]>;
217
218def UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
219 return X86::isUNPCKLMask(N);
220}]>;
221
222def UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
223 return X86::isUNPCKHMask(N);
224}]>;
225
226def UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
227 return X86::isUNPCKL_v_undef_Mask(N);
228}]>;
229
230def UNPCKH_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
231 return X86::isUNPCKH_v_undef_Mask(N);
232}]>;
233
234def PSHUFD_shuffle_mask : PatLeaf<(build_vector), [{
235 return X86::isPSHUFDMask(N);
236}], SHUFFLE_get_shuf_imm>;
237
238def PSHUFHW_shuffle_mask : PatLeaf<(build_vector), [{
239 return X86::isPSHUFHWMask(N);
240}], SHUFFLE_get_pshufhw_imm>;
241
242def PSHUFLW_shuffle_mask : PatLeaf<(build_vector), [{
243 return X86::isPSHUFLWMask(N);
244}], SHUFFLE_get_pshuflw_imm>;
245
246def SHUFP_unary_shuffle_mask : PatLeaf<(build_vector), [{
247 return X86::isPSHUFDMask(N);
248}], SHUFFLE_get_shuf_imm>;
249
250def SHUFP_shuffle_mask : PatLeaf<(build_vector), [{
251 return X86::isSHUFPMask(N);
252}], SHUFFLE_get_shuf_imm>;
253
254def PSHUFD_binary_shuffle_mask : PatLeaf<(build_vector), [{
255 return X86::isSHUFPMask(N);
256}], SHUFFLE_get_shuf_imm>;
257
258//===----------------------------------------------------------------------===//
259// SSE scalar FP Instructions
260//===----------------------------------------------------------------------===//
261
262// CMOV* - Used to implement the SSE SELECT DAG operation. Expanded by the
263// scheduler into a branch sequence.
Evan Cheng950aac02007-09-25 01:57:46 +0000264// These are expanded by the scheduler.
265let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 def CMOV_FR32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000267 (outs FR32:$dst), (ins FR32:$t, FR32:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268 "#CMOV_FR32 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000269 [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
270 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271 def CMOV_FR64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000272 (outs FR64:$dst), (ins FR64:$t, FR64:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 "#CMOV_FR64 PSEUDO!",
Evan Cheng621216e2007-09-29 00:00:36 +0000274 [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
275 EFLAGS))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 def CMOV_V4F32 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000277 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278 "#CMOV_V4F32 PSEUDO!",
279 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000280 (v4f32 (X86cmov VR128:$t, VR128:$f, imm:$cond,
281 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 def CMOV_V2F64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000283 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 "#CMOV_V2F64 PSEUDO!",
285 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000286 (v2f64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
287 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 def CMOV_V2I64 : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +0000289 (outs VR128:$dst), (ins VR128:$t, VR128:$f, i8imm:$cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290 "#CMOV_V2I64 PSEUDO!",
291 [(set VR128:$dst,
Evan Cheng621216e2007-09-29 00:00:36 +0000292 (v2i64 (X86cmov VR128:$t, VR128:$f, imm:$cond,
Evan Cheng950aac02007-09-25 01:57:46 +0000293 EFLAGS)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294}
295
296//===----------------------------------------------------------------------===//
297// SSE1 Instructions
298//===----------------------------------------------------------------------===//
299
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000301def MOVSSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000302 "movss\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +0000303let isLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000304def MOVSSrm : SSI<0x10, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000305 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 [(set FR32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000307def MOVSSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000308 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 [(store FR32:$src, addr:$dst)]>;
310
311// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000312def CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000313 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 [(set GR32:$dst, (fp_to_sint FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000315def CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$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, (fp_to_sint (loadf32 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000318def CVTSI2SSrr : SSI<0x2A, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000319 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320 [(set FR32:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000321def CVTSI2SSrm : SSI<0x2A, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000322 "cvtsi2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
324
325// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +0000326def Int_CVTSS2SIrr : SSI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000327 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000328 [(set GR32:$dst, (int_x86_sse_cvtss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000329def Int_CVTSS2SIrm : SSI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "cvtss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set GR32:$dst, (int_x86_sse_cvtss2si
332 (load addr:$src)))]>;
333
Dale Johannesen1fbb4a52007-10-30 22:15:38 +0000334// Match intrinisics which expect MM and XMM operand(s).
335def Int_CVTPS2PIrr : PSI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
336 "cvtps2pi\t{$src, $dst|$dst, $src}",
337 [(set VR64:$dst, (int_x86_sse_cvtps2pi VR128:$src))]>;
338def Int_CVTPS2PIrm : PSI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
339 "cvtps2pi\t{$src, $dst|$dst, $src}",
340 [(set VR64:$dst, (int_x86_sse_cvtps2pi
341 (load addr:$src)))]>;
342def Int_CVTTPS2PIrr: PSI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
343 "cvttps2pi\t{$src, $dst|$dst, $src}",
344 [(set VR64:$dst, (int_x86_sse_cvttps2pi VR128:$src))]>;
345def Int_CVTTPS2PIrm: PSI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
346 "cvttps2pi\t{$src, $dst|$dst, $src}",
347 [(set VR64:$dst, (int_x86_sse_cvttps2pi
348 (load addr:$src)))]>;
349let isTwoAddress = 1 in {
350 def Int_CVTPI2PSrr : PSI<0x2A, MRMSrcReg,
351 (outs VR128:$dst), (ins VR128:$src1, VR64:$src2),
352 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
353 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
354 VR64:$src2))]>;
355 def Int_CVTPI2PSrm : PSI<0x2A, MRMSrcMem,
356 (outs VR128:$dst), (ins VR128:$src1, i64mem:$src2),
357 "cvtpi2ps\t{$src2, $dst|$dst, $src2}",
358 [(set VR128:$dst, (int_x86_sse_cvtpi2ps VR128:$src1,
359 (load addr:$src2)))]>;
360}
361
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +0000363def Int_CVTTSS2SIrr : SSI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000364 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000365 [(set GR32:$dst,
366 (int_x86_sse_cvttss2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000367def Int_CVTTSS2SIrm : SSI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000368 "cvttss2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 [(set GR32:$dst,
370 (int_x86_sse_cvttss2si(load addr:$src)))]>;
371
372let isTwoAddress = 1 in {
373 def Int_CVTSI2SSrr : SSI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000374 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000375 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
377 GR32:$src2))]>;
378 def Int_CVTSI2SSrm : SSI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000379 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000380 "cvtsi2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 [(set VR128:$dst, (int_x86_sse_cvtsi2ss VR128:$src1,
382 (loadi32 addr:$src2)))]>;
383}
384
385// Comparison instructions
386let isTwoAddress = 1 in {
387 def CMPSSrr : SSI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000388 (outs FR32:$dst), (ins FR32:$src1, FR32:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000389 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390 def CMPSSrm : SSI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000391 (outs FR32:$dst), (ins FR32:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000392 "cmp${cc}ss\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393}
394
Evan Cheng55687072007-09-14 21:48:26 +0000395let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000396def UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000397 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000398 [(X86cmp FR32:$src1, FR32:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000399def UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000400 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000401 [(X86cmp FR32:$src1, (loadf32 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000402 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000403} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404
405// Aliases to match intrinsics which expect XMM operand(s).
406let isTwoAddress = 1 in {
407 def Int_CMPSSrr : SSI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000408 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
411 VR128:$src, imm:$cc))]>;
412 def Int_CMPSSrm : SSI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000413 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000414 "cmp${cc}ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 [(set VR128:$dst, (int_x86_sse_cmp_ss VR128:$src1,
416 (load addr:$src), imm:$cc))]>;
417}
418
Evan Cheng55687072007-09-14 21:48:26 +0000419let Defs = [EFLAGS] in {
Evan Cheng621216e2007-09-29 00:00:36 +0000420def Int_UCOMISSrr: PSI<0x2E, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000421 (ins VR128:$src1, VR128:$src2),
422 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000423 [(X86ucomi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000424 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000425def Int_UCOMISSrm: PSI<0x2E, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000426 (ins VR128:$src1, f128mem:$src2),
427 "ucomiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000428 [(X86ucomi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000429 (implicit EFLAGS)]>;
430
Evan Cheng621216e2007-09-29 00:00:36 +0000431def Int_COMISSrr: PSI<0x2F, MRMSrcReg, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000432 (ins VR128:$src1, VR128:$src2),
433 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000434 [(X86comi (v4f32 VR128:$src1), VR128:$src2),
Evan Cheng950aac02007-09-25 01:57:46 +0000435 (implicit EFLAGS)]>;
Evan Cheng621216e2007-09-29 00:00:36 +0000436def Int_COMISSrm: PSI<0x2F, MRMSrcMem, (outs),
Evan Cheng950aac02007-09-25 01:57:46 +0000437 (ins VR128:$src1, f128mem:$src2),
438 "comiss\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +0000439 [(X86comi (v4f32 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +0000440 (implicit EFLAGS)]>;
Evan Cheng55687072007-09-14 21:48:26 +0000441} // Defs = [EFLAGS]
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442
443// Aliases of packed SSE1 instructions for scalar use. These all have names that
444// start with 'Fs'.
445
446// Alias instructions that map fld0 to pxor for sse.
Dan Gohman8aef09b2007-09-07 21:32:51 +0000447let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000448def FsFLD0SS : I<0xEF, MRMInitReg, (outs FR32:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "pxor\t$dst, $dst", [(set FR32:$dst, fp32imm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450 Requires<[HasSSE1]>, TB, OpSize;
451
452// Alias instruction to do FR32 reg-to-reg copy using movaps. Upper bits are
453// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +0000454def FsMOVAPSrr : PSI<0x28, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000455 "movaps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456
457// Alias instruction to load FR32 from f128mem using movaps. Upper bits are
458// disregarded.
Evan Cheng4e84e452007-08-30 05:49:43 +0000459let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000460def FsMOVAPSrm : PSI<0x28, MRMSrcMem, (outs FR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000461 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +0000462 [(set FR32:$dst, (alignedloadfsf32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
464// Alias bitwise logical operations using SSE logical ops on packed FP values.
465let isTwoAddress = 1 in {
466let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000467 def FsANDPSrr : PSI<0x54, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000468 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469 [(set FR32:$dst, (X86fand FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000470 def FsORPSrr : PSI<0x56, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000471 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472 [(set FR32:$dst, (X86for FR32:$src1, FR32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000473 def FsXORPSrr : PSI<0x57, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000474 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 [(set FR32:$dst, (X86fxor FR32:$src1, FR32:$src2))]>;
476}
477
Evan Chengb783fa32007-07-19 01:14:50 +0000478def FsANDPSrm : PSI<0x54, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000479 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480 [(set FR32:$dst, (X86fand FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000481 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000482def FsORPSrm : PSI<0x56, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000483 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484 [(set FR32:$dst, (X86for FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000485 (memopfsf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000486def FsXORPSrm : PSI<0x57, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000487 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488 [(set FR32:$dst, (X86fxor FR32:$src1,
Dan Gohman11821702007-07-27 17:16:43 +0000489 (memopfsf32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490
491def FsANDNPSrr : PSI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000492 (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000493 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494def FsANDNPSrm : PSI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000495 (outs FR32:$dst), (ins FR32:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000496 "andnps\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497}
498
499/// basic_sse1_fp_binop_rm - SSE1 binops come in both scalar and vector forms.
500///
501/// In addition, we also have a special variant of the scalar form here to
502/// represent the associated intrinsic operation. This form is unlike the
503/// plain scalar form, in that it takes an entire vector (instead of a scalar)
504/// and leaves the top elements undefined.
505///
506/// These three forms can each be reg+reg or reg+mem, so there are a total of
507/// six "instructions".
508///
509let isTwoAddress = 1 in {
510multiclass basic_sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
511 SDNode OpNode, Intrinsic F32Int,
512 bit Commutable = 0> {
513 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000514 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000515 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
517 let isCommutable = Commutable;
518 }
519
520 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000521 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000522 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
524
525 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000526 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000527 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
529 let isCommutable = Commutable;
530 }
531
532 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000533 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000534 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000535 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536
537 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000538 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000539 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
541 let isCommutable = Commutable;
542 }
543
544 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000545 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000546 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 [(set VR128:$dst, (F32Int VR128:$src1,
548 sse_load_f32:$src2))]>;
549}
550}
551
552// Arithmetic instructions
553defm ADD : basic_sse1_fp_binop_rm<0x58, "add", fadd, int_x86_sse_add_ss, 1>;
554defm MUL : basic_sse1_fp_binop_rm<0x59, "mul", fmul, int_x86_sse_mul_ss, 1>;
555defm SUB : basic_sse1_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse_sub_ss>;
556defm DIV : basic_sse1_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse_div_ss>;
557
558/// sse1_fp_binop_rm - Other SSE1 binops
559///
560/// This multiclass is like basic_sse1_fp_binop_rm, with the addition of
561/// instructions for a full-vector intrinsic form. Operations that map
562/// onto C operators don't use this form since they just use the plain
563/// vector form instead of having a separate vector intrinsic form.
564///
565/// This provides a total of eight "instructions".
566///
567let isTwoAddress = 1 in {
568multiclass sse1_fp_binop_rm<bits<8> opc, string OpcodeStr,
569 SDNode OpNode,
570 Intrinsic F32Int,
571 Intrinsic V4F32Int,
572 bit Commutable = 0> {
573
574 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000575 def SSrr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000576 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577 [(set FR32:$dst, (OpNode FR32:$src1, FR32:$src2))]> {
578 let isCommutable = Commutable;
579 }
580
581 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000582 def SSrm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins FR32:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000583 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584 [(set FR32:$dst, (OpNode FR32:$src1, (load addr:$src2)))]>;
585
586 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000587 def PSrr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000588 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589 [(set VR128:$dst, (v4f32 (OpNode VR128:$src1, VR128:$src2)))]> {
590 let isCommutable = Commutable;
591 }
592
593 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000594 def PSrm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000595 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000596 [(set VR128:$dst, (OpNode VR128:$src1, (memopv4f32 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597
598 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000599 def SSrr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000600 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 [(set VR128:$dst, (F32Int VR128:$src1, VR128:$src2))]> {
602 let isCommutable = Commutable;
603 }
604
605 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000606 def SSrm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, ssmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000607 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608 [(set VR128:$dst, (F32Int VR128:$src1,
609 sse_load_f32:$src2))]>;
610
611 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000612 def PSrr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000613 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 [(set VR128:$dst, (V4F32Int VR128:$src1, VR128:$src2))]> {
615 let isCommutable = Commutable;
616 }
617
618 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +0000619 def PSrm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000620 !strconcat(OpcodeStr, "ps\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621 [(set VR128:$dst, (V4F32Int VR128:$src1, (load addr:$src2)))]>;
622}
623}
624
625defm MAX : sse1_fp_binop_rm<0x5F, "max", X86fmax,
626 int_x86_sse_max_ss, int_x86_sse_max_ps>;
627defm MIN : sse1_fp_binop_rm<0x5D, "min", X86fmin,
628 int_x86_sse_min_ss, int_x86_sse_min_ps>;
629
630//===----------------------------------------------------------------------===//
631// SSE packed FP Instructions
632
633// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000634def MOVAPSrr : PSI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000635 "movaps\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +0000636let isLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000637def MOVAPSrm : PSI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000638 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000639 [(set VR128:$dst, (alignedloadv4f32 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640
Evan Chengb783fa32007-07-19 01:14:50 +0000641def MOVAPSmr : PSI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000642 "movaps\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000643 [(alignedstore (v4f32 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000644
Evan Chengb783fa32007-07-19 01:14:50 +0000645def MOVUPSrr : PSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000646 "movups\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +0000647let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000648def MOVUPSrm : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000649 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000650 [(set VR128:$dst, (loadv4f32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000651def MOVUPSmr : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000652 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000653 [(store (v4f32 VR128:$src), addr:$dst)]>;
654
655// Intrinsic forms of MOVUPS load and store
Evan Cheng4e84e452007-08-30 05:49:43 +0000656let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000657def MOVUPSrm_Int : PSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000658 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000659 [(set VR128:$dst, (int_x86_sse_loadu_ps addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000660def MOVUPSmr_Int : PSI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000661 "movups\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +0000662 [(int_x86_sse_storeu_ps addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663
664let isTwoAddress = 1 in {
665 let AddedComplexity = 20 in {
666 def MOVLPSrm : PSI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000667 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000668 "movlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 [(set VR128:$dst,
670 (v4f32 (vector_shuffle VR128:$src1,
671 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
672 MOVLP_shuffle_mask)))]>;
673 def MOVHPSrm : PSI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000674 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000675 "movhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 [(set VR128:$dst,
677 (v4f32 (vector_shuffle VR128:$src1,
678 (bc_v4f32 (v2f64 (scalar_to_vector (loadf64 addr:$src2)))),
679 MOVHP_shuffle_mask)))]>;
680 } // AddedComplexity
681} // isTwoAddress
682
Evan Chengb783fa32007-07-19 01:14:50 +0000683def MOVLPSmr : PSI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000684 "movlps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 [(store (f64 (vector_extract (bc_v2f64 (v4f32 VR128:$src)),
686 (iPTR 0))), addr:$dst)]>;
687
688// v2f64 extract element 1 is always custom lowered to unpack high to low
689// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +0000690def MOVHPSmr : PSI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000691 "movhps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000692 [(store (f64 (vector_extract
693 (v2f64 (vector_shuffle
694 (bc_v2f64 (v4f32 VR128:$src)), (undef),
695 UNPCKH_shuffle_mask)), (iPTR 0))),
696 addr:$dst)]>;
697
698let isTwoAddress = 1 in {
699let AddedComplexity = 15 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000700def MOVLHPSrr : PSI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000701 "movlhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 [(set VR128:$dst,
703 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
704 MOVHP_shuffle_mask)))]>;
705
Evan Chengb783fa32007-07-19 01:14:50 +0000706def MOVHLPSrr : PSI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000707 "movhlps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000708 [(set VR128:$dst,
709 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
710 MOVHLPS_shuffle_mask)))]>;
711} // AddedComplexity
712} // isTwoAddress
713
714
715
716// Arithmetic
717
718/// sse1_fp_unop_rm - SSE1 unops come in both scalar and vector forms.
719///
720/// In addition, we also have a special variant of the scalar form here to
721/// represent the associated intrinsic operation. This form is unlike the
722/// plain scalar form, in that it takes an entire vector (instead of a
723/// scalar) and leaves the top elements undefined.
724///
725/// And, we have a special variant form for a full-vector intrinsic form.
726///
727/// These four forms can each have a reg or a mem operand, so there are a
728/// total of eight "instructions".
729///
730multiclass sse1_fp_unop_rm<bits<8> opc, string OpcodeStr,
731 SDNode OpNode,
732 Intrinsic F32Int,
733 Intrinsic V4F32Int,
734 bit Commutable = 0> {
735 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000736 def SSr : SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000737 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738 [(set FR32:$dst, (OpNode FR32:$src))]> {
739 let isCommutable = Commutable;
740 }
741
742 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000743 def SSm : SSI<opc, MRMSrcMem, (outs FR32:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000744 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 [(set FR32:$dst, (OpNode (load addr:$src)))]>;
746
747 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000748 def PSr : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000749 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 [(set VR128:$dst, (v4f32 (OpNode VR128:$src)))]> {
751 let isCommutable = Commutable;
752 }
753
754 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000755 def PSm : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000756 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +0000757 [(set VR128:$dst, (OpNode (memopv4f32 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000758
759 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +0000760 def SSr_Int : SSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000761 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 [(set VR128:$dst, (F32Int VR128:$src))]> {
763 let isCommutable = Commutable;
764 }
765
766 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +0000767 def SSm_Int : SSI<opc, MRMSrcMem, (outs VR128:$dst), (ins ssmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000768 !strconcat(OpcodeStr, "ss\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000769 [(set VR128:$dst, (F32Int sse_load_f32:$src))]>;
770
771 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +0000772 def PSr_Int : PSI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000773 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 [(set VR128:$dst, (V4F32Int VR128:$src))]> {
775 let isCommutable = Commutable;
776 }
777
778 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +0000779 def PSm_Int : PSI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000780 !strconcat(OpcodeStr, "ps\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781 [(set VR128:$dst, (V4F32Int (load addr:$src)))]>;
782}
783
784// Square root.
785defm SQRT : sse1_fp_unop_rm<0x51, "sqrt", fsqrt,
786 int_x86_sse_sqrt_ss, int_x86_sse_sqrt_ps>;
787
788// Reciprocal approximations. Note that these typically require refinement
789// in order to obtain suitable precision.
790defm RSQRT : sse1_fp_unop_rm<0x52, "rsqrt", X86frsqrt,
791 int_x86_sse_rsqrt_ss, int_x86_sse_rsqrt_ps>;
792defm RCP : sse1_fp_unop_rm<0x53, "rcp", X86frcp,
793 int_x86_sse_rcp_ss, int_x86_sse_rcp_ps>;
794
795// Logical
796let isTwoAddress = 1 in {
797 let isCommutable = 1 in {
798 def ANDPSrr : PSI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000799 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000800 "andps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 [(set VR128:$dst, (v2i64
802 (and VR128:$src1, VR128:$src2)))]>;
803 def ORPSrr : PSI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000804 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000805 "orps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 [(set VR128:$dst, (v2i64
807 (or VR128:$src1, VR128:$src2)))]>;
808 def XORPSrr : PSI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000809 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000810 "xorps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 [(set VR128:$dst, (v2i64
812 (xor VR128:$src1, VR128:$src2)))]>;
813 }
814
815 def ANDPSrm : PSI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000816 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000817 "andps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000818 [(set VR128:$dst, (and (bc_v2i64 (v4f32 VR128:$src1)),
819 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000820 def ORPSrm : PSI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000821 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000822 "orps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000823 [(set VR128:$dst, (or (bc_v2i64 (v4f32 VR128:$src1)),
824 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000825 def XORPSrm : PSI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000826 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000827 "xorps\t{$src2, $dst|$dst, $src2}",
Evan Cheng8e92cd12007-07-19 23:34:10 +0000828 [(set VR128:$dst, (xor (bc_v2i64 (v4f32 VR128:$src1)),
829 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830 def ANDNPSrr : PSI<0x55, 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 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 [(set VR128:$dst,
834 (v2i64 (and (xor VR128:$src1,
835 (bc_v2i64 (v4i32 immAllOnesV))),
836 VR128:$src2)))]>;
837 def ANDNPSrm : PSI<0x55, 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 "andnps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840 [(set VR128:$dst,
Evan Cheng8e92cd12007-07-19 23:34:10 +0000841 (v2i64 (and (xor (bc_v2i64 (v4f32 VR128:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 (bc_v2i64 (v4i32 immAllOnesV))),
Evan Cheng8e92cd12007-07-19 23:34:10 +0000843 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000844}
845
846let isTwoAddress = 1 in {
847 def CMPPSrri : PSIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000848 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000849 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
851 VR128:$src, imm:$cc))]>;
852 def CMPPSrmi : PSIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000853 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +0000854 "cmp${cc}ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 [(set VR128:$dst, (int_x86_sse_cmp_ps VR128:$src1,
856 (load addr:$src), imm:$cc))]>;
857}
858
859// Shuffle and unpack instructions
860let isTwoAddress = 1 in {
861 let isConvertibleToThreeAddress = 1 in // Convert to pshufd
862 def SHUFPSrri : PSIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000863 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000864 VR128:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000865 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000866 [(set VR128:$dst,
867 (v4f32 (vector_shuffle
868 VR128:$src1, VR128:$src2,
869 SHUFP_shuffle_mask:$src3)))]>;
870 def SHUFPSrmi : PSIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000871 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000872 f128mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000873 "shufps\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000874 [(set VR128:$dst,
875 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000876 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877 SHUFP_shuffle_mask:$src3)))]>;
878
879 let AddedComplexity = 10 in {
880 def UNPCKHPSrr : PSI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000881 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000882 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883 [(set VR128:$dst,
884 (v4f32 (vector_shuffle
885 VR128:$src1, VR128:$src2,
886 UNPCKH_shuffle_mask)))]>;
887 def UNPCKHPSrm : PSI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000888 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000889 "unpckhps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000890 [(set VR128:$dst,
891 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000892 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000893 UNPCKH_shuffle_mask)))]>;
894
895 def UNPCKLPSrr : PSI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000896 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000897 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898 [(set VR128:$dst,
899 (v4f32 (vector_shuffle
900 VR128:$src1, VR128:$src2,
901 UNPCKL_shuffle_mask)))]>;
902 def UNPCKLPSrm : PSI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000903 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000904 "unpcklps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000905 [(set VR128:$dst,
906 (v4f32 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +0000907 VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908 UNPCKL_shuffle_mask)))]>;
909 } // AddedComplexity
910} // isTwoAddress
911
912// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000913def MOVMSKPSrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000914 "movmskps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915 [(set GR32:$dst, (int_x86_sse_movmsk_ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000916def MOVMSKPDrr : PSI<0x50, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000917 "movmskpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000918 [(set GR32:$dst, (int_x86_sse2_movmsk_pd VR128:$src))]>;
919
920// Prefetching loads.
921// TODO: no intrinsics for these?
Dan Gohman91888f02007-07-31 20:11:57 +0000922def PREFETCHT0 : PSI<0x18, MRM1m, (outs), (ins i8mem:$src), "prefetcht0\t$src", []>;
923def PREFETCHT1 : PSI<0x18, MRM2m, (outs), (ins i8mem:$src), "prefetcht1\t$src", []>;
924def PREFETCHT2 : PSI<0x18, MRM3m, (outs), (ins i8mem:$src), "prefetcht2\t$src", []>;
925def PREFETCHNTA : PSI<0x18, MRM0m, (outs), (ins i8mem:$src), "prefetchnta\t$src", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000926
927// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +0000928def MOVNTPSmr : PSI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000929 "movntps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 [(int_x86_sse_movnt_ps addr:$dst, VR128:$src)]>;
931
932// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +0000933def SFENCE : PSI<0xAE, MRM7m, (outs), (ins), "sfence", [(int_x86_sse_sfence)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934
935// MXCSR register
Evan Chengb783fa32007-07-19 01:14:50 +0000936def LDMXCSR : PSI<0xAE, MRM2m, (outs), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000937 "ldmxcsr\t$src", [(int_x86_sse_ldmxcsr addr:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000938def STMXCSR : PSI<0xAE, MRM3m, (outs), (ins i32mem:$dst),
Dan Gohman91888f02007-07-31 20:11:57 +0000939 "stmxcsr\t$dst", [(int_x86_sse_stmxcsr addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000940
941// Alias instructions that map zero vector to pxor / xorp* for sse.
942// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
943let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000944def V_SET0 : PSI<0x57, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000945 "xorps\t$dst, $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946 [(set VR128:$dst, (v4f32 immAllZerosV))]>;
947
948// FR32 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +0000949def MOVSS2PSrr : SSI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000950 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000951 [(set VR128:$dst,
952 (v4f32 (scalar_to_vector FR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000953def MOVSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000954 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set VR128:$dst,
956 (v4f32 (scalar_to_vector (loadf32 addr:$src))))]>;
957
958// FIXME: may not be able to eliminate this movss with coalescing the src and
959// dest register classes are different. We really want to write this pattern
960// like this:
961// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
962// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +0000963def MOVPS2SSrr : SSI<0x10, MRMSrcReg, (outs FR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000964 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000965 [(set FR32:$dst, (vector_extract (v4f32 VR128:$src),
966 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000967def MOVPS2SSmr : SSI<0x11, MRMDestMem, (outs), (ins f32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000968 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000969 [(store (f32 (vector_extract (v4f32 VR128:$src),
970 (iPTR 0))), addr:$dst)]>;
971
972
973// Move to lower bits of a VR128, leaving upper bits alone.
974// Three operand (but two address) aliases.
975let isTwoAddress = 1 in {
976 def MOVLSS2PSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000977 (outs VR128:$dst), (ins VR128:$src1, FR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000978 "movss\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000979
980 let AddedComplexity = 15 in
981 def MOVLPSrr : SSI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000982 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000983 "movss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000984 [(set VR128:$dst,
985 (v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
986 MOVL_shuffle_mask)))]>;
987}
988
989// Move to lower bits of a VR128 and zeroing upper bits.
990// Loading from memory automatically zeroing upper bits.
991let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +0000992def MOVZSS2PSrm : SSI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000993 "movss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994 [(set VR128:$dst, (v4f32 (vector_shuffle immAllZerosV,
995 (v4f32 (scalar_to_vector (loadf32 addr:$src))),
996 MOVL_shuffle_mask)))]>;
997
998
999//===----------------------------------------------------------------------===//
1000// SSE2 Instructions
1001//===----------------------------------------------------------------------===//
1002
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001004def MOVSDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001005 "movsd\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +00001006let isLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001007def MOVSDrm : SDI<0x10, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001008 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001009 [(set FR64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001010def MOVSDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001011 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001012 [(store FR64:$src, addr:$dst)]>;
1013
1014// Conversion instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001015def CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001016 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001017 [(set GR32:$dst, (fp_to_sint FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001018def CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001019 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020 [(set GR32:$dst, (fp_to_sint (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001021def CVTSD2SSrr : SDI<0x5A, MRMSrcReg, (outs FR32:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001022 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 [(set FR32:$dst, (fround FR64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001024def CVTSD2SSrm : SDI<0x5A, MRMSrcMem, (outs FR32:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001025 "cvtsd2ss\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001026 [(set FR32:$dst, (fround (loadf64 addr:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001027def CVTSI2SDrr : SDI<0x2A, MRMSrcReg, (outs FR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001028 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001029 [(set FR64:$dst, (sint_to_fp GR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001030def CVTSI2SDrm : SDI<0x2A, MRMSrcMem, (outs FR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001031 "cvtsi2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001032 [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
1033
1034// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001035def CVTSS2SDrr : I<0x5A, MRMSrcReg, (outs FR64:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001036 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001037 [(set FR64:$dst, (fextend FR32:$src))]>, XS,
1038 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001039def CVTSS2SDrm : I<0x5A, MRMSrcMem, (outs FR64:$dst), (ins f32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001040 "cvtss2sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 [(set FR64:$dst, (extloadf32 addr:$src))]>, XS,
1042 Requires<[HasSSE2]>;
1043
1044// Match intrinsics which expect XMM operand(s).
Evan Chengb783fa32007-07-19 01:14:50 +00001045def Int_CVTSD2SIrr : SDI<0x2D, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001046 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001047 [(set GR32:$dst, (int_x86_sse2_cvtsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001048def Int_CVTSD2SIrm : SDI<0x2D, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001049 "cvtsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050 [(set GR32:$dst, (int_x86_sse2_cvtsd2si
1051 (load addr:$src)))]>;
1052
Dale Johannesen1fbb4a52007-10-30 22:15:38 +00001053// Match intrinisics which expect MM and XMM operand(s).
1054def Int_CVTPD2PIrr : PDI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1055 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1056 [(set VR64:$dst, (int_x86_sse_cvtpd2pi VR128:$src))]>;
1057def Int_CVTPD2PIrm : PDI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1058 "cvtpd2pi\t{$src, $dst|$dst, $src}",
1059 [(set VR64:$dst, (int_x86_sse_cvtpd2pi
1060 (load addr:$src)))]>;
1061def Int_CVTTPD2PIrr: PDI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
1062 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1063 [(set VR64:$dst, (int_x86_sse_cvttpd2pi VR128:$src))]>;
1064def Int_CVTTPD2PIrm: PDI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
1065 "cvttpd2pi\t{$src, $dst|$dst, $src}",
1066 [(set VR64:$dst, (int_x86_sse_cvttpd2pi
1067 (load addr:$src)))]>;
1068def Int_CVTPI2PDrr : PDI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
1069 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1070 [(set VR128:$dst, (int_x86_sse_cvtpi2pd VR64:$src))]>;
1071def Int_CVTPI2PDrm : PDI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
1072 "cvtpi2pd\t{$src, $dst|$dst, $src}",
1073 [(set VR128:$dst, (int_x86_sse_cvtpi2pd
1074 (load addr:$src)))]>;
1075
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001076// Aliases for intrinsics
Evan Chengb783fa32007-07-19 01:14:50 +00001077def Int_CVTTSD2SIrr : SDI<0x2C, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001078 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001079 [(set GR32:$dst,
1080 (int_x86_sse2_cvttsd2si VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001081def Int_CVTTSD2SIrm : SDI<0x2C, MRMSrcMem, (outs GR32:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001082 "cvttsd2si\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001083 [(set GR32:$dst, (int_x86_sse2_cvttsd2si
1084 (load addr:$src)))]>;
1085
1086// Comparison instructions
1087let isTwoAddress = 1 in {
1088 def CMPSDrr : SDI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001089 (outs FR64:$dst), (ins FR64:$src1, FR64:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001090 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091 def CMPSDrm : SDI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001092 (outs FR64:$dst), (ins FR64:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001093 "cmp${cc}sd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094}
1095
Evan Cheng950aac02007-09-25 01:57:46 +00001096let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001097def UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001098 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001099 [(X86cmp FR64:$src1, FR64:$src2), (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001100def UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001101 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001102 [(X86cmp FR64:$src1, (loadf64 addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001103 (implicit EFLAGS)]>;
1104}
1105
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001106// Aliases to match intrinsics which expect XMM operand(s).
1107let isTwoAddress = 1 in {
1108 def Int_CMPSDrr : SDI<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001109 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001110 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1112 VR128:$src, imm:$cc))]>;
1113 def Int_CMPSDrm : SDI<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001114 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001115 "cmp${cc}sd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116 [(set VR128:$dst, (int_x86_sse2_cmp_sd VR128:$src1,
1117 (load addr:$src), imm:$cc))]>;
1118}
1119
Evan Cheng950aac02007-09-25 01:57:46 +00001120let Defs = [EFLAGS] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001121def Int_UCOMISDrr: PDI<0x2E, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001122 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001123 [(X86ucomi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1124 (implicit EFLAGS)]>;
1125def Int_UCOMISDrm: PDI<0x2E, MRMSrcMem, (outs),(ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001126 "ucomisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001127 [(X86ucomi (v2f64 VR128:$src1), (load addr:$src2)),
1128 (implicit EFLAGS)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129
Evan Chengb783fa32007-07-19 01:14:50 +00001130def Int_COMISDrr: PDI<0x2F, MRMSrcReg, (outs), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001131 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001132 [(X86comi (v2f64 VR128:$src1), (v2f64 VR128:$src2)),
1133 (implicit EFLAGS)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001134def Int_COMISDrm: PDI<0x2F, MRMSrcMem, (outs), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001135 "comisd\t{$src2, $src1|$src1, $src2}",
Evan Cheng621216e2007-09-29 00:00:36 +00001136 [(X86comi (v2f64 VR128:$src1), (load addr:$src2)),
Evan Cheng950aac02007-09-25 01:57:46 +00001137 (implicit EFLAGS)]>;
1138} // Defs = EFLAGS]
1139
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140// Aliases of packed SSE2 instructions for scalar use. These all have names that
1141// start with 'Fs'.
1142
1143// Alias instructions that map fld0 to pxor for sse.
Dan Gohman8aef09b2007-09-07 21:32:51 +00001144let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001145def FsFLD0SD : I<0xEF, MRMInitReg, (outs FR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00001146 "pxor\t$dst, $dst", [(set FR64:$dst, fpimm0)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 Requires<[HasSSE2]>, TB, OpSize;
1148
1149// Alias instruction to do FR64 reg-to-reg copy using movapd. Upper bits are
1150// disregarded.
Evan Chengb783fa32007-07-19 01:14:50 +00001151def FsMOVAPDrr : PDI<0x28, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001152 "movapd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153
1154// Alias instruction to load FR64 from f128mem using movapd. Upper bits are
1155// disregarded.
Evan Cheng4e84e452007-08-30 05:49:43 +00001156let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001157def FsMOVAPDrm : PDI<0x28, MRMSrcMem, (outs FR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001158 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman11821702007-07-27 17:16:43 +00001159 [(set FR64:$dst, (alignedloadfsf64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001160
1161// Alias bitwise logical operations using SSE logical ops on packed FP values.
1162let isTwoAddress = 1 in {
1163let isCommutable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +00001164 def FsANDPDrr : PDI<0x54, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001165 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166 [(set FR64:$dst, (X86fand FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001167 def FsORPDrr : PDI<0x56, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001168 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001169 [(set FR64:$dst, (X86for FR64:$src1, FR64:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001170 def FsXORPDrr : PDI<0x57, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001171 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001172 [(set FR64:$dst, (X86fxor FR64:$src1, FR64:$src2))]>;
1173}
1174
Evan Chengb783fa32007-07-19 01:14:50 +00001175def FsANDPDrm : PDI<0x54, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001176 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 [(set FR64:$dst, (X86fand FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001178 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001179def FsORPDrm : PDI<0x56, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001180 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001181 [(set FR64:$dst, (X86for FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001182 (memopfsf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001183def FsXORPDrm : PDI<0x57, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001184 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001185 [(set FR64:$dst, (X86fxor FR64:$src1,
Dan Gohman11821702007-07-27 17:16:43 +00001186 (memopfsf64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001187
1188def FsANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001189 (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001190 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001191def FsANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001192 (outs FR64:$dst), (ins FR64:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001193 "andnpd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001194}
1195
1196/// basic_sse2_fp_binop_rm - SSE2 binops come in both scalar and vector forms.
1197///
1198/// In addition, we also have a special variant of the scalar form here to
1199/// represent the associated intrinsic operation. This form is unlike the
1200/// plain scalar form, in that it takes an entire vector (instead of a scalar)
1201/// and leaves the top elements undefined.
1202///
1203/// These three forms can each be reg+reg or reg+mem, so there are a total of
1204/// six "instructions".
1205///
1206let isTwoAddress = 1 in {
1207multiclass basic_sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1208 SDNode OpNode, Intrinsic F64Int,
1209 bit Commutable = 0> {
1210 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001211 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001212 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001213 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1214 let isCommutable = Commutable;
1215 }
1216
1217 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001218 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001219 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001220 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1221
1222 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001223 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001224 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1226 let isCommutable = Commutable;
1227 }
1228
1229 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001230 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001231 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001232 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001233
1234 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001235 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001236 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001237 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1238 let isCommutable = Commutable;
1239 }
1240
1241 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001242 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001243 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001244 [(set VR128:$dst, (F64Int VR128:$src1,
1245 sse_load_f64:$src2))]>;
1246}
1247}
1248
1249// Arithmetic instructions
1250defm ADD : basic_sse2_fp_binop_rm<0x58, "add", fadd, int_x86_sse2_add_sd, 1>;
1251defm MUL : basic_sse2_fp_binop_rm<0x59, "mul", fmul, int_x86_sse2_mul_sd, 1>;
1252defm SUB : basic_sse2_fp_binop_rm<0x5C, "sub", fsub, int_x86_sse2_sub_sd>;
1253defm DIV : basic_sse2_fp_binop_rm<0x5E, "div", fdiv, int_x86_sse2_div_sd>;
1254
1255/// sse2_fp_binop_rm - Other SSE2 binops
1256///
1257/// This multiclass is like basic_sse2_fp_binop_rm, with the addition of
1258/// instructions for a full-vector intrinsic form. Operations that map
1259/// onto C operators don't use this form since they just use the plain
1260/// vector form instead of having a separate vector intrinsic form.
1261///
1262/// This provides a total of eight "instructions".
1263///
1264let isTwoAddress = 1 in {
1265multiclass sse2_fp_binop_rm<bits<8> opc, string OpcodeStr,
1266 SDNode OpNode,
1267 Intrinsic F64Int,
1268 Intrinsic V2F64Int,
1269 bit Commutable = 0> {
1270
1271 // Scalar operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001272 def SDrr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001273 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001274 [(set FR64:$dst, (OpNode FR64:$src1, FR64:$src2))]> {
1275 let isCommutable = Commutable;
1276 }
1277
1278 // Scalar operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001279 def SDrm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins FR64:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001280 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281 [(set FR64:$dst, (OpNode FR64:$src1, (load addr:$src2)))]>;
1282
1283 // Vector operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001284 def PDrr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001285 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286 [(set VR128:$dst, (v2f64 (OpNode VR128:$src1, VR128:$src2)))]> {
1287 let isCommutable = Commutable;
1288 }
1289
1290 // Vector operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001291 def PDrm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001292 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001293 [(set VR128:$dst, (OpNode VR128:$src1, (memopv2f64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001294
1295 // Intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001296 def SDrr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001297 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001298 [(set VR128:$dst, (F64Int VR128:$src1, VR128:$src2))]> {
1299 let isCommutable = Commutable;
1300 }
1301
1302 // Intrinsic operation, reg+mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001303 def SDrm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, sdmem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001304 !strconcat(OpcodeStr, "sd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305 [(set VR128:$dst, (F64Int VR128:$src1,
1306 sse_load_f64:$src2))]>;
1307
1308 // Vector intrinsic operation, reg+reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001309 def PDrr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001310 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001311 [(set VR128:$dst, (V2F64Int VR128:$src1, VR128:$src2))]> {
1312 let isCommutable = Commutable;
1313 }
1314
1315 // Vector intrinsic operation, reg+mem.
Dan Gohmanc747be52007-08-02 21:06:40 +00001316 def PDrm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001317 !strconcat(OpcodeStr, "pd\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001318 [(set VR128:$dst, (V2F64Int VR128:$src1, (load addr:$src2)))]>;
1319}
1320}
1321
1322defm MAX : sse2_fp_binop_rm<0x5F, "max", X86fmax,
1323 int_x86_sse2_max_sd, int_x86_sse2_max_pd>;
1324defm MIN : sse2_fp_binop_rm<0x5D, "min", X86fmin,
1325 int_x86_sse2_min_sd, int_x86_sse2_min_pd>;
1326
1327//===----------------------------------------------------------------------===//
1328// SSE packed FP Instructions
1329
1330// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001331def MOVAPDrr : PDI<0x28, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001332 "movapd\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +00001333let isLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001334def MOVAPDrm : PDI<0x28, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001335 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001336 [(set VR128:$dst, (alignedloadv2f64 addr:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001337
Evan Chengb783fa32007-07-19 01:14:50 +00001338def MOVAPDmr : PDI<0x29, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001339 "movapd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001340 [(alignedstore (v2f64 VR128:$src), addr:$dst)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001341
Evan Chengb783fa32007-07-19 01:14:50 +00001342def MOVUPDrr : PDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001343 "movupd\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +00001344let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001345def MOVUPDrm : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001346 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001347 [(set VR128:$dst, (loadv2f64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001348def MOVUPDmr : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001349 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001350 [(store (v2f64 VR128:$src), addr:$dst)]>;
1351
1352// Intrinsic forms of MOVUPD load and store
Evan Chengb783fa32007-07-19 01:14:50 +00001353def MOVUPDrm_Int : PDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001354 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001355 [(set VR128:$dst, (int_x86_sse2_loadu_pd addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001356def MOVUPDmr_Int : PDI<0x11, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001357 "movupd\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001358 [(int_x86_sse2_storeu_pd addr:$dst, VR128:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001359
1360let isTwoAddress = 1 in {
1361 let AddedComplexity = 20 in {
1362 def MOVLPDrm : PDI<0x12, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001363 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001364 "movlpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001365 [(set VR128:$dst,
1366 (v2f64 (vector_shuffle VR128:$src1,
1367 (scalar_to_vector (loadf64 addr:$src2)),
1368 MOVLP_shuffle_mask)))]>;
1369 def MOVHPDrm : PDI<0x16, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001370 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001371 "movhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001372 [(set VR128:$dst,
1373 (v2f64 (vector_shuffle VR128:$src1,
1374 (scalar_to_vector (loadf64 addr:$src2)),
1375 MOVHP_shuffle_mask)))]>;
1376 } // AddedComplexity
1377} // isTwoAddress
1378
Evan Chengb783fa32007-07-19 01:14:50 +00001379def MOVLPDmr : PDI<0x13, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001380 "movlpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001381 [(store (f64 (vector_extract (v2f64 VR128:$src),
1382 (iPTR 0))), addr:$dst)]>;
1383
1384// v2f64 extract element 1 is always custom lowered to unpack high to low
1385// and extract element 0 so the non-store version isn't too horrible.
Evan Chengb783fa32007-07-19 01:14:50 +00001386def MOVHPDmr : PDI<0x17, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001387 "movhpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001388 [(store (f64 (vector_extract
1389 (v2f64 (vector_shuffle VR128:$src, (undef),
1390 UNPCKH_shuffle_mask)), (iPTR 0))),
1391 addr:$dst)]>;
1392
1393// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001394def Int_CVTDQ2PSrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001395 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001396 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps VR128:$src))]>,
1397 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001398def Int_CVTDQ2PSrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001399 "cvtdq2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001400 [(set VR128:$dst, (int_x86_sse2_cvtdq2ps
Dan Gohman4a4f1512007-07-18 20:23:34 +00001401 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001402 TB, Requires<[HasSSE2]>;
1403
1404// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001405def Int_CVTDQ2PDrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001406 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001407 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd VR128:$src))]>,
1408 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001409def Int_CVTDQ2PDrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001410 "cvtdq2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001411 [(set VR128:$dst, (int_x86_sse2_cvtdq2pd
Dan Gohman4a4f1512007-07-18 20:23:34 +00001412 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001413 XS, Requires<[HasSSE2]>;
1414
Evan Chengb783fa32007-07-19 01:14:50 +00001415def Int_CVTPS2DQrr : PDI<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001416 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001417 [(set VR128:$dst, (int_x86_sse2_cvtps2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001418def Int_CVTPS2DQrm : PDI<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001419 "cvtps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001420 [(set VR128:$dst, (int_x86_sse2_cvtps2dq
1421 (load addr:$src)))]>;
1422// SSE2 packed instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001423def Int_CVTTPS2DQrr : I<0x5B, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001424 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001425 [(set VR128:$dst, (int_x86_sse2_cvttps2dq VR128:$src))]>,
1426 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001427def Int_CVTTPS2DQrm : I<0x5B, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001428 "cvttps2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001429 [(set VR128:$dst, (int_x86_sse2_cvttps2dq
1430 (load addr:$src)))]>,
1431 XS, Requires<[HasSSE2]>;
1432
1433// SSE2 packed instructions with XD prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001434def Int_CVTPD2DQrr : I<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001435 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001436 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq VR128:$src))]>,
1437 XD, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001438def Int_CVTPD2DQrm : I<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001439 "cvtpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001440 [(set VR128:$dst, (int_x86_sse2_cvtpd2dq
1441 (load addr:$src)))]>,
1442 XD, Requires<[HasSSE2]>;
1443
Evan Chengb783fa32007-07-19 01:14:50 +00001444def Int_CVTTPD2DQrr : PDI<0xE6, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001445 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001446 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001447def Int_CVTTPD2DQrm : PDI<0xE6, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001448 "cvttpd2dq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001449 [(set VR128:$dst, (int_x86_sse2_cvttpd2dq
1450 (load addr:$src)))]>;
1451
1452// SSE2 instructions without OpSize prefix
Evan Chengb783fa32007-07-19 01:14:50 +00001453def Int_CVTPS2PDrr : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001454 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001455 [(set VR128:$dst, (int_x86_sse2_cvtps2pd VR128:$src))]>,
1456 TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001457def Int_CVTPS2PDrm : I<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001458 "cvtps2pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001459 [(set VR128:$dst, (int_x86_sse2_cvtps2pd
1460 (load addr:$src)))]>,
1461 TB, Requires<[HasSSE2]>;
1462
Evan Chengb783fa32007-07-19 01:14:50 +00001463def Int_CVTPD2PSrr : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001464 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001465 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps VR128:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001466def Int_CVTPD2PSrm : PDI<0x5A, MRMSrcReg, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001467 "cvtpd2ps\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001468 [(set VR128:$dst, (int_x86_sse2_cvtpd2ps
1469 (load addr:$src)))]>;
1470
1471// Match intrinsics which expect XMM operand(s).
1472// Aliases for intrinsics
1473let isTwoAddress = 1 in {
1474def Int_CVTSI2SDrr: SDI<0x2A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001475 (outs VR128:$dst), (ins VR128:$src1, GR32:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001476 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001477 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1478 GR32:$src2))]>;
1479def Int_CVTSI2SDrm: SDI<0x2A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001480 (outs VR128:$dst), (ins VR128:$src1, i32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001481 "cvtsi2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001482 [(set VR128:$dst, (int_x86_sse2_cvtsi2sd VR128:$src1,
1483 (loadi32 addr:$src2)))]>;
1484def Int_CVTSD2SSrr: SDI<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001485 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001486 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001487 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1488 VR128:$src2))]>;
1489def Int_CVTSD2SSrm: SDI<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001490 (outs VR128:$dst), (ins VR128:$src1, f64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001491 "cvtsd2ss\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001492 [(set VR128:$dst, (int_x86_sse2_cvtsd2ss VR128:$src1,
1493 (load addr:$src2)))]>;
1494def Int_CVTSS2SDrr: I<0x5A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001495 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001496 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001497 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1498 VR128:$src2))]>, XS,
1499 Requires<[HasSSE2]>;
1500def Int_CVTSS2SDrm: I<0x5A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001501 (outs VR128:$dst), (ins VR128:$src1, f32mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001502 "cvtss2sd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001503 [(set VR128:$dst, (int_x86_sse2_cvtss2sd VR128:$src1,
1504 (load addr:$src2)))]>, XS,
1505 Requires<[HasSSE2]>;
1506}
1507
1508// Arithmetic
1509
1510/// sse2_fp_unop_rm - SSE2 unops come in both scalar and vector forms.
1511///
1512/// In addition, we also have a special variant of the scalar form here to
1513/// represent the associated intrinsic operation. This form is unlike the
1514/// plain scalar form, in that it takes an entire vector (instead of a
1515/// scalar) and leaves the top elements undefined.
1516///
1517/// And, we have a special variant form for a full-vector intrinsic form.
1518///
1519/// These four forms can each have a reg or a mem operand, so there are a
1520/// total of eight "instructions".
1521///
1522multiclass sse2_fp_unop_rm<bits<8> opc, string OpcodeStr,
1523 SDNode OpNode,
1524 Intrinsic F64Int,
1525 Intrinsic V2F64Int,
1526 bit Commutable = 0> {
1527 // Scalar operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001528 def SDr : SDI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001529 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001530 [(set FR64:$dst, (OpNode FR64:$src))]> {
1531 let isCommutable = Commutable;
1532 }
1533
1534 // Scalar operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001535 def SDm : SDI<opc, MRMSrcMem, (outs FR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001536 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001537 [(set FR64:$dst, (OpNode (load addr:$src)))]>;
1538
1539 // Vector operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001540 def PDr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001541 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001542 [(set VR128:$dst, (v2f64 (OpNode VR128:$src)))]> {
1543 let isCommutable = Commutable;
1544 }
1545
1546 // Vector operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001547 def PDm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001548 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001549 [(set VR128:$dst, (OpNode (memopv2f64 addr:$src)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001550
1551 // Intrinsic operation, reg.
Evan Chengb783fa32007-07-19 01:14:50 +00001552 def SDr_Int : SDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001553 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001554 [(set VR128:$dst, (F64Int VR128:$src))]> {
1555 let isCommutable = Commutable;
1556 }
1557
1558 // Intrinsic operation, mem.
Evan Chengb783fa32007-07-19 01:14:50 +00001559 def SDm_Int : SDI<opc, MRMSrcMem, (outs VR128:$dst), (ins sdmem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001560 !strconcat(OpcodeStr, "sd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001561 [(set VR128:$dst, (F64Int sse_load_f64:$src))]>;
1562
1563 // Vector intrinsic operation, reg
Evan Chengb783fa32007-07-19 01:14:50 +00001564 def PDr_Int : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001565 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001566 [(set VR128:$dst, (V2F64Int VR128:$src))]> {
1567 let isCommutable = Commutable;
1568 }
1569
1570 // Vector intrinsic operation, mem
Dan Gohmanc747be52007-08-02 21:06:40 +00001571 def PDm_Int : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001572 !strconcat(OpcodeStr, "pd\t{$src, $dst|$dst, $src}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001573 [(set VR128:$dst, (V2F64Int (load addr:$src)))]>;
1574}
1575
1576// Square root.
1577defm SQRT : sse2_fp_unop_rm<0x51, "sqrt", fsqrt,
1578 int_x86_sse2_sqrt_sd, int_x86_sse2_sqrt_pd>;
1579
1580// There is no f64 version of the reciprocal approximation instructions.
1581
1582// Logical
1583let isTwoAddress = 1 in {
1584 let isCommutable = 1 in {
1585 def ANDPDrr : PDI<0x54, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001586 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001587 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001588 [(set VR128:$dst,
1589 (and (bc_v2i64 (v2f64 VR128:$src1)),
1590 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1591 def ORPDrr : PDI<0x56, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001592 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001593 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001594 [(set VR128:$dst,
1595 (or (bc_v2i64 (v2f64 VR128:$src1)),
1596 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1597 def XORPDrr : PDI<0x57, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001598 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001599 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001600 [(set VR128:$dst,
1601 (xor (bc_v2i64 (v2f64 VR128:$src1)),
1602 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1603 }
1604
1605 def ANDPDrm : PDI<0x54, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001606 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001607 "andpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001608 [(set VR128:$dst,
1609 (and (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001610 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001611 def ORPDrm : PDI<0x56, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001612 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001613 "orpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001614 [(set VR128:$dst,
1615 (or (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001616 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001617 def XORPDrm : PDI<0x57, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001618 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001619 "xorpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001620 [(set VR128:$dst,
1621 (xor (bc_v2i64 (v2f64 VR128:$src1)),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001622 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001623 def ANDNPDrr : PDI<0x55, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001624 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001625 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001626 [(set VR128:$dst,
1627 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
1628 (bc_v2i64 (v2f64 VR128:$src2))))]>;
1629 def ANDNPDrm : PDI<0x55, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001630 (outs VR128:$dst), (ins VR128:$src1,f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001631 "andnpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001632 [(set VR128:$dst,
1633 (and (vnot (bc_v2i64 (v2f64 VR128:$src1))),
Evan Cheng8e92cd12007-07-19 23:34:10 +00001634 (memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001635}
1636
1637let isTwoAddress = 1 in {
1638 def CMPPDrri : PDIi8<0xC2, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001639 (outs VR128:$dst), (ins VR128:$src1, VR128:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001640 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001641 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1642 VR128:$src, imm:$cc))]>;
1643 def CMPPDrmi : PDIi8<0xC2, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001644 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src, SSECC:$cc),
Dan Gohman91888f02007-07-31 20:11:57 +00001645 "cmp${cc}pd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001646 [(set VR128:$dst, (int_x86_sse2_cmp_pd VR128:$src1,
1647 (load addr:$src), imm:$cc))]>;
1648}
1649
1650// Shuffle and unpack instructions
1651let isTwoAddress = 1 in {
1652 def SHUFPDrri : PDIi8<0xC6, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001653 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001654 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001655 [(set VR128:$dst, (v2f64 (vector_shuffle
1656 VR128:$src1, VR128:$src2,
1657 SHUFP_shuffle_mask:$src3)))]>;
1658 def SHUFPDrmi : PDIi8<0xC6, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001659 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001660 f128mem:$src2, i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00001661 "shufpd\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001662 [(set VR128:$dst,
1663 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001664 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001665 SHUFP_shuffle_mask:$src3)))]>;
1666
1667 let AddedComplexity = 10 in {
1668 def UNPCKHPDrr : PDI<0x15, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001669 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001670 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001671 [(set VR128:$dst,
1672 (v2f64 (vector_shuffle
1673 VR128:$src1, VR128:$src2,
1674 UNPCKH_shuffle_mask)))]>;
1675 def UNPCKHPDrm : PDI<0x15, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001676 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001677 "unpckhpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001678 [(set VR128:$dst,
1679 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001680 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001681 UNPCKH_shuffle_mask)))]>;
1682
1683 def UNPCKLPDrr : PDI<0x14, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001684 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001685 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001686 [(set VR128:$dst,
1687 (v2f64 (vector_shuffle
1688 VR128:$src1, VR128:$src2,
1689 UNPCKL_shuffle_mask)))]>;
1690 def UNPCKLPDrm : PDI<0x14, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001691 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001692 "unpcklpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001693 [(set VR128:$dst,
1694 (v2f64 (vector_shuffle
Dan Gohman7dc19012007-08-02 21:17:01 +00001695 VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001696 UNPCKL_shuffle_mask)))]>;
1697 } // AddedComplexity
1698} // isTwoAddress
1699
1700
1701//===----------------------------------------------------------------------===//
1702// SSE integer instructions
1703
1704// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00001705def MOVDQArr : PDI<0x6F, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001706 "movdqa\t{$src, $dst|$dst, $src}", []>;
Evan Cheng4e84e452007-08-30 05:49:43 +00001707let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001708def MOVDQArm : PDI<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001709 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001710 [/*(set VR128:$dst, (alignedloadv2i64 addr:$src))*/]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001711def MOVDQAmr : PDI<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001712 "movdqa\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001713 [/*(alignedstore (v2i64 VR128:$src), addr:$dst)*/]>;
Evan Cheng4e84e452007-08-30 05:49:43 +00001714let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001715def MOVDQUrm : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001716 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001717 [/*(set VR128:$dst, (loadv2i64 addr:$src))*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001718 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001719def MOVDQUmr : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001720 "movdqu\t{$src, $dst|$dst, $src}",
Evan Cheng51a49b22007-07-20 00:27:43 +00001721 [/*(store (v2i64 VR128:$src), addr:$dst)*/]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001722 XS, Requires<[HasSSE2]>;
1723
Dan Gohman4a4f1512007-07-18 20:23:34 +00001724// Intrinsic forms of MOVDQU load and store
Evan Cheng4e84e452007-08-30 05:49:43 +00001725let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001726def MOVDQUrm_Int : I<0x6F, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001727 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001728 [(set VR128:$dst, (int_x86_sse2_loadu_dq addr:$src))]>,
1729 XS, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001730def MOVDQUmr_Int : I<0x7F, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00001731 "movdqu\t{$src, $dst|$dst, $src}",
Dan Gohman4a4f1512007-07-18 20:23:34 +00001732 [(int_x86_sse2_storeu_dq addr:$dst, VR128:$src)]>,
1733 XS, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001734
1735let isTwoAddress = 1 in {
1736
1737multiclass PDI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
1738 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001739 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001740 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001741 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]> {
1742 let isCommutable = Commutable;
1743 }
Evan Chengb783fa32007-07-19 01:14:50 +00001744 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001745 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001746 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001747 (bitconvert (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001748}
1749
1750multiclass PDI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
1751 string OpcodeStr, Intrinsic IntId> {
Evan Chengb783fa32007-07-19 01:14:50 +00001752 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001753 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001754 [(set VR128:$dst, (IntId VR128:$src1, VR128:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001755 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001756 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001757 [(set VR128:$dst, (IntId VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001758 (bitconvert (memopv2i64 addr:$src2))))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001759 def ri : PDIi8<opc2, ImmForm, (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001760 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001761 [(set VR128:$dst, (IntId VR128:$src1,
1762 (scalar_to_vector (i32 imm:$src2))))]>;
1763}
1764
1765
1766/// PDI_binop_rm - Simple SSE2 binary operator.
1767multiclass PDI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
1768 ValueType OpVT, bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001769 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001770 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001771 [(set VR128:$dst, (OpVT (OpNode VR128:$src1, VR128:$src2)))]> {
1772 let isCommutable = Commutable;
1773 }
Evan Chengb783fa32007-07-19 01:14:50 +00001774 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001775 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001776 [(set VR128:$dst, (OpVT (OpNode VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001777 (bitconvert (memopv2i64 addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778}
1779
1780/// PDI_binop_rm_v2i64 - Simple SSE2 binary operator whose type is v2i64.
1781///
1782/// FIXME: we could eliminate this and use PDI_binop_rm instead if tblgen knew
1783/// to collapse (bitconvert VT to VT) into its operand.
1784///
1785multiclass PDI_binop_rm_v2i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
1786 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +00001787 def rr : PDI<opc, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001788 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001789 [(set VR128:$dst, (v2i64 (OpNode VR128:$src1, VR128:$src2)))]> {
1790 let isCommutable = Commutable;
1791 }
Evan Chengb783fa32007-07-19 01:14:50 +00001792 def rm : PDI<opc, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001793 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohman4a4f1512007-07-18 20:23:34 +00001794 [(set VR128:$dst, (OpNode VR128:$src1,(memopv2i64 addr:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001795}
1796
1797} // isTwoAddress
1798
1799// 128-bit Integer Arithmetic
1800
1801defm PADDB : PDI_binop_rm<0xFC, "paddb", add, v16i8, 1>;
1802defm PADDW : PDI_binop_rm<0xFD, "paddw", add, v8i16, 1>;
1803defm PADDD : PDI_binop_rm<0xFE, "paddd", add, v4i32, 1>;
1804defm PADDQ : PDI_binop_rm_v2i64<0xD4, "paddq", add, 1>;
1805
1806defm PADDSB : PDI_binop_rm_int<0xEC, "paddsb" , int_x86_sse2_padds_b, 1>;
1807defm PADDSW : PDI_binop_rm_int<0xED, "paddsw" , int_x86_sse2_padds_w, 1>;
1808defm PADDUSB : PDI_binop_rm_int<0xDC, "paddusb", int_x86_sse2_paddus_b, 1>;
1809defm PADDUSW : PDI_binop_rm_int<0xDD, "paddusw", int_x86_sse2_paddus_w, 1>;
1810
1811defm PSUBB : PDI_binop_rm<0xF8, "psubb", sub, v16i8>;
1812defm PSUBW : PDI_binop_rm<0xF9, "psubw", sub, v8i16>;
1813defm PSUBD : PDI_binop_rm<0xFA, "psubd", sub, v4i32>;
1814defm PSUBQ : PDI_binop_rm_v2i64<0xFB, "psubq", sub>;
1815
1816defm PSUBSB : PDI_binop_rm_int<0xE8, "psubsb" , int_x86_sse2_psubs_b>;
1817defm PSUBSW : PDI_binop_rm_int<0xE9, "psubsw" , int_x86_sse2_psubs_w>;
1818defm PSUBUSB : PDI_binop_rm_int<0xD8, "psubusb", int_x86_sse2_psubus_b>;
1819defm PSUBUSW : PDI_binop_rm_int<0xD9, "psubusw", int_x86_sse2_psubus_w>;
1820
1821defm PMULLW : PDI_binop_rm<0xD5, "pmullw", mul, v8i16, 1>;
1822
1823defm PMULHUW : PDI_binop_rm_int<0xE4, "pmulhuw", int_x86_sse2_pmulhu_w, 1>;
1824defm PMULHW : PDI_binop_rm_int<0xE5, "pmulhw" , int_x86_sse2_pmulh_w , 1>;
1825defm PMULUDQ : PDI_binop_rm_int<0xF4, "pmuludq", int_x86_sse2_pmulu_dq, 1>;
1826
1827defm PMADDWD : PDI_binop_rm_int<0xF5, "pmaddwd", int_x86_sse2_pmadd_wd, 1>;
1828
1829defm PAVGB : PDI_binop_rm_int<0xE0, "pavgb", int_x86_sse2_pavg_b, 1>;
1830defm PAVGW : PDI_binop_rm_int<0xE3, "pavgw", int_x86_sse2_pavg_w, 1>;
1831
1832
1833defm PMINUB : PDI_binop_rm_int<0xDA, "pminub", int_x86_sse2_pminu_b, 1>;
1834defm PMINSW : PDI_binop_rm_int<0xEA, "pminsw", int_x86_sse2_pmins_w, 1>;
1835defm PMAXUB : PDI_binop_rm_int<0xDE, "pmaxub", int_x86_sse2_pmaxu_b, 1>;
1836defm PMAXSW : PDI_binop_rm_int<0xEE, "pmaxsw", int_x86_sse2_pmaxs_w, 1>;
1837defm PSADBW : PDI_binop_rm_int<0xE0, "psadbw", int_x86_sse2_psad_bw, 1>;
1838
1839
1840defm PSLLW : PDI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw", int_x86_sse2_psll_w>;
1841defm PSLLD : PDI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld", int_x86_sse2_psll_d>;
1842defm PSLLQ : PDI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq", int_x86_sse2_psll_q>;
1843
1844defm PSRLW : PDI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw", int_x86_sse2_psrl_w>;
1845defm PSRLD : PDI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld", int_x86_sse2_psrl_d>;
1846defm PSRLQ : PDI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq", int_x86_sse2_psrl_q>;
1847
1848defm PSRAW : PDI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw", int_x86_sse2_psra_w>;
1849defm PSRAD : PDI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad", int_x86_sse2_psra_d>;
1850// PSRAQ doesn't exist in SSE[1-3].
1851
1852// 128-bit logical shifts.
1853let isTwoAddress = 1 in {
1854 def PSLLDQri : PDIi8<0x73, MRM7r,
Evan Chengb783fa32007-07-19 01:14:50 +00001855 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001856 "pslldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001857 def PSRLDQri : PDIi8<0x73, MRM3r,
Evan Chengb783fa32007-07-19 01:14:50 +00001858 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001859 "psrldq\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001860 // PSRADQri doesn't exist in SSE[1-3].
1861}
1862
1863let Predicates = [HasSSE2] in {
1864 def : Pat<(int_x86_sse2_psll_dq VR128:$src1, imm:$src2),
1865 (v2i64 (PSLLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1866 def : Pat<(int_x86_sse2_psrl_dq VR128:$src1, imm:$src2),
1867 (v2i64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1868 def : Pat<(v2f64 (X86fsrl VR128:$src1, i32immSExt8:$src2)),
1869 (v2f64 (PSRLDQri VR128:$src1, (PSxLDQ_imm imm:$src2)))>;
1870}
1871
1872// Logical
1873defm PAND : PDI_binop_rm_v2i64<0xDB, "pand", and, 1>;
1874defm POR : PDI_binop_rm_v2i64<0xEB, "por" , or , 1>;
1875defm PXOR : PDI_binop_rm_v2i64<0xEF, "pxor", xor, 1>;
1876
1877let isTwoAddress = 1 in {
1878 def PANDNrr : PDI<0xDF, 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 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001881 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
1882 VR128:$src2)))]>;
1883
1884 def PANDNrm : PDI<0xDF, 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 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001887 [(set VR128:$dst, (v2i64 (and (vnot VR128:$src1),
Dan Gohman7dc19012007-08-02 21:17:01 +00001888 (memopv2i64 addr:$src2))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889}
1890
1891// SSE2 Integer comparison
1892defm PCMPEQB : PDI_binop_rm_int<0x74, "pcmpeqb", int_x86_sse2_pcmpeq_b>;
1893defm PCMPEQW : PDI_binop_rm_int<0x75, "pcmpeqw", int_x86_sse2_pcmpeq_w>;
1894defm PCMPEQD : PDI_binop_rm_int<0x76, "pcmpeqd", int_x86_sse2_pcmpeq_d>;
1895defm PCMPGTB : PDI_binop_rm_int<0x64, "pcmpgtb", int_x86_sse2_pcmpgt_b>;
1896defm PCMPGTW : PDI_binop_rm_int<0x65, "pcmpgtw", int_x86_sse2_pcmpgt_w>;
1897defm PCMPGTD : PDI_binop_rm_int<0x66, "pcmpgtd", int_x86_sse2_pcmpgt_d>;
1898
1899// Pack instructions
1900defm PACKSSWB : PDI_binop_rm_int<0x63, "packsswb", int_x86_sse2_packsswb_128>;
1901defm PACKSSDW : PDI_binop_rm_int<0x6B, "packssdw", int_x86_sse2_packssdw_128>;
1902defm PACKUSWB : PDI_binop_rm_int<0x67, "packuswb", int_x86_sse2_packuswb_128>;
1903
1904// Shuffle and unpack instructions
1905def PSHUFDri : PDIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001906 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001907 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001908 [(set VR128:$dst, (v4i32 (vector_shuffle
1909 VR128:$src1, (undef),
1910 PSHUFD_shuffle_mask:$src2)))]>;
1911def PSHUFDmi : PDIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001912 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001913 "pshufd\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001914 [(set VR128:$dst, (v4i32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001915 (bc_v4i32(memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001916 (undef),
1917 PSHUFD_shuffle_mask:$src2)))]>;
1918
1919// SSE2 with ImmT == Imm8 and XS prefix.
1920def PSHUFHWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001921 (outs VR128:$dst), (ins VR128:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001922 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001923 [(set VR128:$dst, (v8i16 (vector_shuffle
1924 VR128:$src1, (undef),
1925 PSHUFHW_shuffle_mask:$src2)))]>,
1926 XS, Requires<[HasSSE2]>;
1927def PSHUFHWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001928 (outs VR128:$dst), (ins i128mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001929 "pshufhw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001930 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001931 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001932 (undef),
1933 PSHUFHW_shuffle_mask:$src2)))]>,
1934 XS, Requires<[HasSSE2]>;
1935
1936// SSE2 with ImmT == Imm8 and XD prefix.
1937def PSHUFLWri : Ii8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001938 (outs VR128:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001939 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001940 [(set VR128:$dst, (v8i16 (vector_shuffle
1941 VR128:$src1, (undef),
1942 PSHUFLW_shuffle_mask:$src2)))]>,
1943 XD, Requires<[HasSSE2]>;
1944def PSHUFLWmi : Ii8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001945 (outs VR128:$dst), (ins i128mem:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001946 "pshuflw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001947 [(set VR128:$dst, (v8i16 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00001948 (bc_v8i16 (memopv2i64 addr:$src1)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001949 (undef),
1950 PSHUFLW_shuffle_mask:$src2)))]>,
1951 XD, Requires<[HasSSE2]>;
1952
1953
1954let isTwoAddress = 1 in {
1955 def PUNPCKLBWrr : PDI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001956 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001957 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001958 [(set VR128:$dst,
1959 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
1960 UNPCKL_shuffle_mask)))]>;
1961 def PUNPCKLBWrm : PDI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001962 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001963 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001964 [(set VR128:$dst,
1965 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001966 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001967 UNPCKL_shuffle_mask)))]>;
1968 def PUNPCKLWDrr : PDI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001969 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001970 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001971 [(set VR128:$dst,
1972 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
1973 UNPCKL_shuffle_mask)))]>;
1974 def PUNPCKLWDrm : PDI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001975 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001976 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001977 [(set VR128:$dst,
1978 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001979 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001980 UNPCKL_shuffle_mask)))]>;
1981 def PUNPCKLDQrr : PDI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001982 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001983 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001984 [(set VR128:$dst,
1985 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
1986 UNPCKL_shuffle_mask)))]>;
1987 def PUNPCKLDQrm : PDI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00001988 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001989 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001990 [(set VR128:$dst,
1991 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00001992 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001993 UNPCKL_shuffle_mask)))]>;
1994 def PUNPCKLQDQrr : PDI<0x6C, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00001995 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00001996 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001997 [(set VR128:$dst,
1998 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
1999 UNPCKL_shuffle_mask)))]>;
2000 def PUNPCKLQDQrm : PDI<0x6C, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002001 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002002 "punpcklqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002003 [(set VR128:$dst,
2004 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002005 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002006 UNPCKL_shuffle_mask)))]>;
2007
2008 def PUNPCKHBWrr : PDI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002009 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002010 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002011 [(set VR128:$dst,
2012 (v16i8 (vector_shuffle VR128:$src1, VR128:$src2,
2013 UNPCKH_shuffle_mask)))]>;
2014 def PUNPCKHBWrm : PDI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002015 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002016 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002017 [(set VR128:$dst,
2018 (v16i8 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002019 (bc_v16i8 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002020 UNPCKH_shuffle_mask)))]>;
2021 def PUNPCKHWDrr : PDI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002022 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002023 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002024 [(set VR128:$dst,
2025 (v8i16 (vector_shuffle VR128:$src1, VR128:$src2,
2026 UNPCKH_shuffle_mask)))]>;
2027 def PUNPCKHWDrm : PDI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002028 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002029 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002030 [(set VR128:$dst,
2031 (v8i16 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002032 (bc_v8i16 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002033 UNPCKH_shuffle_mask)))]>;
2034 def PUNPCKHDQrr : PDI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002035 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002036 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002037 [(set VR128:$dst,
2038 (v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2039 UNPCKH_shuffle_mask)))]>;
2040 def PUNPCKHDQrm : PDI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002041 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002042 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002043 [(set VR128:$dst,
2044 (v4i32 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002045 (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002046 UNPCKH_shuffle_mask)))]>;
2047 def PUNPCKHQDQrr : PDI<0x6D, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002048 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002049 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002050 [(set VR128:$dst,
2051 (v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2052 UNPCKH_shuffle_mask)))]>;
2053 def PUNPCKHQDQrm : PDI<0x6D, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002054 (outs VR128:$dst), (ins VR128:$src1, i128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002055 "punpckhqdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002056 [(set VR128:$dst,
2057 (v2i64 (vector_shuffle VR128:$src1,
Dan Gohman4a4f1512007-07-18 20:23:34 +00002058 (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002059 UNPCKH_shuffle_mask)))]>;
2060}
2061
2062// Extract / Insert
2063def PEXTRWri : PDIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002064 (outs GR32:$dst), (ins VR128:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002065 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002066 [(set GR32:$dst, (X86pextrw (v8i16 VR128:$src1),
2067 (iPTR imm:$src2)))]>;
2068let isTwoAddress = 1 in {
2069 def PINSRWrri : PDIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002070 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002071 GR32:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002072 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002073 [(set VR128:$dst,
2074 (v8i16 (X86pinsrw (v8i16 VR128:$src1),
2075 GR32:$src2, (iPTR imm:$src3))))]>;
2076 def PINSRWrmi : PDIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002077 (outs VR128:$dst), (ins VR128:$src1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002078 i16mem:$src2, i32i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +00002079 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002080 [(set VR128:$dst,
2081 (v8i16 (X86pinsrw (v8i16 VR128:$src1),
2082 (i32 (anyext (loadi16 addr:$src2))),
2083 (iPTR imm:$src3))))]>;
2084}
2085
2086// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +00002087def PMOVMSKBrr : PDI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002088 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002089 [(set GR32:$dst, (int_x86_sse2_pmovmskb_128 VR128:$src))]>;
2090
2091// Conditional store
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002092let Uses = [EDI] in
Evan Chengb783fa32007-07-19 01:14:50 +00002093def MASKMOVDQU : PDI<0xF7, MRMSrcReg, (outs), (ins VR128:$src, VR128:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +00002094 "maskmovdqu\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00002095 [(int_x86_sse2_maskmov_dqu VR128:$src, VR128:$mask, EDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002096
2097// Non-temporal stores
Evan Chengb783fa32007-07-19 01:14:50 +00002098def MOVNTPDmr : PDI<0x2B, MRMDestMem, (outs), (ins i128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002099 "movntpd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002100 [(int_x86_sse2_movnt_pd addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002101def MOVNTDQmr : PDI<0xE7, MRMDestMem, (outs), (ins f128mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002102 "movntdq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002103 [(int_x86_sse2_movnt_dq addr:$dst, VR128:$src)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002104def MOVNTImr : I<0xC3, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002105 "movnti\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002106 [(int_x86_sse2_movnt_i addr:$dst, GR32:$src)]>,
2107 TB, Requires<[HasSSE2]>;
2108
2109// Flush cache
Evan Chengb783fa32007-07-19 01:14:50 +00002110def CLFLUSH : I<0xAE, MRM7m, (outs), (ins i8mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002111 "clflush\t$src", [(int_x86_sse2_clflush addr:$src)]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002112 TB, Requires<[HasSSE2]>;
2113
2114// Load, store, and memory fence
Evan Chengb783fa32007-07-19 01:14:50 +00002115def LFENCE : I<0xAE, MRM5m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002116 "lfence", [(int_x86_sse2_lfence)]>, TB, Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002117def MFENCE : I<0xAE, MRM6m, (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002118 "mfence", [(int_x86_sse2_mfence)]>, TB, Requires<[HasSSE2]>;
2119
2120
2121// Alias instructions that map zero vector to pxor / xorp* for sse.
2122// FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2123let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00002124 def V_SETALLONES : PDI<0x76, MRMInitReg, (outs VR128:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +00002125 "pcmpeqd\t$dst, $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002126 [(set VR128:$dst, (v2f64 immAllOnesV))]>;
2127
2128// FR64 to 128-bit vector conversion.
Evan Chengb783fa32007-07-19 01:14:50 +00002129def MOVSD2PDrr : SDI<0x10, MRMSrcReg, (outs VR128:$dst), (ins FR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002130 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002131 [(set VR128:$dst,
2132 (v2f64 (scalar_to_vector FR64:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002133def MOVSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002134 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002135 [(set VR128:$dst,
2136 (v2f64 (scalar_to_vector (loadf64 addr:$src))))]>;
2137
Evan Chengb783fa32007-07-19 01:14:50 +00002138def MOVDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002139 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002140 [(set VR128:$dst,
2141 (v4i32 (scalar_to_vector GR32:$src)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002142def MOVDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002143 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002144 [(set VR128:$dst,
2145 (v4i32 (scalar_to_vector (loadi32 addr:$src))))]>;
2146
Evan Chengb783fa32007-07-19 01:14:50 +00002147def MOVDI2SSrr : PDI<0x6E, MRMSrcReg, (outs FR32:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002148 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002149 [(set FR32:$dst, (bitconvert GR32:$src))]>;
2150
Evan Chengb783fa32007-07-19 01:14:50 +00002151def MOVDI2SSrm : PDI<0x6E, MRMSrcMem, (outs FR32:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002152 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002153 [(set FR32:$dst, (bitconvert (loadi32 addr:$src)))]>;
2154
2155// SSE2 instructions with XS prefix
Evan Chengb783fa32007-07-19 01:14:50 +00002156def MOVQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002157 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002158 [(set VR128:$dst,
2159 (v2i64 (scalar_to_vector (loadi64 addr:$src))))]>, XS,
2160 Requires<[HasSSE2]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002161def MOVPQI2QImr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002162 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002163 [(store (i64 (vector_extract (v2i64 VR128:$src),
2164 (iPTR 0))), addr:$dst)]>;
2165
2166// FIXME: may not be able to eliminate this movss with coalescing the src and
2167// dest register classes are different. We really want to write this pattern
2168// like this:
2169// def : Pat<(f32 (vector_extract (v4f32 VR128:$src), (iPTR 0))),
2170// (f32 FR32:$src)>;
Evan Chengb783fa32007-07-19 01:14:50 +00002171def MOVPD2SDrr : SDI<0x10, MRMSrcReg, (outs FR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002172 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002173 [(set FR64:$dst, (vector_extract (v2f64 VR128:$src),
2174 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002175def MOVPD2SDmr : SDI<0x11, MRMDestMem, (outs), (ins f64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002176 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002177 [(store (f64 (vector_extract (v2f64 VR128:$src),
2178 (iPTR 0))), addr:$dst)]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002179def MOVPDI2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002180 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002181 [(set GR32:$dst, (vector_extract (v4i32 VR128:$src),
2182 (iPTR 0)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002183def MOVPDI2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002184 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002185 [(store (i32 (vector_extract (v4i32 VR128:$src),
2186 (iPTR 0))), addr:$dst)]>;
2187
Evan Chengb783fa32007-07-19 01:14:50 +00002188def MOVSS2DIrr : PDI<0x7E, MRMDestReg, (outs GR32:$dst), (ins FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002189 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002190 [(set GR32:$dst, (bitconvert FR32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002191def MOVSS2DImr : PDI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, FR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002192 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002193 [(store (i32 (bitconvert FR32:$src)), addr:$dst)]>;
2194
2195
2196// Move to lower bits of a VR128, leaving upper bits alone.
2197// Three operand (but two address) aliases.
2198let isTwoAddress = 1 in {
2199 def MOVLSD2PDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002200 (outs VR128:$dst), (ins VR128:$src1, FR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002201 "movsd\t{$src2, $dst|$dst, $src2}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002202
2203 let AddedComplexity = 15 in
2204 def MOVLPDrr : SDI<0x10, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002205 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002206 "movsd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002207 [(set VR128:$dst,
2208 (v2f64 (vector_shuffle VR128:$src1, VR128:$src2,
2209 MOVL_shuffle_mask)))]>;
2210}
2211
2212// Store / copy lower 64-bits of a XMM register.
Evan Chengb783fa32007-07-19 01:14:50 +00002213def MOVLQ128mr : PDI<0xD6, MRMDestMem, (outs), (ins i64mem:$dst, VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002214 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002215 [(int_x86_sse2_storel_dq addr:$dst, VR128:$src)]>;
2216
2217// Move to lower bits of a VR128 and zeroing upper bits.
2218// Loading from memory automatically zeroing upper bits.
2219let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002220 def MOVZSD2PDrm : SDI<0x10, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002221 "movsd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002222 [(set VR128:$dst,
2223 (v2f64 (vector_shuffle immAllZerosV,
2224 (v2f64 (scalar_to_vector
2225 (loadf64 addr:$src))),
2226 MOVL_shuffle_mask)))]>;
2227
2228let AddedComplexity = 15 in
2229// movd / movq to XMM register zero-extends
Evan Chengb783fa32007-07-19 01:14:50 +00002230def MOVZDI2PDIrr : PDI<0x6E, MRMSrcReg, (outs VR128:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002231 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002232 [(set VR128:$dst,
2233 (v4i32 (vector_shuffle immAllZerosV,
2234 (v4i32 (scalar_to_vector GR32:$src)),
2235 MOVL_shuffle_mask)))]>;
2236let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002237def MOVZDI2PDIrm : PDI<0x6E, MRMSrcMem, (outs VR128:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002238 "movd\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002239 [(set VR128:$dst,
2240 (v4i32 (vector_shuffle immAllZerosV,
2241 (v4i32 (scalar_to_vector (loadi32 addr:$src))),
2242 MOVL_shuffle_mask)))]>;
2243
2244// Moving from XMM to XMM but still clear upper 64 bits.
2245let AddedComplexity = 15 in
Evan Chengb783fa32007-07-19 01:14:50 +00002246def MOVZQI2PQIrr : I<0x7E, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002247 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002248 [(set VR128:$dst, (int_x86_sse2_movl_dq VR128:$src))]>,
2249 XS, Requires<[HasSSE2]>;
2250let AddedComplexity = 20 in
Evan Chengb783fa32007-07-19 01:14:50 +00002251def MOVZQI2PQIrm : I<0x7E, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002252 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002253 [(set VR128:$dst, (int_x86_sse2_movl_dq
Dan Gohman4a4f1512007-07-18 20:23:34 +00002254 (bitconvert (memopv2i64 addr:$src))))]>,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002255 XS, Requires<[HasSSE2]>;
2256
2257
2258//===----------------------------------------------------------------------===//
2259// SSE3 Instructions
2260//===----------------------------------------------------------------------===//
2261
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002262// Move Instructions
Evan Chengb783fa32007-07-19 01:14:50 +00002263def MOVSHDUPrr : S3SI<0x16, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002264 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002265 [(set VR128:$dst, (v4f32 (vector_shuffle
2266 VR128:$src, (undef),
2267 MOVSHDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002268def MOVSHDUPrm : S3SI<0x16, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002269 "movshdup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002270 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002271 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002272 MOVSHDUP_shuffle_mask)))]>;
2273
Evan Chengb783fa32007-07-19 01:14:50 +00002274def MOVSLDUPrr : S3SI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002275 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002276 [(set VR128:$dst, (v4f32 (vector_shuffle
2277 VR128:$src, (undef),
2278 MOVSLDUP_shuffle_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002279def MOVSLDUPrm : S3SI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002280 "movsldup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002281 [(set VR128:$dst, (v4f32 (vector_shuffle
Dan Gohman4a4f1512007-07-18 20:23:34 +00002282 (memopv4f32 addr:$src), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002283 MOVSLDUP_shuffle_mask)))]>;
2284
Evan Chengb783fa32007-07-19 01:14:50 +00002285def MOVDDUPrr : S3DI<0x12, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002286 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002287 [(set VR128:$dst, (v2f64 (vector_shuffle
2288 VR128:$src, (undef),
2289 SSE_splat_lo_mask)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002290def MOVDDUPrm : S3DI<0x12, MRMSrcMem, (outs VR128:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002291 "movddup\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002292 [(set VR128:$dst,
2293 (v2f64 (vector_shuffle
2294 (scalar_to_vector (loadf64 addr:$src)),
2295 (undef),
2296 SSE_splat_lo_mask)))]>;
2297
2298// Arithmetic
2299let isTwoAddress = 1 in {
2300 def ADDSUBPSrr : S3DI<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002301 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002302 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002303 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2304 VR128:$src2))]>;
2305 def ADDSUBPSrm : S3DI<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002306 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002307 "addsubps\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002308 [(set VR128:$dst, (int_x86_sse3_addsub_ps VR128:$src1,
2309 (load addr:$src2)))]>;
2310 def ADDSUBPDrr : S3I<0xD0, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +00002311 (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002312 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002313 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2314 VR128:$src2))]>;
2315 def ADDSUBPDrm : S3I<0xD0, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +00002316 (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002317 "addsubpd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002318 [(set VR128:$dst, (int_x86_sse3_addsub_pd VR128:$src1,
2319 (load addr:$src2)))]>;
2320}
2321
Evan Chengb783fa32007-07-19 01:14:50 +00002322def LDDQUrm : S3DI<0xF0, MRMSrcMem, (outs VR128:$dst), (ins i128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +00002323 "lddqu\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002324 [(set VR128:$dst, (int_x86_sse3_ldu_dq addr:$src))]>;
2325
2326// Horizontal ops
2327class S3D_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002328 : S3DI<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002329 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002330 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, VR128:$src2)))]>;
2331class S3D_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002332 : S3DI<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002333 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002334 [(set VR128:$dst, (v4f32 (IntId VR128:$src1, (load addr:$src2))))]>;
2335class S3_Intrr<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002336 : S3I<o, MRMSrcReg, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002337 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002338 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, VR128:$src2)))]>;
2339class S3_Intrm<bits<8> o, string OpcodeStr, Intrinsic IntId>
Evan Chengb783fa32007-07-19 01:14:50 +00002340 : S3I<o, MRMSrcMem, (outs VR128:$dst), (ins VR128:$src1, f128mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +00002341 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002342 [(set VR128:$dst, (v2f64 (IntId VR128:$src1, (load addr:$src2))))]>;
2343
2344let isTwoAddress = 1 in {
2345 def HADDPSrr : S3D_Intrr<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2346 def HADDPSrm : S3D_Intrm<0x7C, "haddps", int_x86_sse3_hadd_ps>;
2347 def HADDPDrr : S3_Intrr <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2348 def HADDPDrm : S3_Intrm <0x7C, "haddpd", int_x86_sse3_hadd_pd>;
2349 def HSUBPSrr : S3D_Intrr<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2350 def HSUBPSrm : S3D_Intrm<0x7D, "hsubps", int_x86_sse3_hsub_ps>;
2351 def HSUBPDrr : S3_Intrr <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2352 def HSUBPDrm : S3_Intrm <0x7D, "hsubpd", int_x86_sse3_hsub_pd>;
2353}
2354
2355// Thread synchronization
Evan Chengb783fa32007-07-19 01:14:50 +00002356def MONITOR : I<0xC8, RawFrm, (outs), (ins), "monitor",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002357 [(int_x86_sse3_monitor EAX, ECX, EDX)]>,TB, Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002358def MWAIT : I<0xC9, RawFrm, (outs), (ins), "mwait",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002359 [(int_x86_sse3_mwait ECX, EAX)]>, TB, Requires<[HasSSE3]>;
2360
2361// vector_shuffle v1, <undef> <1, 1, 3, 3>
2362let AddedComplexity = 15 in
2363def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2364 MOVSHDUP_shuffle_mask)),
2365 (MOVSHDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2366let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002367def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002368 MOVSHDUP_shuffle_mask)),
2369 (MOVSHDUPrm addr:$src)>, Requires<[HasSSE3]>;
2370
2371// vector_shuffle v1, <undef> <0, 0, 2, 2>
2372let AddedComplexity = 15 in
2373 def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2374 MOVSLDUP_shuffle_mask)),
2375 (MOVSLDUPrr VR128:$src)>, Requires<[HasSSE3]>;
2376let AddedComplexity = 20 in
Dan Gohman4a4f1512007-07-18 20:23:34 +00002377 def : Pat<(v4i32 (vector_shuffle (bc_v4i32 (memopv2i64 addr:$src)), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002378 MOVSLDUP_shuffle_mask)),
2379 (MOVSLDUPrm addr:$src)>, Requires<[HasSSE3]>;
2380
2381//===----------------------------------------------------------------------===//
2382// SSSE3 Instructions
2383//===----------------------------------------------------------------------===//
2384
Bill Wendling3b15d722007-08-11 09:52:53 +00002385// SSSE3 Instruction Templates:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002386//
Bill Wendling98680292007-08-10 06:22:27 +00002387// SS38I - SSSE3 instructions with T8 prefix.
2388// SS3AI - SSSE3 instructions with TA prefix.
Bill Wendling3b15d722007-08-11 09:52:53 +00002389//
2390// Note: SSSE3 instructions have 64-bit and 128-bit versions. The 64-bit version
2391// uses the MMX registers. We put those instructions here because they better
2392// fit into the SSSE3 instruction category rather than the MMX category.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002393
Evan Chengb783fa32007-07-19 01:14:50 +00002394class SS38I<bits<8> o, Format F, dag outs, dag ins, string asm,
2395 list<dag> pattern>
Bill Wendling98680292007-08-10 06:22:27 +00002396 : I<o, F, outs, ins, asm, pattern>, T8, Requires<[HasSSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +00002397class SS3AI<bits<8> o, Format F, dag outs, dag ins, string asm,
2398 list<dag> pattern>
Bill Wendling98680292007-08-10 06:22:27 +00002399 : I<o, F, outs, ins, asm, pattern>, TA, Requires<[HasSSSE3]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002400
Bill Wendling98680292007-08-10 06:22:27 +00002401/// SS3I_unop_rm_int_8 - Simple SSSE3 unary operator whose type is v*i8.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002402let isTwoAddress = 1 in {
Bill Wendling98680292007-08-10 06:22:27 +00002403 multiclass SS3I_unop_rm_int_8<bits<8> opc, string OpcodeStr,
2404 Intrinsic IntId64, Intrinsic IntId128,
2405 bit Commutable = 0> {
2406 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
2407 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2408 [(set VR64:$dst, (IntId64 VR64:$src))]> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002409 let isCommutable = Commutable;
2410 }
Bill Wendling98680292007-08-10 06:22:27 +00002411 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
2412 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2413 [(set VR64:$dst,
2414 (IntId64 (bitconvert (memopv8i8 addr:$src))))]>;
2415
2416 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2417 (ins VR128:$src),
2418 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2419 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2420 OpSize {
2421 let isCommutable = Commutable;
2422 }
2423 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2424 (ins i128mem:$src),
2425 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2426 [(set VR128:$dst,
2427 (IntId128
2428 (bitconvert (memopv16i8 addr:$src))))]>, OpSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002429 }
2430}
2431
Bill Wendling98680292007-08-10 06:22:27 +00002432/// SS3I_unop_rm_int_16 - Simple SSSE3 unary operator whose type is v*i16.
2433let isTwoAddress = 1 in {
2434 multiclass SS3I_unop_rm_int_16<bits<8> opc, string OpcodeStr,
2435 Intrinsic IntId64, Intrinsic IntId128,
2436 bit Commutable = 0> {
2437 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2438 (ins VR64:$src),
2439 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2440 [(set VR64:$dst, (IntId64 VR64:$src))]> {
2441 let isCommutable = Commutable;
2442 }
2443 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2444 (ins i64mem:$src),
2445 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2446 [(set VR64:$dst,
2447 (IntId64
2448 (bitconvert (memopv4i16 addr:$src))))]>;
2449
2450 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2451 (ins VR128:$src),
2452 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2453 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2454 OpSize {
2455 let isCommutable = Commutable;
2456 }
2457 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2458 (ins i128mem:$src),
2459 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2460 [(set VR128:$dst,
2461 (IntId128
2462 (bitconvert (memopv8i16 addr:$src))))]>, OpSize;
2463 }
2464}
2465
2466/// SS3I_unop_rm_int_32 - Simple SSSE3 unary operator whose type is v*i32.
2467let isTwoAddress = 1 in {
2468 multiclass SS3I_unop_rm_int_32<bits<8> opc, string OpcodeStr,
2469 Intrinsic IntId64, Intrinsic IntId128,
2470 bit Commutable = 0> {
2471 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2472 (ins VR64:$src),
2473 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2474 [(set VR64:$dst, (IntId64 VR64:$src))]> {
2475 let isCommutable = Commutable;
2476 }
2477 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2478 (ins i64mem:$src),
2479 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2480 [(set VR64:$dst,
2481 (IntId64
2482 (bitconvert (memopv2i32 addr:$src))))]>;
2483
2484 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2485 (ins VR128:$src),
2486 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2487 [(set VR128:$dst, (IntId128 VR128:$src))]>,
2488 OpSize {
2489 let isCommutable = Commutable;
2490 }
2491 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2492 (ins i128mem:$src),
2493 !strconcat(OpcodeStr, "\t{$src, $dst|$dst, $src}"),
2494 [(set VR128:$dst,
2495 (IntId128
2496 (bitconvert (memopv4i32 addr:$src))))]>, OpSize;
2497 }
2498}
2499
2500defm PABSB : SS3I_unop_rm_int_8 <0x1C, "pabsb",
2501 int_x86_ssse3_pabs_b,
2502 int_x86_ssse3_pabs_b_128>;
2503defm PABSW : SS3I_unop_rm_int_16<0x1D, "pabsw",
2504 int_x86_ssse3_pabs_w,
2505 int_x86_ssse3_pabs_w_128>;
2506defm PABSD : SS3I_unop_rm_int_32<0x1E, "pabsd",
2507 int_x86_ssse3_pabs_d,
2508 int_x86_ssse3_pabs_d_128>;
2509
2510/// SS3I_binop_rm_int_8 - Simple SSSE3 binary operator whose type is v*i8.
2511let isTwoAddress = 1 in {
2512 multiclass SS3I_binop_rm_int_8<bits<8> opc, string OpcodeStr,
2513 Intrinsic IntId64, Intrinsic IntId128,
2514 bit Commutable = 0> {
2515 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2516 (ins VR64:$src1, VR64:$src2),
2517 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2518 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2519 let isCommutable = Commutable;
2520 }
2521 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2522 (ins VR64:$src1, i64mem:$src2),
2523 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2524 [(set VR64:$dst,
2525 (IntId64 VR64:$src1,
2526 (bitconvert (memopv8i8 addr:$src2))))]>;
2527
2528 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2529 (ins VR128:$src1, VR128:$src2),
2530 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2531 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2532 OpSize {
2533 let isCommutable = Commutable;
2534 }
2535 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2536 (ins VR128:$src1, i128mem:$src2),
2537 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2538 [(set VR128:$dst,
2539 (IntId128 VR128:$src1,
2540 (bitconvert (memopv16i8 addr:$src2))))]>, OpSize;
2541 }
2542}
2543
2544/// SS3I_binop_rm_int_16 - Simple SSSE3 binary operator whose type is v*i16.
2545let isTwoAddress = 1 in {
2546 multiclass SS3I_binop_rm_int_16<bits<8> opc, string OpcodeStr,
2547 Intrinsic IntId64, Intrinsic IntId128,
2548 bit Commutable = 0> {
2549 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2550 (ins VR64:$src1, VR64:$src2),
2551 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2552 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2553 let isCommutable = Commutable;
2554 }
2555 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2556 (ins VR64:$src1, i64mem:$src2),
2557 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2558 [(set VR64:$dst,
2559 (IntId64 VR64:$src1,
2560 (bitconvert (memopv4i16 addr:$src2))))]>;
2561
2562 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2563 (ins VR128:$src1, VR128:$src2),
2564 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2565 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2566 OpSize {
2567 let isCommutable = Commutable;
2568 }
2569 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2570 (ins VR128:$src1, i128mem:$src2),
2571 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2572 [(set VR128:$dst,
2573 (IntId128 VR128:$src1,
2574 (bitconvert (memopv8i16 addr:$src2))))]>, OpSize;
2575 }
2576}
2577
2578/// SS3I_binop_rm_int_32 - Simple SSSE3 binary operator whose type is v*i32.
2579let isTwoAddress = 1 in {
2580 multiclass SS3I_binop_rm_int_32<bits<8> opc, string OpcodeStr,
2581 Intrinsic IntId64, Intrinsic IntId128,
2582 bit Commutable = 0> {
2583 def rr64 : SS38I<opc, MRMSrcReg, (outs VR64:$dst),
2584 (ins VR64:$src1, VR64:$src2),
2585 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2586 [(set VR64:$dst, (IntId64 VR64:$src1, VR64:$src2))]> {
2587 let isCommutable = Commutable;
2588 }
2589 def rm64 : SS38I<opc, MRMSrcMem, (outs VR64:$dst),
2590 (ins VR64:$src1, i64mem:$src2),
2591 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2592 [(set VR64:$dst,
2593 (IntId64 VR64:$src1,
2594 (bitconvert (memopv2i32 addr:$src2))))]>;
2595
2596 def rr128 : SS38I<opc, MRMSrcReg, (outs VR128:$dst),
2597 (ins VR128:$src1, VR128:$src2),
2598 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2599 [(set VR128:$dst, (IntId128 VR128:$src1, VR128:$src2))]>,
2600 OpSize {
2601 let isCommutable = Commutable;
2602 }
2603 def rm128 : SS38I<opc, MRMSrcMem, (outs VR128:$dst),
2604 (ins VR128:$src1, i128mem:$src2),
2605 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
2606 [(set VR128:$dst,
2607 (IntId128 VR128:$src1,
2608 (bitconvert (memopv4i32 addr:$src2))))]>, OpSize;
2609 }
2610}
2611
2612defm PHADDW : SS3I_binop_rm_int_16<0x01, "phaddw",
2613 int_x86_ssse3_phadd_w,
2614 int_x86_ssse3_phadd_w_128, 1>;
2615defm PHADDD : SS3I_binop_rm_int_32<0x02, "phaddd",
2616 int_x86_ssse3_phadd_d,
2617 int_x86_ssse3_phadd_d_128, 1>;
2618defm PHADDSW : SS3I_binop_rm_int_16<0x03, "phaddsw",
2619 int_x86_ssse3_phadd_sw,
2620 int_x86_ssse3_phadd_sw_128, 1>;
2621defm PHSUBW : SS3I_binop_rm_int_16<0x05, "phsubw",
2622 int_x86_ssse3_phsub_w,
2623 int_x86_ssse3_phsub_w_128>;
2624defm PHSUBD : SS3I_binop_rm_int_32<0x06, "phsubd",
2625 int_x86_ssse3_phsub_d,
2626 int_x86_ssse3_phsub_d_128>;
2627defm PHSUBSW : SS3I_binop_rm_int_16<0x07, "phsubsw",
2628 int_x86_ssse3_phsub_sw,
2629 int_x86_ssse3_phsub_sw_128>;
2630defm PMADDUBSW : SS3I_binop_rm_int_8 <0x04, "pmaddubsw",
2631 int_x86_ssse3_pmadd_ub_sw,
2632 int_x86_ssse3_pmadd_ub_sw_128, 1>;
2633defm PMULHRSW : SS3I_binop_rm_int_16<0x0B, "pmulhrsw",
2634 int_x86_ssse3_pmul_hr_sw,
2635 int_x86_ssse3_pmul_hr_sw_128, 1>;
2636defm PSHUFB : SS3I_binop_rm_int_8 <0x00, "pshufb",
2637 int_x86_ssse3_pshuf_b,
2638 int_x86_ssse3_pshuf_b_128>;
2639defm PSIGNB : SS3I_binop_rm_int_8 <0x08, "psignb",
2640 int_x86_ssse3_psign_b,
2641 int_x86_ssse3_psign_b_128>;
2642defm PSIGNW : SS3I_binop_rm_int_16<0x09, "psignw",
2643 int_x86_ssse3_psign_w,
2644 int_x86_ssse3_psign_w_128>;
2645defm PSIGND : SS3I_binop_rm_int_32<0x09, "psignd",
2646 int_x86_ssse3_psign_d,
2647 int_x86_ssse3_psign_d_128>;
2648
2649let isTwoAddress = 1 in {
Bill Wendling1dc817c2007-08-10 09:00:17 +00002650 def PALIGNR64rr : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2651 (ins VR64:$src1, VR64:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002652 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002653 [(set VR64:$dst,
2654 (int_x86_ssse3_palign_r
2655 VR64:$src1, VR64:$src2,
2656 imm:$src3))]>;
2657 def PALIGNR64rm : SS3AI<0x0F, MRMSrcReg, (outs VR64:$dst),
2658 (ins VR64:$src1, i64mem:$src2, i16imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002659 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002660 [(set VR64:$dst,
2661 (int_x86_ssse3_palign_r
2662 VR64:$src1,
2663 (bitconvert (memopv2i32 addr:$src2)),
2664 imm:$src3))]>;
Bill Wendling98680292007-08-10 06:22:27 +00002665
Bill Wendling1dc817c2007-08-10 09:00:17 +00002666 def PALIGNR128rr : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2667 (ins VR128:$src1, VR128:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002668 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002669 [(set VR128:$dst,
2670 (int_x86_ssse3_palign_r_128
2671 VR128:$src1, VR128:$src2,
2672 imm:$src3))]>, OpSize;
2673 def PALIGNR128rm : SS3AI<0x0F, MRMSrcReg, (outs VR128:$dst),
2674 (ins VR128:$src1, i128mem:$src2, i32imm:$src3),
Dale Johannesen576b27e2007-10-11 20:58:37 +00002675 "palignr\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Bill Wendling1dc817c2007-08-10 09:00:17 +00002676 [(set VR128:$dst,
2677 (int_x86_ssse3_palign_r_128
2678 VR128:$src1,
2679 (bitconvert (memopv4i32 addr:$src2)),
2680 imm:$src3))]>, OpSize;
Bill Wendling98680292007-08-10 06:22:27 +00002681}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002682
2683//===----------------------------------------------------------------------===//
2684// Non-Instruction Patterns
2685//===----------------------------------------------------------------------===//
2686
2687// 128-bit vector undef's.
Bill Wendling1dc817c2007-08-10 09:00:17 +00002688def : Pat<(v4f32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002689def : Pat<(v2f64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2690def : Pat<(v16i8 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2691def : Pat<(v8i16 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2692def : Pat<(v4i32 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2693def : Pat<(v2i64 (undef)), (IMPLICIT_DEF_VR128)>, Requires<[HasSSE2]>;
2694
2695// 128-bit vector all zero's.
2696def : Pat<(v16i8 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2697def : Pat<(v8i16 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2698def : Pat<(v4i32 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2699def : Pat<(v2i64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2700def : Pat<(v2f64 immAllZerosV), (V_SET0)>, Requires<[HasSSE2]>;
2701
2702// 128-bit vector all one's.
2703def : Pat<(v16i8 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2704def : Pat<(v8i16 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2705def : Pat<(v4i32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2706def : Pat<(v2i64 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE2]>;
2707def : Pat<(v4f32 immAllOnesV), (V_SETALLONES)>, Requires<[HasSSE1]>;
2708
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002709
2710// Scalar to v8i16 / v16i8. The source may be a GR32, but only the lower 8 or
2711// 16-bits matter.
2712def : Pat<(v8i16 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2713 Requires<[HasSSE2]>;
2714def : Pat<(v16i8 (X86s2vec GR32:$src)), (MOVDI2PDIrr GR32:$src)>,
2715 Requires<[HasSSE2]>;
2716
2717// bit_convert
2718let Predicates = [HasSSE2] in {
2719 def : Pat<(v2i64 (bitconvert (v4i32 VR128:$src))), (v2i64 VR128:$src)>;
2720 def : Pat<(v2i64 (bitconvert (v8i16 VR128:$src))), (v2i64 VR128:$src)>;
2721 def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;
2722 def : Pat<(v2i64 (bitconvert (v2f64 VR128:$src))), (v2i64 VR128:$src)>;
2723 def : Pat<(v2i64 (bitconvert (v4f32 VR128:$src))), (v2i64 VR128:$src)>;
2724 def : Pat<(v4i32 (bitconvert (v2i64 VR128:$src))), (v4i32 VR128:$src)>;
2725 def : Pat<(v4i32 (bitconvert (v8i16 VR128:$src))), (v4i32 VR128:$src)>;
2726 def : Pat<(v4i32 (bitconvert (v16i8 VR128:$src))), (v4i32 VR128:$src)>;
2727 def : Pat<(v4i32 (bitconvert (v2f64 VR128:$src))), (v4i32 VR128:$src)>;
2728 def : Pat<(v4i32 (bitconvert (v4f32 VR128:$src))), (v4i32 VR128:$src)>;
2729 def : Pat<(v8i16 (bitconvert (v2i64 VR128:$src))), (v8i16 VR128:$src)>;
2730 def : Pat<(v8i16 (bitconvert (v4i32 VR128:$src))), (v8i16 VR128:$src)>;
2731 def : Pat<(v8i16 (bitconvert (v16i8 VR128:$src))), (v8i16 VR128:$src)>;
2732 def : Pat<(v8i16 (bitconvert (v2f64 VR128:$src))), (v8i16 VR128:$src)>;
2733 def : Pat<(v8i16 (bitconvert (v4f32 VR128:$src))), (v8i16 VR128:$src)>;
2734 def : Pat<(v16i8 (bitconvert (v2i64 VR128:$src))), (v16i8 VR128:$src)>;
2735 def : Pat<(v16i8 (bitconvert (v4i32 VR128:$src))), (v16i8 VR128:$src)>;
2736 def : Pat<(v16i8 (bitconvert (v8i16 VR128:$src))), (v16i8 VR128:$src)>;
2737 def : Pat<(v16i8 (bitconvert (v2f64 VR128:$src))), (v16i8 VR128:$src)>;
2738 def : Pat<(v16i8 (bitconvert (v4f32 VR128:$src))), (v16i8 VR128:$src)>;
2739 def : Pat<(v4f32 (bitconvert (v2i64 VR128:$src))), (v4f32 VR128:$src)>;
2740 def : Pat<(v4f32 (bitconvert (v4i32 VR128:$src))), (v4f32 VR128:$src)>;
2741 def : Pat<(v4f32 (bitconvert (v8i16 VR128:$src))), (v4f32 VR128:$src)>;
2742 def : Pat<(v4f32 (bitconvert (v16i8 VR128:$src))), (v4f32 VR128:$src)>;
2743 def : Pat<(v4f32 (bitconvert (v2f64 VR128:$src))), (v4f32 VR128:$src)>;
2744 def : Pat<(v2f64 (bitconvert (v2i64 VR128:$src))), (v2f64 VR128:$src)>;
2745 def : Pat<(v2f64 (bitconvert (v4i32 VR128:$src))), (v2f64 VR128:$src)>;
2746 def : Pat<(v2f64 (bitconvert (v8i16 VR128:$src))), (v2f64 VR128:$src)>;
2747 def : Pat<(v2f64 (bitconvert (v16i8 VR128:$src))), (v2f64 VR128:$src)>;
2748 def : Pat<(v2f64 (bitconvert (v4f32 VR128:$src))), (v2f64 VR128:$src)>;
2749}
2750
2751// Move scalar to XMM zero-extended
2752// movd to XMM register zero-extends
2753let AddedComplexity = 15 in {
2754def : Pat<(v8i16 (vector_shuffle immAllZerosV,
2755 (v8i16 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2756 (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2757def : Pat<(v16i8 (vector_shuffle immAllZerosV,
2758 (v16i8 (X86s2vec GR32:$src)), MOVL_shuffle_mask)),
2759 (MOVZDI2PDIrr GR32:$src)>, Requires<[HasSSE2]>;
2760// Zeroing a VR128 then do a MOVS{S|D} to the lower bits.
2761def : Pat<(v2f64 (vector_shuffle immAllZerosV,
2762 (v2f64 (scalar_to_vector FR64:$src)), MOVL_shuffle_mask)),
2763 (MOVLSD2PDrr (V_SET0), FR64:$src)>, Requires<[HasSSE2]>;
2764def : Pat<(v4f32 (vector_shuffle immAllZerosV,
2765 (v4f32 (scalar_to_vector FR32:$src)), MOVL_shuffle_mask)),
2766 (MOVLSS2PSrr (V_SET0), FR32:$src)>, Requires<[HasSSE2]>;
2767}
2768
2769// Splat v2f64 / v2i64
2770let AddedComplexity = 10 in {
2771def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2772 (UNPCKLPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2773def : Pat<(vector_shuffle (v2f64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2774 (UNPCKHPDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2775def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), SSE_splat_lo_mask:$sm),
2776 (PUNPCKLQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2777def : Pat<(vector_shuffle (v2i64 VR128:$src), (undef), UNPCKH_shuffle_mask:$sm),
2778 (PUNPCKHQDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2779}
2780
2781// Splat v4f32
2782def : Pat<(vector_shuffle (v4f32 VR128:$src), (undef), SSE_splat_mask:$sm),
2783 (SHUFPSrri VR128:$src, VR128:$src, SSE_splat_mask:$sm)>,
2784 Requires<[HasSSE1]>;
2785
2786// Special unary SHUFPSrri case.
2787// FIXME: when we want non two-address code, then we should use PSHUFD?
2788def : Pat<(vector_shuffle (v4f32 VR128:$src1), (undef),
2789 SHUFP_unary_shuffle_mask:$sm),
2790 (SHUFPSrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2791 Requires<[HasSSE1]>;
Dan Gohman7dc19012007-08-02 21:17:01 +00002792// Special unary SHUFPDrri case.
2793def : Pat<(vector_shuffle (v2f64 VR128:$src1), (undef),
2794 SHUFP_unary_shuffle_mask:$sm),
2795 (SHUFPDrri VR128:$src1, VR128:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2796 Requires<[HasSSE2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002797// Unary v4f32 shuffle with PSHUF* in order to fold a load.
Dan Gohman4a4f1512007-07-18 20:23:34 +00002798def : Pat<(vector_shuffle (memopv4f32 addr:$src1), (undef),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002799 SHUFP_unary_shuffle_mask:$sm),
2800 (PSHUFDmi addr:$src1, SHUFP_unary_shuffle_mask:$sm)>,
2801 Requires<[HasSSE2]>;
2802// Special binary v4i32 shuffle cases with SHUFPS.
2803def : Pat<(vector_shuffle (v4i32 VR128:$src1), (v4i32 VR128:$src2),
2804 PSHUFD_binary_shuffle_mask:$sm),
2805 (SHUFPSrri VR128:$src1, VR128:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2806 Requires<[HasSSE2]>;
2807def : Pat<(vector_shuffle (v4i32 VR128:$src1),
Dan Gohman4a4f1512007-07-18 20:23:34 +00002808 (bc_v4i32 (memopv2i64 addr:$src2)), PSHUFD_binary_shuffle_mask:$sm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002809 (SHUFPSrmi VR128:$src1, addr:$src2, PSHUFD_binary_shuffle_mask:$sm)>,
2810 Requires<[HasSSE2]>;
2811
2812// vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
2813let AddedComplexity = 10 in {
2814def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2815 UNPCKL_v_undef_shuffle_mask)),
2816 (UNPCKLPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2817def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2818 UNPCKL_v_undef_shuffle_mask)),
2819 (PUNPCKLBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2820def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2821 UNPCKL_v_undef_shuffle_mask)),
2822 (PUNPCKLWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2823def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2824 UNPCKL_v_undef_shuffle_mask)),
2825 (PUNPCKLDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2826}
2827
2828// vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
2829let AddedComplexity = 10 in {
2830def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef),
2831 UNPCKH_v_undef_shuffle_mask)),
2832 (UNPCKHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2833def : Pat<(v16i8 (vector_shuffle VR128:$src, (undef),
2834 UNPCKH_v_undef_shuffle_mask)),
2835 (PUNPCKHBWrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2836def : Pat<(v8i16 (vector_shuffle VR128:$src, (undef),
2837 UNPCKH_v_undef_shuffle_mask)),
2838 (PUNPCKHWDrr VR128:$src, VR128:$src)>, Requires<[HasSSE2]>;
2839def : Pat<(v4i32 (vector_shuffle VR128:$src, (undef),
2840 UNPCKH_v_undef_shuffle_mask)),
2841 (PUNPCKHDQrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;
2842}
2843
2844let AddedComplexity = 15 in {
2845// vector_shuffle v1, v2 <0, 1, 4, 5> using MOVLHPS
2846def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2847 MOVHP_shuffle_mask)),
2848 (MOVLHPSrr VR128:$src1, VR128:$src2)>;
2849
2850// vector_shuffle v1, v2 <6, 7, 2, 3> using MOVHLPS
2851def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2852 MOVHLPS_shuffle_mask)),
2853 (MOVHLPSrr VR128:$src1, VR128:$src2)>;
2854
2855// vector_shuffle v1, undef <2, ?, ?, ?> using MOVHLPS
2856def : Pat<(v4f32 (vector_shuffle VR128:$src1, (undef),
2857 MOVHLPS_v_undef_shuffle_mask)),
2858 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2859def : Pat<(v4i32 (vector_shuffle VR128:$src1, (undef),
2860 MOVHLPS_v_undef_shuffle_mask)),
2861 (MOVHLPSrr VR128:$src1, VR128:$src1)>;
2862}
2863
2864let AddedComplexity = 20 in {
2865// vector_shuffle v1, (load v2) <4, 5, 2, 3> using MOVLPS
2866// vector_shuffle v1, (load v2) <0, 1, 4, 5> using MOVHPS
Dan Gohman4a4f1512007-07-18 20:23:34 +00002867def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002868 MOVLP_shuffle_mask)),
2869 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002870def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002871 MOVLP_shuffle_mask)),
2872 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002873def : Pat<(v4f32 (vector_shuffle VR128:$src1, (memopv4f32 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002874 MOVHP_shuffle_mask)),
2875 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002876def : Pat<(v2f64 (vector_shuffle VR128:$src1, (memopv2f64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002877 MOVHP_shuffle_mask)),
2878 (MOVHPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2879
Dan Gohman4a4f1512007-07-18 20:23:34 +00002880def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002881 MOVLP_shuffle_mask)),
2882 (MOVLPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002883def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002884 MOVLP_shuffle_mask)),
2885 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002886def : Pat<(v4i32 (vector_shuffle VR128:$src1, (bc_v4i32 (memopv2i64 addr:$src2)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002887 MOVHP_shuffle_mask)),
2888 (MOVHPSrm VR128:$src1, addr:$src2)>, Requires<[HasSSE1]>;
Dan Gohman4a4f1512007-07-18 20:23:34 +00002889def : Pat<(v2i64 (vector_shuffle VR128:$src1, (memopv2i64 addr:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002890 MOVLP_shuffle_mask)),
2891 (MOVLPDrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2892}
2893
2894let AddedComplexity = 15 in {
2895// Setting the lowest element in the vector.
2896def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2897 MOVL_shuffle_mask)),
2898 (MOVLPSrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2899def : Pat<(v2i64 (vector_shuffle VR128:$src1, VR128:$src2,
2900 MOVL_shuffle_mask)),
2901 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2902
2903// vector_shuffle v1, v2 <4, 5, 2, 3> using MOVLPDrr (movsd)
2904def : Pat<(v4f32 (vector_shuffle VR128:$src1, VR128:$src2,
2905 MOVLP_shuffle_mask)),
2906 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2907def : Pat<(v4i32 (vector_shuffle VR128:$src1, VR128:$src2,
2908 MOVLP_shuffle_mask)),
2909 (MOVLPDrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2910}
2911
2912// Set lowest element and zero upper elements.
2913let AddedComplexity = 20 in
2914def : Pat<(bc_v2i64 (vector_shuffle immAllZerosV,
2915 (v2f64 (scalar_to_vector (loadf64 addr:$src))),
2916 MOVL_shuffle_mask)),
2917 (MOVZQI2PQIrm addr:$src)>, Requires<[HasSSE2]>;
2918
2919// FIXME: Temporary workaround since 2-wide shuffle is broken.
2920def : Pat<(int_x86_sse2_movs_d VR128:$src1, VR128:$src2),
2921 (v2f64 (MOVLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2922def : Pat<(int_x86_sse2_loadh_pd VR128:$src1, addr:$src2),
2923 (v2f64 (MOVHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2924def : Pat<(int_x86_sse2_loadl_pd VR128:$src1, addr:$src2),
2925 (v2f64 (MOVLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2926def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, VR128:$src2, imm:$src3),
2927 (v2f64 (SHUFPDrri VR128:$src1, VR128:$src2, imm:$src3))>,
2928 Requires<[HasSSE2]>;
2929def : Pat<(int_x86_sse2_shuf_pd VR128:$src1, (load addr:$src2), imm:$src3),
2930 (v2f64 (SHUFPDrmi VR128:$src1, addr:$src2, imm:$src3))>,
2931 Requires<[HasSSE2]>;
2932def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, VR128:$src2),
2933 (v2f64 (UNPCKHPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2934def : Pat<(int_x86_sse2_unpckh_pd VR128:$src1, (load addr:$src2)),
2935 (v2f64 (UNPCKHPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2936def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, VR128:$src2),
2937 (v2f64 (UNPCKLPDrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2938def : Pat<(int_x86_sse2_unpckl_pd VR128:$src1, (load addr:$src2)),
2939 (v2f64 (UNPCKLPDrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2940def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, VR128:$src2),
2941 (v2i64 (PUNPCKHQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2942def : Pat<(int_x86_sse2_punpckh_qdq VR128:$src1, (load addr:$src2)),
2943 (v2i64 (PUNPCKHQDQrm VR128:$src1, addr:$src2))>, Requires<[HasSSE2]>;
2944def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, VR128:$src2),
2945 (v2i64 (PUNPCKLQDQrr VR128:$src1, VR128:$src2))>, Requires<[HasSSE2]>;
2946def : Pat<(int_x86_sse2_punpckl_qdq VR128:$src1, (load addr:$src2)),
2947 (PUNPCKLQDQrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2948
2949// Some special case pandn patterns.
2950def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
2951 VR128:$src2)),
2952 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2953def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
2954 VR128:$src2)),
2955 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2956def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
2957 VR128:$src2)),
2958 (PANDNrr VR128:$src1, VR128:$src2)>, Requires<[HasSSE2]>;
2959
2960def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v4i32 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00002961 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002962 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2963def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v8i16 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00002964 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002965 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2966def : Pat<(v2i64 (and (xor VR128:$src1, (bc_v2i64 (v16i8 immAllOnesV))),
Dan Gohman7dc19012007-08-02 21:17:01 +00002967 (memopv2i64 addr:$src2))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002968 (PANDNrm VR128:$src1, addr:$src2)>, Requires<[HasSSE2]>;
2969
Nate Begeman78246ca2007-11-17 03:58:34 +00002970// vector -> vector casts
2971def : Pat<(v4f32 (sint_to_fp (v4i32 VR128:$src))),
2972 (Int_CVTDQ2PSrr VR128:$src)>, Requires<[HasSSE2]>;
2973def : Pat<(v4i32 (fp_to_sint (v4f32 VR128:$src))),
2974 (Int_CVTTPS2DQrr VR128:$src)>, Requires<[HasSSE2]>;
2975
Evan Cheng51a49b22007-07-20 00:27:43 +00002976// Use movaps / movups for SSE integer load / store (one byte shorter).
Dan Gohman11821702007-07-27 17:16:43 +00002977def : Pat<(alignedloadv4i32 addr:$src),
2978 (MOVAPSrm addr:$src)>, Requires<[HasSSE1]>;
2979def : Pat<(loadv4i32 addr:$src),
2980 (MOVUPSrm addr:$src)>, Requires<[HasSSE1]>;
Evan Cheng51a49b22007-07-20 00:27:43 +00002981def : Pat<(alignedloadv2i64 addr:$src),
2982 (MOVAPSrm addr:$src)>, Requires<[HasSSE2]>;
2983def : Pat<(loadv2i64 addr:$src),
2984 (MOVUPSrm addr:$src)>, Requires<[HasSSE2]>;
2985
2986def : Pat<(alignedstore (v2i64 VR128:$src), addr:$dst),
2987 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2988def : Pat<(alignedstore (v4i32 VR128:$src), addr:$dst),
2989 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2990def : Pat<(alignedstore (v8i16 VR128:$src), addr:$dst),
2991 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2992def : Pat<(alignedstore (v16i8 VR128:$src), addr:$dst),
2993 (MOVAPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2994def : Pat<(store (v2i64 VR128:$src), addr:$dst),
2995 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2996def : Pat<(store (v4i32 VR128:$src), addr:$dst),
2997 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
2998def : Pat<(store (v8i16 VR128:$src), addr:$dst),
2999 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;
3000def : Pat<(store (v16i8 VR128:$src), addr:$dst),
3001 (MOVUPSmr addr:$dst, VR128:$src)>, Requires<[HasSSE2]>;