1 //====- X86InstrMMX.td - Describe the X86 Instruction Set --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the Evan Cheng and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86 MMX instruction set, defining the instructions,
11 // and properties of the instructions which are needed for code generation,
12 // machine code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Instruction templates
18 //===----------------------------------------------------------------------===//
20 // MMXI - MMX instructions with TB prefix.
21 // MMX2I - MMX / SSE2 instructions with TB and OpSize prefixes.
22 // MMXIi8 - MMX instructions with ImmT == Imm8 and TB prefix.
23 class MMXI<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
24 : I<o, F, ops, asm, pattern>, TB, Requires<[HasMMX]>;
25 class MMX2I<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
26 : I<o, F, ops, asm, pattern>, TB, OpSize, Requires<[HasSSE2]>;
27 class MMXIi8<bits<8> o, Format F, dag ops, string asm, list<dag> pattern>
28 : Ii8<o, F, ops, asm, pattern>, TB, Requires<[HasMMX]>;
30 // Some 'special' instructions
31 def IMPLICIT_DEF_VR64 : I<0, Pseudo, (ops VR64:$dst),
33 [(set VR64:$dst, (v8i8 (undef)))]>,
36 // 64-bit vector undef's.
37 def : Pat<(v8i8 (undef)), (IMPLICIT_DEF_VR64)>;
38 def : Pat<(v4i16 (undef)), (IMPLICIT_DEF_VR64)>;
39 def : Pat<(v2i32 (undef)), (IMPLICIT_DEF_VR64)>;
41 //===----------------------------------------------------------------------===//
42 // MMX Pattern Fragments
43 //===----------------------------------------------------------------------===//
45 def loadv2i32 : PatFrag<(ops node:$ptr), (v2i32 (load node:$ptr))>;
47 //===----------------------------------------------------------------------===//
49 //===----------------------------------------------------------------------===//
51 let isTwoAddress = 1 in {
52 // MMXI_binop_rm - Simple MMX binary operator.
53 multiclass MMXI_binop_rm<bits<8> opc, string OpcodeStr, SDNode OpNode,
54 ValueType OpVT, bit Commutable = 0> {
55 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
56 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
57 [(set VR64:$dst, (OpVT (OpNode VR64:$src1, VR64:$src2)))]> {
58 let isCommutable = Commutable;
60 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
61 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
62 [(set VR64:$dst, (OpVT (OpNode VR64:$src1,
64 (loadv2i32 addr:$src2)))))]>;
68 let isTwoAddress = 1 in {
69 multiclass MMXI_binop_rm_int<bits<8> opc, string OpcodeStr, Intrinsic IntId,
71 def rr : MMXI<opc, MRMSrcReg, (ops VR64:$dst, VR64:$src1, VR64:$src2),
72 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
73 [(set VR64:$dst, (IntId VR64:$src1, VR64:$src2))]> {
74 let isCommutable = Commutable;
76 def rm : MMXI<opc, MRMSrcMem, (ops VR64:$dst, VR64:$src1, i64mem:$src2),
77 !strconcat(OpcodeStr, " {$src2, $dst|$dst, $src2}"),
78 [(set VR64:$dst, (IntId VR64:$src1,
79 (bitconvert (loadv2i32 addr:$src2))))]>;
83 //===----------------------------------------------------------------------===//
84 // MMX EMMS Instruction
85 //===----------------------------------------------------------------------===//
87 def EMMS : MMXI<0x77, RawFrm, (ops), "emms", [(int_x86_mmx_emms)]>;
89 //===----------------------------------------------------------------------===//
90 // MMX Scalar Instructions
91 //===----------------------------------------------------------------------===//
93 // Arithmetic Instructions
94 defm MMX_PADDB : MMXI_binop_rm<0xFC, "paddb", add, v8i8, 1>;
95 defm MMX_PADDW : MMXI_binop_rm<0xFD, "paddw", add, v4i16, 1>;
96 defm MMX_PADDD : MMXI_binop_rm<0xFE, "paddd", add, v2i32, 1>;
98 defm MMX_PADDSB : MMXI_binop_rm_int<0xEC, "paddsb" , int_x86_mmx_padds_b, 1>;
99 defm MMX_PADDSW : MMXI_binop_rm_int<0xED, "paddsw" , int_x86_mmx_padds_w, 1>;
101 defm MMX_PADDUSB : MMXI_binop_rm_int<0xDC, "paddusb", int_x86_mmx_paddus_b, 1>;
102 defm MMX_PADDUSW : MMXI_binop_rm_int<0xDD, "paddusw", int_x86_mmx_paddus_w, 1>;
104 defm MMX_PSUBB : MMXI_binop_rm<0xF8, "psubb", sub, v8i8>;
105 defm MMX_PSUBW : MMXI_binop_rm<0xF9, "psubw", sub, v4i16>;
106 defm MMX_PSUBD : MMXI_binop_rm<0xFA, "psubd", sub, v2i32>;
108 defm MMX_PSUBSB : MMXI_binop_rm_int<0xE8, "psubsb" , int_x86_mmx_psubs_b>;
109 defm MMX_PSUBSW : MMXI_binop_rm_int<0xE9, "psubsw" , int_x86_mmx_psubs_w>;
111 defm MMX_PSUBUSB : MMXI_binop_rm_int<0xD8, "psubusb", int_x86_mmx_psubus_b>;
112 defm MMX_PSUBUSW : MMXI_binop_rm_int<0xD9, "psubusw", int_x86_mmx_psubus_w>;
115 def MOVD64rr : MMXI<0x6E, MRMSrcReg, (ops VR64:$dst, GR32:$src),
116 "movd {$src, $dst|$dst, $src}", []>;
117 def MOVD64rm : MMXI<0x6E, MRMSrcMem, (ops VR64:$dst, i32mem:$src),
118 "movd {$src, $dst|$dst, $src}", []>;
119 def MOVD64mr : MMXI<0x7E, MRMDestMem, (ops i32mem:$dst, VR64:$src),
120 "movd {$src, $dst|$dst, $src}", []>;
122 def MOVQ64rr : MMXI<0x6F, MRMSrcReg, (ops VR64:$dst, VR64:$src),
123 "movq {$src, $dst|$dst, $src}", []>;
124 def MOVQ64rm : MMXI<0x6F, MRMSrcMem, (ops VR64:$dst, i64mem:$src),
125 "movq {$src, $dst|$dst, $src}",
126 [(set VR64:$dst, (loadv2i32 addr:$src))]>;
127 def MOVQ64mr : MMXI<0x7F, MRMDestMem, (ops i64mem:$dst, VR64:$src),
128 "movq {$src, $dst|$dst, $src}",
129 [(store (v2i32 VR64:$src), addr:$dst)]>;
131 // Conversion instructions
132 def CVTPI2PSrr : MMXI<0x2A, MRMSrcReg, (ops VR128:$dst, VR64:$src),
133 "cvtpi2ps {$src, $dst|$dst, $src}", []>;
134 def CVTPI2PSrm : MMXI<0x2A, MRMSrcMem, (ops VR128:$dst, i64mem:$src),
135 "cvtpi2ps {$src, $dst|$dst, $src}", []>;
136 def CVTPI2PDrr : MMX2I<0x2A, MRMSrcReg, (ops VR128:$dst, VR64:$src),
137 "cvtpi2pd {$src, $dst|$dst, $src}", []>;
138 def CVTPI2PDrm : MMX2I<0x2A, MRMSrcMem, (ops VR128:$dst, i64mem:$src),
139 "cvtpi2pd {$src, $dst|$dst, $src}", []>;
140 def CVTTPS2PIrr: I<0x2C, MRMSrcReg, (ops VR64:$dst, VR128:$src),
141 "cvttps2pi {$src, $dst|$dst, $src}", []>, TB,
143 def CVTTPS2PIrm: I<0x2C, MRMSrcMem, (ops VR64:$dst, f64mem:$src),
144 "cvttps2pi {$src, $dst|$dst, $src}", []>, TB,
146 def CVTPS2PIrr : MMXI<0x2D, MRMSrcReg, (ops VR64:$dst, VR128:$src),
147 "cvtps2pi {$src, $dst|$dst, $src}", []>;
148 def CVTPS2PIrm : MMXI<0x2D, MRMSrcMem, (ops VR64:$dst, f64mem:$src),
149 "cvtps2pi {$src, $dst|$dst, $src}", []>;
150 def CVTPD2PIrr : MMX2I<0x2D, MRMSrcReg, (ops VR64:$dst, VR128:$src),
151 "cvtpd2pi {$src, $dst|$dst, $src}", []>;
152 def CVTPD2PIrm : MMX2I<0x2D, MRMSrcMem, (ops VR64:$dst, f128mem:$src),
153 "cvtpd2pi {$src, $dst|$dst, $src}", []>;
155 // Shuffle and unpack instructions
156 def PSHUFWri : MMXIi8<0x70, MRMSrcReg,
157 (ops VR64:$dst, VR64:$src1, i8imm:$src2),
158 "pshufw {$src2, $src1, $dst|$dst, $src1, $src2}", []>;
159 def PSHUFWmi : MMXIi8<0x70, MRMSrcMem,
160 (ops VR64:$dst, i64mem:$src1, i8imm:$src2),
161 "pshufw {$src2, $src1, $dst|$dst, $src1, $src2}", []>;
164 def MOVNTQ : I<0xE7, MRMDestMem, (ops i64mem:$dst, VR64:$src),
165 "movntq {$src, $dst|$dst, $src}", []>, TB,
168 def MASKMOVQ : I<0xF7, MRMDestMem, (ops VR64:$src, VR64:$mask),
169 "maskmovq {$mask, $src|$src, $mask}", []>, TB,
172 //===----------------------------------------------------------------------===//
173 // Non-Instruction Patterns
174 //===----------------------------------------------------------------------===//
176 // Store 64-bit integer vector values.
177 def : Pat<(store (v8i8 VR64:$src), addr:$dst),
178 (MOVQ64mr addr:$dst, VR64:$src)>;
179 def : Pat<(store (v4i16 VR64:$src), addr:$dst),
180 (MOVQ64mr addr:$dst, VR64:$src)>;
183 def : Pat<(v8i8 (bitconvert (v2i32 VR64:$src))), (v8i8 VR64:$src)>;
184 def : Pat<(v8i8 (bitconvert (v4i16 VR64:$src))), (v8i8 VR64:$src)>;
185 def : Pat<(v4i16 (bitconvert (v2i32 VR64:$src))), (v4i16 VR64:$src)>;
186 def : Pat<(v4i16 (bitconvert (v8i8 VR64:$src))), (v4i16 VR64:$src)>;
187 def : Pat<(v2i32 (bitconvert (v4i16 VR64:$src))), (v2i32 VR64:$src)>;
188 def : Pat<(v2i32 (bitconvert (v8i8 VR64:$src))), (v2i32 VR64:$src)>;