blob: 3e84df07c3d03abee73cd6a64933ef01729a8dd4 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//====- X86InstrMMX.td - Describe the X86 Instruction Set --*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the X86 MMX 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016//===----------------------------------------------------------------------===//
17// MMX Pattern Fragments
18//===----------------------------------------------------------------------===//
19
20def load_mmx : PatFrag<(ops node:$ptr), (v1i64 (load node:$ptr))>;
21
22def bc_v8i8 : PatFrag<(ops node:$in), (v8i8 (bitconvert node:$in))>;
23def bc_v4i16 : PatFrag<(ops node:$in), (v4i16 (bitconvert node:$in))>;
24def bc_v2i32 : PatFrag<(ops node:$in), (v2i32 (bitconvert node:$in))>;
25def bc_v1i64 : PatFrag<(ops node:$in), (v1i64 (bitconvert node:$in))>;
26
27//===----------------------------------------------------------------------===//
28// MMX Masks
29//===----------------------------------------------------------------------===//
30
31// MMX_SHUFFLE_get_shuf_imm xform function: convert vector_shuffle mask to
32// PSHUFW imm.
Nate Begeman543d2142009-04-27 18:41:29 +000033def MMX_SHUFFLE_get_shuf_imm : SDNodeXForm<vector_shuffle, [{
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034 return getI8Imm(X86::getShuffleSHUFImmediate(N));
35}]>;
36
37// Patterns for: vector_shuffle v1, v2, <2, 6, 3, 7, ...>
Nate Begeman543d2142009-04-27 18:41:29 +000038def mmx_unpckh : PatFrag<(ops node:$lhs, node:$rhs),
39 (vector_shuffle node:$lhs, node:$rhs), [{
40 return X86::isUNPCKHMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041}]>;
42
43// Patterns for: vector_shuffle v1, v2, <0, 4, 2, 5, ...>
Nate Begeman543d2142009-04-27 18:41:29 +000044def mmx_unpckl : PatFrag<(ops node:$lhs, node:$rhs),
45 (vector_shuffle node:$lhs, node:$rhs), [{
46 return X86::isUNPCKLMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047}]>;
48
49// Patterns for: vector_shuffle v1, <undef>, <0, 0, 1, 1, ...>
Nate Begeman543d2142009-04-27 18:41:29 +000050def mmx_unpckh_undef : PatFrag<(ops node:$lhs, node:$rhs),
51 (vector_shuffle node:$lhs, node:$rhs), [{
52 return X86::isUNPCKH_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053}]>;
54
55// Patterns for: vector_shuffle v1, <undef>, <2, 2, 3, 3, ...>
Nate Begeman543d2142009-04-27 18:41:29 +000056def mmx_unpckl_undef : PatFrag<(ops node:$lhs, node:$rhs),
57 (vector_shuffle node:$lhs, node:$rhs), [{
58 return X86::isUNPCKL_v_undef_Mask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059}]>;
60
Nate Begeman543d2142009-04-27 18:41:29 +000061def mmx_pshufw : PatFrag<(ops node:$lhs, node:$rhs),
62 (vector_shuffle node:$lhs, node:$rhs), [{
63 return X86::isPSHUFDMask(cast<ShuffleVectorSDNode>(N));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064}], MMX_SHUFFLE_get_shuf_imm>;
65
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066//===----------------------------------------------------------------------===//
67// MMX Multiclasses
68//===----------------------------------------------------------------------===//
69
70let isTwoAddress = 1 in {
71 // MMXI_binop_rm - Simple MMX binary operator.
72 multiclass MMXI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
73 ValueType OpVT, bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +000074 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000075 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076 [(set VR64:$dst, (OpVT (OpNode VR64:$src1, VR64:$src2)))]> {
77 let isCommutable = Commutable;
78 }
Evan Chengb783fa32007-07-19 01:14:50 +000079 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000080 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081 [(set VR64:$dst, (OpVT (OpNode VR64:$src1,
82 (bitconvert
83 (load_mmx addr:$src2)))))]>;
84 }
85
86 multiclass MMXI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
87 bit Commutable = 0> {
Evan Chengb783fa32007-07-19 01:14:50 +000088 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000089 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]> {
91 let isCommutable = Commutable;
92 }
Evan Chengb783fa32007-07-19 01:14:50 +000093 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000094 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095 [(set VR64:$dst, (IntId VR64:$src1,
96 (bitconvert (load_mmx addr:$src2))))]>;
97 }
98
99 // MMXI_binop_rm_v1i64 - Simple MMX binary operator whose type is v1i64.
100 //
101 // FIXME: we could eliminate this and use MMXI_binop_rm instead if tblgen knew
102 // to collapse (bitconvert VT to VT) into its operand.
103 //
104 multiclass MMXI_binop_rm_v1i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
105 bit Commutable = 0> {
Evan Cheng7fcccab2008-03-21 00:40:09 +0000106 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
107 (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000108 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 [(set VR64:$dst, (v1i64 (OpNode VR64:$src1, VR64:$src2)))]> {
110 let isCommutable = Commutable;
111 }
Evan Cheng7fcccab2008-03-21 00:40:09 +0000112 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
113 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000114 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115 [(set VR64:$dst,
116 (OpNode VR64:$src1,(load_mmx addr:$src2)))]>;
117 }
118
119 multiclass MMXI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
Evan Chengf90f8f82008-05-03 00:52:09 +0000120 string OpcodeStr, Intrinsic IntId,
121 Intrinsic IntId2> {
Evan Cheng7fcccab2008-03-21 00:40:09 +0000122 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
123 (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000124 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000125 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]>;
Evan Cheng7fcccab2008-03-21 00:40:09 +0000126 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
127 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000128 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129 [(set VR64:$dst, (IntId VR64:$src1,
130 (bitconvert (load_mmx addr:$src2))))]>;
Evan Cheng7fcccab2008-03-21 00:40:09 +0000131 def ri : MMXIi8<opc2, ImmForm, (outs VR64:$dst),
132 (ins VR64:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000133 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengf90f8f82008-05-03 00:52:09 +0000134 [(set VR64:$dst, (IntId2 VR64:$src1, (i32 imm:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135 }
136}
137
138//===----------------------------------------------------------------------===//
139// MMX EMMS & FEMMS Instructions
140//===----------------------------------------------------------------------===//
141
Evan Chengb783fa32007-07-19 01:14:50 +0000142def MMX_EMMS : MMXI<0x77, RawFrm, (outs), (ins), "emms", [(int_x86_mmx_emms)]>;
143def MMX_FEMMS : MMXI<0x0E, RawFrm, (outs), (ins), "femms", [(int_x86_mmx_femms)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000144
145//===----------------------------------------------------------------------===//
146// MMX Scalar Instructions
147//===----------------------------------------------------------------------===//
148
149// Data Transfer Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000150def MMX_MOVD64rr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
Evan Chengd1045a62008-02-18 23:04:32 +0000151 "movd\t{$src, $dst|$dst, $src}",
152 [(set VR64:$dst, (v2i32 (scalar_to_vector GR32:$src)))]>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000153let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000154def MMX_MOVD64rm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst), (ins i32mem:$src),
Evan Chengd1045a62008-02-18 23:04:32 +0000155 "movd\t{$src, $dst|$dst, $src}",
156 [(set VR64:$dst, (v2i32 (scalar_to_vector (loadi32 addr:$src))))]>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000157let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000158def MMX_MOVD64mr : MMXI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000159 "movd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000161let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000162def MMX_MOVD64to64rr : MMXRI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
Evan Chengef356282009-02-23 09:03:22 +0000163 "movd\t{$src, $dst|$dst, $src}",
164 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000165
Evan Chengcd6d09d2009-08-03 18:07:19 +0000166let neverHasSideEffects = 1 in
Rafael Espindola97b78282009-08-03 05:21:05 +0000167// These are 64 bit moves, but since the OS X assembler doesn't
168// recognize a register-register movq, we write them as
169// movd.
Rafael Espindolac1fcb8c2009-08-03 03:27:05 +0000170def MMX_MOVD64from64rr : MMXRI<0x7E, MRMDestReg,
Evan Chengef356282009-02-23 09:03:22 +0000171 (outs GR64:$dst), (ins VR64:$src),
Rafael Espindola97b78282009-08-03 05:21:05 +0000172 "movd\t{$src, $dst|$dst, $src}", []>;
Rafael Espindolac1fcb8c2009-08-03 03:27:05 +0000173def MMX_MOVD64rrv164 : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
Rafael Espindola97b78282009-08-03 05:21:05 +0000174 "movd\t{$src, $dst|$dst, $src}",
Rafael Espindolafe2a3972009-08-03 02:45:34 +0000175 [(set VR64:$dst, (v1i64 (scalar_to_vector GR64:$src)))]>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000176
177let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000178def MMX_MOVQ64rr : MMXI<0x6F, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000179 "movq\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000180let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000181def MMX_MOVQ64rm : MMXI<0x6F, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000182 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000183 [(set VR64:$dst, (load_mmx addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000184def MMX_MOVQ64mr : MMXI<0x7F, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000185 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 [(store (v1i64 VR64:$src), addr:$dst)]>;
187
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000188def MMX_MOVDQ2Qrr : SDIi8<0xD6, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000189 "movdq2q\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190 [(set VR64:$dst,
Evan Cheng1428f582008-04-25 20:12:46 +0000191 (v1i64 (bitconvert
192 (i64 (vector_extract (v2i64 VR128:$src),
193 (iPTR 0))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000195def MMX_MOVQ2DQrr : SSDIi8<0xD6, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Bill Wendling64fe3dd2008-08-27 21:32:04 +0000196 "movq2dq\t{$src, $dst|$dst, $src}",
Evan Cheng5e4d1e72008-04-25 18:19:54 +0000197 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000198 (movl immAllZerosV,
199 (v2i64 (scalar_to_vector (i64 (bitconvert VR64:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000200
Evan Chengef356282009-02-23 09:03:22 +0000201let neverHasSideEffects = 1 in
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000202def MMX_MOVQ2FR64rr: SSDIi8<0xD6, MRMSrcReg, (outs FR64:$dst), (ins VR64:$src),
Evan Chengef356282009-02-23 09:03:22 +0000203 "movq2dq\t{$src, $dst|$dst, $src}", []>;
204
Evan Chengb783fa32007-07-19 01:14:50 +0000205def MMX_MOVNTQmr : MMXI<0xE7, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000206 "movntq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207 [(int_x86_mmx_movnt_dq addr:$dst, VR64:$src)]>;
208
209let AddedComplexity = 15 in
210// movd to MMX register zero-extends
Anders Carlssona31d51a2008-02-29 01:35:12 +0000211def MMX_MOVZDI2PDIrr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000212 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000213 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000214 (v2i32 (X86vzmovl (v2i32 (scalar_to_vector GR32:$src)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215let AddedComplexity = 20 in
Anders Carlssona31d51a2008-02-29 01:35:12 +0000216def MMX_MOVZDI2PDIrm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000217 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000218 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000219 (v2i32 (X86vzmovl (v2i32
Evan Cheng40ee6e52008-05-08 00:57:18 +0000220 (scalar_to_vector (loadi32 addr:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
222// Arithmetic Instructions
223
224// -- Addition
225defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
226defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
227defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
228defm MMX_PADDQ : MMXI_binop_rm<0xD4, "paddq", add, v1i64, 1>;
229
230defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
231defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
232
233defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
234defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
235
236// -- Subtraction
237defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
238defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
239defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
240defm MMX_PSUBQ : MMXI_binop_rm<0xFB, "psubq", sub, v1i64>;
241
242defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
243defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
244
245defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
246defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
247
248// -- Multiplication
249defm MMX_PMULLW : MMXI_binop_rm<0xD5, "pmullw", mul, v4i16, 1>;
250
251defm MMX_PMULHW : MMXI_binop_rm_int<0xE5, "pmulhw", int_x86_mmx_pmulh_w, 1>;
252defm MMX_PMULHUW : MMXI_binop_rm_int<0xE4, "pmulhuw", int_x86_mmx_pmulhu_w, 1>;
253defm MMX_PMULUDQ : MMXI_binop_rm_int<0xF4, "pmuludq", int_x86_mmx_pmulu_dq, 1>;
254
255// -- Miscellanea
256defm MMX_PMADDWD : MMXI_binop_rm_int<0xF5, "pmaddwd", int_x86_mmx_pmadd_wd, 1>;
257
258defm MMX_PAVGB : MMXI_binop_rm_int<0xE0, "pavgb", int_x86_mmx_pavg_b, 1>;
259defm MMX_PAVGW : MMXI_binop_rm_int<0xE3, "pavgw", int_x86_mmx_pavg_w, 1>;
260
261defm MMX_PMINUB : MMXI_binop_rm_int<0xDA, "pminub", int_x86_mmx_pminu_b, 1>;
262defm MMX_PMINSW : MMXI_binop_rm_int<0xEA, "pminsw", int_x86_mmx_pmins_w, 1>;
263
264defm MMX_PMAXUB : MMXI_binop_rm_int<0xDE, "pmaxub", int_x86_mmx_pmaxu_b, 1>;
265defm MMX_PMAXSW : MMXI_binop_rm_int<0xEE, "pmaxsw", int_x86_mmx_pmaxs_w, 1>;
266
Bill Wendling953ad2e2009-05-28 02:04:00 +0000267defm MMX_PSADBW : MMXI_binop_rm_int<0xF6, "psadbw", int_x86_mmx_psad_bw, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268
269// Logical Instructions
270defm MMX_PAND : MMXI_binop_rm_v1i64<0xDB, "pand", and, 1>;
271defm MMX_POR : MMXI_binop_rm_v1i64<0xEB, "por" , or, 1>;
272defm MMX_PXOR : MMXI_binop_rm_v1i64<0xEF, "pxor", xor, 1>;
273
274let isTwoAddress = 1 in {
275 def MMX_PANDNrr : MMXI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000276 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000277 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
279 VR64:$src2)))]>;
280 def MMX_PANDNrm : MMXI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000281 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000282 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000283 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
284 (load addr:$src2))))]>;
285}
286
287// Shift Instructions
288defm MMX_PSRLW : MMXI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000289 int_x86_mmx_psrl_w, int_x86_mmx_psrli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290defm MMX_PSRLD : MMXI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000291 int_x86_mmx_psrl_d, int_x86_mmx_psrli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292defm MMX_PSRLQ : MMXI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000293 int_x86_mmx_psrl_q, int_x86_mmx_psrli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294
295defm MMX_PSLLW : MMXI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000296 int_x86_mmx_psll_w, int_x86_mmx_pslli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297defm MMX_PSLLD : MMXI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000298 int_x86_mmx_psll_d, int_x86_mmx_pslli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299defm MMX_PSLLQ : MMXI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000300 int_x86_mmx_psll_q, int_x86_mmx_pslli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
302defm MMX_PSRAW : MMXI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000303 int_x86_mmx_psra_w, int_x86_mmx_psrai_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304defm MMX_PSRAD : MMXI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Chengf90f8f82008-05-03 00:52:09 +0000305 int_x86_mmx_psra_d, int_x86_mmx_psrai_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306
Evan Chengdea99362008-05-29 08:22:04 +0000307// Shift up / down and insert zero's.
308def : Pat<(v1i64 (X86vshl VR64:$src, (i8 imm:$amt))),
309 (v1i64 (MMX_PSLLQri VR64:$src, imm:$amt))>;
310def : Pat<(v1i64 (X86vshr VR64:$src, (i8 imm:$amt))),
311 (v1i64 (MMX_PSRLQri VR64:$src, imm:$amt))>;
312
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313// Comparison Instructions
314defm MMX_PCMPEQB : MMXI_binop_rm_int<0x74, "pcmpeqb", int_x86_mmx_pcmpeq_b>;
315defm MMX_PCMPEQW : MMXI_binop_rm_int<0x75, "pcmpeqw", int_x86_mmx_pcmpeq_w>;
316defm MMX_PCMPEQD : MMXI_binop_rm_int<0x76, "pcmpeqd", int_x86_mmx_pcmpeq_d>;
317
318defm MMX_PCMPGTB : MMXI_binop_rm_int<0x64, "pcmpgtb", int_x86_mmx_pcmpgt_b>;
319defm MMX_PCMPGTW : MMXI_binop_rm_int<0x65, "pcmpgtw", int_x86_mmx_pcmpgt_w>;
320defm MMX_PCMPGTD : MMXI_binop_rm_int<0x66, "pcmpgtd", int_x86_mmx_pcmpgt_d>;
321
322// Conversion Instructions
323
324// -- Unpack Instructions
325let isTwoAddress = 1 in {
326 // Unpack High Packed Data Instructions
327 def MMX_PUNPCKHBWrr : MMXI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000328 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000329 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000331 (v8i8 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 def MMX_PUNPCKHBWrm : MMXI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000333 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000334 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000336 (v8i8 (mmx_unpckh VR64:$src1,
337 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338
339 def MMX_PUNPCKHWDrr : MMXI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000340 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000341 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000343 (v4i16 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000344 def MMX_PUNPCKHWDrm : MMXI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000345 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000346 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000348 (v4i16 (mmx_unpckh VR64:$src1,
349 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350
351 def MMX_PUNPCKHDQrr : MMXI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000352 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000353 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000355 (v2i32 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 def MMX_PUNPCKHDQrm : MMXI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000357 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000358 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000360 (v2i32 (mmx_unpckh VR64:$src1,
361 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362
363 // Unpack Low Packed Data Instructions
364 def MMX_PUNPCKLBWrr : MMXI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000365 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000366 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000367 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000368 (v8i8 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 def MMX_PUNPCKLBWrm : MMXI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000370 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000371 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000373 (v8i8 (mmx_unpckl VR64:$src1,
374 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375
376 def MMX_PUNPCKLWDrr : MMXI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000377 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000378 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000380 (v4i16 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 def MMX_PUNPCKLWDrm : MMXI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000382 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000383 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000385 (v4i16 (mmx_unpckl VR64:$src1,
386 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387
388 def MMX_PUNPCKLDQrr : MMXI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000389 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000390 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000392 (v2i32 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 def MMX_PUNPCKLDQrm : MMXI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000394 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000395 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000397 (v2i32 (mmx_unpckl VR64:$src1,
398 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399}
400
401// -- Pack Instructions
402defm MMX_PACKSSWB : MMXI_binop_rm_int<0x63, "packsswb", int_x86_mmx_packsswb>;
403defm MMX_PACKSSDW : MMXI_binop_rm_int<0x6B, "packssdw", int_x86_mmx_packssdw>;
404defm MMX_PACKUSWB : MMXI_binop_rm_int<0x67, "packuswb", int_x86_mmx_packuswb>;
405
406// -- Shuffle Instructions
407def MMX_PSHUFWri : MMXIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000408 (outs VR64:$dst), (ins VR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000409 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000411 (v4i16 (mmx_pshufw:$src2 VR64:$src1, (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000412def MMX_PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000413 (outs VR64:$dst), (ins i64mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000414 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000416 (mmx_pshufw:$src2 (bc_v4i16 (load_mmx addr:$src1)),
417 (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418
419// -- Conversion Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000420let neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000421def MMX_CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000422 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000423let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000424def MMX_CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000425 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426
Evan Chengb783fa32007-07-19 01:14:50 +0000427def MMX_CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000428 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000429let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000430def MMX_CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000431 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432
Evan Chengb783fa32007-07-19 01:14:50 +0000433def MMX_CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000434 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000435let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000436def MMX_CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000437 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438
Evan Chengb783fa32007-07-19 01:14:50 +0000439def MMX_CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000440 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000441let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000442def MMX_CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444
Evan Chengb783fa32007-07-19 01:14:50 +0000445def MMX_CVTTPD2PIrr : MMX2I<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000447let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000448def MMX_CVTTPD2PIrm : MMX2I<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000449 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450
Evan Chengb783fa32007-07-19 01:14:50 +0000451def MMX_CVTTPS2PIrr : MMXI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000452 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000453let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000454def MMX_CVTTPS2PIrm : MMXI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000455 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000456} // end neverHasSideEffects
457
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458
459// Extract / Insert
460def MMX_X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
461def MMX_X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
462
463def MMX_PEXTRWri : MMXIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000464 (outs GR32:$dst), (ins VR64:$src1, i16i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000465 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466 [(set GR32:$dst, (MMX_X86pextrw (v4i16 VR64:$src1),
467 (iPTR imm:$src2)))]>;
468let isTwoAddress = 1 in {
469 def MMX_PINSRWrri : MMXIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000470 (outs VR64:$dst), (ins VR64:$src1, GR32:$src2, i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000471 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472 [(set VR64:$dst, (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
473 GR32:$src2, (iPTR imm:$src3))))]>;
474 def MMX_PINSRWrmi : MMXIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000475 (outs VR64:$dst), (ins VR64:$src1, i16mem:$src2, i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000476 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 [(set VR64:$dst,
478 (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
479 (i32 (anyext (loadi16 addr:$src2))),
480 (iPTR imm:$src3))))]>;
481}
482
483// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000484def MMX_PMOVMSKBrr : MMXI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000485 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 [(set GR32:$dst, (int_x86_mmx_pmovmskb VR64:$src))]>;
487
488// Misc.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000489let Uses = [EDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000490def MMX_MASKMOVQ : MMXI<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +0000491 "maskmovq\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000492 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, EDI)]>;
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000493let Uses = [RDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000494def MMX_MASKMOVQ64: MMXI64<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000495 "maskmovq\t{$mask, $src|$src, $mask}",
496 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, RDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497
498//===----------------------------------------------------------------------===//
499// Alias Instructions
500//===----------------------------------------------------------------------===//
501
502// Alias instructions that map zero vector to pxor.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000503let isReMaterializable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000504 def MMX_V_SET0 : MMXI<0xEF, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000505 "pxor\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000506 [(set VR64:$dst, (v2i32 immAllZerosV))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000507 def MMX_V_SETALLONES : MMXI<0x76, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000508 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000509 [(set VR64:$dst, (v2i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000510}
511
Evan Chenga15896e2008-03-12 07:02:50 +0000512let Predicates = [HasMMX] in {
513 def : Pat<(v1i64 immAllZerosV), (MMX_V_SET0)>;
514 def : Pat<(v4i16 immAllZerosV), (MMX_V_SET0)>;
515 def : Pat<(v8i8 immAllZerosV), (MMX_V_SET0)>;
516}
517
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518//===----------------------------------------------------------------------===//
519// Non-Instruction Patterns
520//===----------------------------------------------------------------------===//
521
522// Store 64-bit integer vector values.
523def : Pat<(store (v8i8 VR64:$src), addr:$dst),
524 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
525def : Pat<(store (v4i16 VR64:$src), addr:$dst),
526 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
527def : Pat<(store (v2i32 VR64:$src), addr:$dst),
528 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000529def : Pat<(store (v2f32 VR64:$src), addr:$dst),
530 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531def : Pat<(store (v1i64 VR64:$src), addr:$dst),
532 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
533
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534// Bit convert.
535def : Pat<(v8i8 (bitconvert (v1i64 VR64:$src))), (v8i8 VR64:$src)>;
536def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000537def : Pat<(v8i8 (bitconvert (v2f32 VR64:$src))), (v8i8 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000538def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
539def : Pat<(v4i16 (bitconvert (v1i64 VR64:$src))), (v4i16 VR64:$src)>;
540def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000541def : Pat<(v4i16 (bitconvert (v2f32 VR64:$src))), (v4i16 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
543def : Pat<(v2i32 (bitconvert (v1i64 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000544def : Pat<(v2i32 (bitconvert (v2f32 VR64:$src))), (v2i32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
546def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000547def : Pat<(v2f32 (bitconvert (v1i64 VR64:$src))), (v2f32 VR64:$src)>;
548def : Pat<(v2f32 (bitconvert (v2i32 VR64:$src))), (v2f32 VR64:$src)>;
549def : Pat<(v2f32 (bitconvert (v4i16 VR64:$src))), (v2f32 VR64:$src)>;
550def : Pat<(v2f32 (bitconvert (v8i8 VR64:$src))), (v2f32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551def : Pat<(v1i64 (bitconvert (v2i32 VR64:$src))), (v1i64 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000552def : Pat<(v1i64 (bitconvert (v2f32 VR64:$src))), (v1i64 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553def : Pat<(v1i64 (bitconvert (v4i16 VR64:$src))), (v1i64 VR64:$src)>;
554def : Pat<(v1i64 (bitconvert (v8i8 VR64:$src))), (v1i64 VR64:$src)>;
555
556// 64-bit bit convert.
557def : Pat<(v1i64 (bitconvert (i64 GR64:$src))),
558 (MMX_MOVD64to64rr GR64:$src)>;
559def : Pat<(v2i32 (bitconvert (i64 GR64:$src))),
560 (MMX_MOVD64to64rr GR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000561def : Pat<(v2f32 (bitconvert (i64 GR64:$src))),
562 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563def : Pat<(v4i16 (bitconvert (i64 GR64:$src))),
564 (MMX_MOVD64to64rr GR64:$src)>;
565def : Pat<(v8i8 (bitconvert (i64 GR64:$src))),
566 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000567def : Pat<(i64 (bitconvert (v1i64 VR64:$src))),
568 (MMX_MOVD64from64rr VR64:$src)>;
569def : Pat<(i64 (bitconvert (v2i32 VR64:$src))),
570 (MMX_MOVD64from64rr VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000571def : Pat<(i64 (bitconvert (v2f32 VR64:$src))),
572 (MMX_MOVD64from64rr VR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000573def : Pat<(i64 (bitconvert (v4i16 VR64:$src))),
574 (MMX_MOVD64from64rr VR64:$src)>;
575def : Pat<(i64 (bitconvert (v8i8 VR64:$src))),
576 (MMX_MOVD64from64rr VR64:$src)>;
Evan Chengef356282009-02-23 09:03:22 +0000577def : Pat<(f64 (bitconvert (v1i64 VR64:$src))),
578 (MMX_MOVQ2FR64rr VR64:$src)>;
579def : Pat<(f64 (bitconvert (v2i32 VR64:$src))),
580 (MMX_MOVQ2FR64rr VR64:$src)>;
581def : Pat<(f64 (bitconvert (v4i16 VR64:$src))),
582 (MMX_MOVQ2FR64rr VR64:$src)>;
583def : Pat<(f64 (bitconvert (v8i8 VR64:$src))),
584 (MMX_MOVQ2FR64rr VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585
Evan Cheng778641e2008-11-05 06:04:51 +0000586let AddedComplexity = 20 in {
Evan Cheng778641e2008-11-05 06:04:51 +0000587 def : Pat<(v2i32 (X86vzmovl (bc_v2i32 (load_mmx addr:$src)))),
Evan Chengb76ecc82008-12-03 19:38:05 +0000588 (MMX_MOVZDI2PDIrm addr:$src)>;
589}
590
591// Clear top half.
592let AddedComplexity = 15 in {
Evan Chengb76ecc82008-12-03 19:38:05 +0000593 def : Pat<(v2i32 (X86vzmovl VR64:$src)),
594 (MMX_PUNPCKLDQrr VR64:$src, (MMX_V_SET0))>;
Evan Cheng778641e2008-11-05 06:04:51 +0000595}
596
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597// Patterns to perform canonical versions of vector shuffling.
598let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000599 def : Pat<(v8i8 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600 (MMX_PUNPCKLBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000601 def : Pat<(v4i16 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602 (MMX_PUNPCKLWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000603 def : Pat<(v2i32 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604 (MMX_PUNPCKLDQrr VR64:$src, VR64:$src)>;
605}
606
607let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000608 def : Pat<(v8i8 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 (MMX_PUNPCKHBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000610 def : Pat<(v4i16 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 (MMX_PUNPCKHWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000612 def : Pat<(v2i32 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613 (MMX_PUNPCKHDQrr VR64:$src, VR64:$src)>;
614}
615
616// Patterns to perform vector shuffling with a zeroed out vector.
617let AddedComplexity = 20 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000618 def : Pat<(bc_v2i32 (mmx_unpckl immAllZerosV,
619 (v2i32 (scalar_to_vector (load_mmx addr:$src))))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 (MMX_PUNPCKLDQrm VR64:$src, VR64:$src)>;
621}
622
623// Some special case PANDN patterns.
624// FIXME: Get rid of these.
625def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
626 VR64:$src2)),
627 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000628def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 VR64:$src2)),
630 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000631def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 VR64:$src2)),
633 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
634
635def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
636 (load addr:$src2))),
637 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000638def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 (load addr:$src2))),
640 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000641def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642 (load addr:$src2))),
643 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Evan Cheng2aea0b42008-04-25 19:11:04 +0000644
645// Move MMX to lower 64-bit of XMM
Evan Chengef356282009-02-23 09:03:22 +0000646def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v8i8 VR64:$src))))),
647 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
648def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v4i16 VR64:$src))))),
649 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
650def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v2i32 VR64:$src))))),
651 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
652def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v1i64 VR64:$src))))),
Evan Cheng2aea0b42008-04-25 19:11:04 +0000653 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
Evan Cheng1428f582008-04-25 20:12:46 +0000654
655// Move lower 64-bit of XMM to MMX.
656def : Pat<(v2i32 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
657 (iPTR 0))))),
658 (v2i32 (MMX_MOVDQ2Qrr VR128:$src))>;
659def : Pat<(v4i16 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
660 (iPTR 0))))),
661 (v4i16 (MMX_MOVDQ2Qrr VR128:$src))>;
662def : Pat<(v8i8 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
663 (iPTR 0))))),
664 (v8i8 (MMX_MOVDQ2Qrr VR128:$src))>;
665
Eli Friedman7dab4932009-07-22 01:06:52 +0000666// Patterns for vector comparisons
667def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, VR64:$src2)),
668 (MMX_PCMPEQBrr VR64:$src1, VR64:$src2)>;
669def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
670 (MMX_PCMPEQBrm VR64:$src1, addr:$src2)>;
671def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, VR64:$src2)),
672 (MMX_PCMPEQWrr VR64:$src1, VR64:$src2)>;
673def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
674 (MMX_PCMPEQWrm VR64:$src1, addr:$src2)>;
675def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, VR64:$src2)),
676 (MMX_PCMPEQDrr VR64:$src1, VR64:$src2)>;
677def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
678 (MMX_PCMPEQDrm VR64:$src1, addr:$src2)>;
679
680def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, VR64:$src2)),
681 (MMX_PCMPGTBrr VR64:$src1, VR64:$src2)>;
682def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
683 (MMX_PCMPGTBrm VR64:$src1, addr:$src2)>;
684def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, VR64:$src2)),
685 (MMX_PCMPGTWrr VR64:$src1, VR64:$src2)>;
686def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
687 (MMX_PCMPGTWrm VR64:$src1, addr:$src2)>;
688def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, VR64:$src2)),
689 (MMX_PCMPGTDrr VR64:$src1, VR64:$src2)>;
690def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
691 (MMX_PCMPGTDrm VR64:$src1, addr:$src2)>;
692
Mon P Wang83edba52008-12-12 01:25:51 +0000693// CMOV* - Used to implement the SELECT DAG operation. Expanded by the
694// scheduler into a branch sequence.
695// These are expanded by the scheduler.
696let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
697 def CMOV_V1I64 : I<0, Pseudo,
698 (outs VR64:$dst), (ins VR64:$t, VR64:$f, i8imm:$cond),
699 "#CMOV_V1I64 PSEUDO!",
700 [(set VR64:$dst,
701 (v1i64 (X86cmov VR64:$t, VR64:$f, imm:$cond,
702 EFLAGS)))]>;
703}