1 //====- X86InstrMMX.td - Describe the X86 Instruction Set --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
20 let Constraints = "$src1 = $dst" in {
21 // MMXI_binop_rm - Simple MMX binary operator.
22 multiclass MMXI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
23 ValueType OpVT, bit Commutable = 0> {
24 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
25 (ins VR64:$src1, VR64:$src2),
26 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
27 [(set VR64:$dst, (OpVT (OpNode VR64:$src1, VR64:$src2)))]> {
28 let isCommutable = Commutable;
30 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
31 (ins VR64:$src1, i64mem:$src2),
32 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
33 [(set VR64:$dst, (OpVT (OpNode VR64:$src1,
35 (load_mmx addr:$src2)))))]>;
38 multiclass MMXI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
40 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
41 (ins VR64:$src1, VR64:$src2),
42 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
43 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]> {
44 let isCommutable = Commutable;
46 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
47 (ins VR64:$src1, i64mem:$src2),
48 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
49 [(set VR64:$dst, (IntId VR64:$src1,
50 (bitconvert (load_mmx addr:$src2))))]>;
53 // MMXI_binop_rm_v1i64 - Simple MMX binary operator whose type is v1i64.
55 // FIXME: we could eliminate this and use MMXI_binop_rm instead if tblgen knew
56 // to collapse (bitconvert VT to VT) into its operand.
58 multiclass MMXI_binop_rm_v1i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
60 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
61 (ins VR64:$src1, VR64:$src2),
62 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
63 [(set VR64:$dst, (v1i64 (OpNode VR64:$src1, VR64:$src2)))]> {
64 let isCommutable = Commutable;
66 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
67 (ins VR64:$src1, i64mem:$src2),
68 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
70 (OpNode VR64:$src1,(load_mmx addr:$src2)))]>;
73 multiclass MMXI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
74 string OpcodeStr, Intrinsic IntId,
76 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
77 (ins VR64:$src1, VR64:$src2),
78 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
79 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]>;
80 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
81 (ins VR64:$src1, i64mem:$src2),
82 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
83 [(set VR64:$dst, (IntId VR64:$src1,
84 (bitconvert (load_mmx addr:$src2))))]>;
85 def ri : MMXIi8<opc2, ImmForm, (outs VR64:$dst),
86 (ins VR64:$src1, i32i8imm:$src2),
87 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
88 [(set VR64:$dst, (IntId2 VR64:$src1, (i32 imm:$src2)))]>;
92 //===----------------------------------------------------------------------===//
93 // MMX EMMS & FEMMS Instructions
94 //===----------------------------------------------------------------------===//
96 def MMX_EMMS : MMXI<0x77, RawFrm, (outs), (ins), "emms",
97 [(int_x86_mmx_emms)]>;
98 def MMX_FEMMS : MMXI<0x0E, RawFrm, (outs), (ins), "femms",
99 [(int_x86_mmx_femms)]>;
101 //===----------------------------------------------------------------------===//
102 // MMX Scalar Instructions
103 //===----------------------------------------------------------------------===//
105 // Data Transfer Instructions
106 def MMX_MOVD64rr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
107 "movd\t{$src, $dst|$dst, $src}",
109 (v2i32 (scalar_to_vector GR32:$src)))]>;
110 let canFoldAsLoad = 1, isReMaterializable = 1 in
111 def MMX_MOVD64rm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst), (ins i32mem:$src),
112 "movd\t{$src, $dst|$dst, $src}",
114 (v2i32 (scalar_to_vector (loadi32 addr:$src))))]>;
116 def MMX_MOVD64mr : MMXI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR64:$src),
117 "movd\t{$src, $dst|$dst, $src}", []>;
118 def MMX_MOVD64grr : MMXI<0x7E, MRMDestReg, (outs), (ins GR32:$dst, VR64:$src),
119 "movd\t{$src, $dst|$dst, $src}", []>;
120 def MMX_MOVQ64gmr : MMXRI<0x7E, MRMDestMem, (outs),
121 (ins i64mem:$dst, VR64:$src),
122 "movq\t{$src, $dst|$dst, $src}", []>;
124 let neverHasSideEffects = 1 in
125 def MMX_MOVD64to64rr : MMXRI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
126 "movd\t{$src, $dst|$dst, $src}",
129 let neverHasSideEffects = 1 in
130 // These are 64 bit moves, but since the OS X assembler doesn't
131 // recognize a register-register movq, we write them as
133 def MMX_MOVD64from64rr : MMXRI<0x7E, MRMDestReg,
134 (outs GR64:$dst), (ins VR64:$src),
135 "movd\t{$src, $dst|$dst, $src}", []>;
136 def MMX_MOVD64rrv164 : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
137 "movd\t{$src, $dst|$dst, $src}",
139 (v1i64 (scalar_to_vector GR64:$src)))]>;
141 let neverHasSideEffects = 1 in
142 def MMX_MOVQ64rr : MMXI<0x6F, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
143 "movq\t{$src, $dst|$dst, $src}", []>;
144 let canFoldAsLoad = 1, isReMaterializable = 1 in
145 def MMX_MOVQ64rm : MMXI<0x6F, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
146 "movq\t{$src, $dst|$dst, $src}",
147 [(set VR64:$dst, (load_mmx addr:$src))]>;
148 def MMX_MOVQ64mr : MMXI<0x7F, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
149 "movq\t{$src, $dst|$dst, $src}",
150 [(store (v1i64 VR64:$src), addr:$dst)]>;
152 def MMX_MOVDQ2Qrr : SDIi8<0xD6, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
153 "movdq2q\t{$src, $dst|$dst, $src}",
156 (i64 (vector_extract (v2i64 VR128:$src),
159 def MMX_MOVQ2DQrr : SSDIi8<0xD6, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
160 "movq2dq\t{$src, $dst|$dst, $src}",
163 (v2i64 (scalar_to_vector
164 (i64 (bitconvert (v1i64 VR64:$src)))))))]>;
166 let neverHasSideEffects = 1 in
167 def MMX_MOVQ2FR64rr: SSDIi8<0xD6, MRMSrcReg, (outs FR64:$dst), (ins VR64:$src),
168 "movq2dq\t{$src, $dst|$dst, $src}", []>;
170 def MMX_MOVNTQmr : MMXI<0xE7, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
171 "movntq\t{$src, $dst|$dst, $src}",
172 [(int_x86_mmx_movnt_dq addr:$dst, VR64:$src)]>;
174 let AddedComplexity = 15 in
175 // movd to MMX register zero-extends
176 def MMX_MOVZDI2PDIrr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
177 "movd\t{$src, $dst|$dst, $src}",
179 (v2i32 (X86vzmovl (v2i32 (scalar_to_vector GR32:$src)))))]>;
180 let AddedComplexity = 20 in
181 def MMX_MOVZDI2PDIrm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst),
183 "movd\t{$src, $dst|$dst, $src}",
185 (v2i32 (X86vzmovl (v2i32
186 (scalar_to_vector (loadi32 addr:$src))))))]>;
188 // Arithmetic Instructions
191 defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
192 defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
193 defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
194 defm MMX_PADDQ : MMXI_binop_rm<0xD4, "paddq", add, v1i64, 1>;
196 defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
197 defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
199 defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
200 defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
203 defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
204 defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
205 defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
206 defm MMX_PSUBQ : MMXI_binop_rm<0xFB, "psubq", sub, v1i64>;
208 defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
209 defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
211 defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
212 defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
215 defm MMX_PMULLW : MMXI_binop_rm<0xD5, "pmullw", mul, v4i16, 1>;
217 defm MMX_PMULHW : MMXI_binop_rm_int<0xE5, "pmulhw", int_x86_mmx_pmulh_w, 1>;
218 defm MMX_PMULHUW : MMXI_binop_rm_int<0xE4, "pmulhuw", int_x86_mmx_pmulhu_w, 1>;
219 defm MMX_PMULUDQ : MMXI_binop_rm_int<0xF4, "pmuludq", int_x86_mmx_pmulu_dq, 1>;
222 defm MMX_PMADDWD : MMXI_binop_rm_int<0xF5, "pmaddwd", int_x86_mmx_pmadd_wd, 1>;
224 defm MMX_PAVGB : MMXI_binop_rm_int<0xE0, "pavgb", int_x86_mmx_pavg_b, 1>;
225 defm MMX_PAVGW : MMXI_binop_rm_int<0xE3, "pavgw", int_x86_mmx_pavg_w, 1>;
227 defm MMX_PMINUB : MMXI_binop_rm_int<0xDA, "pminub", int_x86_mmx_pminu_b, 1>;
228 defm MMX_PMINSW : MMXI_binop_rm_int<0xEA, "pminsw", int_x86_mmx_pmins_w, 1>;
230 defm MMX_PMAXUB : MMXI_binop_rm_int<0xDE, "pmaxub", int_x86_mmx_pmaxu_b, 1>;
231 defm MMX_PMAXSW : MMXI_binop_rm_int<0xEE, "pmaxsw", int_x86_mmx_pmaxs_w, 1>;
233 defm MMX_PSADBW : MMXI_binop_rm_int<0xF6, "psadbw", int_x86_mmx_psad_bw, 1>;
235 // Logical Instructions
236 defm MMX_PAND : MMXI_binop_rm_v1i64<0xDB, "pand", and, 1>;
237 defm MMX_POR : MMXI_binop_rm_v1i64<0xEB, "por" , or, 1>;
238 defm MMX_PXOR : MMXI_binop_rm_v1i64<0xEF, "pxor", xor, 1>;
240 let Constraints = "$src1 = $dst" in {
241 def MMX_PANDNrr : MMXI<0xDF, MRMSrcReg,
242 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
243 "pandn\t{$src2, $dst|$dst, $src2}",
244 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
246 def MMX_PANDNrm : MMXI<0xDF, MRMSrcMem,
247 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
248 "pandn\t{$src2, $dst|$dst, $src2}",
249 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
250 (load addr:$src2))))]>;
253 // Shift Instructions
254 defm MMX_PSRLW : MMXI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
255 int_x86_mmx_psrl_w, int_x86_mmx_psrli_w>;
256 defm MMX_PSRLD : MMXI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
257 int_x86_mmx_psrl_d, int_x86_mmx_psrli_d>;
258 defm MMX_PSRLQ : MMXI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
259 int_x86_mmx_psrl_q, int_x86_mmx_psrli_q>;
261 defm MMX_PSLLW : MMXI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
262 int_x86_mmx_psll_w, int_x86_mmx_pslli_w>;
263 defm MMX_PSLLD : MMXI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
264 int_x86_mmx_psll_d, int_x86_mmx_pslli_d>;
265 defm MMX_PSLLQ : MMXI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
266 int_x86_mmx_psll_q, int_x86_mmx_pslli_q>;
268 defm MMX_PSRAW : MMXI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
269 int_x86_mmx_psra_w, int_x86_mmx_psrai_w>;
270 defm MMX_PSRAD : MMXI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
271 int_x86_mmx_psra_d, int_x86_mmx_psrai_d>;
273 // Shift up / down and insert zero's.
274 def : Pat<(v1i64 (X86vshl VR64:$src, (i8 imm:$amt))),
275 (MMX_PSLLQri VR64:$src, (GetLo32XForm imm:$amt))>;
276 def : Pat<(v1i64 (X86vshr VR64:$src, (i8 imm:$amt))),
277 (MMX_PSRLQri VR64:$src, (GetLo32XForm imm:$amt))>;
279 // Comparison Instructions
280 defm MMX_PCMPEQB : MMXI_binop_rm_int<0x74, "pcmpeqb", int_x86_mmx_pcmpeq_b>;
281 defm MMX_PCMPEQW : MMXI_binop_rm_int<0x75, "pcmpeqw", int_x86_mmx_pcmpeq_w>;
282 defm MMX_PCMPEQD : MMXI_binop_rm_int<0x76, "pcmpeqd", int_x86_mmx_pcmpeq_d>;
284 defm MMX_PCMPGTB : MMXI_binop_rm_int<0x64, "pcmpgtb", int_x86_mmx_pcmpgt_b>;
285 defm MMX_PCMPGTW : MMXI_binop_rm_int<0x65, "pcmpgtw", int_x86_mmx_pcmpgt_w>;
286 defm MMX_PCMPGTD : MMXI_binop_rm_int<0x66, "pcmpgtd", int_x86_mmx_pcmpgt_d>;
288 // Conversion Instructions
290 // -- Unpack Instructions
291 let Constraints = "$src1 = $dst" in {
292 // Unpack High Packed Data Instructions
293 def MMX_PUNPCKHBWrr : MMXI<0x68, MRMSrcReg,
294 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
295 "punpckhbw\t{$src2, $dst|$dst, $src2}",
297 (v8i8 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
298 def MMX_PUNPCKHBWrm : MMXI<0x68, MRMSrcMem,
299 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
300 "punpckhbw\t{$src2, $dst|$dst, $src2}",
302 (v8i8 (mmx_unpckh VR64:$src1,
303 (bc_v8i8 (load_mmx addr:$src2)))))]>;
305 def MMX_PUNPCKHWDrr : MMXI<0x69, MRMSrcReg,
306 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
307 "punpckhwd\t{$src2, $dst|$dst, $src2}",
309 (v4i16 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
310 def MMX_PUNPCKHWDrm : MMXI<0x69, MRMSrcMem,
311 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
312 "punpckhwd\t{$src2, $dst|$dst, $src2}",
314 (v4i16 (mmx_unpckh VR64:$src1,
315 (bc_v4i16 (load_mmx addr:$src2)))))]>;
317 def MMX_PUNPCKHDQrr : MMXI<0x6A, MRMSrcReg,
318 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
319 "punpckhdq\t{$src2, $dst|$dst, $src2}",
321 (v2i32 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
322 def MMX_PUNPCKHDQrm : MMXI<0x6A, MRMSrcMem,
323 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
324 "punpckhdq\t{$src2, $dst|$dst, $src2}",
326 (v2i32 (mmx_unpckh VR64:$src1,
327 (bc_v2i32 (load_mmx addr:$src2)))))]>;
329 // Unpack Low Packed Data Instructions
330 def MMX_PUNPCKLBWrr : MMXI<0x60, MRMSrcReg,
331 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
332 "punpcklbw\t{$src2, $dst|$dst, $src2}",
334 (v8i8 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
335 def MMX_PUNPCKLBWrm : MMXI<0x60, MRMSrcMem,
336 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
337 "punpcklbw\t{$src2, $dst|$dst, $src2}",
339 (v8i8 (mmx_unpckl VR64:$src1,
340 (bc_v8i8 (load_mmx addr:$src2)))))]>;
342 def MMX_PUNPCKLWDrr : MMXI<0x61, MRMSrcReg,
343 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
344 "punpcklwd\t{$src2, $dst|$dst, $src2}",
346 (v4i16 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
347 def MMX_PUNPCKLWDrm : MMXI<0x61, MRMSrcMem,
348 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
349 "punpcklwd\t{$src2, $dst|$dst, $src2}",
351 (v4i16 (mmx_unpckl VR64:$src1,
352 (bc_v4i16 (load_mmx addr:$src2)))))]>;
354 def MMX_PUNPCKLDQrr : MMXI<0x62, MRMSrcReg,
355 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
356 "punpckldq\t{$src2, $dst|$dst, $src2}",
358 (v2i32 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
359 def MMX_PUNPCKLDQrm : MMXI<0x62, MRMSrcMem,
360 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
361 "punpckldq\t{$src2, $dst|$dst, $src2}",
363 (v2i32 (mmx_unpckl VR64:$src1,
364 (bc_v2i32 (load_mmx addr:$src2)))))]>;
367 // -- Pack Instructions
368 defm MMX_PACKSSWB : MMXI_binop_rm_int<0x63, "packsswb", int_x86_mmx_packsswb>;
369 defm MMX_PACKSSDW : MMXI_binop_rm_int<0x6B, "packssdw", int_x86_mmx_packssdw>;
370 defm MMX_PACKUSWB : MMXI_binop_rm_int<0x67, "packuswb", int_x86_mmx_packuswb>;
372 // -- Shuffle Instructions
373 def MMX_PSHUFWri : MMXIi8<0x70, MRMSrcReg,
374 (outs VR64:$dst), (ins VR64:$src1, i8imm:$src2),
375 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
377 (v4i16 (mmx_pshufw:$src2 VR64:$src1, (undef))))]>;
378 def MMX_PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
379 (outs VR64:$dst), (ins i64mem:$src1, i8imm:$src2),
380 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
382 (mmx_pshufw:$src2 (bc_v4i16 (load_mmx addr:$src1)),
385 // -- Conversion Instructions
386 let neverHasSideEffects = 1 in {
387 def MMX_CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
388 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
390 def MMX_CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (outs VR64:$dst),
392 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
394 def MMX_CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
395 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
397 def MMX_CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (outs VR128:$dst),
399 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
401 def MMX_CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
402 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
404 def MMX_CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (outs VR128:$dst),
406 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
408 def MMX_CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
409 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
411 def MMX_CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
412 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
414 def MMX_CVTTPD2PIrr : MMX2I<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
415 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
417 def MMX_CVTTPD2PIrm : MMX2I<0x2C, MRMSrcMem, (outs VR64:$dst),
419 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
421 def MMX_CVTTPS2PIrr : MMXI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
422 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
424 def MMX_CVTTPS2PIrm : MMXI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
425 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
426 } // end neverHasSideEffects
430 def MMX_X86pinsrw : SDNode<"X86ISD::MMX_PINSRW",
431 SDTypeProfile<1, 3, [SDTCisVT<0, v4i16>, SDTCisSameAs<0,1>,
432 SDTCisVT<2, i32>, SDTCisPtrTy<3>]>>;
435 def MMX_PEXTRWri : MMXIi8<0xC5, MRMSrcReg,
436 (outs GR32:$dst), (ins VR64:$src1, i16i8imm:$src2),
437 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
438 [(set GR32:$dst, (X86pextrw (v4i16 VR64:$src1),
439 (iPTR imm:$src2)))]>;
440 let Constraints = "$src1 = $dst" in {
441 def MMX_PINSRWrri : MMXIi8<0xC4, MRMSrcReg,
443 (ins VR64:$src1, GR32:$src2,i16i8imm:$src3),
444 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
445 [(set VR64:$dst, (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
446 GR32:$src2,(iPTR imm:$src3))))]>;
447 def MMX_PINSRWrmi : MMXIi8<0xC4, MRMSrcMem,
449 (ins VR64:$src1, i16mem:$src2, i16i8imm:$src3),
450 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
452 (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
453 (i32 (anyext (loadi16 addr:$src2))),
454 (iPTR imm:$src3))))]>;
457 // MMX to XMM for vector types
458 def MMX_X86movq2dq : SDNode<"X86ISD::MOVQ2DQ", SDTypeProfile<1, 1,
459 [SDTCisVT<0, v2i64>, SDTCisVT<1, v1i64>]>>;
461 def : Pat<(v2i64 (MMX_X86movq2dq VR64:$src)),
462 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
464 def : Pat<(v2i64 (MMX_X86movq2dq (load_mmx addr:$src))),
465 (v2i64 (MOVQI2PQIrm addr:$src))>;
467 def : Pat<(v2i64 (MMX_X86movq2dq (v1i64 (bitconvert
468 (v2i32 (scalar_to_vector (loadi32 addr:$src))))))),
469 (v2i64 (MOVDI2PDIrm addr:$src))>;
472 def MMX_PMOVMSKBrr : MMXI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR64:$src),
473 "pmovmskb\t{$src, $dst|$dst, $src}",
474 [(set GR32:$dst, (int_x86_mmx_pmovmskb VR64:$src))]>;
478 def MMX_MASKMOVQ : MMXI<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
479 "maskmovq\t{$mask, $src|$src, $mask}",
480 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, EDI)]>;
482 def MMX_MASKMOVQ64: MMXI64<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
483 "maskmovq\t{$mask, $src|$src, $mask}",
484 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, RDI)]>;
486 //===----------------------------------------------------------------------===//
487 // Alias Instructions
488 //===----------------------------------------------------------------------===//
490 // Alias instructions that map zero vector to pxor.
491 let isReMaterializable = 1, isCodeGenOnly = 1 in {
492 // FIXME: Change encoding to pseudo.
493 def MMX_V_SET0 : MMXI<0xEF, MRMInitReg, (outs VR64:$dst), (ins), "",
494 [(set VR64:$dst, (v2i32 immAllZerosV))]>;
495 def MMX_V_SETALLONES : MMXI<0x76, MRMInitReg, (outs VR64:$dst), (ins), "",
496 [(set VR64:$dst, (v2i32 immAllOnesV))]>;
499 let Predicates = [HasMMX] in {
500 def : Pat<(v1i64 immAllZerosV), (MMX_V_SET0)>;
501 def : Pat<(v4i16 immAllZerosV), (MMX_V_SET0)>;
502 def : Pat<(v8i8 immAllZerosV), (MMX_V_SET0)>;
505 //===----------------------------------------------------------------------===//
506 // Non-Instruction Patterns
507 //===----------------------------------------------------------------------===//
509 // Store 64-bit integer vector values.
510 def : Pat<(store (v8i8 VR64:$src), addr:$dst),
511 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
512 def : Pat<(store (v4i16 VR64:$src), addr:$dst),
513 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
514 def : Pat<(store (v2i32 VR64:$src), addr:$dst),
515 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
516 def : Pat<(store (v2f32 VR64:$src), addr:$dst),
517 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
518 def : Pat<(store (v1i64 VR64:$src), addr:$dst),
519 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
522 def : Pat<(v8i8 (bitconvert (v1i64 VR64:$src))), (v8i8 VR64:$src)>;
523 def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
524 def : Pat<(v8i8 (bitconvert (v2f32 VR64:$src))), (v8i8 VR64:$src)>;
525 def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
526 def : Pat<(v4i16 (bitconvert (v1i64 VR64:$src))), (v4i16 VR64:$src)>;
527 def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
528 def : Pat<(v4i16 (bitconvert (v2f32 VR64:$src))), (v4i16 VR64:$src)>;
529 def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
530 def : Pat<(v2i32 (bitconvert (v1i64 VR64:$src))), (v2i32 VR64:$src)>;
531 def : Pat<(v2i32 (bitconvert (v2f32 VR64:$src))), (v2i32 VR64:$src)>;
532 def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
533 def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;
534 def : Pat<(v2f32 (bitconvert (v1i64 VR64:$src))), (v2f32 VR64:$src)>;
535 def : Pat<(v2f32 (bitconvert (v2i32 VR64:$src))), (v2f32 VR64:$src)>;
536 def : Pat<(v2f32 (bitconvert (v4i16 VR64:$src))), (v2f32 VR64:$src)>;
537 def : Pat<(v2f32 (bitconvert (v8i8 VR64:$src))), (v2f32 VR64:$src)>;
538 def : Pat<(v1i64 (bitconvert (v2i32 VR64:$src))), (v1i64 VR64:$src)>;
539 def : Pat<(v1i64 (bitconvert (v2f32 VR64:$src))), (v1i64 VR64:$src)>;
540 def : Pat<(v1i64 (bitconvert (v4i16 VR64:$src))), (v1i64 VR64:$src)>;
541 def : Pat<(v1i64 (bitconvert (v8i8 VR64:$src))), (v1i64 VR64:$src)>;
543 // 64-bit bit convert.
544 def : Pat<(v1i64 (bitconvert (i64 GR64:$src))),
545 (MMX_MOVD64to64rr GR64:$src)>;
546 def : Pat<(v2i32 (bitconvert (i64 GR64:$src))),
547 (MMX_MOVD64to64rr GR64:$src)>;
548 def : Pat<(v2f32 (bitconvert (i64 GR64:$src))),
549 (MMX_MOVD64to64rr GR64:$src)>;
550 def : Pat<(v4i16 (bitconvert (i64 GR64:$src))),
551 (MMX_MOVD64to64rr GR64:$src)>;
552 def : Pat<(v8i8 (bitconvert (i64 GR64:$src))),
553 (MMX_MOVD64to64rr GR64:$src)>;
554 def : Pat<(i64 (bitconvert (v1i64 VR64:$src))),
555 (MMX_MOVD64from64rr VR64:$src)>;
556 def : Pat<(i64 (bitconvert (v2i32 VR64:$src))),
557 (MMX_MOVD64from64rr VR64:$src)>;
558 def : Pat<(i64 (bitconvert (v2f32 VR64:$src))),
559 (MMX_MOVD64from64rr VR64:$src)>;
560 def : Pat<(i64 (bitconvert (v4i16 VR64:$src))),
561 (MMX_MOVD64from64rr VR64:$src)>;
562 def : Pat<(i64 (bitconvert (v8i8 VR64:$src))),
563 (MMX_MOVD64from64rr VR64:$src)>;
564 def : Pat<(f64 (bitconvert (v1i64 VR64:$src))),
565 (MMX_MOVQ2FR64rr VR64:$src)>;
566 def : Pat<(f64 (bitconvert (v2i32 VR64:$src))),
567 (MMX_MOVQ2FR64rr VR64:$src)>;
568 def : Pat<(f64 (bitconvert (v4i16 VR64:$src))),
569 (MMX_MOVQ2FR64rr VR64:$src)>;
570 def : Pat<(f64 (bitconvert (v8i8 VR64:$src))),
571 (MMX_MOVQ2FR64rr VR64:$src)>;
573 let AddedComplexity = 20 in {
574 def : Pat<(v2i32 (X86vzmovl (bc_v2i32 (load_mmx addr:$src)))),
575 (MMX_MOVZDI2PDIrm addr:$src)>;
579 let AddedComplexity = 15 in {
580 def : Pat<(v2i32 (X86vzmovl VR64:$src)),
581 (MMX_PUNPCKLDQrr VR64:$src, (v2i32 (MMX_V_SET0)))>;
584 // Patterns to perform canonical versions of vector shuffling.
585 let AddedComplexity = 10 in {
586 def : Pat<(v8i8 (mmx_unpckl_undef VR64:$src, (undef))),
587 (MMX_PUNPCKLBWrr VR64:$src, VR64:$src)>;
588 def : Pat<(v4i16 (mmx_unpckl_undef VR64:$src, (undef))),
589 (MMX_PUNPCKLWDrr VR64:$src, VR64:$src)>;
590 def : Pat<(v2i32 (mmx_unpckl_undef VR64:$src, (undef))),
591 (MMX_PUNPCKLDQrr VR64:$src, VR64:$src)>;
594 let AddedComplexity = 10 in {
595 def : Pat<(v8i8 (mmx_unpckh_undef VR64:$src, (undef))),
596 (MMX_PUNPCKHBWrr VR64:$src, VR64:$src)>;
597 def : Pat<(v4i16 (mmx_unpckh_undef VR64:$src, (undef))),
598 (MMX_PUNPCKHWDrr VR64:$src, VR64:$src)>;
599 def : Pat<(v2i32 (mmx_unpckh_undef VR64:$src, (undef))),
600 (MMX_PUNPCKHDQrr VR64:$src, VR64:$src)>;
603 // Some special case PANDN patterns.
604 // FIXME: Get rid of these.
605 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
607 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
608 def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
610 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
612 // Move MMX to lower 64-bit of XMM
613 def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v8i8 VR64:$src))))),
614 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
615 def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v4i16 VR64:$src))))),
616 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
617 def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v2i32 VR64:$src))))),
618 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
619 def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v1i64 VR64:$src))))),
620 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
622 // Move lower 64-bit of XMM to MMX.
623 def : Pat<(v2i32 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
625 (v2i32 (MMX_MOVDQ2Qrr VR128:$src))>;
626 def : Pat<(v4i16 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
628 (v4i16 (MMX_MOVDQ2Qrr VR128:$src))>;
629 def : Pat<(v8i8 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
631 (v8i8 (MMX_MOVDQ2Qrr VR128:$src))>;
633 // Patterns for vector comparisons
634 def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, VR64:$src2)),
635 (MMX_PCMPEQBrr VR64:$src1, VR64:$src2)>;
636 def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
637 (MMX_PCMPEQBrm VR64:$src1, addr:$src2)>;
638 def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, VR64:$src2)),
639 (MMX_PCMPEQWrr VR64:$src1, VR64:$src2)>;
640 def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
641 (MMX_PCMPEQWrm VR64:$src1, addr:$src2)>;
642 def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, VR64:$src2)),
643 (MMX_PCMPEQDrr VR64:$src1, VR64:$src2)>;
644 def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
645 (MMX_PCMPEQDrm VR64:$src1, addr:$src2)>;
647 def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, VR64:$src2)),
648 (MMX_PCMPGTBrr VR64:$src1, VR64:$src2)>;
649 def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
650 (MMX_PCMPGTBrm VR64:$src1, addr:$src2)>;
651 def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, VR64:$src2)),
652 (MMX_PCMPGTWrr VR64:$src1, VR64:$src2)>;
653 def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
654 (MMX_PCMPGTWrm VR64:$src1, addr:$src2)>;
655 def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, VR64:$src2)),
656 (MMX_PCMPGTDrr VR64:$src1, VR64:$src2)>;
657 def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
658 (MMX_PCMPGTDrm VR64:$src1, addr:$src2)>;
660 // CMOV* - Used to implement the SELECT DAG operation. Expanded after
661 // instruction selection into a branch sequence.
662 let Uses = [EFLAGS], usesCustomInserter = 1 in {
663 def CMOV_V1I64 : I<0, Pseudo,
664 (outs VR64:$dst), (ins VR64:$t, VR64:$f, i8imm:$cond),
665 "#CMOV_V1I64 PSEUDO!",
667 (v1i64 (X86cmov VR64:$t, VR64:$f, imm:$cond,