blob: e9a8f582dd02b3517700f45531f10fbca4e2d406 [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
Rafael Espindolafe2a3972009-08-03 02:45:34 +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)))]>;
176}
Dan Gohman4535ae32008-04-15 23:55:07 +0000177
178let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000179def MMX_MOVQ64rr : MMXI<0x6F, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000180 "movq\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000181let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000182def MMX_MOVQ64rm : MMXI<0x6F, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000183 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 [(set VR64:$dst, (load_mmx addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000185def MMX_MOVQ64mr : MMXI<0x7F, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000186 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 [(store (v1i64 VR64:$src), addr:$dst)]>;
188
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000189def MMX_MOVDQ2Qrr : SDIi8<0xD6, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000190 "movdq2q\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191 [(set VR64:$dst,
Evan Cheng1428f582008-04-25 20:12:46 +0000192 (v1i64 (bitconvert
193 (i64 (vector_extract (v2i64 VR128:$src),
194 (iPTR 0))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000196def MMX_MOVQ2DQrr : SSDIi8<0xD6, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Bill Wendling64fe3dd2008-08-27 21:32:04 +0000197 "movq2dq\t{$src, $dst|$dst, $src}",
Evan Cheng5e4d1e72008-04-25 18:19:54 +0000198 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000199 (movl immAllZerosV,
200 (v2i64 (scalar_to_vector (i64 (bitconvert VR64:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201
Evan Chengef356282009-02-23 09:03:22 +0000202let neverHasSideEffects = 1 in
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000203def MMX_MOVQ2FR64rr: SSDIi8<0xD6, MRMSrcReg, (outs FR64:$dst), (ins VR64:$src),
Evan Chengef356282009-02-23 09:03:22 +0000204 "movq2dq\t{$src, $dst|$dst, $src}", []>;
205
Evan Chengb783fa32007-07-19 01:14:50 +0000206def MMX_MOVNTQmr : MMXI<0xE7, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000207 "movntq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208 [(int_x86_mmx_movnt_dq addr:$dst, VR64:$src)]>;
209
210let AddedComplexity = 15 in
211// movd to MMX register zero-extends
Anders Carlssona31d51a2008-02-29 01:35:12 +0000212def MMX_MOVZDI2PDIrr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000213 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000214 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000215 (v2i32 (X86vzmovl (v2i32 (scalar_to_vector GR32:$src)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216let AddedComplexity = 20 in
Anders Carlssona31d51a2008-02-29 01:35:12 +0000217def MMX_MOVZDI2PDIrm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst), (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000218 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000219 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000220 (v2i32 (X86vzmovl (v2i32
Evan Cheng40ee6e52008-05-08 00:57:18 +0000221 (scalar_to_vector (loadi32 addr:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222
223// Arithmetic Instructions
224
225// -- Addition
226defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
227defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
228defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
229defm MMX_PADDQ : MMXI_binop_rm<0xD4, "paddq", add, v1i64, 1>;
230
231defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
232defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
233
234defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
235defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
236
237// -- Subtraction
238defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
239defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
240defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
241defm MMX_PSUBQ : MMXI_binop_rm<0xFB, "psubq", sub, v1i64>;
242
243defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
244defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
245
246defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
247defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
248
249// -- Multiplication
250defm MMX_PMULLW : MMXI_binop_rm<0xD5, "pmullw", mul, v4i16, 1>;
251
252defm MMX_PMULHW : MMXI_binop_rm_int<0xE5, "pmulhw", int_x86_mmx_pmulh_w, 1>;
253defm MMX_PMULHUW : MMXI_binop_rm_int<0xE4, "pmulhuw", int_x86_mmx_pmulhu_w, 1>;
254defm MMX_PMULUDQ : MMXI_binop_rm_int<0xF4, "pmuludq", int_x86_mmx_pmulu_dq, 1>;
255
256// -- Miscellanea
257defm MMX_PMADDWD : MMXI_binop_rm_int<0xF5, "pmaddwd", int_x86_mmx_pmadd_wd, 1>;
258
259defm MMX_PAVGB : MMXI_binop_rm_int<0xE0, "pavgb", int_x86_mmx_pavg_b, 1>;
260defm MMX_PAVGW : MMXI_binop_rm_int<0xE3, "pavgw", int_x86_mmx_pavg_w, 1>;
261
262defm MMX_PMINUB : MMXI_binop_rm_int<0xDA, "pminub", int_x86_mmx_pminu_b, 1>;
263defm MMX_PMINSW : MMXI_binop_rm_int<0xEA, "pminsw", int_x86_mmx_pmins_w, 1>;
264
265defm MMX_PMAXUB : MMXI_binop_rm_int<0xDE, "pmaxub", int_x86_mmx_pmaxu_b, 1>;
266defm MMX_PMAXSW : MMXI_binop_rm_int<0xEE, "pmaxsw", int_x86_mmx_pmaxs_w, 1>;
267
Bill Wendling953ad2e2009-05-28 02:04:00 +0000268defm MMX_PSADBW : MMXI_binop_rm_int<0xF6, "psadbw", int_x86_mmx_psad_bw, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269
270// Logical Instructions
271defm MMX_PAND : MMXI_binop_rm_v1i64<0xDB, "pand", and, 1>;
272defm MMX_POR : MMXI_binop_rm_v1i64<0xEB, "por" , or, 1>;
273defm MMX_PXOR : MMXI_binop_rm_v1i64<0xEF, "pxor", xor, 1>;
274
275let isTwoAddress = 1 in {
276 def MMX_PANDNrr : MMXI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000277 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000278 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
280 VR64:$src2)))]>;
281 def MMX_PANDNrm : MMXI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000282 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000283 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
285 (load addr:$src2))))]>;
286}
287
288// Shift Instructions
289defm MMX_PSRLW : MMXI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000290 int_x86_mmx_psrl_w, int_x86_mmx_psrli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291defm MMX_PSRLD : MMXI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000292 int_x86_mmx_psrl_d, int_x86_mmx_psrli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293defm MMX_PSRLQ : MMXI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000294 int_x86_mmx_psrl_q, int_x86_mmx_psrli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295
296defm MMX_PSLLW : MMXI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000297 int_x86_mmx_psll_w, int_x86_mmx_pslli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298defm MMX_PSLLD : MMXI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000299 int_x86_mmx_psll_d, int_x86_mmx_pslli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300defm MMX_PSLLQ : MMXI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000301 int_x86_mmx_psll_q, int_x86_mmx_pslli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302
303defm MMX_PSRAW : MMXI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000304 int_x86_mmx_psra_w, int_x86_mmx_psrai_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305defm MMX_PSRAD : MMXI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Chengf90f8f82008-05-03 00:52:09 +0000306 int_x86_mmx_psra_d, int_x86_mmx_psrai_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307
Evan Chengdea99362008-05-29 08:22:04 +0000308// Shift up / down and insert zero's.
309def : Pat<(v1i64 (X86vshl VR64:$src, (i8 imm:$amt))),
310 (v1i64 (MMX_PSLLQri VR64:$src, imm:$amt))>;
311def : Pat<(v1i64 (X86vshr VR64:$src, (i8 imm:$amt))),
312 (v1i64 (MMX_PSRLQri VR64:$src, imm:$amt))>;
313
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314// Comparison Instructions
315defm MMX_PCMPEQB : MMXI_binop_rm_int<0x74, "pcmpeqb", int_x86_mmx_pcmpeq_b>;
316defm MMX_PCMPEQW : MMXI_binop_rm_int<0x75, "pcmpeqw", int_x86_mmx_pcmpeq_w>;
317defm MMX_PCMPEQD : MMXI_binop_rm_int<0x76, "pcmpeqd", int_x86_mmx_pcmpeq_d>;
318
319defm MMX_PCMPGTB : MMXI_binop_rm_int<0x64, "pcmpgtb", int_x86_mmx_pcmpgt_b>;
320defm MMX_PCMPGTW : MMXI_binop_rm_int<0x65, "pcmpgtw", int_x86_mmx_pcmpgt_w>;
321defm MMX_PCMPGTD : MMXI_binop_rm_int<0x66, "pcmpgtd", int_x86_mmx_pcmpgt_d>;
322
323// Conversion Instructions
324
325// -- Unpack Instructions
326let isTwoAddress = 1 in {
327 // Unpack High Packed Data Instructions
328 def MMX_PUNPCKHBWrr : MMXI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000329 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000330 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000332 (v8i8 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333 def MMX_PUNPCKHBWrm : MMXI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000334 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000335 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000337 (v8i8 (mmx_unpckh VR64:$src1,
338 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339
340 def MMX_PUNPCKHWDrr : MMXI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000341 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000342 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000344 (v4i16 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 def MMX_PUNPCKHWDrm : MMXI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000346 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000347 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000349 (v4i16 (mmx_unpckh VR64:$src1,
350 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351
352 def MMX_PUNPCKHDQrr : MMXI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000353 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000354 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000356 (v2i32 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 def MMX_PUNPCKHDQrm : MMXI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000358 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000359 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000361 (v2i32 (mmx_unpckh VR64:$src1,
362 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363
364 // Unpack Low Packed Data Instructions
365 def MMX_PUNPCKLBWrr : MMXI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000366 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000367 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000369 (v8i8 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370 def MMX_PUNPCKLBWrm : MMXI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000371 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000372 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000374 (v8i8 (mmx_unpckl VR64:$src1,
375 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000376
377 def MMX_PUNPCKLWDrr : MMXI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000378 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000379 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000381 (v4i16 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 def MMX_PUNPCKLWDrm : MMXI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000383 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000384 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000386 (v4i16 (mmx_unpckl VR64:$src1,
387 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388
389 def MMX_PUNPCKLDQrr : MMXI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000390 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000391 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000393 (v2i32 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 def MMX_PUNPCKLDQrm : MMXI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000395 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000396 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000398 (v2i32 (mmx_unpckl VR64:$src1,
399 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400}
401
402// -- Pack Instructions
403defm MMX_PACKSSWB : MMXI_binop_rm_int<0x63, "packsswb", int_x86_mmx_packsswb>;
404defm MMX_PACKSSDW : MMXI_binop_rm_int<0x6B, "packssdw", int_x86_mmx_packssdw>;
405defm MMX_PACKUSWB : MMXI_binop_rm_int<0x67, "packuswb", int_x86_mmx_packuswb>;
406
407// -- Shuffle Instructions
408def MMX_PSHUFWri : MMXIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000409 (outs VR64:$dst), (ins VR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000410 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000412 (v4i16 (mmx_pshufw:$src2 VR64:$src1, (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413def MMX_PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000414 (outs VR64:$dst), (ins i64mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000415 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000417 (mmx_pshufw:$src2 (bc_v4i16 (load_mmx addr:$src1)),
418 (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419
420// -- Conversion Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000421let neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000422def MMX_CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000423 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000424let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000425def MMX_CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000426 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427
Evan Chengb783fa32007-07-19 01:14:50 +0000428def MMX_CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000429 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000430let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000431def MMX_CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000432 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433
Evan Chengb783fa32007-07-19 01:14:50 +0000434def MMX_CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000435 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000436let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000437def MMX_CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (outs VR128:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000438 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439
Evan Chengb783fa32007-07-19 01:14:50 +0000440def MMX_CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000441 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000442let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000443def MMX_CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000444 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445
Evan Chengb783fa32007-07-19 01:14:50 +0000446def MMX_CVTTPD2PIrr : MMX2I<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000447 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000448let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000449def MMX_CVTTPD2PIrm : MMX2I<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000450 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451
Evan Chengb783fa32007-07-19 01:14:50 +0000452def MMX_CVTTPS2PIrr : MMXI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000453 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000454let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000455def MMX_CVTTPS2PIrm : MMXI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000457} // end neverHasSideEffects
458
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459
460// Extract / Insert
461def MMX_X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
462def MMX_X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
463
464def MMX_PEXTRWri : MMXIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000465 (outs GR32:$dst), (ins VR64:$src1, i16i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000466 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467 [(set GR32:$dst, (MMX_X86pextrw (v4i16 VR64:$src1),
468 (iPTR imm:$src2)))]>;
469let isTwoAddress = 1 in {
470 def MMX_PINSRWrri : MMXIi8<0xC4, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000471 (outs VR64:$dst), (ins VR64:$src1, GR32:$src2, i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000472 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 [(set VR64:$dst, (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
474 GR32:$src2, (iPTR imm:$src3))))]>;
475 def MMX_PINSRWrmi : MMXIi8<0xC4, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000476 (outs VR64:$dst), (ins VR64:$src1, i16mem:$src2, i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000477 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478 [(set VR64:$dst,
479 (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
480 (i32 (anyext (loadi16 addr:$src2))),
481 (iPTR imm:$src3))))]>;
482}
483
484// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000485def MMX_PMOVMSKBrr : MMXI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 [(set GR32:$dst, (int_x86_mmx_pmovmskb VR64:$src))]>;
488
489// Misc.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000490let Uses = [EDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000491def MMX_MASKMOVQ : MMXI<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +0000492 "maskmovq\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000493 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, EDI)]>;
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000494let Uses = [RDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000495def MMX_MASKMOVQ64: MMXI64<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000496 "maskmovq\t{$mask, $src|$src, $mask}",
497 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, RDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
499//===----------------------------------------------------------------------===//
500// Alias Instructions
501//===----------------------------------------------------------------------===//
502
503// Alias instructions that map zero vector to pxor.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000504let isReMaterializable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000505 def MMX_V_SET0 : MMXI<0xEF, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000506 "pxor\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000507 [(set VR64:$dst, (v2i32 immAllZerosV))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000508 def MMX_V_SETALLONES : MMXI<0x76, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000509 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000510 [(set VR64:$dst, (v2i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511}
512
Evan Chenga15896e2008-03-12 07:02:50 +0000513let Predicates = [HasMMX] in {
514 def : Pat<(v1i64 immAllZerosV), (MMX_V_SET0)>;
515 def : Pat<(v4i16 immAllZerosV), (MMX_V_SET0)>;
516 def : Pat<(v8i8 immAllZerosV), (MMX_V_SET0)>;
517}
518
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519//===----------------------------------------------------------------------===//
520// Non-Instruction Patterns
521//===----------------------------------------------------------------------===//
522
523// Store 64-bit integer vector values.
524def : Pat<(store (v8i8 VR64:$src), addr:$dst),
525 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
526def : Pat<(store (v4i16 VR64:$src), addr:$dst),
527 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
528def : Pat<(store (v2i32 VR64:$src), addr:$dst),
529 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000530def : Pat<(store (v2f32 VR64:$src), addr:$dst),
531 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532def : Pat<(store (v1i64 VR64:$src), addr:$dst),
533 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
534
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535// Bit convert.
536def : Pat<(v8i8 (bitconvert (v1i64 VR64:$src))), (v8i8 VR64:$src)>;
537def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000538def : Pat<(v8i8 (bitconvert (v2f32 VR64:$src))), (v8i8 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
540def : Pat<(v4i16 (bitconvert (v1i64 VR64:$src))), (v4i16 VR64:$src)>;
541def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000542def : Pat<(v4i16 (bitconvert (v2f32 VR64:$src))), (v4i16 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
544def : Pat<(v2i32 (bitconvert (v1i64 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000545def : Pat<(v2i32 (bitconvert (v2f32 VR64:$src))), (v2i32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
547def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000548def : Pat<(v2f32 (bitconvert (v1i64 VR64:$src))), (v2f32 VR64:$src)>;
549def : Pat<(v2f32 (bitconvert (v2i32 VR64:$src))), (v2f32 VR64:$src)>;
550def : Pat<(v2f32 (bitconvert (v4i16 VR64:$src))), (v2f32 VR64:$src)>;
551def : Pat<(v2f32 (bitconvert (v8i8 VR64:$src))), (v2f32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552def : Pat<(v1i64 (bitconvert (v2i32 VR64:$src))), (v1i64 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000553def : Pat<(v1i64 (bitconvert (v2f32 VR64:$src))), (v1i64 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554def : Pat<(v1i64 (bitconvert (v4i16 VR64:$src))), (v1i64 VR64:$src)>;
555def : Pat<(v1i64 (bitconvert (v8i8 VR64:$src))), (v1i64 VR64:$src)>;
556
557// 64-bit bit convert.
558def : Pat<(v1i64 (bitconvert (i64 GR64:$src))),
559 (MMX_MOVD64to64rr GR64:$src)>;
560def : Pat<(v2i32 (bitconvert (i64 GR64:$src))),
561 (MMX_MOVD64to64rr GR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000562def : Pat<(v2f32 (bitconvert (i64 GR64:$src))),
563 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564def : Pat<(v4i16 (bitconvert (i64 GR64:$src))),
565 (MMX_MOVD64to64rr GR64:$src)>;
566def : Pat<(v8i8 (bitconvert (i64 GR64:$src))),
567 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000568def : Pat<(i64 (bitconvert (v1i64 VR64:$src))),
569 (MMX_MOVD64from64rr VR64:$src)>;
570def : Pat<(i64 (bitconvert (v2i32 VR64:$src))),
571 (MMX_MOVD64from64rr VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000572def : Pat<(i64 (bitconvert (v2f32 VR64:$src))),
573 (MMX_MOVD64from64rr VR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000574def : Pat<(i64 (bitconvert (v4i16 VR64:$src))),
575 (MMX_MOVD64from64rr VR64:$src)>;
576def : Pat<(i64 (bitconvert (v8i8 VR64:$src))),
577 (MMX_MOVD64from64rr VR64:$src)>;
Evan Chengef356282009-02-23 09:03:22 +0000578def : Pat<(f64 (bitconvert (v1i64 VR64:$src))),
579 (MMX_MOVQ2FR64rr VR64:$src)>;
580def : Pat<(f64 (bitconvert (v2i32 VR64:$src))),
581 (MMX_MOVQ2FR64rr VR64:$src)>;
582def : Pat<(f64 (bitconvert (v4i16 VR64:$src))),
583 (MMX_MOVQ2FR64rr VR64:$src)>;
584def : Pat<(f64 (bitconvert (v8i8 VR64:$src))),
585 (MMX_MOVQ2FR64rr VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586
Evan Cheng778641e2008-11-05 06:04:51 +0000587let AddedComplexity = 20 in {
Evan Cheng778641e2008-11-05 06:04:51 +0000588 def : Pat<(v2i32 (X86vzmovl (bc_v2i32 (load_mmx addr:$src)))),
Evan Chengb76ecc82008-12-03 19:38:05 +0000589 (MMX_MOVZDI2PDIrm addr:$src)>;
590}
591
592// Clear top half.
593let AddedComplexity = 15 in {
Evan Chengb76ecc82008-12-03 19:38:05 +0000594 def : Pat<(v2i32 (X86vzmovl VR64:$src)),
595 (MMX_PUNPCKLDQrr VR64:$src, (MMX_V_SET0))>;
Evan Cheng778641e2008-11-05 06:04:51 +0000596}
597
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598// Patterns to perform canonical versions of vector shuffling.
599let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000600 def : Pat<(v8i8 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 (MMX_PUNPCKLBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000602 def : Pat<(v4i16 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000603 (MMX_PUNPCKLWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000604 def : Pat<(v2i32 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605 (MMX_PUNPCKLDQrr VR64:$src, VR64:$src)>;
606}
607
608let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000609 def : Pat<(v8i8 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610 (MMX_PUNPCKHBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000611 def : Pat<(v4i16 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 (MMX_PUNPCKHWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000613 def : Pat<(v2i32 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 (MMX_PUNPCKHDQrr VR64:$src, VR64:$src)>;
615}
616
617// Patterns to perform vector shuffling with a zeroed out vector.
618let AddedComplexity = 20 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000619 def : Pat<(bc_v2i32 (mmx_unpckl immAllZerosV,
620 (v2i32 (scalar_to_vector (load_mmx addr:$src))))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621 (MMX_PUNPCKLDQrm VR64:$src, VR64:$src)>;
622}
623
624// Some special case PANDN patterns.
625// FIXME: Get rid of these.
626def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
627 VR64:$src2)),
628 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000629def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630 VR64:$src2)),
631 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000632def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633 VR64:$src2)),
634 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
635
636def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
637 (load addr:$src2))),
638 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000639def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640 (load addr:$src2))),
641 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000642def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 (load addr:$src2))),
644 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Evan Cheng2aea0b42008-04-25 19:11:04 +0000645
646// Move MMX to lower 64-bit of XMM
Evan Chengef356282009-02-23 09:03:22 +0000647def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v8i8 VR64:$src))))),
648 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
649def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v4i16 VR64:$src))))),
650 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
651def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v2i32 VR64:$src))))),
652 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
653def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v1i64 VR64:$src))))),
Evan Cheng2aea0b42008-04-25 19:11:04 +0000654 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
Evan Cheng1428f582008-04-25 20:12:46 +0000655
656// Move lower 64-bit of XMM to MMX.
657def : Pat<(v2i32 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
658 (iPTR 0))))),
659 (v2i32 (MMX_MOVDQ2Qrr VR128:$src))>;
660def : Pat<(v4i16 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
661 (iPTR 0))))),
662 (v4i16 (MMX_MOVDQ2Qrr VR128:$src))>;
663def : Pat<(v8i8 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
664 (iPTR 0))))),
665 (v8i8 (MMX_MOVDQ2Qrr VR128:$src))>;
666
Eli Friedman7dab4932009-07-22 01:06:52 +0000667// Patterns for vector comparisons
668def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, VR64:$src2)),
669 (MMX_PCMPEQBrr VR64:$src1, VR64:$src2)>;
670def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
671 (MMX_PCMPEQBrm VR64:$src1, addr:$src2)>;
672def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, VR64:$src2)),
673 (MMX_PCMPEQWrr VR64:$src1, VR64:$src2)>;
674def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
675 (MMX_PCMPEQWrm VR64:$src1, addr:$src2)>;
676def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, VR64:$src2)),
677 (MMX_PCMPEQDrr VR64:$src1, VR64:$src2)>;
678def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
679 (MMX_PCMPEQDrm VR64:$src1, addr:$src2)>;
680
681def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, VR64:$src2)),
682 (MMX_PCMPGTBrr VR64:$src1, VR64:$src2)>;
683def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
684 (MMX_PCMPGTBrm VR64:$src1, addr:$src2)>;
685def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, VR64:$src2)),
686 (MMX_PCMPGTWrr VR64:$src1, VR64:$src2)>;
687def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
688 (MMX_PCMPGTWrm VR64:$src1, addr:$src2)>;
689def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, VR64:$src2)),
690 (MMX_PCMPGTDrr VR64:$src1, VR64:$src2)>;
691def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
692 (MMX_PCMPGTDrm VR64:$src1, addr:$src2)>;
693
Mon P Wang83edba52008-12-12 01:25:51 +0000694// CMOV* - Used to implement the SELECT DAG operation. Expanded by the
695// scheduler into a branch sequence.
696// These are expanded by the scheduler.
697let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
698 def CMOV_V1I64 : I<0, Pseudo,
699 (outs VR64:$dst), (ins VR64:$t, VR64:$f, i8imm:$cond),
700 "#CMOV_V1I64 PSEUDO!",
701 [(set VR64:$dst,
702 (v1i64 (X86cmov VR64:$t, VR64:$f, imm:$cond,
703 EFLAGS)))]>;
704}