blob: dfdf700e4662f79ae9740e63cbfc95c4078a854b [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//====- X86InstrMMX.td - Describe the X86 Instruction Set --*- tablegen -*-===//
Eric Christopher74c525e2009-08-10 22:37:37 +00002//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003// 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.
Eric Christopher74c525e2009-08-10 22:37:37 +00007//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00008//===----------------------------------------------------------------------===//
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
Eric Christopher74c525e2009-08-10 22:37:37 +000070let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071 // 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> {
Eric Christopher74c525e2009-08-10 22:37:37 +000074 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
75 (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000076 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 [(set VR64:$dst, (OpVT (OpNode VR64:$src1, VR64:$src2)))]> {
78 let isCommutable = Commutable;
79 }
Eric Christopher74c525e2009-08-10 22:37:37 +000080 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
81 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000082 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000083 [(set VR64:$dst, (OpVT (OpNode VR64:$src1,
84 (bitconvert
85 (load_mmx addr:$src2)))))]>;
86 }
87
88 multiclass MMXI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
89 bit Commutable = 0> {
Eric Christopher74c525e2009-08-10 22:37:37 +000090 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
91 (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000092 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000093 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]> {
94 let isCommutable = Commutable;
95 }
Eric Christopher74c525e2009-08-10 22:37:37 +000096 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
97 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +000098 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099 [(set VR64:$dst, (IntId VR64:$src1,
100 (bitconvert (load_mmx addr:$src2))))]>;
101 }
102
103 // MMXI_binop_rm_v1i64 - Simple MMX binary operator whose type is v1i64.
104 //
105 // FIXME: we could eliminate this and use MMXI_binop_rm instead if tblgen knew
106 // to collapse (bitconvert VT to VT) into its operand.
107 //
108 multiclass MMXI_binop_rm_v1i64<bits<8> opc, string OpcodeStr, SDNode OpNode,
109 bit Commutable = 0> {
Evan Cheng7fcccab2008-03-21 00:40:09 +0000110 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
111 (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000112 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000113 [(set VR64:$dst, (v1i64 (OpNode VR64:$src1, VR64:$src2)))]> {
114 let isCommutable = Commutable;
115 }
Evan Cheng7fcccab2008-03-21 00:40:09 +0000116 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
117 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000118 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119 [(set VR64:$dst,
120 (OpNode VR64:$src1,(load_mmx addr:$src2)))]>;
121 }
122
123 multiclass MMXI_binop_rmi_int<bits<8> opc, bits<8> opc2, Format ImmForm,
Evan Chengf90f8f82008-05-03 00:52:09 +0000124 string OpcodeStr, Intrinsic IntId,
125 Intrinsic IntId2> {
Evan Cheng7fcccab2008-03-21 00:40:09 +0000126 def rr : MMXI<opc, MRMSrcReg, (outs VR64:$dst),
127 (ins VR64:$src1, VR64:$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, VR64:$src2))]>;
Evan Cheng7fcccab2008-03-21 00:40:09 +0000130 def rm : MMXI<opc, MRMSrcMem, (outs VR64:$dst),
131 (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000132 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 [(set VR64:$dst, (IntId VR64:$src1,
134 (bitconvert (load_mmx addr:$src2))))]>;
Evan Cheng7fcccab2008-03-21 00:40:09 +0000135 def ri : MMXIi8<opc2, ImmForm, (outs VR64:$dst),
136 (ins VR64:$src1, i32i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000137 !strconcat(OpcodeStr, "\t{$src2, $dst|$dst, $src2}"),
Evan Chengf90f8f82008-05-03 00:52:09 +0000138 [(set VR64:$dst, (IntId2 VR64:$src1, (i32 imm:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139 }
140}
141
142//===----------------------------------------------------------------------===//
143// MMX EMMS & FEMMS Instructions
144//===----------------------------------------------------------------------===//
145
Eric Christopher74c525e2009-08-10 22:37:37 +0000146def MMX_EMMS : MMXI<0x77, RawFrm, (outs), (ins), "emms",
147 [(int_x86_mmx_emms)]>;
148def MMX_FEMMS : MMXI<0x0E, RawFrm, (outs), (ins), "femms",
149 [(int_x86_mmx_femms)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150
151//===----------------------------------------------------------------------===//
152// MMX Scalar Instructions
153//===----------------------------------------------------------------------===//
154
155// Data Transfer Instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000156def MMX_MOVD64rr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
Evan Chengd1045a62008-02-18 23:04:32 +0000157 "movd\t{$src, $dst|$dst, $src}",
Eric Christopher74c525e2009-08-10 22:37:37 +0000158 [(set VR64:$dst,
159 (v2i32 (scalar_to_vector GR32:$src)))]>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000160let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000161def MMX_MOVD64rm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst), (ins i32mem:$src),
Evan Chengd1045a62008-02-18 23:04:32 +0000162 "movd\t{$src, $dst|$dst, $src}",
Eric Christopher74c525e2009-08-10 22:37:37 +0000163 [(set VR64:$dst,
164 (v2i32 (scalar_to_vector (loadi32 addr:$src))))]>;
165let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000166def MMX_MOVD64mr : MMXI<0x7E, MRMDestMem, (outs), (ins i32mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000167 "movd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000169let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000170def MMX_MOVD64to64rr : MMXRI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
Evan Chengef356282009-02-23 09:03:22 +0000171 "movd\t{$src, $dst|$dst, $src}",
172 []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173
Evan Chengcd6d09d2009-08-03 18:07:19 +0000174let neverHasSideEffects = 1 in
Rafael Espindola97b78282009-08-03 05:21:05 +0000175// These are 64 bit moves, but since the OS X assembler doesn't
176// recognize a register-register movq, we write them as
177// movd.
Rafael Espindolac1fcb8c2009-08-03 03:27:05 +0000178def MMX_MOVD64from64rr : MMXRI<0x7E, MRMDestReg,
Evan Chengef356282009-02-23 09:03:22 +0000179 (outs GR64:$dst), (ins VR64:$src),
Rafael Espindola97b78282009-08-03 05:21:05 +0000180 "movd\t{$src, $dst|$dst, $src}", []>;
Rafael Espindolac1fcb8c2009-08-03 03:27:05 +0000181def MMX_MOVD64rrv164 : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR64:$src),
Rafael Espindola97b78282009-08-03 05:21:05 +0000182 "movd\t{$src, $dst|$dst, $src}",
Eric Christopher74c525e2009-08-10 22:37:37 +0000183 [(set VR64:$dst,
184 (v1i64 (scalar_to_vector GR64:$src)))]>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000185
186let neverHasSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000187def MMX_MOVQ64rr : MMXI<0x6F, MRMSrcReg, (outs VR64:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000188 "movq\t{$src, $dst|$dst, $src}", []>;
Dan Gohman5574cc72008-12-03 18:15:48 +0000189let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000190def MMX_MOVQ64rm : MMXI<0x6F, MRMSrcMem, (outs VR64:$dst), (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000191 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 [(set VR64:$dst, (load_mmx addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000193def MMX_MOVQ64mr : MMXI<0x7F, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000194 "movq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195 [(store (v1i64 VR64:$src), addr:$dst)]>;
196
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000197def MMX_MOVDQ2Qrr : SDIi8<0xD6, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000198 "movdq2q\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199 [(set VR64:$dst,
Evan Cheng1428f582008-04-25 20:12:46 +0000200 (v1i64 (bitconvert
201 (i64 (vector_extract (v2i64 VR128:$src),
202 (iPTR 0))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000204def MMX_MOVQ2DQrr : SSDIi8<0xD6, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Bill Wendling64fe3dd2008-08-27 21:32:04 +0000205 "movq2dq\t{$src, $dst|$dst, $src}",
Evan Cheng5e4d1e72008-04-25 18:19:54 +0000206 [(set VR128:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000207 (movl immAllZerosV,
208 (v2i64 (scalar_to_vector (i64 (bitconvert VR64:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209
Evan Chengef356282009-02-23 09:03:22 +0000210let neverHasSideEffects = 1 in
Eli Friedman6ff96fc2009-07-09 16:49:25 +0000211def MMX_MOVQ2FR64rr: SSDIi8<0xD6, MRMSrcReg, (outs FR64:$dst), (ins VR64:$src),
Evan Chengef356282009-02-23 09:03:22 +0000212 "movq2dq\t{$src, $dst|$dst, $src}", []>;
213
Evan Chengb783fa32007-07-19 01:14:50 +0000214def MMX_MOVNTQmr : MMXI<0xE7, MRMDestMem, (outs), (ins i64mem:$dst, VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000215 "movntq\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 [(int_x86_mmx_movnt_dq addr:$dst, VR64:$src)]>;
217
218let AddedComplexity = 15 in
219// movd to MMX register zero-extends
Anders Carlssona31d51a2008-02-29 01:35:12 +0000220def MMX_MOVZDI2PDIrr : MMXI<0x6E, MRMSrcReg, (outs VR64:$dst), (ins GR32:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000221 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000222 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000223 (v2i32 (X86vzmovl (v2i32 (scalar_to_vector GR32:$src)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224let AddedComplexity = 20 in
Eric Christopher74c525e2009-08-10 22:37:37 +0000225def MMX_MOVZDI2PDIrm : MMXI<0x6E, MRMSrcMem, (outs VR64:$dst),
226 (ins i32mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000227 "movd\t{$src, $dst|$dst, $src}",
Evan Cheng40ee6e52008-05-08 00:57:18 +0000228 [(set VR64:$dst,
Evan Chenge9b9c672008-05-09 21:53:03 +0000229 (v2i32 (X86vzmovl (v2i32
Evan Cheng40ee6e52008-05-08 00:57:18 +0000230 (scalar_to_vector (loadi32 addr:$src))))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231
232// Arithmetic Instructions
233
234// -- Addition
235defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
236defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
237defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
238defm MMX_PADDQ : MMXI_binop_rm<0xD4, "paddq", add, v1i64, 1>;
239
240defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
241defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
242
243defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
244defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
245
246// -- Subtraction
247defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
248defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
249defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
250defm MMX_PSUBQ : MMXI_binop_rm<0xFB, "psubq", sub, v1i64>;
251
252defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
253defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
254
255defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
256defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
257
258// -- Multiplication
259defm MMX_PMULLW : MMXI_binop_rm<0xD5, "pmullw", mul, v4i16, 1>;
260
261defm MMX_PMULHW : MMXI_binop_rm_int<0xE5, "pmulhw", int_x86_mmx_pmulh_w, 1>;
262defm MMX_PMULHUW : MMXI_binop_rm_int<0xE4, "pmulhuw", int_x86_mmx_pmulhu_w, 1>;
263defm MMX_PMULUDQ : MMXI_binop_rm_int<0xF4, "pmuludq", int_x86_mmx_pmulu_dq, 1>;
264
265// -- Miscellanea
266defm MMX_PMADDWD : MMXI_binop_rm_int<0xF5, "pmaddwd", int_x86_mmx_pmadd_wd, 1>;
267
268defm MMX_PAVGB : MMXI_binop_rm_int<0xE0, "pavgb", int_x86_mmx_pavg_b, 1>;
269defm MMX_PAVGW : MMXI_binop_rm_int<0xE3, "pavgw", int_x86_mmx_pavg_w, 1>;
270
271defm MMX_PMINUB : MMXI_binop_rm_int<0xDA, "pminub", int_x86_mmx_pminu_b, 1>;
272defm MMX_PMINSW : MMXI_binop_rm_int<0xEA, "pminsw", int_x86_mmx_pmins_w, 1>;
273
274defm MMX_PMAXUB : MMXI_binop_rm_int<0xDE, "pmaxub", int_x86_mmx_pmaxu_b, 1>;
275defm MMX_PMAXSW : MMXI_binop_rm_int<0xEE, "pmaxsw", int_x86_mmx_pmaxs_w, 1>;
276
Bill Wendling953ad2e2009-05-28 02:04:00 +0000277defm MMX_PSADBW : MMXI_binop_rm_int<0xF6, "psadbw", int_x86_mmx_psad_bw, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278
279// Logical Instructions
280defm MMX_PAND : MMXI_binop_rm_v1i64<0xDB, "pand", and, 1>;
281defm MMX_POR : MMXI_binop_rm_v1i64<0xEB, "por" , or, 1>;
282defm MMX_PXOR : MMXI_binop_rm_v1i64<0xEF, "pxor", xor, 1>;
283
Eric Christopher74c525e2009-08-10 22:37:37 +0000284let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 def MMX_PANDNrr : MMXI<0xDF, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000286 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000287 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
289 VR64:$src2)))]>;
290 def MMX_PANDNrm : MMXI<0xDF, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000291 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000292 "pandn\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000293 [(set VR64:$dst, (v1i64 (and (vnot VR64:$src1),
294 (load addr:$src2))))]>;
295}
296
297// Shift Instructions
298defm MMX_PSRLW : MMXI_binop_rmi_int<0xD1, 0x71, MRM2r, "psrlw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000299 int_x86_mmx_psrl_w, int_x86_mmx_psrli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300defm MMX_PSRLD : MMXI_binop_rmi_int<0xD2, 0x72, MRM2r, "psrld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000301 int_x86_mmx_psrl_d, int_x86_mmx_psrli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302defm MMX_PSRLQ : MMXI_binop_rmi_int<0xD3, 0x73, MRM2r, "psrlq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000303 int_x86_mmx_psrl_q, int_x86_mmx_psrli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304
305defm MMX_PSLLW : MMXI_binop_rmi_int<0xF1, 0x71, MRM6r, "psllw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000306 int_x86_mmx_psll_w, int_x86_mmx_pslli_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307defm MMX_PSLLD : MMXI_binop_rmi_int<0xF2, 0x72, MRM6r, "pslld",
Evan Chengf90f8f82008-05-03 00:52:09 +0000308 int_x86_mmx_psll_d, int_x86_mmx_pslli_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309defm MMX_PSLLQ : MMXI_binop_rmi_int<0xF3, 0x73, MRM6r, "psllq",
Evan Chengf90f8f82008-05-03 00:52:09 +0000310 int_x86_mmx_psll_q, int_x86_mmx_pslli_q>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311
312defm MMX_PSRAW : MMXI_binop_rmi_int<0xE1, 0x71, MRM4r, "psraw",
Evan Chengf90f8f82008-05-03 00:52:09 +0000313 int_x86_mmx_psra_w, int_x86_mmx_psrai_w>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314defm MMX_PSRAD : MMXI_binop_rmi_int<0xE2, 0x72, MRM4r, "psrad",
Evan Chengf90f8f82008-05-03 00:52:09 +0000315 int_x86_mmx_psra_d, int_x86_mmx_psrai_d>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316
Evan Chengdea99362008-05-29 08:22:04 +0000317// Shift up / down and insert zero's.
318def : Pat<(v1i64 (X86vshl VR64:$src, (i8 imm:$amt))),
319 (v1i64 (MMX_PSLLQri VR64:$src, imm:$amt))>;
320def : Pat<(v1i64 (X86vshr VR64:$src, (i8 imm:$amt))),
321 (v1i64 (MMX_PSRLQri VR64:$src, imm:$amt))>;
322
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323// Comparison Instructions
324defm MMX_PCMPEQB : MMXI_binop_rm_int<0x74, "pcmpeqb", int_x86_mmx_pcmpeq_b>;
325defm MMX_PCMPEQW : MMXI_binop_rm_int<0x75, "pcmpeqw", int_x86_mmx_pcmpeq_w>;
326defm MMX_PCMPEQD : MMXI_binop_rm_int<0x76, "pcmpeqd", int_x86_mmx_pcmpeq_d>;
327
328defm MMX_PCMPGTB : MMXI_binop_rm_int<0x64, "pcmpgtb", int_x86_mmx_pcmpgt_b>;
329defm MMX_PCMPGTW : MMXI_binop_rm_int<0x65, "pcmpgtw", int_x86_mmx_pcmpgt_w>;
330defm MMX_PCMPGTD : MMXI_binop_rm_int<0x66, "pcmpgtd", int_x86_mmx_pcmpgt_d>;
331
332// Conversion Instructions
333
334// -- Unpack Instructions
Eric Christopher74c525e2009-08-10 22:37:37 +0000335let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336 // Unpack High Packed Data Instructions
Eric Christopher74c525e2009-08-10 22:37:37 +0000337 def MMX_PUNPCKHBWrr : MMXI<0x68, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000338 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000339 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000341 (v8i8 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Eric Christopher74c525e2009-08-10 22:37:37 +0000342 def MMX_PUNPCKHBWrm : MMXI<0x68, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000343 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000344 "punpckhbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000346 (v8i8 (mmx_unpckh VR64:$src1,
347 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348
Eric Christopher74c525e2009-08-10 22:37:37 +0000349 def MMX_PUNPCKHWDrr : MMXI<0x69, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000350 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000351 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000353 (v4i16 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Eric Christopher74c525e2009-08-10 22:37:37 +0000354 def MMX_PUNPCKHWDrm : MMXI<0x69, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000355 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000356 "punpckhwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000358 (v4i16 (mmx_unpckh VR64:$src1,
359 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360
Eric Christopher74c525e2009-08-10 22:37:37 +0000361 def MMX_PUNPCKHDQrr : MMXI<0x6A, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000362 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000363 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000365 (v2i32 (mmx_unpckh VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 def MMX_PUNPCKHDQrm : MMXI<0x6A, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000367 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000368 "punpckhdq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000370 (v2i32 (mmx_unpckh VR64:$src1,
371 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372
373 // Unpack Low Packed Data Instructions
374 def MMX_PUNPCKLBWrr : MMXI<0x60, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000375 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000376 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000378 (v8i8 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379 def MMX_PUNPCKLBWrm : MMXI<0x60, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000380 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000381 "punpcklbw\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000383 (v8i8 (mmx_unpckl VR64:$src1,
384 (bc_v8i8 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
386 def MMX_PUNPCKLWDrr : MMXI<0x61, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000387 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000388 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000390 (v4i16 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391 def MMX_PUNPCKLWDrm : MMXI<0x61, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000392 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000393 "punpcklwd\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000395 (v4i16 (mmx_unpckl VR64:$src1,
396 (bc_v4i16 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397
Eric Christopher74c525e2009-08-10 22:37:37 +0000398 def MMX_PUNPCKLDQrr : MMXI<0x62, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000399 (outs VR64:$dst), (ins VR64:$src1, VR64:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000400 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000402 (v2i32 (mmx_unpckl VR64:$src1, VR64:$src2)))]>;
Eric Christopher74c525e2009-08-10 22:37:37 +0000403 def MMX_PUNPCKLDQrm : MMXI<0x62, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000404 (outs VR64:$dst), (ins VR64:$src1, i64mem:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000405 "punpckldq\t{$src2, $dst|$dst, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000407 (v2i32 (mmx_unpckl VR64:$src1,
408 (bc_v2i32 (load_mmx addr:$src2)))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409}
410
411// -- Pack Instructions
412defm MMX_PACKSSWB : MMXI_binop_rm_int<0x63, "packsswb", int_x86_mmx_packsswb>;
413defm MMX_PACKSSDW : MMXI_binop_rm_int<0x6B, "packssdw", int_x86_mmx_packssdw>;
414defm MMX_PACKUSWB : MMXI_binop_rm_int<0x67, "packuswb", int_x86_mmx_packuswb>;
415
416// -- Shuffle Instructions
417def MMX_PSHUFWri : MMXIi8<0x70, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000418 (outs VR64:$dst), (ins VR64:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000419 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000421 (v4i16 (mmx_pshufw:$src2 VR64:$src1, (undef))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422def MMX_PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
Evan Chengb783fa32007-07-19 01:14:50 +0000423 (outs VR64:$dst), (ins i64mem:$src1, i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000424 "pshufw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425 [(set VR64:$dst,
Nate Begeman543d2142009-04-27 18:41:29 +0000426 (mmx_pshufw:$src2 (bc_v4i16 (load_mmx addr:$src1)),
427 (undef)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428
429// -- Conversion Instructions
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000430let neverHasSideEffects = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000431def MMX_CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000432 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000433let mayLoad = 1 in
Eric Christopher74c525e2009-08-10 22:37:37 +0000434def MMX_CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (outs VR64:$dst),
435 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000436 "cvtpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437
Evan Chengb783fa32007-07-19 01:14:50 +0000438def MMX_CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000439 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000440let mayLoad = 1 in
Eric Christopher74c525e2009-08-10 22:37:37 +0000441def MMX_CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (outs VR128:$dst),
442 (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000443 "cvtpi2pd\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444
Evan Chengb783fa32007-07-19 01:14:50 +0000445def MMX_CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (outs VR128:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000446 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000447let mayLoad = 1 in
Eric Christopher74c525e2009-08-10 22:37:37 +0000448def MMX_CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (outs VR128:$dst),
449 (ins i64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000450 "cvtpi2ps\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451
Evan Chengb783fa32007-07-19 01:14:50 +0000452def MMX_CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000453 "cvtps2pi\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_CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000456 "cvtps2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457
Evan Chengb783fa32007-07-19 01:14:50 +0000458def MMX_CVTTPD2PIrr : MMX2I<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000459 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000460let mayLoad = 1 in
Eric Christopher74c525e2009-08-10 22:37:37 +0000461def MMX_CVTTPD2PIrm : MMX2I<0x2C, MRMSrcMem, (outs VR64:$dst),
462 (ins f128mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000463 "cvttpd2pi\t{$src, $dst|$dst, $src}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464
Evan Chengb783fa32007-07-19 01:14:50 +0000465def MMX_CVTTPS2PIrr : MMXI<0x2C, MRMSrcReg, (outs VR64:$dst), (ins VR128:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000466 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000467let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000468def MMX_CVTTPS2PIrm : MMXI<0x2C, MRMSrcMem, (outs VR64:$dst), (ins f64mem:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000469 "cvttps2pi\t{$src, $dst|$dst, $src}", []>;
Chris Lattnerc90ee9c2008-01-10 07:59:24 +0000470} // end neverHasSideEffects
471
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472
473// Extract / Insert
474def MMX_X86pextrw : SDNode<"X86ISD::PEXTRW", SDTypeProfile<1, 2, []>, []>;
475def MMX_X86pinsrw : SDNode<"X86ISD::PINSRW", SDTypeProfile<1, 3, []>, []>;
476
477def MMX_PEXTRWri : MMXIi8<0xC5, MRMSrcReg,
Evan Chengb783fa32007-07-19 01:14:50 +0000478 (outs GR32:$dst), (ins VR64:$src1, i16i8imm:$src2),
Dan Gohman91888f02007-07-31 20:11:57 +0000479 "pextrw\t{$src2, $src1, $dst|$dst, $src1, $src2}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480 [(set GR32:$dst, (MMX_X86pextrw (v4i16 VR64:$src1),
481 (iPTR imm:$src2)))]>;
Eric Christopher74c525e2009-08-10 22:37:37 +0000482let Constraints = "$src1 = $dst" in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483 def MMX_PINSRWrri : MMXIi8<0xC4, MRMSrcReg,
Eric Christopher74c525e2009-08-10 22:37:37 +0000484 (outs VR64:$dst), (ins VR64:$src1, GR32:$src2,
485 i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000486 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 [(set VR64:$dst, (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
Eric Christopher74c525e2009-08-10 22:37:37 +0000488 GR32:$src2,(iPTR imm:$src3))))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489 def MMX_PINSRWrmi : MMXIi8<0xC4, MRMSrcMem,
Eric Christopher74c525e2009-08-10 22:37:37 +0000490 (outs VR64:$dst), (ins VR64:$src1, i16mem:$src2,
491 i16i8imm:$src3),
Dan Gohman91888f02007-07-31 20:11:57 +0000492 "pinsrw\t{$src3, $src2, $dst|$dst, $src2, $src3}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493 [(set VR64:$dst,
494 (v4i16 (MMX_X86pinsrw (v4i16 VR64:$src1),
495 (i32 (anyext (loadi16 addr:$src2))),
496 (iPTR imm:$src3))))]>;
497}
498
499// Mask creation
Evan Chengb783fa32007-07-19 01:14:50 +0000500def MMX_PMOVMSKBrr : MMXI<0xD7, MRMSrcReg, (outs GR32:$dst), (ins VR64:$src),
Dan Gohman91888f02007-07-31 20:11:57 +0000501 "pmovmskb\t{$src, $dst|$dst, $src}",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 [(set GR32:$dst, (int_x86_mmx_pmovmskb VR64:$src))]>;
503
504// Misc.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000505let Uses = [EDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000506def MMX_MASKMOVQ : MMXI<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Dan Gohman91888f02007-07-31 20:11:57 +0000507 "maskmovq\t{$mask, $src|$src, $mask}",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000508 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, EDI)]>;
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000509let Uses = [RDI] in
Bill Wendling8fb68282009-06-23 19:52:59 +0000510def MMX_MASKMOVQ64: MMXI64<0xF7, MRMSrcReg, (outs), (ins VR64:$src, VR64:$mask),
Anton Korobeynikov0e70d102008-08-23 15:53:19 +0000511 "maskmovq\t{$mask, $src|$src, $mask}",
512 [(int_x86_mmx_maskmovq VR64:$src, VR64:$mask, RDI)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513
514//===----------------------------------------------------------------------===//
515// Alias Instructions
516//===----------------------------------------------------------------------===//
517
518// Alias instructions that map zero vector to pxor.
Chris Lattner17dab4a2008-01-10 05:45:39 +0000519let isReMaterializable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000520 def MMX_V_SET0 : MMXI<0xEF, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000521 "pxor\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000522 [(set VR64:$dst, (v2i32 immAllZerosV))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000523 def MMX_V_SETALLONES : MMXI<0x76, MRMInitReg, (outs VR64:$dst), (ins),
Dan Gohman91888f02007-07-31 20:11:57 +0000524 "pcmpeqd\t$dst, $dst",
Chris Lattnere6aa3862007-11-25 00:24:49 +0000525 [(set VR64:$dst, (v2i32 immAllOnesV))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526}
527
Evan Chenga15896e2008-03-12 07:02:50 +0000528let Predicates = [HasMMX] in {
529 def : Pat<(v1i64 immAllZerosV), (MMX_V_SET0)>;
530 def : Pat<(v4i16 immAllZerosV), (MMX_V_SET0)>;
531 def : Pat<(v8i8 immAllZerosV), (MMX_V_SET0)>;
532}
533
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534//===----------------------------------------------------------------------===//
535// Non-Instruction Patterns
536//===----------------------------------------------------------------------===//
537
538// Store 64-bit integer vector values.
539def : Pat<(store (v8i8 VR64:$src), addr:$dst),
540 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
541def : Pat<(store (v4i16 VR64:$src), addr:$dst),
542 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
543def : Pat<(store (v2i32 VR64:$src), addr:$dst),
544 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000545def : Pat<(store (v2f32 VR64:$src), addr:$dst),
546 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547def : Pat<(store (v1i64 VR64:$src), addr:$dst),
548 (MMX_MOVQ64mr addr:$dst, VR64:$src)>;
549
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550// Bit convert.
551def : Pat<(v8i8 (bitconvert (v1i64 VR64:$src))), (v8i8 VR64:$src)>;
552def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000553def : Pat<(v8i8 (bitconvert (v2f32 VR64:$src))), (v8i8 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
555def : Pat<(v4i16 (bitconvert (v1i64 VR64:$src))), (v4i16 VR64:$src)>;
556def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000557def : Pat<(v4i16 (bitconvert (v2f32 VR64:$src))), (v4i16 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
559def : Pat<(v2i32 (bitconvert (v1i64 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000560def : Pat<(v2i32 (bitconvert (v2f32 VR64:$src))), (v2i32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
562def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000563def : Pat<(v2f32 (bitconvert (v1i64 VR64:$src))), (v2f32 VR64:$src)>;
564def : Pat<(v2f32 (bitconvert (v2i32 VR64:$src))), (v2f32 VR64:$src)>;
565def : Pat<(v2f32 (bitconvert (v4i16 VR64:$src))), (v2f32 VR64:$src)>;
566def : Pat<(v2f32 (bitconvert (v8i8 VR64:$src))), (v2f32 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567def : Pat<(v1i64 (bitconvert (v2i32 VR64:$src))), (v1i64 VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000568def : Pat<(v1i64 (bitconvert (v2f32 VR64:$src))), (v1i64 VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569def : Pat<(v1i64 (bitconvert (v4i16 VR64:$src))), (v1i64 VR64:$src)>;
570def : Pat<(v1i64 (bitconvert (v8i8 VR64:$src))), (v1i64 VR64:$src)>;
571
572// 64-bit bit convert.
573def : Pat<(v1i64 (bitconvert (i64 GR64:$src))),
574 (MMX_MOVD64to64rr GR64:$src)>;
575def : Pat<(v2i32 (bitconvert (i64 GR64:$src))),
576 (MMX_MOVD64to64rr GR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000577def : Pat<(v2f32 (bitconvert (i64 GR64:$src))),
578 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579def : Pat<(v4i16 (bitconvert (i64 GR64:$src))),
580 (MMX_MOVD64to64rr GR64:$src)>;
581def : Pat<(v8i8 (bitconvert (i64 GR64:$src))),
582 (MMX_MOVD64to64rr GR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000583def : Pat<(i64 (bitconvert (v1i64 VR64:$src))),
584 (MMX_MOVD64from64rr VR64:$src)>;
585def : Pat<(i64 (bitconvert (v2i32 VR64:$src))),
586 (MMX_MOVD64from64rr VR64:$src)>;
Dale Johannesena585daf2008-06-24 22:01:44 +0000587def : Pat<(i64 (bitconvert (v2f32 VR64:$src))),
588 (MMX_MOVD64from64rr VR64:$src)>;
Dan Gohman4535ae32008-04-15 23:55:07 +0000589def : Pat<(i64 (bitconvert (v4i16 VR64:$src))),
590 (MMX_MOVD64from64rr VR64:$src)>;
591def : Pat<(i64 (bitconvert (v8i8 VR64:$src))),
592 (MMX_MOVD64from64rr VR64:$src)>;
Evan Chengef356282009-02-23 09:03:22 +0000593def : Pat<(f64 (bitconvert (v1i64 VR64:$src))),
594 (MMX_MOVQ2FR64rr VR64:$src)>;
595def : Pat<(f64 (bitconvert (v2i32 VR64:$src))),
596 (MMX_MOVQ2FR64rr VR64:$src)>;
597def : Pat<(f64 (bitconvert (v4i16 VR64:$src))),
598 (MMX_MOVQ2FR64rr VR64:$src)>;
599def : Pat<(f64 (bitconvert (v8i8 VR64:$src))),
600 (MMX_MOVQ2FR64rr VR64:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601
Evan Cheng778641e2008-11-05 06:04:51 +0000602let AddedComplexity = 20 in {
Evan Cheng778641e2008-11-05 06:04:51 +0000603 def : Pat<(v2i32 (X86vzmovl (bc_v2i32 (load_mmx addr:$src)))),
Eric Christopher74c525e2009-08-10 22:37:37 +0000604 (MMX_MOVZDI2PDIrm addr:$src)>;
Evan Chengb76ecc82008-12-03 19:38:05 +0000605}
606
607// Clear top half.
608let AddedComplexity = 15 in {
Evan Chengb76ecc82008-12-03 19:38:05 +0000609 def : Pat<(v2i32 (X86vzmovl VR64:$src)),
610 (MMX_PUNPCKLDQrr VR64:$src, (MMX_V_SET0))>;
Evan Cheng778641e2008-11-05 06:04:51 +0000611}
612
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613// Patterns to perform canonical versions of vector shuffling.
614let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000615 def : Pat<(v8i8 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616 (MMX_PUNPCKLBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000617 def : Pat<(v4i16 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 (MMX_PUNPCKLWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000619 def : Pat<(v2i32 (mmx_unpckl_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 (MMX_PUNPCKLDQrr VR64:$src, VR64:$src)>;
621}
622
623let AddedComplexity = 10 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000624 def : Pat<(v8i8 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625 (MMX_PUNPCKHBWrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000626 def : Pat<(v4i16 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 (MMX_PUNPCKHWDrr VR64:$src, VR64:$src)>;
Nate Begeman543d2142009-04-27 18:41:29 +0000628 def : Pat<(v2i32 (mmx_unpckh_undef VR64:$src, (undef))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 (MMX_PUNPCKHDQrr VR64:$src, VR64:$src)>;
630}
631
632// Patterns to perform vector shuffling with a zeroed out vector.
633let AddedComplexity = 20 in {
Nate Begeman543d2142009-04-27 18:41:29 +0000634 def : Pat<(bc_v2i32 (mmx_unpckl immAllZerosV,
635 (v2i32 (scalar_to_vector (load_mmx addr:$src))))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636 (MMX_PUNPCKLDQrm VR64:$src, VR64:$src)>;
637}
638
639// Some special case PANDN patterns.
640// FIXME: Get rid of these.
641def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
642 VR64:$src2)),
643 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000644def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645 VR64:$src2)),
646 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000647def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000648 VR64:$src2)),
649 (MMX_PANDNrr VR64:$src1, VR64:$src2)>;
650
651def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v2i32 immAllOnesV))),
652 (load addr:$src2))),
653 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000654def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v4i16 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655 (load addr:$src2))),
656 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Chris Lattnere6aa3862007-11-25 00:24:49 +0000657def : Pat<(v1i64 (and (xor VR64:$src1, (bc_v1i64 (v8i8 immAllOnesV_bc))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 (load addr:$src2))),
659 (MMX_PANDNrm VR64:$src1, addr:$src2)>;
Evan Cheng2aea0b42008-04-25 19:11:04 +0000660
661// Move MMX to lower 64-bit of XMM
Evan Chengef356282009-02-23 09:03:22 +0000662def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v8i8 VR64:$src))))),
663 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
664def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v4i16 VR64:$src))))),
665 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
666def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v2i32 VR64:$src))))),
667 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
668def : Pat<(v2i64 (scalar_to_vector (i64 (bitconvert (v1i64 VR64:$src))))),
Evan Cheng2aea0b42008-04-25 19:11:04 +0000669 (v2i64 (MMX_MOVQ2DQrr VR64:$src))>;
Evan Cheng1428f582008-04-25 20:12:46 +0000670
671// Move lower 64-bit of XMM to MMX.
672def : Pat<(v2i32 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
673 (iPTR 0))))),
674 (v2i32 (MMX_MOVDQ2Qrr VR128:$src))>;
675def : Pat<(v4i16 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
676 (iPTR 0))))),
677 (v4i16 (MMX_MOVDQ2Qrr VR128:$src))>;
678def : Pat<(v8i8 (bitconvert (i64 (vector_extract (v2i64 VR128:$src),
679 (iPTR 0))))),
680 (v8i8 (MMX_MOVDQ2Qrr VR128:$src))>;
681
Eli Friedman7dab4932009-07-22 01:06:52 +0000682// Patterns for vector comparisons
683def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, VR64:$src2)),
684 (MMX_PCMPEQBrr VR64:$src1, VR64:$src2)>;
685def : Pat<(v8i8 (X86pcmpeqb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
686 (MMX_PCMPEQBrm VR64:$src1, addr:$src2)>;
687def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, VR64:$src2)),
688 (MMX_PCMPEQWrr VR64:$src1, VR64:$src2)>;
689def : Pat<(v4i16 (X86pcmpeqw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
690 (MMX_PCMPEQWrm VR64:$src1, addr:$src2)>;
691def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, VR64:$src2)),
692 (MMX_PCMPEQDrr VR64:$src1, VR64:$src2)>;
693def : Pat<(v2i32 (X86pcmpeqd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
694 (MMX_PCMPEQDrm VR64:$src1, addr:$src2)>;
695
696def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, VR64:$src2)),
697 (MMX_PCMPGTBrr VR64:$src1, VR64:$src2)>;
698def : Pat<(v8i8 (X86pcmpgtb VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
699 (MMX_PCMPGTBrm VR64:$src1, addr:$src2)>;
700def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, VR64:$src2)),
701 (MMX_PCMPGTWrr VR64:$src1, VR64:$src2)>;
702def : Pat<(v4i16 (X86pcmpgtw VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
703 (MMX_PCMPGTWrm VR64:$src1, addr:$src2)>;
704def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, VR64:$src2)),
705 (MMX_PCMPGTDrr VR64:$src1, VR64:$src2)>;
706def : Pat<(v2i32 (X86pcmpgtd VR64:$src1, (bitconvert (load_mmx addr:$src2)))),
707 (MMX_PCMPGTDrm VR64:$src1, addr:$src2)>;
708
Mon P Wang83edba52008-12-12 01:25:51 +0000709// CMOV* - Used to implement the SELECT DAG operation. Expanded by the
710// scheduler into a branch sequence.
711// These are expanded by the scheduler.
712let Uses = [EFLAGS], usesCustomDAGSchedInserter = 1 in {
713 def CMOV_V1I64 : I<0, Pseudo,
714 (outs VR64:$dst), (ins VR64:$t, VR64:$f, i8imm:$cond),
715 "#CMOV_V1I64 PSEUDO!",
716 [(set VR64:$dst,
717 (v1i64 (X86cmov VR64:$t, VR64:$f, imm:$cond,
718 EFLAGS)))]>;
719}