1 //====- X86InstrMMX.td - Describe the X86 Instruction Set --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Evan Cheng and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86 MMX instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Instruction templates
18 //===----------------------------------------------------------------------===//
20 // MMXI - MMX instructions with TB prefix.
21 // MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
22 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
23 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
24 // MMXID - MMX instructions with XD prefix.
25 // MMXIS - MMX instructions with XS prefix.
26 class MMXI<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
27 : I<o, F, ops, asm, pattern>, TB, Requires<[HasMMX]>;
28 class MMX2I<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
29 : I<o, F, ops, asm, pattern>, TB, OpSize, Requires<[HasMMX]>;
30 class MMXIi8<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
31 : Ii8<o, F, ops, asm, pattern>, TB, Requires<[HasMMX]>;
32 class MMXID<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
33 : Ii8<o, F, ops, asm, pattern>, XD, Requires<[HasMMX]>;
34 class MMXIS<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
35 : Ii8<o, F, ops, asm, pattern>, XS, Requires<[HasMMX]>;
37 // Some 'special' instructions
38 def IMPLICIT_DEF_VR64 : I<0, Pseudo, (ops VR64:$dst),
40 [(set VR64:$dst, (v8i8 (undef)))]>,
43 // 64-bit vector undef's.
44 def : Pat<(v8i8 (undef)), (IMPLICIT_DEF_VR64)>;
45 def : Pat<(v4i16 (undef)), (IMPLICIT_DEF_VR64)>;
46 def : Pat<(v2i32 (undef)), (IMPLICIT_DEF_VR64)>;
47 def : Pat<(v1i64 (undef)), (IMPLICIT_DEF_VR64)>;
49 //===----------------------------------------------------------------------===//
50 // MMX Pattern Fragments
51 //===----------------------------------------------------------------------===//
53 def load_mmx : PatFrag<(ops node:$ptr), (v1i64 (load node:$ptr))>;
55 def bc_v8i8 : PatFrag<(ops node:$in), (v8i8 (bitconvert node:$in))>;
56 def bc_v4i16 : PatFrag<(ops node:$in), (v4i16 (bitconvert node:$in))>;
57 def bc_v2i32 : PatFrag<(ops node:$in), (v2i32 (bitconvert node:$in))>;
58 def bc_v1i64 : PatFrag<(ops node:$in), (v1i64 (bitconvert node:$in))>;
60 //===----------------------------------------------------------------------===//
62 //===----------------------------------------------------------------------===//
64 def MMX_UNPCKH_shuffle_mask : PatLeaf<(build_vector), [{
65 return X86::isUNPCKHMask(N);
68 def MMX_UNPCKL_shuffle_mask : PatLeaf<(build_vector), [{
69 return X86::isUNPCKLMask(N);
72 //===----------------------------------------------------------------------===//
74 //===----------------------------------------------------------------------===//
76 let isTwoAddress = 1 in {
77 // MMXI_binop_rm - Simple MMX binary operator.
78 multiclass MMXI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
79 ValueType OpVT, bit Commutable = 0> {
80 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
81 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
82 [(set VR64:$dst, (OpVT (OpNode VR64:$src1, VR64:$src2)))]> {
83 let isCommutable = Commutable;
85 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
86 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
87 [(set VR64:$dst, (OpVT (OpNode VR64:$src1,
89 (load_mmx addr:$src2)))))]>;
92 multiclass MMXI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
94 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
95 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
96 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]> {
97 let isCommutable = Commutable;
99 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
100 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
101 [(set VR64:$dst, (IntId VR64:$src1,
102 (bitconvert (load_mmx addr:$src2))))]>;
105 // MMXI_binop_rm_v1i64 - Simple MMX binary operator whose type is v1i64.
107 // FIXME: we could eliminate this and use MMXI_binop_rm instead if tblgen knew
108 // to collapse (bitconvert VT to VT) into its operand.
110 multiclass MMXI_binop_rm_v1i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
111 bit Commutable = 0> {
112 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
113 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
114 [(set VR64:$dst, (v1i64 (OpNode VR64:$src1, VR64:$src2)))]> {
115 let isCommutable = Commutable;
117 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
118 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
120 (OpNode VR64:$src1,(load_mmx addr:$src2)))]>;
123 multiclass MMXI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
124 string OpcodeStr, Intrinsic IntId> {
125 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
126 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
127 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]>;
128 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
129 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
130 [(set VR64:$dst, (IntId VR64:$src1,
131 (bitconvert (load_mmx addr:$src2))))]>;
132 def ri : MMXIi8<opc2, ImmForm, (ops VR64:$dst, VR64:$src1, i32i8imm:$src2),
133 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
134 [(set VR64:$dst, (IntId VR64:$src1,
135 (scalar_to_vector (i32 imm:$src2))))]>;
139 //===----------------------------------------------------------------------===//
140 // MMX EMMS & FEMMS Instructions
141 //===----------------------------------------------------------------------===//
143 def MMX_EMMS : MMXI<0x77, RawFrm, (ops), "emms", [(int_x86_mmx_emms)]>;
144 def MMX_FEMMS : MMXI<0x0E, RawFrm, (ops), "femms", [(int_x86_mmx_femms)]>;
146 //===----------------------------------------------------------------------===//
147 // MMX Scalar Instructions
148 //===----------------------------------------------------------------------===//
150 // Data Transfer Instructions
151 def MMX_MOVD64rr : MMXI<0x6E, MRMSrcReg, (ops VR64:$dst, GR32:$src),
152 "movd {$src, $dst|$dst, $src}", []>;
153 def MMX_MOVD64rm : MMXI<0x6E, MRMSrcMem, (ops VR64:$dst, i32mem:$src),
154 "movd {$src, $dst|$dst, $src}", []>;
155 def MMX_MOVD64mr : MMXI<0x7E, MRMDestMem, (ops i32mem:$dst, VR64:$src),
156 "movd {$src, $dst|$dst, $src}", []>;
158 def MMX_MOVQ64rr : MMXI<0x6F, MRMSrcReg, (ops VR64:$dst, VR64:$src),
159 "movq {$src, $dst|$dst, $src}", []>;
160 def MMX_MOVQ64rm : MMXI<0x6F, MRMSrcMem, (ops VR64:$dst, i64mem:$src),
161 "movq {$src, $dst|$dst, $src}",
162 [(set VR64:$dst, (load_mmx addr:$src))]>;
163 def MMX_MOVQ64mr : MMXI<0x7F, MRMDestMem, (ops i64mem:$dst, VR64:$src),
164 "movq {$src, $dst|$dst, $src}",
165 [(store (v1i64 VR64:$src), addr:$dst)]>;
167 def MMX_MOVDQ2Qrr : MMXID<0xD6, MRMDestMem, (ops VR64:$dst, VR128:$src),
168 "movdq2q {$src, $dst|$dst, $src}",
169 [(store (i64 (vector_extract (v2i64 VR128:$src),
170 (iPTR 0))), VR64:$dst)]>;
171 def MMX_MOVQ2DQrr : MMXIS<0xD6, MRMDestMem, (ops VR128:$dst, VR64:$src),
172 "movq2dq {$src, $dst|$dst, $src}",
173 [(store (v1i64 VR64:$src), VR128:$dst)]>;
175 def MMX_MOVNTQmr : MMXI<0xE7, MRMDestMem, (ops i64mem:$dst, VR64:$src),
176 "movntq {$src, $dst|$dst, $src}", []>;
179 // Arithmetic Instructions
182 defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
183 defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
184 defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
185 defm MMX_PADDQ : MMXI_binop_rm<0xD4, "paddq", add, v1i64, 1>;
187 defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
188 defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
190 defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
191 defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
194 defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
195 defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
196 defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
198 defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
199 defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
201 defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
202 defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
205 defm MMX_PMULLW : MMXI_binop_rm<0xD5, "pmullw", mul, v4i16, 1>;
207 defm MMX_PMULHW : MMXI_binop_rm_int<0xE5, "pmulhw", int_x86_mmx_pmulh_w, 1>;
208 defm MMX_PMULHUW : MMXI_binop_rm_int<0xE4, "pmulhuw", int_x86_mmx_pmulhu_w, 1>;
209 defm MMX_PMULUDQ : MMXI_binop_rm_int<0xF4, "pmuludq", int_x86_mmx_pmulu_dq, 1>;
212 defm MMX_PMADDWD : MMXI_binop_rm_int<0xF5, "pmaddwd", int_x86_mmx_pmadd_wd, 1>;
214 defm MMX_PAVGB : MMXI_binop_rm_int<0xE0, "pavgb", int_x86_mmx_pavg_b, 1>;
215 defm MMX_PAVGW : MMXI_binop_rm_int<0xE3, "pavgw", int_x86_mmx_pavg_w, 1>;
217 defm MMX_PMINUB : MMXI_binop_rm_int<0xDA, "pminub", int_x86_mmx_pminu_b, 1>;
218 defm MMX_PMINSW : MMXI_binop_rm_int<0xEA, "pminsw", int_x86_mmx_pmins_w, 1>;
220 defm MMX_PMAXUB : MMXI_binop_rm_int<0xDE, "pmaxub", int_x86_mmx_pmaxu_b, 1>;
221 defm MMX_PMAXSW : MMXI_binop_rm_int<0xEE, "pmaxsw", int_x86_mmx_pmaxs_w, 1>;
223 defm MMX_PSADBW : MMXI_binop_rm_int<0xE0, "psadbw", int_x86_mmx_psad_bw, 1>;
225 // Logical Instructions
226 defm MMX_PAND : MMXI_binop_rm_v1i64<0xDB, "pand", and, 1>;
227 defm MMX_POR : MMXI_binop_rm_v1i64<0xEB, "por" , or, 1>;
228 defm MMX_PXOR : MMXI_binop_rm_v1i64<0xEF, "pxor", xor, 1>;
230 let isTwoAddress = 1 in {
231 def MMX_PANDNrr : MMXI<0xDF, MRMSrcReg,
232 (ops VR64:$dst, VR64:$src1, VR64:$src2),
233 "pandn {$src2, $dst|$dst, $src2}",
234 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
236 def MMX_PANDNrm : MMXI<0xDF, MRMSrcMem,
237 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
238 "pandn {$src2, $dst|$dst, $src2}",
239 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
240 (load addr:$src2))))]>;
243 // Shift Instructions
244 defm MMX_PSRLW : MMXI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
246 defm MMX_PSRLD : MMXI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
248 defm MMX_PSRLQ : MMXI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
251 defm MMX_PSLLW : MMXI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
253 defm MMX_PSLLD : MMXI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
255 defm MMX_PSLLQ : MMXI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
258 defm MMX_PSRAW : MMXI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
260 defm MMX_PSRAD : MMXI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
263 // Comparison Instructions
264 defm MMX_PCMPEQB : MMXI_binop_rm_int<0x74, "pcmpeqb", int_x86_mmx_pcmpeq_b>;
265 defm MMX_PCMPEQW : MMXI_binop_rm_int<0x75, "pcmpeqw", int_x86_mmx_pcmpeq_w>;
266 defm MMX_PCMPEQD : MMXI_binop_rm_int<0x76, "pcmpeqd", int_x86_mmx_pcmpeq_d>;
268 defm MMX_PCMPGTB : MMXI_binop_rm_int<0x64, "pcmpgtb", int_x86_mmx_pcmpgt_b>;
269 defm MMX_PCMPGTW : MMXI_binop_rm_int<0x65, "pcmpgtw", int_x86_mmx_pcmpgt_w>;
270 defm MMX_PCMPGTD : MMXI_binop_rm_int<0x66, "pcmpgtd", int_x86_mmx_pcmpgt_d>;
272 // Conversion Instructions
274 // -- Unpack Instructions
275 let isTwoAddress = 1 in {
276 // Unpack High Packed Data Instructions
277 def MMX_PUNPCKHBWrr : MMXI<0x68, MRMSrcReg,
278 (ops VR64:$dst, VR64:$src1, VR64:$src2),
279 "punpckhbw {$src2, $dst|$dst, $src2}",
281 (v8i8 (vector_shuffle VR64:$src1, VR64:$src2,
282 MMX_UNPCKH_shuffle_mask)))]>;
283 def MMX_PUNPCKHBWrm : MMXI<0x68, MRMSrcMem,
284 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
285 "punpckhbw {$src2, $dst|$dst, $src2}",
287 (v8i8 (vector_shuffle VR64:$src1,
288 (bc_v8i8 (load_mmx addr:$src2)),
289 MMX_UNPCKH_shuffle_mask)))]>;
291 def MMX_PUNPCKHWDrr : MMXI<0x69, MRMSrcReg,
292 (ops VR64:$dst, VR64:$src1, VR64:$src2),
293 "punpckhwd {$src2, $dst|$dst, $src2}",
295 (v4i16 (vector_shuffle VR64:$src1, VR64:$src2,
296 MMX_UNPCKH_shuffle_mask)))]>;
297 def MMX_PUNPCKHWDrm : MMXI<0x69, MRMSrcMem,
298 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
299 "punpckhwd {$src2, $dst|$dst, $src2}",
301 (v4i16 (vector_shuffle VR64:$src1,
302 (bc_v4i16 (load_mmx addr:$src2)),
303 MMX_UNPCKH_shuffle_mask)))]>;
305 def MMX_PUNPCKHDQrr : MMXI<0x6A, MRMSrcReg,
306 (ops VR64:$dst, VR64:$src1, VR64:$src2),
307 "punpckhdq {$src2, $dst|$dst, $src2}",
309 (v2i32 (vector_shuffle VR64:$src1, VR64:$src2,
310 MMX_UNPCKH_shuffle_mask)))]>;
311 def MMX_PUNPCKHDQrm : MMXI<0x6A, MRMSrcMem,
312 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
313 "punpckhdq {$src2, $dst|$dst, $src2}",
315 (v2i32 (vector_shuffle VR64:$src1,
316 (bc_v2i32 (load_mmx addr:$src2)),
317 MMX_UNPCKH_shuffle_mask)))]>;
319 // Unpack Low Packed Data Instructions
320 def MMX_PUNPCKLBWrr : MMXI<0x60, MRMSrcReg,
321 (ops VR64:$dst, VR64:$src1, VR64:$src2),
322 "punpcklbw {$src2, $dst|$dst, $src2}",
324 (v8i8 (vector_shuffle VR64:$src1, VR64:$src2,
325 MMX_UNPCKL_shuffle_mask)))]>;
326 def MMX_PUNPCKLBWrm : MMXI<0x60, MRMSrcMem,
327 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
328 "punpcklbw {$src2, $dst|$dst, $src2}",
330 (v8i8 (vector_shuffle VR64:$src1,
331 (bc_v8i8 (load_mmx addr:$src2)),
332 MMX_UNPCKL_shuffle_mask)))]>;
334 def MMX_PUNPCKLWDrr : MMXI<0x61, MRMSrcReg,
335 (ops VR64:$dst, VR64:$src1, VR64:$src2),
336 "punpcklwd {$src2, $dst|$dst, $src2}",
338 (v4i16 (vector_shuffle VR64:$src1, VR64:$src2,
339 MMX_UNPCKL_shuffle_mask)))]>;
340 def MMX_PUNPCKLWDrm : MMXI<0x61, MRMSrcMem,
341 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
342 "punpcklwd {$src2, $dst|$dst, $src2}",
344 (v4i16 (vector_shuffle VR64:$src1,
345 (bc_v4i16 (load_mmx addr:$src2)),
346 MMX_UNPCKL_shuffle_mask)))]>;
348 def MMX_PUNPCKLDQrr : MMXI<0x62, MRMSrcReg,
349 (ops VR64:$dst, VR64:$src1, VR64:$src2),
350 "punpckldq {$src2, $dst|$dst, $src2}",
352 (v2i32 (vector_shuffle VR64:$src1, VR64:$src2,
353 MMX_UNPCKL_shuffle_mask)))]>;
354 def MMX_PUNPCKLDQrm : MMXI<0x62, MRMSrcMem,
355 (ops VR64:$dst, VR64:$src1, i64mem:$src2),
356 "punpckldq {$src2, $dst|$dst, $src2}",
358 (v2i32 (vector_shuffle VR64:$src1,
359 (bc_v2i32 (load_mmx addr:$src2)),
360 MMX_UNPCKL_shuffle_mask)))]>;
363 // -- Pack Instructions
364 defm MMX_PACKSSWB : MMXI_binop_rm_int<0x63, "packsswb", int_x86_mmx_packsswb>;
365 defm MMX_PACKSSDW : MMXI_binop_rm_int<0x6B, "packssdw", int_x86_mmx_packssdw>;
366 defm MMX_PACKUSWB : MMXI_binop_rm_int<0x67, "packuswb", int_x86_mmx_packuswb>;
368 // -- Conversion Instructions
369 def MMX_CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (ops VR64:$dst, VR128:$src),
370 "cvtpd2pi {$src, $dst|$dst, $src}", []>;
371 def MMX_CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (ops VR64:$dst, f128mem:$src),
372 "cvtpd2pi {$src, $dst|$dst, $src}", []>;
374 def MMX_CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (ops VR128:$dst, VR64:$src),
375 "cvtpi2pd {$src, $dst|$dst, $src}", []>;
376 def MMX_CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (ops VR128:$dst, i64mem:$src),
377 "cvtpi2pd {$src, $dst|$dst, $src}", []>;
379 def MMX_CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (ops VR128:$dst, VR64:$src),
380 "cvtpi2ps {$src, $dst|$dst, $src}", []>;
381 def MMX_CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (ops VR128:$dst, i64mem:$src),
382 "cvtpi2ps {$src, $dst|$dst, $src}", []>;
384 def MMX_CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (ops VR64:$dst, VR128:$src),
385 "cvtps2pi {$src, $dst|$dst, $src}", []>;
386 def MMX_CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (ops VR64:$dst, f64mem:$src),
387 "cvtps2pi {$src, $dst|$dst, $src}", []>;
389 def MMX_CVTTPD2PIrr : MMX2I<0x2C, MRMSrcReg, (ops VR64:$dst, VR128:$src),
390 "cvttpd2pi {$src, $dst|$dst, $src}", []>;
391 def MMX_CVTTPD2PIrm : MMX2I<0x2C, MRMSrcMem, (ops VR64:$dst, f128mem:$src),
392 "cvttpd2pi {$src, $dst|$dst, $src}", []>;
394 def MMX_CVTTPS2PIrr : MMXI<0x2C, MRMSrcReg, (ops VR64:$dst, VR128:$src),
395 "cvttps2pi {$src, $dst|$dst, $src}", []>;
396 def MMX_CVTTPS2PIrm : MMXI<0x2C, MRMSrcMem, (ops VR64:$dst, f64mem:$src),
397 "cvttps2pi {$src, $dst|$dst, $src}", []>;
399 // Shuffle and unpack instructions
400 def PSHUFWri : MMXIi8<0x70, MRMSrcReg,
401 (ops VR64:$dst, VR64:$src1, i8imm:$src2),
402 "pshufw {$src2, $src1, $dst|$dst, $src1, $src2}", []>;
403 def PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
404 (ops VR64:$dst, i64mem:$src1, i8imm:$src2),
405 "pshufw {$src2, $src1, $dst|$dst, $src1, $src2}", []>;
408 def MMX_X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
409 def MMX_X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
411 def MMX_PEXTRWri : MMXIi8<0xC5, MRMSrcReg,
412 (ops GR32:$dst, VR64:$src1, i16i8imm:$src2),
413 "pextrw {$src2, $src1, $dst|$dst, $src1, $src2}",
414 [(set GR32:$dst, (MMX_X86pextrw (v4i16 VR64:$src1),
415 (iPTR imm:$src2)))]>;
416 let isTwoAddress = 1 in {
417 def MMX_PINSRWrri : MMXIi8<0xC4, MRMSrcReg,
418 (ops VR64:$dst, VR64:$src1, GR32:$src2, i16i8imm:$src3),
419 "pinsrw {$src3, $src2, $dst|$dst, $src2, $src3}",
420 [(set VR64:$dst, (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
421 GR32:$src2, (iPTR imm:$src3))))]>;
422 def MMX_PINSRWrmi : MMXIi8<0xC4, MRMSrcMem,
423 (ops VR64:$dst, VR64:$src1, i16mem:$src2, i16i8imm:$src3),
424 "pinsrw {$src3, $src2, $dst|$dst, $src2, $src3}",
426 (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
427 (i32 (anyext (loadi16 addr:$src2))),
428 (iPTR imm:$src3))))]>;
432 def MMX_PMOVMSKBrr : MMXI<0xD7, MRMSrcReg, (ops GR32:$dst, VR64:$src),
433 "pmovmskb {$src, $dst|$dst, $src}",
434 [(set GR32:$dst, (int_x86_mmx_pmovmskb VR64:$src))]>;
437 def MMX_MASKMOVQ : MMXI<0xF7, MRMDestMem, (ops VR64:$src, VR64:$mask),
438 "maskmovq {$mask, $src|$src, $mask}", []>;
440 //===----------------------------------------------------------------------===//
441 // Alias Instructions
442 //===----------------------------------------------------------------------===//
444 // Alias instructions that map zero vector to pxor.
445 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
446 let isReMaterializable = 1 in {
447 def MMX_V_SET0 : MMXI<0xEF, MRMInitReg, (ops VR64:$dst),
449 [(set VR64:$dst, (v1i64 immAllZerosV))]>;
450 def MMX_V_SETALLONES : MMXI<0x76, MRMInitReg, (ops VR64:$dst),
451 "pcmpeqd $dst, $dst",
452 [(set VR64:$dst, (v1i64 immAllOnesV))]>;
455 //===----------------------------------------------------------------------===//
456 // Non-Instruction Patterns
457 //===----------------------------------------------------------------------===//
459 // Store 64-bit integer vector values.
460 def : Pat<(store (v8i8 VR64:$src), addr:$dst),
461 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
462 def : Pat<(store (v4i16 VR64:$src), addr:$dst),
463 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
464 def : Pat<(store (v2i32 VR64:$src), addr:$dst),
465 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
466 def : Pat<(store (v1i64 VR64:$src), addr:$dst),
467 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
469 // 64-bit vector all zero's.
470 def : Pat<(v8i8 immAllZerosV), (MMX_V_SET0)>;
471 def : Pat<(v4i16 immAllZerosV), (MMX_V_SET0)>;
472 def : Pat<(v2i32 immAllZerosV), (MMX_V_SET0)>;
473 def : Pat<(v1i64 immAllZerosV), (MMX_V_SET0)>;
475 // 64-bit vector all one's.
476 def : Pat<(v8i8 immAllOnesV), (MMX_V_SETALLONES)>;
477 def : Pat<(v4i16 immAllOnesV), (MMX_V_SETALLONES)>;
478 def : Pat<(v2i32 immAllOnesV), (MMX_V_SETALLONES)>;
479 def : Pat<(v1i64 immAllOnesV), (MMX_V_SETALLONES)>;
482 def : Pat<(v8i8 (bitconvert (v1i64 VR64:$src))), (v8i8 VR64:$src)>;
483 def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
484 def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
485 def : Pat<(v4i16 (bitconvert (v1i64 VR64:$src))), (v4i16 VR64:$src)>;
486 def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
487 def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
488 def : Pat<(v2i32 (bitconvert (v1i64 VR64:$src))), (v2i32 VR64:$src)>;
489 def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
490 def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;
491 def : Pat<(v1i64 (bitconvert (v2i32 VR64:$src))), (v1i64 VR64:$src)>;
492 def : Pat<(v1i64 (bitconvert (v4i16 VR64:$src))), (v1i64 VR64:$src)>;
493 def : Pat<(v1i64 (bitconvert (v8i8 VR64:$src))), (v1i64 VR64:$src)>;
495 def MMX_X86s2vec : SDNode<"X86ISD::S2VEC", SDTypeProfile<1, 1, []>, []>;
497 // Scalar to v4i16 / v8i8. The source may be a GR32, but only the lower 8 or
499 def : Pat<(v8i8 (MMX_X86s2vec GR32:$src)), (MMX_MOVD64rr GR32:$src)>;
500 def : Pat<(v4i16 (MMX_X86s2vec GR32:$src)), (MMX_MOVD64rr GR32:$src)>;
502 // Recipes for: vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
503 def MMX_UNPCKL_v_undef_shuffle_mask : PatLeaf<(build_vector), [{
504 return X86::isUNPCKL_v_undef_Mask(N);
507 let AddedComplexity = 10 in {
508 def : Pat<(v8i8 (vector_shuffle VR64:$src, (undef),
509 MMX_UNPCKL_v_undef_shuffle_mask)),
510 (MMX_PUNPCKLBWrr VR64:$src, VR64:$src)>;
511 def : Pat<(v4i16 (vector_shuffle VR64:$src, (undef),
512 MMX_UNPCKL_v_undef_shuffle_mask)),
513 (MMX_PUNPCKLWDrr VR64:$src, VR64:$src)>;
514 def : Pat<(v2i32 (vector_shuffle VR64:$src, (undef),
515 MMX_UNPCKL_v_undef_shuffle_mask)),
516 (MMX_PUNPCKLDQrr VR64:$src, VR64:$src)>;
519 let AddedComplexity = 20 in {
520 def : Pat<(bc_v2i32 (vector_shuffle immAllZerosV,
521 (v2i32 (scalar_to_vector (load_mmx addr:$src))),
522 MMX_UNPCKL_shuffle_mask)),
523 (MMX_PUNPCKLDQrm VR64:$src, VR64:$src)>;
526 // Some special case PANDN patterns.
527 // FIXME: Get rid of these.
528 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
530 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
531 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV))),
533 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
534 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV))),
536 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
538 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
540 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
541 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV))),
543 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
544 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV))),
546 (MMX_PANDNrm VR64:$src1, addr:$src2)>;