1 //===- PPCInstrAltivec.td - The PowerPC Altivec Extension --*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Altivec extension to the PowerPC instruction set.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Altivec transformation functions and pattern fragments.
18 // VSPLT_get_imm xform function: convert vector_shuffle mask to VSPLT* imm.
19 def VSPLT_get_imm : SDNodeXForm<build_vector, [{
20 return getI32Imm(PPC::getVSPLTImmediate(N));
23 def VSPLT_shuffle_mask : PatLeaf<(build_vector), [{
24 return PPC::isSplatShuffleMask(N);
27 def vecimm0 : PatLeaf<(build_vector), [{
28 return PPC::isZeroVector(N);
32 // VSPLTISB_get_imm xform function: convert build_vector to VSPLTISB imm.
33 def VSPLTISB_get_imm : SDNodeXForm<build_vector, [{
35 PPC::isVecSplatImm(N, 1, &Val);
36 return getI32Imm(Val);
38 def vecspltisb : PatLeaf<(build_vector), [{
39 return PPC::isVecSplatImm(N, 1);
40 }], VSPLTISB_get_imm>;
42 // VSPLTISH_get_imm xform function: convert build_vector to VSPLTISH imm.
43 def VSPLTISH_get_imm : SDNodeXForm<build_vector, [{
45 PPC::isVecSplatImm(N, 2, &Val);
46 return getI32Imm(Val);
48 def vecspltish : PatLeaf<(build_vector), [{
49 return PPC::isVecSplatImm(N, 2);
50 }], VSPLTISH_get_imm>;
52 // VSPLTISW_get_imm xform function: convert build_vector to VSPLTISW imm.
53 def VSPLTISW_get_imm : SDNodeXForm<build_vector, [{
55 PPC::isVecSplatImm(N, 4, &Val);
56 return getI32Imm(Val);
58 def vecspltisw : PatLeaf<(build_vector), [{
59 return PPC::isVecSplatImm(N, 4);
60 }], VSPLTISW_get_imm>;
64 //===----------------------------------------------------------------------===//
65 // Instruction Definitions.
67 def IMPLICIT_DEF_VRRC : Pseudo<(ops VRRC:$rD), "; $rD = IMPLICIT_DEF_VRRC",
68 [(set VRRC:$rD, (v4f32 (undef)))]>;
70 let isLoad = 1, PPC970_Unit = 2 in { // Loads.
71 def LVEBX: XForm_1<31, 7, (ops VRRC:$vD, memrr:$src),
72 "lvebx $vD, $src", LdStGeneral,
73 [(set VRRC:$vD, (v16i8 (PPClve_x xoaddr:$src)))]>;
74 def LVEHX: XForm_1<31, 39, (ops VRRC:$vD, memrr:$src),
75 "lvehx $vD, $src", LdStGeneral,
76 [(set VRRC:$vD, (v8i16 (PPClve_x xoaddr:$src)))]>;
77 def LVEWX: XForm_1<31, 71, (ops VRRC:$vD, memrr:$src),
78 "lvewx $vD, $src", LdStGeneral,
79 [(set VRRC:$vD, (v4f32 (PPClve_x xoaddr:$src)))]>;
80 def LVX : XForm_1<31, 103, (ops VRRC:$vD, memrr:$src),
81 "lvx $vD, $src", LdStGeneral,
82 [(set VRRC:$vD, (v4f32 (load xoaddr:$src)))]>;
85 def LVSL : XForm_1<31, 6, (ops VRRC:$vD, GPRC:$base, GPRC:$rA),
86 "lvsl $vD, $base, $rA", LdStGeneral,
88 def LVSR : XForm_1<31, 38, (ops VRRC:$vD, GPRC:$base, GPRC:$rA),
89 "lvsl $vD, $base, $rA", LdStGeneral,
92 let isStore = 1, noResults = 1, PPC970_Unit = 2 in { // Stores.
93 def STVEBX: XForm_8<31, 135, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
94 "stvebx $rS, $rA, $rB", LdStGeneral,
96 def STVEHX: XForm_8<31, 167, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
97 "stvehx $rS, $rA, $rB", LdStGeneral,
99 def STVEWX: XForm_8<31, 199, (ops VRRC:$rS, GPRC:$rA, GPRC:$rB),
100 "stvewx $rS, $rA, $rB", LdStGeneral,
102 def STVX : XForm_8<31, 231, (ops VRRC:$rS, memrr:$dst),
103 "stvx $rS, $dst", LdStGeneral,
104 [(store (v4f32 VRRC:$rS), xoaddr:$dst)]>;
107 let PPC970_Unit = 5 in { // VALU Operations.
108 // VA-Form instructions. 3-input AltiVec ops.
109 def VMADDFP : VAForm_1<46, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
110 "vmaddfp $vD, $vA, $vC, $vB", VecFP,
111 [(set VRRC:$vD, (fadd (fmul VRRC:$vA, VRRC:$vC),
113 Requires<[FPContractions]>;
114 def VNMSUBFP: VAForm_1<47, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
115 "vnmsubfp $vD, $vA, $vC, $vB", VecFP,
116 [(set VRRC:$vD, (fneg (fsub (fmul VRRC:$vA, VRRC:$vC),
118 Requires<[FPContractions]>;
120 def VPERM : VAForm_1<43, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
121 "vperm $vD, $vA, $vB, $vC", VecPerm,
123 (PPCvperm (v4f32 VRRC:$vA), VRRC:$vB, VRRC:$vC))]>;
126 // VX-Form instructions. AltiVec arithmetic ops.
127 def VADDCUW : VXForm_1<384, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
128 "vaddcuw $vD, $vA, $vB", VecFP,
130 (int_ppc_altivec_vaddcuw VRRC:$vA, VRRC:$vB))]>;
131 def VADDFP : VXForm_1<10, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
132 "vaddfp $vD, $vA, $vB", VecFP,
133 [(set VRRC:$vD, (fadd VRRC:$vA, VRRC:$vB))]>;
134 def VADDSBS : VXForm_1<768, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
135 "vaddsbs $vD, $vA, $vB", VecFP,
137 (int_ppc_altivec_vaddsbs VRRC:$vA, VRRC:$vB))]>;
138 def VADDSHS : VXForm_1<832, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
139 "vaddshs $vD, $vA, $vB", VecFP,
141 (int_ppc_altivec_vaddshs VRRC:$vA, VRRC:$vB))]>;
142 def VADDSWS : VXForm_1<896, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
143 "vaddsws $vD, $vA, $vB", VecFP,
145 (int_ppc_altivec_vaddsws VRRC:$vA, VRRC:$vB))]>;
146 def VADDUBS : VXForm_1<512, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
147 "vaddubs $vD, $vA, $vB", VecFP,
149 (int_ppc_altivec_vaddubs VRRC:$vA, VRRC:$vB))]>;
150 def VADDUHS : VXForm_1<576, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
151 "vadduhs $vD, $vA, $vB", VecFP,
153 (int_ppc_altivec_vadduhs VRRC:$vA, VRRC:$vB))]>;
154 def VADDUWM : VXForm_1<128, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
155 "vadduwm $vD, $vA, $vB", VecGeneral,
156 [(set VRRC:$vD, (add (v4i32 VRRC:$vA), VRRC:$vB))]>;
157 def VADDUWS : VXForm_1<640, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
158 "vadduws $vD, $vA, $vB", VecFP,
160 (int_ppc_altivec_vadduws VRRC:$vA, VRRC:$vB))]>;
161 def VAND : VXForm_1<1028, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
162 "vand $vD, $vA, $vB", VecFP,
163 [(set VRRC:$vD, (and (v4i32 VRRC:$vA), VRRC:$vB))]>;
164 def VANDC : VXForm_1<1092, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
165 "vandc $vD, $vA, $vB", VecFP,
166 [(set VRRC:$vD, (vnot (and (v4i32 VRRC:$vA), VRRC:$vB)))]>;
168 def VCFSX : VXForm_1<842, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
169 "vcfsx $vD, $vB, $UIMM", VecFP,
171 (int_ppc_altivec_vcfsx VRRC:$vB, imm:$UIMM))]>;
172 def VCFUX : VXForm_1<778, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
173 "vcfux $vD, $vB, $UIMM", VecFP,
175 (int_ppc_altivec_vcfux VRRC:$vB, imm:$UIMM))]>;
176 def VCTSXS : VXForm_1<970, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
177 "vctsxs $vD, $vB, $UIMM", VecFP,
179 def VCTUXS : VXForm_1<906, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
180 "vctuxs $vD, $vB, $UIMM", VecFP,
182 def VEXPTEFP : VXForm_2<394, (ops VRRC:$vD, VRRC:$vB),
183 "vexptefp $vD, $vB", VecFP,
185 def VLOGEFP : VXForm_2<458, (ops VRRC:$vD, VRRC:$vB),
186 "vlogefp $vD, $vB", VecFP,
188 def VMAXFP : VXForm_1<1034, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
189 "vmaxfp $vD, $vA, $vB", VecFP,
191 def VMINFP : VXForm_1<1098, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
192 "vminfp $vD, $vA, $vB", VecFP,
194 def VREFP : VXForm_2<266, (ops VRRC:$vD, VRRC:$vB),
195 "vrefp $vD, $vB", VecFP,
197 def VRFIM : VXForm_2<714, (ops VRRC:$vD, VRRC:$vB),
198 "vrfim $vD, $vB", VecFP,
200 def VRFIN : VXForm_2<522, (ops VRRC:$vD, VRRC:$vB),
201 "vrfin $vD, $vB", VecFP,
203 def VRFIP : VXForm_2<650, (ops VRRC:$vD, VRRC:$vB),
204 "vrfip $vD, $vB", VecFP,
206 def VRFIZ : VXForm_2<586, (ops VRRC:$vD, VRRC:$vB),
207 "vrfiz $vD, $vB", VecFP,
209 def VRSQRTEFP : VXForm_2<330, (ops VRRC:$vD, VRRC:$vB),
210 "vrsqrtefp $vD, $vB", VecFP,
211 [(set VRRC:$vD,(int_ppc_altivec_vrsqrtefp VRRC:$vB))]>;
212 def VSUBFP : VXForm_1<74, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
213 "vsubfp $vD, $vA, $vB", VecFP,
214 [(set VRRC:$vD, (fsub VRRC:$vA, VRRC:$vB))]>;
215 def VNOR : VXForm_1<1284, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
216 "vnor $vD, $vA, $vB", VecFP,
217 [(set VRRC:$vD, (vnot (or (v4i32 VRRC:$vA), VRRC:$vB)))]>;
218 def VOR : VXForm_1<1156, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
219 "vor $vD, $vA, $vB", VecFP,
220 [(set VRRC:$vD, (or (v4i32 VRRC:$vA), VRRC:$vB))]>;
221 def VXOR : VXForm_1<1220, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
222 "vxor $vD, $vA, $vB", VecFP,
223 [(set VRRC:$vD, (xor (v4i32 VRRC:$vA), VRRC:$vB))]>;
225 def VSPLTB : VXForm_1<524, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
226 "vspltb $vD, $vB, $UIMM", VecPerm,
228 def VSPLTH : VXForm_1<588, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
229 "vsplth $vD, $vB, $UIMM", VecPerm,
231 def VSPLTW : VXForm_1<652, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
232 "vspltw $vD, $vB, $UIMM", VecPerm,
233 [(set VRRC:$vD, (vector_shuffle (v4f32 VRRC:$vB), (undef),
234 VSPLT_shuffle_mask:$UIMM))]>;
236 def VSPLTISB : VXForm_1<780, (ops VRRC:$vD, s5imm:$SIMM),
237 "vspltisb $vD, $SIMM", VecPerm,
238 [(set VRRC:$vD, (v4f32 vecspltisb:$SIMM))]>;
239 def VSPLTISH : VXForm_1<844, (ops VRRC:$vD, s5imm:$SIMM),
240 "vspltish $vD, $SIMM", VecPerm,
241 [(set VRRC:$vD, (v4f32 vecspltish:$SIMM))]>;
242 def VSPLTISW : VXForm_1<908, (ops VRRC:$vD, s5imm:$SIMM),
243 "vspltisw $vD, $SIMM", VecPerm,
244 [(set VRRC:$vD, (v4f32 vecspltisw:$SIMM))]>;
247 // VX-Form Pseudo Instructions
249 def V_SET0 : VXForm_setzero<1220, (ops VRRC:$vD),
250 "vxor $vD, $vD, $vD", VecFP,
251 [(set VRRC:$vD, (v4f32 vecimm0))]>;
254 //===----------------------------------------------------------------------===//
255 // Additional Altivec Patterns
259 def : Pat<(v16i8 (undef)), (v16i8 (IMPLICIT_DEF_VRRC))>;
260 def : Pat<(v8i16 (undef)), (v8i16 (IMPLICIT_DEF_VRRC))>;
261 def : Pat<(v4i32 (undef)), (v4i32 (IMPLICIT_DEF_VRRC))>;
262 def : Pat<(v16i8 vecimm0), (v16i8 (V_SET0))>;
263 def : Pat<(v8i16 vecimm0), (v8i16 (V_SET0))>;
264 def : Pat<(v4i32 vecimm0), (v4i32 (V_SET0))>;
267 def : Pat<(v16i8 (load xoaddr:$src)), (v16i8 (LVX xoaddr:$src))>;
268 def : Pat<(v8i16 (load xoaddr:$src)), (v8i16 (LVX xoaddr:$src))>;
269 def : Pat<(v4i32 (load xoaddr:$src)), (v4i32 (LVX xoaddr:$src))>;
272 def : Pat<(store (v16i8 VRRC:$rS), xoaddr:$dst),
273 (STVX (v16i8 VRRC:$rS), xoaddr:$dst)>;
274 def : Pat<(store (v8i16 VRRC:$rS), xoaddr:$dst),
275 (STVX (v8i16 VRRC:$rS), xoaddr:$dst)>;
276 def : Pat<(store (v4i32 VRRC:$rS), xoaddr:$dst),
277 (STVX (v4i32 VRRC:$rS), xoaddr:$dst)>;
280 def : Pat<(v16i8 (bitconvert (v8i16 VRRC:$src))), (v16i8 VRRC:$src)>;
281 def : Pat<(v16i8 (bitconvert (v4i32 VRRC:$src))), (v16i8 VRRC:$src)>;
282 def : Pat<(v16i8 (bitconvert (v4f32 VRRC:$src))), (v16i8 VRRC:$src)>;
284 def : Pat<(v8i16 (bitconvert (v16i8 VRRC:$src))), (v8i16 VRRC:$src)>;
285 def : Pat<(v8i16 (bitconvert (v4i32 VRRC:$src))), (v8i16 VRRC:$src)>;
286 def : Pat<(v8i16 (bitconvert (v4f32 VRRC:$src))), (v8i16 VRRC:$src)>;
288 def : Pat<(v4i32 (bitconvert (v16i8 VRRC:$src))), (v4i32 VRRC:$src)>;
289 def : Pat<(v4i32 (bitconvert (v8i16 VRRC:$src))), (v4i32 VRRC:$src)>;
290 def : Pat<(v4i32 (bitconvert (v4f32 VRRC:$src))), (v4i32 VRRC:$src)>;
292 def : Pat<(v4f32 (bitconvert (v16i8 VRRC:$src))), (v4f32 VRRC:$src)>;
293 def : Pat<(v4f32 (bitconvert (v8i16 VRRC:$src))), (v4f32 VRRC:$src)>;
294 def : Pat<(v4f32 (bitconvert (v4i32 VRRC:$src))), (v4f32 VRRC:$src)>;
296 // Immediate vector formation with vsplti*.
297 def : Pat<(v16i8 vecspltisb:$invec), (v16i8 (VSPLTISB vecspltisb:$invec))>;
298 def : Pat<(v16i8 vecspltish:$invec), (v16i8 (VSPLTISH vecspltish:$invec))>;
299 def : Pat<(v16i8 vecspltisw:$invec), (v16i8 (VSPLTISW vecspltisw:$invec))>;
301 def : Pat<(v8i16 vecspltisb:$invec), (v8i16 (VSPLTISB vecspltisb:$invec))>;
302 def : Pat<(v8i16 vecspltish:$invec), (v8i16 (VSPLTISH vecspltish:$invec))>;
303 def : Pat<(v8i16 vecspltisw:$invec), (v8i16 (VSPLTISW vecspltisw:$invec))>;
305 def : Pat<(v4i32 vecspltisb:$invec), (v4i32 (VSPLTISB vecspltisb:$invec))>;
306 def : Pat<(v4i32 vecspltish:$invec), (v4i32 (VSPLTISH vecspltish:$invec))>;
307 def : Pat<(v4i32 vecspltisw:$invec), (v4i32 (VSPLTISW vecspltisw:$invec))>;
309 // Logical Operations
310 def : Pat<(v16i8 (and VRRC:$A, VRRC:$B)), (v16i8 (VAND VRRC:$A, VRRC:$B))>;
311 def : Pat<(v8i16 (and VRRC:$A, VRRC:$B)), (v8i16 (VAND VRRC:$A, VRRC:$B))>;
312 def : Pat<(v16i8 (or VRRC:$A, VRRC:$B)), (v16i8 (VOR VRRC:$A, VRRC:$B))>;
313 def : Pat<(v8i16 (or VRRC:$A, VRRC:$B)), (v8i16 (VOR VRRC:$A, VRRC:$B))>;
314 def : Pat<(v16i8 (xor VRRC:$A, VRRC:$B)), (v16i8 (VXOR VRRC:$A, VRRC:$B))>;
315 def : Pat<(v8i16 (xor VRRC:$A, VRRC:$B)), (v8i16 (VXOR VRRC:$A, VRRC:$B))>;
316 def : Pat<(v16i8 (vnot (or VRRC:$A, VRRC:$B))),(v16i8 (VNOR VRRC:$A, VRRC:$B))>;
317 def : Pat<(v8i16 (vnot (or VRRC:$A, VRRC:$B))),(v8i16 (VNOR VRRC:$A, VRRC:$B))>;
318 def : Pat<(v16i8 (vnot (and VRRC:$A, VRRC:$B))),
319 (v16i8 (VANDC VRRC:$A, VRRC:$B))>;
320 def : Pat<(v8i16 (vnot (and VRRC:$A, VRRC:$B))),
321 (v8i16 (VANDC VRRC:$A, VRRC:$B))>;
323 def : Pat<(fmul VRRC:$vA, VRRC:$vB),
324 (VMADDFP VRRC:$vA, VRRC:$vB, (V_SET0))>;
326 // Fused multiply add and multiply sub for packed float. These are represented
327 // separately from the real instructions above, for operations that must have
328 // the additional precision, such as Newton-Rhapson (used by divide, sqrt)
329 def : Pat<(PPCvmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
330 (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
331 def : Pat<(PPCvnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
332 (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
334 def : Pat<(int_ppc_altivec_vmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
335 (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
336 def : Pat<(int_ppc_altivec_vnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
337 (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
339 def : Pat<(vector_shuffle (v4i32 VRRC:$vB), (undef), VSPLT_shuffle_mask:$UIMM),
340 (v4i32 (VSPLTW VSPLT_shuffle_mask:$UIMM, VRRC:$vB))>;
342 def : Pat<(PPCvperm (v4i32 VRRC:$vA), VRRC:$vB, VRRC:$vC),
343 (v4i32 (VPERM VRRC:$vA, VRRC:$vB, VRRC:$vC))>;
345 def : Pat<(v4i32 (PPClve_x xoaddr:$src)),
346 (v4i32 (LVEWX xoaddr:$src))>;