Add m[tf]vscr instructions.
[oota-llvm.git] / lib / Target / PowerPC / PPCInstrAltivec.td
1 //===- PPCInstrAltivec.td - The PowerPC Altivec Extension --*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the Altivec extension to the PowerPC instruction set.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Altivec transformation functions and pattern fragments.
16 //
17
18 // VSPLT*_get_imm xform function: convert vector_shuffle mask to VSPLT* imm.
19 def VSPLTB_get_imm : SDNodeXForm<build_vector, [{
20   return getI32Imm(PPC::getVSPLTImmediate(N, 1));
21 }]>;
22 def VSPLTB_shuffle_mask : PatLeaf<(build_vector), [{
23   return PPC::isSplatShuffleMask(N, 1);
24 }], VSPLTB_get_imm>;
25 def VSPLTH_get_imm : SDNodeXForm<build_vector, [{
26   return getI32Imm(PPC::getVSPLTImmediate(N, 2));
27 }]>;
28 def VSPLTH_shuffle_mask : PatLeaf<(build_vector), [{
29   return PPC::isSplatShuffleMask(N, 2);
30 }], VSPLTH_get_imm>;
31 def VSPLTW_get_imm : SDNodeXForm<build_vector, [{
32   return getI32Imm(PPC::getVSPLTImmediate(N, 4));
33 }]>;
34 def VSPLTW_shuffle_mask : PatLeaf<(build_vector), [{
35   return PPC::isSplatShuffleMask(N, 4);
36 }], VSPLTW_get_imm>;
37
38
39 // VSPLTISB_get_imm xform function: convert build_vector to VSPLTISB imm.
40 def VSPLTISB_get_imm : SDNodeXForm<build_vector, [{
41   char Val;
42   PPC::isVecSplatImm(N, 1, &Val);
43   return getI32Imm(Val);
44 }]>;
45 def vecspltisb : PatLeaf<(build_vector), [{
46   return PPC::isVecSplatImm(N, 1);
47 }], VSPLTISB_get_imm>;
48
49 // VSPLTISH_get_imm xform function: convert build_vector to VSPLTISH imm.
50 def VSPLTISH_get_imm : SDNodeXForm<build_vector, [{
51   char Val;
52   PPC::isVecSplatImm(N, 2, &Val);
53   return getI32Imm(Val);
54 }]>;
55 def vecspltish : PatLeaf<(build_vector), [{
56   return PPC::isVecSplatImm(N, 2);
57 }], VSPLTISH_get_imm>;
58
59 // VSPLTISW_get_imm xform function: convert build_vector to VSPLTISW imm.
60 def VSPLTISW_get_imm : SDNodeXForm<build_vector, [{
61   char Val;
62   PPC::isVecSplatImm(N, 4, &Val);
63   return getI32Imm(Val);
64 }]>;
65 def vecspltisw : PatLeaf<(build_vector), [{
66   return PPC::isVecSplatImm(N, 4);
67 }], VSPLTISW_get_imm>;
68
69 //===----------------------------------------------------------------------===//
70 // Helpers for defining instructions that directly correspond to intrinsics.
71
72 // VA1a_Int - A VAForm_1a intrinsic definition.
73 class VA1a_Int<bits<6> xo, string opc, Intrinsic IntID>
74   : VAForm_1a<xo, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB, VRRC:$vC),
75               !strconcat(opc, " $vD, $vA, $vB, $vC"), VecFP,
76                        [(set VRRC:$vD, (IntID VRRC:$vA, VRRC:$vB, VRRC:$vC))]>;
77
78 // VX1_Int - A VXForm_1 intrinsic definition.
79 class VX1_Int<bits<11> xo, string opc, Intrinsic IntID>
80   : VXForm_1<xo, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
81              !strconcat(opc, " $vD, $vA, $vB"), VecFP,
82              [(set VRRC:$vD, (IntID VRRC:$vA, VRRC:$vB))]>;
83
84 // VX2_Int - A VXForm_2 intrinsic definition.
85 class VX2_Int<bits<11> xo, string opc, Intrinsic IntID>
86   : VXForm_2<xo, (ops VRRC:$vD, VRRC:$vB),
87              !strconcat(opc, " $vD, $vB"), VecFP,
88              [(set VRRC:$vD, (IntID VRRC:$vB))]>;
89
90 //===----------------------------------------------------------------------===//
91 // Instruction Definitions.
92
93 def IMPLICIT_DEF_VRRC : Pseudo<(ops VRRC:$rD), "; $rD = IMPLICIT_DEF_VRRC",
94                                [(set VRRC:$rD, (v4f32 (undef)))]>;
95
96 def MFVSCR : VXForm_4<1540, (ops VRRC:$vD),
97                       "mfvcr $vD", LdStGeneral,
98                       [(set VRRC:$vD, (int_ppc_altivec_mfvscr))]>; 
99 def MTVSCR : VXForm_5<1604, (ops VRRC:$vB),
100                       "mtvcr $vB", LdStGeneral,
101                       [(int_ppc_altivec_mtvscr VRRC:$vB)]>; 
102
103 let isLoad = 1, PPC970_Unit = 2 in {  // Loads.
104 def LVEBX: XForm_1<31,   7, (ops VRRC:$vD, memrr:$src),
105                    "lvebx $vD, $src", LdStGeneral,
106                    [(set VRRC:$vD, (int_ppc_altivec_lvebx xoaddr:$src))]>;
107 def LVEHX: XForm_1<31,  39, (ops VRRC:$vD, memrr:$src),
108                    "lvehx $vD, $src", LdStGeneral,
109                    [(set VRRC:$vD, (int_ppc_altivec_lvehx xoaddr:$src))]>;
110 def LVEWX: XForm_1<31,  71, (ops VRRC:$vD, memrr:$src),
111                    "lvewx $vD, $src", LdStGeneral,
112                    [(set VRRC:$vD, (int_ppc_altivec_lvewx xoaddr:$src))]>;
113 def LVX  : XForm_1<31, 103, (ops VRRC:$vD, memrr:$src),
114                    "lvx $vD, $src", LdStGeneral,
115                    [(set VRRC:$vD, (int_ppc_altivec_lvx xoaddr:$src))]>;
116 def LVXL : XForm_1<31, 359, (ops VRRC:$vD, memrr:$src),
117                    "lvxl $vD, $src", LdStGeneral,
118                    [(set VRRC:$vD, (int_ppc_altivec_lvxl xoaddr:$src))]>;
119 }
120
121 def LVSL : XForm_1<31,   6, (ops VRRC:$vD, memrr:$src),
122                    "lvsl $vD, $src", LdStGeneral,
123                    [(set VRRC:$vD, (int_ppc_altivec_lvsl xoaddr:$src))]>,
124                    PPC970_Unit_LSU;
125 def LVSR : XForm_1<31,  38, (ops VRRC:$vD, memrr:$src),
126                    "lvsl $vD, $src", LdStGeneral,
127                    [(set VRRC:$vD, (int_ppc_altivec_lvsr xoaddr:$src))]>,
128                    PPC970_Unit_LSU;
129
130 let isStore = 1, noResults = 1, PPC970_Unit = 2 in {   // Stores.
131 def STVEBX: XForm_8<31, 135, (ops VRRC:$rS, memrr:$dst),
132                    "stvebx $rS, $dst", LdStGeneral,
133                    [(int_ppc_altivec_stvebx VRRC:$rS, xoaddr:$dst)]>;
134 def STVEHX: XForm_8<31, 167, (ops VRRC:$rS, memrr:$dst),
135                    "stvehx $rS, $dst", LdStGeneral,
136                    [(int_ppc_altivec_stvehx VRRC:$rS, xoaddr:$dst)]>;
137 def STVEWX: XForm_8<31, 199, (ops VRRC:$rS, memrr:$dst),
138                    "stvewx $rS, $dst", LdStGeneral,
139                    [(int_ppc_altivec_stvewx VRRC:$rS, xoaddr:$dst)]>;
140 def STVX  : XForm_8<31, 231, (ops VRRC:$rS, memrr:$dst),
141                    "stvx $rS, $dst", LdStGeneral,
142                    [(int_ppc_altivec_stvx VRRC:$rS, xoaddr:$dst)]>;
143 def STVXL : XForm_8<31, 487, (ops VRRC:$rS, memrr:$dst),
144                    "stvxl $rS, $dst", LdStGeneral,
145                    [(int_ppc_altivec_stvxl VRRC:$rS, xoaddr:$dst)]>;
146 }
147
148 let PPC970_Unit = 5 in {  // VALU Operations.
149 // VA-Form instructions.  3-input AltiVec ops.
150 def VMADDFP : VAForm_1<46, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
151                        "vmaddfp $vD, $vA, $vC, $vB", VecFP,
152                        [(set VRRC:$vD, (fadd (fmul VRRC:$vA, VRRC:$vC),
153                                              VRRC:$vB))]>,
154                        Requires<[FPContractions]>;
155 def VNMSUBFP: VAForm_1<47, (ops VRRC:$vD, VRRC:$vA, VRRC:$vC, VRRC:$vB),
156                        "vnmsubfp $vD, $vA, $vC, $vB", VecFP,
157                        [(set VRRC:$vD, (fneg (fsub (fmul VRRC:$vA, VRRC:$vC),
158                                                    VRRC:$vB)))]>,
159                        Requires<[FPContractions]>;
160 def VMHADDSHS  : VA1a_Int<32, "vmhaddshs",  int_ppc_altivec_vmhaddshs>;
161 def VMHRADDSHS : VA1a_Int<33, "vmhraddshs", int_ppc_altivec_vmhraddshs>;
162 def VPERM      : VA1a_Int<43, "vperm",      int_ppc_altivec_vperm>;
163 def VSEL       : VA1a_Int<42, "vsel",       int_ppc_altivec_vsel>;
164
165 def VSLDOI  : VAForm_2<44, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB, u5imm:$SH),
166                        "vsldoi $vD, $vA, $vB, $SH", VecFP,
167                        [(set VRRC:$vD,
168                              (int_ppc_altivec_vsldoi VRRC:$vA, VRRC:$vB,
169                                                      imm:$SH))]>;
170
171 // VX-Form instructions.  AltiVec arithmetic ops.
172 def VADDFP : VXForm_1<10, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
173                       "vaddfp $vD, $vA, $vB", VecFP,
174                       [(set VRRC:$vD, (fadd VRRC:$vA, VRRC:$vB))]>;
175                       
176 def VADDUBM : VXForm_1<0, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
177                       "vaddubm $vD, $vA, $vB", VecGeneral,
178                       [(set VRRC:$vD, (add (v16i8 VRRC:$vA), VRRC:$vB))]>;
179 def VADDUHM : VXForm_1<64, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
180                       "vadduhm $vD, $vA, $vB", VecGeneral,
181                       [(set VRRC:$vD, (add (v8i16 VRRC:$vA), VRRC:$vB))]>;
182 def VADDUWM : VXForm_1<128, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
183                       "vadduwm $vD, $vA, $vB", VecGeneral,
184                       [(set VRRC:$vD, (add (v4i32 VRRC:$vA), VRRC:$vB))]>;
185                       
186 def VADDCUW : VX1_Int<384, "vaddcuw", int_ppc_altivec_vaddcuw>;
187 def VADDSBS : VX1_Int<768, "vaddsbs", int_ppc_altivec_vaddsbs>;
188 def VADDSHS : VX1_Int<832, "vaddshs", int_ppc_altivec_vaddshs>;
189 def VADDSWS : VX1_Int<896, "vaddsws", int_ppc_altivec_vaddsws>;
190 def VADDUBS : VX1_Int<512, "vaddubs", int_ppc_altivec_vaddubs>;
191 def VADDUHS : VX1_Int<576, "vadduhs", int_ppc_altivec_vadduhs>;
192 def VADDUWS : VX1_Int<640, "vadduws", int_ppc_altivec_vadduws>;
193                              
194                              
195 def VAND : VXForm_1<1028, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
196                     "vand $vD, $vA, $vB", VecFP,
197                     [(set VRRC:$vD, (and (v4i32 VRRC:$vA), VRRC:$vB))]>;
198 def VANDC : VXForm_1<1092, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
199                      "vandc $vD, $vA, $vB", VecFP,
200                      [(set VRRC:$vD, (and (v4i32 VRRC:$vA), (vnot VRRC:$vB)))]>;
201
202 def VCFSX  : VXForm_1<842, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
203                       "vcfsx $vD, $vB, $UIMM", VecFP,
204                       [(set VRRC:$vD,
205                              (int_ppc_altivec_vcfsx VRRC:$vB, imm:$UIMM))]>;
206 def VCFUX  : VXForm_1<778, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
207                       "vcfux $vD, $vB, $UIMM", VecFP,
208                       [(set VRRC:$vD,
209                              (int_ppc_altivec_vcfux VRRC:$vB, imm:$UIMM))]>;
210 def VCTSXS : VXForm_1<970, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
211                       "vctsxs $vD, $vB, $UIMM", VecFP,
212                       [(set VRRC:$vD,
213                              (int_ppc_altivec_vctsxs VRRC:$vB, imm:$UIMM))]>;
214 def VCTUXS : VXForm_1<906, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
215                       "vctuxs $vD, $vB, $UIMM", VecFP,
216                       [(set VRRC:$vD,
217                              (int_ppc_altivec_vctuxs VRRC:$vB, imm:$UIMM))]>;
218 def VEXPTEFP : VX2_Int<394, "vexptefp", int_ppc_altivec_vexptefp>;
219 def VLOGEFP  : VX2_Int<458, "vlogefp",  int_ppc_altivec_vlogefp>;
220
221 def VAVGSB : VX1_Int<1282, "vavgsb", int_ppc_altivec_vavgsb>;
222 def VAVGSH : VX1_Int<1346, "vavgsh", int_ppc_altivec_vavgsh>;
223 def VAVGSW : VX1_Int<1410, "vavgsw", int_ppc_altivec_vavgsw>;
224 def VAVGUB : VX1_Int<1026, "vavgub", int_ppc_altivec_vavgub>;
225 def VAVGUH : VX1_Int<1090, "vavguh", int_ppc_altivec_vavguh>;
226 def VAVGUW : VX1_Int<1154, "vavguw", int_ppc_altivec_vavguw>;
227
228 def VMAXFP : VX1_Int<1034, "vmaxfp", int_ppc_altivec_vmaxfp>;
229 def VMAXSB : VX1_Int< 258, "vmaxsb", int_ppc_altivec_vmaxsb>;
230 def VMAXSH : VX1_Int< 322, "vmaxsh", int_ppc_altivec_vmaxsh>;
231 def VMAXSW : VX1_Int< 386, "vmaxsw", int_ppc_altivec_vmaxsw>;
232 def VMAXUB : VX1_Int<   2, "vmaxub", int_ppc_altivec_vmaxub>;
233 def VMAXUH : VX1_Int<  66, "vmaxuh", int_ppc_altivec_vmaxuh>;
234 def VMAXUW : VX1_Int< 130, "vmaxuw", int_ppc_altivec_vmaxuw>;
235 def VMINFP : VX1_Int<1098, "vminfp", int_ppc_altivec_vminfp>;
236 def VMINSB : VX1_Int< 770, "vminsb", int_ppc_altivec_vminsb>;
237 def VMINSH : VX1_Int< 834, "vminsh", int_ppc_altivec_vminsh>;
238 def VMINSW : VX1_Int< 896, "vminsw", int_ppc_altivec_vminsw>;
239 def VMINUB : VX1_Int< 514, "vminub", int_ppc_altivec_vminub>;
240 def VMINUH : VX1_Int< 578, "vminuh", int_ppc_altivec_vminuh>;
241 def VMINUW : VX1_Int< 642, "vminuw", int_ppc_altivec_vminuw>;
242
243 def VMRGHB : VX1_Int<12 , "vmrghb", int_ppc_altivec_vmrghb>;
244 def VMRGHH : VX1_Int<76 , "vmrghh", int_ppc_altivec_vmrghh>;
245 def VMRGHW : VX1_Int<140, "vmrghw", int_ppc_altivec_vmrghw>;
246 def VMRGLB : VX1_Int<268, "vmrglb", int_ppc_altivec_vmrglb>;
247 def VMRGLH : VX1_Int<332, "vmrglh", int_ppc_altivec_vmrglh>;
248 def VMRGLW : VX1_Int<396, "vmrglw", int_ppc_altivec_vmrglw>;
249
250 def VMSUMMBM : VA1a_Int<37, "vmsummbm", int_ppc_altivec_vmsummbm>;
251 def VMSUMSHM : VA1a_Int<40, "vmsumshm", int_ppc_altivec_vmsumshm>;
252 def VMSUMSHS : VA1a_Int<41, "vmsumshs", int_ppc_altivec_vmsumshs>;
253 def VMSUMUBM : VA1a_Int<36, "vmsumubm", int_ppc_altivec_vmsumubm>;
254 def VMSUMUHM : VA1a_Int<38, "vmsumuhm", int_ppc_altivec_vmsumuhm>;
255 def VMSUMUHS : VA1a_Int<39, "vmsumuhs", int_ppc_altivec_vmsumuhs>;
256
257 def VMULESB : VX1_Int<776, "vmulesb", int_ppc_altivec_vmulesb>;
258 def VMULESH : VX1_Int<840, "vmulesh", int_ppc_altivec_vmulesh>;
259 def VMULEUB : VX1_Int<520, "vmuleub", int_ppc_altivec_vmuleub>;
260 def VMULEUH : VX1_Int<584, "vmuleuh", int_ppc_altivec_vmuleuh>;
261 def VMULOSB : VX1_Int<264, "vmulosb", int_ppc_altivec_vmulosb>;
262 def VMULOSH : VX1_Int<328, "vmulosh", int_ppc_altivec_vmulosh>;
263 def VMULOUB : VX1_Int<  8, "vmuloub", int_ppc_altivec_vmuloub>;
264 def VMULOUH : VX1_Int< 72, "vmulouh", int_ppc_altivec_vmulouh>;
265                        
266 def VREFP     : VX2_Int<266, "vrefp",     int_ppc_altivec_vrefp>;
267 def VRFIM     : VX2_Int<714, "vrfim",     int_ppc_altivec_vrfim>;
268 def VRFIN     : VX2_Int<522, "vrfin",     int_ppc_altivec_vrfin>;
269 def VRFIP     : VX2_Int<650, "vrfip",     int_ppc_altivec_vrfip>;
270 def VRFIZ     : VX2_Int<586, "vrfiz",     int_ppc_altivec_vrfiz>;
271 def VRSQRTEFP : VX2_Int<330, "vrsqrtefp", int_ppc_altivec_vrsqrtefp>;
272
273 def VSUBCUW : VX1_Int<74, "vsubcuw", int_ppc_altivec_vsubcuw>;
274
275 def VSUBFP  : VXForm_1<74, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
276                       "vsubfp $vD, $vA, $vB", VecGeneral,
277                       [(set VRRC:$vD, (fsub VRRC:$vA, VRRC:$vB))]>;
278 def VSUBUBM : VXForm_1<1024, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
279                       "vsububm $vD, $vA, $vB", VecGeneral,
280                       [(set VRRC:$vD, (sub (v16i8 VRRC:$vA), VRRC:$vB))]>;
281 def VSUBUHM : VXForm_1<1088, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
282                       "vsubuhm $vD, $vA, $vB", VecGeneral,
283                       [(set VRRC:$vD, (sub (v8i16 VRRC:$vA), VRRC:$vB))]>;
284 def VSUBUWM : VXForm_1<1152, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
285                       "vsubuwm $vD, $vA, $vB", VecGeneral,
286                       [(set VRRC:$vD, (sub (v4i32 VRRC:$vA), VRRC:$vB))]>;
287                       
288 def VSUBSBS : VX1_Int<1792, "vsubsbs" , int_ppc_altivec_vsubsbs>;
289 def VSUBSHS : VX1_Int<1856, "vsubshs" , int_ppc_altivec_vsubshs>;
290 def VSUBSWS : VX1_Int<1920, "vsubsws" , int_ppc_altivec_vsubsws>;
291 def VSUBUBS : VX1_Int<1536, "vsububs" , int_ppc_altivec_vsububs>;
292 def VSUBUHS : VX1_Int<1600, "vsubuhs" , int_ppc_altivec_vsubuhs>;
293 def VSUBUWS : VX1_Int<1664, "vsubuws" , int_ppc_altivec_vsubuws>;
294 def VSUMSWS : VX1_Int<1928, "vsumsws" , int_ppc_altivec_vsumsws>;
295 def VSUM2SWS: VX1_Int<1672, "vsum2sws", int_ppc_altivec_vsum2sws>;
296 def VSUM4SBS: VX1_Int<1672, "vsum4sbs", int_ppc_altivec_vsum4sbs>;
297 def VSUM4SHS: VX1_Int<1608, "vsum4shs", int_ppc_altivec_vsum4shs>;
298 def VSUM4UBS: VX1_Int<1544, "vsum4ubs", int_ppc_altivec_vsum4ubs>;
299
300 def VNOR : VXForm_1<1284, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
301                     "vnor $vD, $vA, $vB", VecFP,
302                     [(set VRRC:$vD, (vnot (or (v4i32 VRRC:$vA), VRRC:$vB)))]>;
303 def VOR : VXForm_1<1156, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
304                       "vor $vD, $vA, $vB", VecFP,
305                       [(set VRRC:$vD, (or (v4i32 VRRC:$vA), VRRC:$vB))]>;
306 def VXOR : VXForm_1<1220, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
307                       "vxor $vD, $vA, $vB", VecFP,
308                       [(set VRRC:$vD, (xor (v4i32 VRRC:$vA), VRRC:$vB))]>;
309
310 def VRLB   : VX1_Int<   4, "vrlb", int_ppc_altivec_vrlb>;
311 def VRLH   : VX1_Int<  68, "vrlh", int_ppc_altivec_vrlh>;
312 def VRLW   : VX1_Int< 132, "vrlw", int_ppc_altivec_vrlw>;
313 def VSLO   : VX1_Int<1036, "vslo", int_ppc_altivec_vslo>;
314 def VSLB   : VX1_Int< 260, "vslb", int_ppc_altivec_vslb>;
315 def VSLH   : VX1_Int< 324, "vslh", int_ppc_altivec_vslh>;
316 def VSLW   : VX1_Int< 388, "vslw", int_ppc_altivec_vslw>;
317
318 def VSPLTB : VXForm_1<524, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
319                       "vspltb $vD, $vB, $UIMM", VecPerm,
320                       [(set VRRC:$vD, (vector_shuffle (v16i8 VRRC:$vB), (undef),
321                                       VSPLTB_shuffle_mask:$UIMM))]>;
322 def VSPLTH : VXForm_1<588, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
323                       "vsplth $vD, $vB, $UIMM", VecPerm,
324                       [(set VRRC:$vD, (vector_shuffle (v16i8 VRRC:$vB), (undef),
325                                       VSPLTH_shuffle_mask:$UIMM))]>;
326 def VSPLTW : VXForm_1<652, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB),
327                       "vspltw $vD, $vB, $UIMM", VecPerm,
328                       [(set VRRC:$vD, (vector_shuffle (v16i8 VRRC:$vB), (undef),
329                                       VSPLTW_shuffle_mask:$UIMM))]>;
330
331 def VSR    : VX1_Int< 708, "vsr"  , int_ppc_altivec_vsr>;
332 def VSRO   : VX1_Int<1100, "vsro" , int_ppc_altivec_vsro>;
333 def VSRAB  : VX1_Int< 772, "vsrab", int_ppc_altivec_vsrab>;
334 def VSRAH  : VX1_Int< 836, "vsrah", int_ppc_altivec_vsrah>;
335 def VSRAW  : VX1_Int< 900, "vsraw", int_ppc_altivec_vsraw>;
336 def VSRB   : VX1_Int< 516, "vsrb" , int_ppc_altivec_vsrb>;
337 def VSRH   : VX1_Int< 580, "vsrh" , int_ppc_altivec_vsrh>;
338 def VSRW   : VX1_Int< 644, "vsrw" , int_ppc_altivec_vsrw>;
339
340
341 def VSPLTISB : VXForm_3<780, (ops VRRC:$vD, s5imm:$SIMM),
342                        "vspltisb $vD, $SIMM", VecPerm,
343                        [(set VRRC:$vD, (v4f32 vecspltisb:$SIMM))]>;
344 def VSPLTISH : VXForm_3<844, (ops VRRC:$vD, s5imm:$SIMM),
345                        "vspltish $vD, $SIMM", VecPerm,
346                        [(set VRRC:$vD, (v4f32 vecspltish:$SIMM))]>;
347 def VSPLTISW : VXForm_3<908, (ops VRRC:$vD, s5imm:$SIMM),
348                        "vspltisw $vD, $SIMM", VecPerm,
349                        [(set VRRC:$vD, (v4f32 vecspltisw:$SIMM))]>;
350
351 // Vector Pack.
352 def VPKPX   : VX1_Int<782, "vpkpx", int_ppc_altivec_vpkpx>;
353 def VPKSHSS : VX1_Int<398, "vpkshss", int_ppc_altivec_vpkshss>;
354 def VPKSHUS : VX1_Int<270, "vpkshus", int_ppc_altivec_vpkshus>;
355 def VPKSWSS : VX1_Int<462, "vpkswss", int_ppc_altivec_vpkswss>;
356 def VPKSWUS : VX1_Int<334, "vpkswus", int_ppc_altivec_vpkswus>;
357 def VPKUHUM : VXForm_1<14, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
358                        "vpkuhum $vD, $vA, $vB", VecFP,
359                        [/*TODO*/]>;
360 def VPKUHUS : VX1_Int<142, "vpkuhus", int_ppc_altivec_vpkuhus>;
361 def VPKUWUM : VXForm_1<78, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB),
362                        "vpkuwum $vD, $vA, $vB", VecFP,
363                        [/*TODO*/]>;
364 def VPKUWUS : VX1_Int<206, "vpkuwus", int_ppc_altivec_vpkuwus>;
365
366 // Vector Unpack.
367 def VUPKHPX : VX2_Int<846, "vupkhpx", int_ppc_altivec_vupkhpx>;
368 def VUPKHSB : VX2_Int<526, "vupkhsb", int_ppc_altivec_vupkhsb>;
369 def VUPKHSH : VX2_Int<590, "vupkhsh", int_ppc_altivec_vupkhsh>;
370 def VUPKLPX : VX2_Int<974, "vupklpx", int_ppc_altivec_vupklpx>;
371 def VUPKLSB : VX2_Int<654, "vupklsb", int_ppc_altivec_vupklsb>;
372 def VUPKLSH : VX2_Int<718, "vupklsh", int_ppc_altivec_vupklsh>;
373
374
375 // Altivec Comparisons.
376
377 class VCMP<bits<10> xo, string asmstr, ValueType Ty>
378   : VXRForm_1<xo, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB), asmstr, VecFPCompare,
379               [(set VRRC:$vD, (Ty (PPCvcmp VRRC:$vA, VRRC:$vB, xo)))]>;
380 class VCMPo<bits<10> xo, string asmstr, ValueType Ty>
381   : VXRForm_1<xo, (ops VRRC:$vD, VRRC:$vA, VRRC:$vB), asmstr, VecFPCompare,
382               [(set VRRC:$vD, (Ty (PPCvcmp_o VRRC:$vA, VRRC:$vB, xo)))]> {
383   let Defs = [CR6];
384   let RC = 1;
385 }
386
387 // f32 element comparisons.0
388 def VCMPBFP   : VCMP <966, "vcmpbfp $vD, $vA, $vB"  , v4f32>;
389 def VCMPBFPo  : VCMPo<966, "vcmpbfp. $vD, $vA, $vB" , v4f32>;
390 def VCMPEQFP  : VCMP <198, "vcmpeqfp $vD, $vA, $vB" , v4f32>;
391 def VCMPEQFPo : VCMPo<198, "vcmpeqfp. $vD, $vA, $vB", v4f32>;
392 def VCMPGEFP  : VCMP <454, "vcmpgefp $vD, $vA, $vB" , v4f32>;
393 def VCMPGEFPo : VCMPo<454, "vcmpgefp. $vD, $vA, $vB", v4f32>;
394 def VCMPGTFP  : VCMP <710, "vcmpgtfp $vD, $vA, $vB" , v4f32>;
395 def VCMPGTFPo : VCMPo<710, "vcmpgtfp. $vD, $vA, $vB", v4f32>;
396
397 // i8 element comparisons.
398 def VCMPEQUB  : VCMP <  6, "vcmpequb $vD, $vA, $vB" , v16i8>;
399 def VCMPEQUBo : VCMPo<  6, "vcmpequb. $vD, $vA, $vB", v16i8>;
400 def VCMPGTSB  : VCMP <774, "vcmpgtsb $vD, $vA, $vB" , v16i8>;
401 def VCMPGTSBo : VCMPo<774, "vcmpgtsb. $vD, $vA, $vB", v16i8>;
402 def VCMPGTUB  : VCMP <518, "vcmpgtub $vD, $vA, $vB" , v16i8>;
403 def VCMPGTUBo : VCMPo<518, "vcmpgtub. $vD, $vA, $vB", v16i8>;
404
405 // i16 element comparisons.
406 def VCMPEQUH  : VCMP < 70, "vcmpequh $vD, $vA, $vB" , v8i16>;
407 def VCMPEQUHo : VCMPo< 70, "vcmpequh. $vD, $vA, $vB", v8i16>;
408 def VCMPGTSH  : VCMP <838, "vcmpgtsh $vD, $vA, $vB" , v8i16>;
409 def VCMPGTSHo : VCMPo<838, "vcmpgtsh. $vD, $vA, $vB", v8i16>;
410 def VCMPGTUH  : VCMP <582, "vcmpgtuh $vD, $vA, $vB" , v8i16>;
411 def VCMPGTUHo : VCMPo<582, "vcmpgtuh. $vD, $vA, $vB", v8i16>;
412
413 // i32 element comparisons.
414 def VCMPEQUW  : VCMP <134, "vcmpequw $vD, $vA, $vB" , v4i32>;
415 def VCMPEQUWo : VCMPo<134, "vcmpequw. $vD, $vA, $vB", v4i32>;
416 def VCMPGTSW  : VCMP <902, "vcmpgtsw $vD, $vA, $vB" , v4i32>;
417 def VCMPGTSWo : VCMPo<902, "vcmpgtsw. $vD, $vA, $vB", v4i32>;
418 def VCMPGTUW  : VCMP <646, "vcmpgtuw $vD, $vA, $vB" , v4i32>;
419 def VCMPGTUWo : VCMPo<646, "vcmpgtuw. $vD, $vA, $vB", v4i32>;
420                       
421 def V_SET0 : VXForm_setzero<1220, (ops VRRC:$vD),
422                       "vxor $vD, $vD, $vD", VecFP,
423                       [(set VRRC:$vD, (v4f32 immAllZerosV))]>;
424 }
425
426 //===----------------------------------------------------------------------===//
427 // Additional Altivec Patterns
428 //
429
430 // Undef/Zero.
431 def : Pat<(v16i8 (undef)), (v16i8 (IMPLICIT_DEF_VRRC))>;
432 def : Pat<(v8i16 (undef)), (v8i16 (IMPLICIT_DEF_VRRC))>;
433 def : Pat<(v4i32 (undef)), (v4i32 (IMPLICIT_DEF_VRRC))>;
434 def : Pat<(v16i8 immAllZerosV), (v16i8 (V_SET0))>;
435 def : Pat<(v8i16 immAllZerosV), (v8i16 (V_SET0))>;
436 def : Pat<(v4i32 immAllZerosV), (v4i32 (V_SET0))>;
437
438 // Loads.
439 def : Pat<(v16i8 (load xoaddr:$src)), (v16i8 (LVX xoaddr:$src))>;
440 def : Pat<(v8i16 (load xoaddr:$src)), (v8i16 (LVX xoaddr:$src))>;
441 def : Pat<(v4i32 (load xoaddr:$src)), (v4i32 (LVX xoaddr:$src))>;
442 def : Pat<(v4f32 (load xoaddr:$src)), (v4f32 (LVX xoaddr:$src))>;
443
444 // Stores.
445 def : Pat<(store (v16i8 VRRC:$rS), xoaddr:$dst),
446           (STVX (v16i8 VRRC:$rS), xoaddr:$dst)>;
447 def : Pat<(store (v8i16 VRRC:$rS), xoaddr:$dst),
448           (STVX (v8i16 VRRC:$rS), xoaddr:$dst)>;
449 def : Pat<(store (v4i32 VRRC:$rS), xoaddr:$dst),
450           (STVX (v4i32 VRRC:$rS), xoaddr:$dst)>;
451 def : Pat<(store (v4f32 VRRC:$rS), xoaddr:$dst),
452           (STVX (v4f32 VRRC:$rS), xoaddr:$dst)>;
453
454 // Bit conversions.
455 def : Pat<(v16i8 (bitconvert (v8i16 VRRC:$src))), (v16i8 VRRC:$src)>;
456 def : Pat<(v16i8 (bitconvert (v4i32 VRRC:$src))), (v16i8 VRRC:$src)>;
457 def : Pat<(v16i8 (bitconvert (v4f32 VRRC:$src))), (v16i8 VRRC:$src)>;
458
459 def : Pat<(v8i16 (bitconvert (v16i8 VRRC:$src))), (v8i16 VRRC:$src)>;
460 def : Pat<(v8i16 (bitconvert (v4i32 VRRC:$src))), (v8i16 VRRC:$src)>;
461 def : Pat<(v8i16 (bitconvert (v4f32 VRRC:$src))), (v8i16 VRRC:$src)>;
462
463 def : Pat<(v4i32 (bitconvert (v16i8 VRRC:$src))), (v4i32 VRRC:$src)>;
464 def : Pat<(v4i32 (bitconvert (v8i16 VRRC:$src))), (v4i32 VRRC:$src)>;
465 def : Pat<(v4i32 (bitconvert (v4f32 VRRC:$src))), (v4i32 VRRC:$src)>;
466
467 def : Pat<(v4f32 (bitconvert (v16i8 VRRC:$src))), (v4f32 VRRC:$src)>;
468 def : Pat<(v4f32 (bitconvert (v8i16 VRRC:$src))), (v4f32 VRRC:$src)>;
469 def : Pat<(v4f32 (bitconvert (v4i32 VRRC:$src))), (v4f32 VRRC:$src)>;
470
471 // Immediate vector formation with vsplti*.
472 def : Pat<(v16i8 vecspltisb:$invec), (v16i8 (VSPLTISB vecspltisb:$invec))>;
473 def : Pat<(v16i8 vecspltish:$invec), (v16i8 (VSPLTISH vecspltish:$invec))>;
474 def : Pat<(v16i8 vecspltisw:$invec), (v16i8 (VSPLTISW vecspltisw:$invec))>;
475
476 def : Pat<(v8i16 vecspltisb:$invec), (v8i16 (VSPLTISB vecspltisb:$invec))>;
477 def : Pat<(v8i16 vecspltish:$invec), (v8i16 (VSPLTISH vecspltish:$invec))>;
478 def : Pat<(v8i16 vecspltisw:$invec), (v8i16 (VSPLTISW vecspltisw:$invec))>;
479
480 def : Pat<(v4i32 vecspltisb:$invec), (v4i32 (VSPLTISB vecspltisb:$invec))>;
481 def : Pat<(v4i32 vecspltish:$invec), (v4i32 (VSPLTISH vecspltish:$invec))>;
482 def : Pat<(v4i32 vecspltisw:$invec), (v4i32 (VSPLTISW vecspltisw:$invec))>;
483
484 // Logical Operations
485 def : Pat<(v16i8 (vnot VRRC:$vA)), (v16i8 (VNOR VRRC:$vA, VRRC:$vA))>;
486 def : Pat<(v8i16 (vnot VRRC:$vA)), (v8i16 (VNOR VRRC:$vA, VRRC:$vA))>;
487 def : Pat<(v4i32 (vnot VRRC:$vA)), (v4i32 (VNOR VRRC:$vA, VRRC:$vA))>;
488
489 def : Pat<(v16i8 (and VRRC:$A, VRRC:$B)), (v16i8 (VAND VRRC:$A, VRRC:$B))>;
490 def : Pat<(v8i16 (and VRRC:$A, VRRC:$B)), (v8i16 (VAND VRRC:$A, VRRC:$B))>;
491 def : Pat<(v16i8 (or  VRRC:$A, VRRC:$B)), (v16i8 (VOR  VRRC:$A, VRRC:$B))>;
492 def : Pat<(v8i16 (or  VRRC:$A, VRRC:$B)), (v8i16 (VOR  VRRC:$A, VRRC:$B))>;
493 def : Pat<(v16i8 (xor VRRC:$A, VRRC:$B)), (v16i8 (VXOR VRRC:$A, VRRC:$B))>;
494 def : Pat<(v8i16 (xor VRRC:$A, VRRC:$B)), (v8i16 (VXOR VRRC:$A, VRRC:$B))>;
495 def : Pat<(v16i8 (vnot (or VRRC:$A, VRRC:$B))),(v16i8 (VNOR VRRC:$A, VRRC:$B))>;
496 def : Pat<(v8i16 (vnot (or VRRC:$A, VRRC:$B))),(v8i16 (VNOR VRRC:$A, VRRC:$B))>;
497 def : Pat<(v16i8 (and VRRC:$A, (vnot VRRC:$B))),
498           (v16i8 (VANDC VRRC:$A, VRRC:$B))>;
499 def : Pat<(v8i16 (and VRRC:$A, (vnot VRRC:$B))),
500           (v8i16 (VANDC VRRC:$A, VRRC:$B))>;
501
502 def : Pat<(fmul VRRC:$vA, VRRC:$vB),
503           (VMADDFP VRRC:$vA, VRRC:$vB, (V_SET0))>; 
504
505 // Fused multiply add and multiply sub for packed float.  These are represented
506 // separately from the real instructions above, for operations that must have
507 // the additional precision, such as Newton-Rhapson (used by divide, sqrt)
508 def : Pat<(PPCvmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
509           (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
510 def : Pat<(PPCvnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
511           (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
512
513 def : Pat<(int_ppc_altivec_vmaddfp VRRC:$A, VRRC:$B, VRRC:$C),
514           (VMADDFP VRRC:$A, VRRC:$B, VRRC:$C)>;
515 def : Pat<(int_ppc_altivec_vnmsubfp VRRC:$A, VRRC:$B, VRRC:$C),
516           (VNMSUBFP VRRC:$A, VRRC:$B, VRRC:$C)>;
517
518 def : Pat<(PPCvperm (v16i8 VRRC:$vA), VRRC:$vB, VRRC:$vC),
519           (v16i8 (VPERM VRRC:$vA, VRRC:$vB, VRRC:$vC))>;