OSDN Git Service

* config/epiphany/epiphany.h (USE_LOAD_POST_INCREMENT): Define.
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / altivec.md
1 ;; AltiVec patterns.
2 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Aldy Hernandez (aldy@quesejoda.com)
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 3, or (at your
11 ;; option) any later version.
12
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16 ;; License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22 (define_c_enum "unspec"
23   [UNSPEC_VCMPBFP
24    UNSPEC_VMSUMU
25    UNSPEC_VMSUMM
26    UNSPEC_VMSUMSHM
27    UNSPEC_VMSUMUHS
28    UNSPEC_VMSUMSHS
29    UNSPEC_VMHADDSHS
30    UNSPEC_VMHRADDSHS
31    UNSPEC_VMLADDUHM
32    UNSPEC_VADDCUW
33    UNSPEC_VADDU
34    UNSPEC_VADDS
35    UNSPEC_VAVGU
36    UNSPEC_VAVGS
37    UNSPEC_VMULEUB
38    UNSPEC_VMULESB
39    UNSPEC_VMULEUH
40    UNSPEC_VMULESH
41    UNSPEC_VMULOUB
42    UNSPEC_VMULOSB
43    UNSPEC_VMULOUH
44    UNSPEC_VMULOSH
45    UNSPEC_VPKUHUM
46    UNSPEC_VPKUWUM
47    UNSPEC_VPKPX
48    UNSPEC_VPKSHSS
49    UNSPEC_VPKSWSS
50    UNSPEC_VPKUHUS
51    UNSPEC_VPKSHUS
52    UNSPEC_VPKUWUS
53    UNSPEC_VPKSWUS
54    UNSPEC_VSLV4SI
55    UNSPEC_VSLO
56    UNSPEC_VSR
57    UNSPEC_VSRO
58    UNSPEC_VSUBCUW
59    UNSPEC_VSUBU
60    UNSPEC_VSUBS
61    UNSPEC_VSUM4UBS
62    UNSPEC_VSUM4S
63    UNSPEC_VSUM2SWS
64    UNSPEC_VSUMSWS
65    UNSPEC_VPERM
66    UNSPEC_VPERM_UNS
67    UNSPEC_VRFIN
68    UNSPEC_VCFUX
69    UNSPEC_VCFSX
70    UNSPEC_VCTUXS
71    UNSPEC_VCTSXS
72    UNSPEC_VLOGEFP
73    UNSPEC_VEXPTEFP
74    UNSPEC_VLSDOI
75    UNSPEC_VUPKHSB
76    UNSPEC_VUPKHPX
77    UNSPEC_VUPKHSH
78    UNSPEC_VUPKLSB
79    UNSPEC_VUPKLPX
80    UNSPEC_VUPKLSH
81    UNSPEC_DST
82    UNSPEC_DSTT
83    UNSPEC_DSTST
84    UNSPEC_DSTSTT
85    UNSPEC_LVSL
86    UNSPEC_LVSR
87    UNSPEC_LVE
88    UNSPEC_STVX
89    UNSPEC_STVXL
90    UNSPEC_STVE
91    UNSPEC_SET_VSCR
92    UNSPEC_GET_VRSAVE
93    UNSPEC_LVX
94    UNSPEC_REDUC_PLUS
95    UNSPEC_VECSH
96    UNSPEC_EXTEVEN_V4SI
97    UNSPEC_EXTEVEN_V8HI
98    UNSPEC_EXTEVEN_V16QI
99    UNSPEC_EXTEVEN_V4SF
100    UNSPEC_EXTODD_V4SI
101    UNSPEC_EXTODD_V8HI
102    UNSPEC_EXTODD_V16QI
103    UNSPEC_EXTODD_V4SF
104    UNSPEC_INTERHI_V4SI
105    UNSPEC_INTERHI_V8HI
106    UNSPEC_INTERHI_V16QI
107    UNSPEC_INTERLO_V4SI
108    UNSPEC_INTERLO_V8HI
109    UNSPEC_INTERLO_V16QI
110    UNSPEC_LVLX
111    UNSPEC_LVLXL
112    UNSPEC_LVRX
113    UNSPEC_LVRXL
114    UNSPEC_STVLX
115    UNSPEC_STVLXL
116    UNSPEC_STVRX
117    UNSPEC_STVRXL
118    UNSPEC_VMULWHUB
119    UNSPEC_VMULWLUB
120    UNSPEC_VMULWHSB
121    UNSPEC_VMULWLSB
122    UNSPEC_VMULWHUH
123    UNSPEC_VMULWLUH
124    UNSPEC_VMULWHSH
125    UNSPEC_VMULWLSH
126    UNSPEC_VUPKHUB
127    UNSPEC_VUPKHUH
128    UNSPEC_VUPKLUB
129    UNSPEC_VUPKLUH
130    UNSPEC_VPERMSI
131    UNSPEC_VPERMHI
132    UNSPEC_INTERHI
133    UNSPEC_INTERLO
134    UNSPEC_VUPKHS_V4SF
135    UNSPEC_VUPKLS_V4SF
136    UNSPEC_VUPKHU_V4SF
137    UNSPEC_VUPKLU_V4SF
138 ])
139
140 (define_c_enum "unspecv"
141   [UNSPECV_SET_VRSAVE
142    UNSPECV_MTVSCR
143    UNSPECV_MFVSCR
144    UNSPECV_DSSALL
145    UNSPECV_DSS
146   ])
147
148 ;; Vec int modes
149 (define_mode_iterator VI [V4SI V8HI V16QI])
150 ;; Short vec in modes
151 (define_mode_iterator VIshort [V8HI V16QI])
152 ;; Vec float modes
153 (define_mode_iterator VF [V4SF])
154 ;; Vec modes, pity mode iterators are not composable
155 (define_mode_iterator V [V4SI V8HI V16QI V4SF])
156 ;; Vec modes for move/logical/permute ops, include vector types for move not
157 ;; otherwise handled by altivec (v2df, v2di, ti)
158 (define_mode_iterator VM [V4SI V8HI V16QI V4SF V2DF V2DI TI])
159
160 ;; Like VM, except don't do TImode
161 (define_mode_iterator VM2 [V4SI V8HI V16QI V4SF V2DF V2DI])
162
163 (define_mode_attr VI_char [(V4SI "w") (V8HI "h") (V16QI "b")])
164 (define_mode_attr VI_scalar [(V4SI "SI") (V8HI "HI") (V16QI "QI")])
165
166 ;; Vector move instructions.
167 (define_insn "*altivec_mov<mode>"
168   [(set (match_operand:VM2 0 "nonimmediate_operand" "=Z,v,v,*o,*r,*r,v,v")
169         (match_operand:VM2 1 "input_operand" "v,Z,v,r,o,r,j,W"))]
170   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)
171    && (register_operand (operands[0], <MODE>mode) 
172        || register_operand (operands[1], <MODE>mode))"
173 {
174   switch (which_alternative)
175     {
176     case 0: return "stvx %1,%y0";
177     case 1: return "lvx %0,%y1";
178     case 2: return "vor %0,%1,%1";
179     case 3: return "#";
180     case 4: return "#";
181     case 5: return "#";
182     case 6: return "vxor %0,%0,%0";
183     case 7: return output_vec_const_move (operands);
184     default: gcc_unreachable ();
185     }
186 }
187   [(set_attr "type" "vecstore,vecload,vecsimple,store,load,*,vecsimple,*")])
188
189 ;; Unlike other altivec moves, allow the GPRs, since a normal use of TImode
190 ;; is for unions.  However for plain data movement, slightly favor the vector
191 ;; loads
192 (define_insn "*altivec_movti"
193   [(set (match_operand:TI 0 "nonimmediate_operand" "=Z,v,v,?o,?r,?r,v,v")
194         (match_operand:TI 1 "input_operand" "v,Z,v,r,o,r,j,W"))]
195   "VECTOR_MEM_ALTIVEC_P (TImode)
196    && (register_operand (operands[0], TImode) 
197        || register_operand (operands[1], TImode))"
198 {
199   switch (which_alternative)
200     {
201     case 0: return "stvx %1,%y0";
202     case 1: return "lvx %0,%y1";
203     case 2: return "vor %0,%1,%1";
204     case 3: return "#";
205     case 4: return "#";
206     case 5: return "#";
207     case 6: return "vxor %0,%0,%0";
208     case 7: return output_vec_const_move (operands);
209     default: gcc_unreachable ();
210     }
211 }
212   [(set_attr "type" "vecstore,vecload,vecsimple,store,load,*,vecsimple,*")])
213
214 ;; Load up a vector with the most significant bit set by loading up -1 and
215 ;; doing a shift left
216 (define_split
217   [(set (match_operand:VM 0 "altivec_register_operand" "")
218         (match_operand:VM 1 "easy_vector_constant_msb" ""))]
219   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && reload_completed"
220   [(const_int 0)]
221 {
222   rtx dest = operands[0];
223   enum machine_mode mode = GET_MODE (operands[0]);
224   rtvec v;
225   int i, num_elements;
226
227   if (mode == V4SFmode)
228     {
229       mode = V4SImode;
230       dest = gen_lowpart (V4SImode, dest);
231     }
232
233   num_elements = GET_MODE_NUNITS (mode);
234   v = rtvec_alloc (num_elements);
235   for (i = 0; i < num_elements; i++)
236     RTVEC_ELT (v, i) = constm1_rtx;
237
238   emit_insn (gen_vec_initv4si (dest, gen_rtx_PARALLEL (mode, v)));
239   emit_insn (gen_rtx_SET (VOIDmode, dest, gen_rtx_ASHIFT (mode, dest, dest)));
240   DONE;
241 })
242
243 (define_split
244   [(set (match_operand:VM 0 "altivec_register_operand" "")
245         (match_operand:VM 1 "easy_vector_constant_add_self" ""))]
246   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && reload_completed"
247   [(set (match_dup 0) (match_dup 3))
248    (set (match_dup 0) (match_dup 4))]
249 {
250   rtx dup = gen_easy_altivec_constant (operands[1]);
251   rtx const_vec;
252   enum machine_mode op_mode = <MODE>mode;
253
254   /* Divide the operand of the resulting VEC_DUPLICATE, and use
255      simplify_rtx to make a CONST_VECTOR.  */
256   XEXP (dup, 0) = simplify_const_binary_operation (ASHIFTRT, QImode,
257                                                    XEXP (dup, 0), const1_rtx);
258   const_vec = simplify_rtx (dup);
259
260   if (op_mode == V4SFmode)
261     {
262       op_mode = V4SImode;
263       operands[0] = gen_lowpart (op_mode, operands[0]);
264     }
265   if (GET_MODE (const_vec) == op_mode)
266     operands[3] = const_vec;
267   else
268     operands[3] = gen_lowpart (op_mode, const_vec);
269   operands[4] = gen_rtx_PLUS (op_mode, operands[0], operands[0]);
270 })
271
272 (define_insn "get_vrsave_internal"
273   [(set (match_operand:SI 0 "register_operand" "=r")
274         (unspec:SI [(reg:SI 109)] UNSPEC_GET_VRSAVE))]
275   "TARGET_ALTIVEC"
276 {
277   if (TARGET_MACHO)
278      return "mfspr %0,256";
279   else
280      return "mfvrsave %0";
281 }
282   [(set_attr "type" "*")])
283
284 (define_insn "*set_vrsave_internal"
285   [(match_parallel 0 "vrsave_operation"
286      [(set (reg:SI 109)
287            (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "r")
288                                 (reg:SI 109)] UNSPECV_SET_VRSAVE))])]
289   "TARGET_ALTIVEC"
290 {
291   if (TARGET_MACHO)
292     return "mtspr 256,%1";
293   else
294     return "mtvrsave %1";
295 }
296   [(set_attr "type" "*")])
297
298 (define_insn "*save_world"
299  [(match_parallel 0 "save_world_operation"
300                   [(clobber (reg:SI 65))
301                    (use (match_operand:SI 1 "call_operand" "s"))])]
302  "TARGET_MACHO && (DEFAULT_ABI == ABI_DARWIN) && TARGET_32BIT"         
303  "bl %z1"
304   [(set_attr "type" "branch")
305    (set_attr "length" "4")])
306
307 (define_insn "*restore_world"
308  [(match_parallel 0 "restore_world_operation"
309                   [(return)
310                    (use (reg:SI 65))
311                    (use (match_operand:SI 1 "call_operand" "s"))
312                    (clobber (match_operand:SI 2 "gpc_reg_operand" "=r"))])]
313  "TARGET_MACHO && (DEFAULT_ABI == ABI_DARWIN) && TARGET_32BIT"
314  "b %z1")
315
316 ;; Simple binary operations.
317
318 ;; add
319 (define_insn "add<mode>3"
320   [(set (match_operand:VI 0 "register_operand" "=v")
321         (plus:VI (match_operand:VI 1 "register_operand" "v")
322                  (match_operand:VI 2 "register_operand" "v")))]
323   "TARGET_ALTIVEC"
324   "vaddu<VI_char>m %0,%1,%2"
325   [(set_attr "type" "vecsimple")])
326
327 (define_insn "*altivec_addv4sf3"
328   [(set (match_operand:V4SF 0 "register_operand" "=v")
329         (plus:V4SF (match_operand:V4SF 1 "register_operand" "v")
330                    (match_operand:V4SF 2 "register_operand" "v")))]
331   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
332   "vaddfp %0,%1,%2"
333   [(set_attr "type" "vecfloat")])
334
335 (define_insn "altivec_vaddcuw"
336   [(set (match_operand:V4SI 0 "register_operand" "=v")
337         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
338                       (match_operand:V4SI 2 "register_operand" "v")]
339                      UNSPEC_VADDCUW))]
340   "TARGET_ALTIVEC"
341   "vaddcuw %0,%1,%2"
342   [(set_attr "type" "vecsimple")])
343
344 (define_insn "altivec_vaddu<VI_char>s"
345   [(set (match_operand:VI 0 "register_operand" "=v")
346         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
347                     (match_operand:VI 2 "register_operand" "v")]
348                    UNSPEC_VADDU))
349    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
350   "TARGET_ALTIVEC"
351   "vaddu<VI_char>s %0,%1,%2"
352   [(set_attr "type" "vecsimple")])
353
354 (define_insn "altivec_vadds<VI_char>s"
355   [(set (match_operand:VI 0 "register_operand" "=v")
356         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
357                     (match_operand:VI 2 "register_operand" "v")]
358                    UNSPEC_VADDS))
359    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
360   "TARGET_ALTIVEC"
361   "vadds<VI_char>s %0,%1,%2"
362   [(set_attr "type" "vecsimple")])
363
364 ;; sub
365 (define_insn "sub<mode>3"
366   [(set (match_operand:VI 0 "register_operand" "=v")
367         (minus:VI (match_operand:VI 1 "register_operand" "v")
368                   (match_operand:VI 2 "register_operand" "v")))]
369   "TARGET_ALTIVEC"
370   "vsubu<VI_char>m %0,%1,%2"
371   [(set_attr "type" "vecsimple")])
372
373 (define_insn "*altivec_subv4sf3"
374   [(set (match_operand:V4SF 0 "register_operand" "=v")
375         (minus:V4SF (match_operand:V4SF 1 "register_operand" "v")
376                     (match_operand:V4SF 2 "register_operand" "v")))]
377   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
378   "vsubfp %0,%1,%2"
379   [(set_attr "type" "vecfloat")])
380
381 (define_insn "altivec_vsubcuw"
382   [(set (match_operand:V4SI 0 "register_operand" "=v")
383         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
384                       (match_operand:V4SI 2 "register_operand" "v")]
385                      UNSPEC_VSUBCUW))]
386   "TARGET_ALTIVEC"
387   "vsubcuw %0,%1,%2"
388   [(set_attr "type" "vecsimple")])
389
390 (define_insn "altivec_vsubu<VI_char>s"
391   [(set (match_operand:VI 0 "register_operand" "=v")
392         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
393                     (match_operand:VI 2 "register_operand" "v")]
394                    UNSPEC_VSUBU))
395    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
396   "TARGET_ALTIVEC"
397   "vsubu<VI_char>s %0,%1,%2"
398   [(set_attr "type" "vecsimple")])
399
400 (define_insn "altivec_vsubs<VI_char>s"
401   [(set (match_operand:VI 0 "register_operand" "=v")
402         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
403                     (match_operand:VI 2 "register_operand" "v")]
404                    UNSPEC_VSUBS))
405    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
406   "TARGET_ALTIVEC"
407   "vsubs<VI_char>s %0,%1,%2"
408   [(set_attr "type" "vecsimple")])
409
410 ;;
411 (define_insn "altivec_vavgu<VI_char>"
412   [(set (match_operand:VI 0 "register_operand" "=v")
413         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
414                     (match_operand:VI 2 "register_operand" "v")]
415                    UNSPEC_VAVGU))]
416   "TARGET_ALTIVEC"
417   "vavgu<VI_char> %0,%1,%2"
418   [(set_attr "type" "vecsimple")])
419
420 (define_insn "altivec_vavgs<VI_char>"
421   [(set (match_operand:VI 0 "register_operand" "=v")
422         (unspec:VI [(match_operand:VI 1 "register_operand" "v")
423                     (match_operand:VI 2 "register_operand" "v")]
424                    UNSPEC_VAVGS))]
425   "TARGET_ALTIVEC"
426   "vavgs<VI_char> %0,%1,%2"
427   [(set_attr "type" "vecsimple")])
428
429 (define_insn "altivec_vcmpbfp"
430   [(set (match_operand:V4SI 0 "register_operand" "=v")
431         (unspec:V4SI [(match_operand:V4SF 1 "register_operand" "v")
432                       (match_operand:V4SF 2 "register_operand" "v")] 
433                       UNSPEC_VCMPBFP))]
434   "TARGET_ALTIVEC"
435   "vcmpbfp %0,%1,%2"
436   [(set_attr "type" "veccmp")])
437
438 (define_insn "*altivec_eq<mode>"
439   [(set (match_operand:VI 0 "altivec_register_operand" "=v")
440         (eq:VI (match_operand:VI 1 "altivec_register_operand" "v")
441                (match_operand:VI 2 "altivec_register_operand" "v")))]
442   "TARGET_ALTIVEC"
443   "vcmpequ<VI_char> %0,%1,%2"
444   [(set_attr "type" "veccmp")])
445
446 (define_insn "*altivec_gt<mode>"
447   [(set (match_operand:VI 0 "altivec_register_operand" "=v")
448         (gt:VI (match_operand:VI 1 "altivec_register_operand" "v")
449                (match_operand:VI 2 "altivec_register_operand" "v")))]
450   "TARGET_ALTIVEC"
451   "vcmpgts<VI_char> %0,%1,%2"
452   [(set_attr "type" "veccmp")])
453
454 (define_insn "*altivec_gtu<mode>"
455   [(set (match_operand:VI 0 "altivec_register_operand" "=v")
456         (gtu:VI (match_operand:VI 1 "altivec_register_operand" "v")
457                 (match_operand:VI 2 "altivec_register_operand" "v")))]
458   "TARGET_ALTIVEC"
459   "vcmpgtu<VI_char> %0,%1,%2"
460   [(set_attr "type" "veccmp")])
461
462 (define_insn "*altivec_eqv4sf"
463   [(set (match_operand:V4SF 0 "altivec_register_operand" "=v")
464         (eq:V4SF (match_operand:V4SF 1 "altivec_register_operand" "v")
465                  (match_operand:V4SF 2 "altivec_register_operand" "v")))]
466   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
467   "vcmpeqfp %0,%1,%2"
468   [(set_attr "type" "veccmp")])
469
470 (define_insn "*altivec_gtv4sf"
471   [(set (match_operand:V4SF 0 "altivec_register_operand" "=v")
472         (gt:V4SF (match_operand:V4SF 1 "altivec_register_operand" "v")
473                  (match_operand:V4SF 2 "altivec_register_operand" "v")))]
474   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
475   "vcmpgtfp %0,%1,%2"
476   [(set_attr "type" "veccmp")])
477
478 (define_insn "*altivec_gev4sf"
479   [(set (match_operand:V4SF 0 "altivec_register_operand" "=v")
480         (ge:V4SF (match_operand:V4SF 1 "altivec_register_operand" "v")
481                  (match_operand:V4SF 2 "altivec_register_operand" "v")))]
482   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
483   "vcmpgefp %0,%1,%2"
484   [(set_attr "type" "veccmp")])
485
486 (define_insn "*altivec_vsel<mode>"
487   [(set (match_operand:VM 0 "altivec_register_operand" "=v")
488         (if_then_else:VM
489          (ne:CC (match_operand:VM 1 "altivec_register_operand" "v")
490                 (match_operand:VM 4 "zero_constant" ""))
491          (match_operand:VM 2 "altivec_register_operand" "v")
492          (match_operand:VM 3 "altivec_register_operand" "v")))]
493   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
494   "vsel %0,%3,%2,%1"
495   [(set_attr "type" "vecperm")])
496
497 (define_insn "*altivec_vsel<mode>_uns"
498   [(set (match_operand:VM 0 "altivec_register_operand" "=v")
499         (if_then_else:VM
500          (ne:CCUNS (match_operand:VM 1 "altivec_register_operand" "v")
501                    (match_operand:VM 4 "zero_constant" ""))
502          (match_operand:VM 2 "altivec_register_operand" "v")
503          (match_operand:VM 3 "altivec_register_operand" "v")))]
504   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
505   "vsel %0,%3,%2,%1"
506   [(set_attr "type" "vecperm")])
507
508 ;; Fused multiply add.
509
510 (define_insn "*altivec_fmav4sf4"
511   [(set (match_operand:V4SF 0 "register_operand" "=v")
512         (fma:V4SF (match_operand:V4SF 1 "register_operand" "v")
513                   (match_operand:V4SF 2 "register_operand" "v")
514                   (match_operand:V4SF 3 "register_operand" "v")))]
515   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
516   "vmaddfp %0,%1,%2,%3"
517   [(set_attr "type" "vecfloat")])
518
519 ;; We do multiply as a fused multiply-add with an add of a -0.0 vector.
520
521 (define_expand "altivec_mulv4sf3"
522   [(set (match_operand:V4SF 0 "register_operand" "")
523         (fma:V4SF (match_operand:V4SF 1 "register_operand" "")
524                   (match_operand:V4SF 2 "register_operand" "")
525                   (match_dup 3)))]
526   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
527 {
528   rtx neg0;
529
530   /* Generate [-0.0, -0.0, -0.0, -0.0].  */
531   neg0 = gen_reg_rtx (V4SImode);
532   emit_insn (gen_altivec_vspltisw (neg0, constm1_rtx));
533   emit_insn (gen_vashlv4si3 (neg0, neg0, neg0));
534
535   operands[3] = gen_lowpart (V4SFmode, neg0);
536 })
537
538 ;; 32-bit integer multiplication
539 ;; A_high = Operand_0 & 0xFFFF0000 >> 16
540 ;; A_low = Operand_0 & 0xFFFF
541 ;; B_high = Operand_1 & 0xFFFF0000 >> 16
542 ;; B_low = Operand_1 & 0xFFFF
543 ;; result = A_low * B_low + (A_high * B_low + B_high * A_low) << 16
544
545 ;; (define_insn "mulv4si3"
546 ;;   [(set (match_operand:V4SI 0 "register_operand" "=v")
547 ;;         (mult:V4SI (match_operand:V4SI 1 "register_operand" "v")
548 ;;                    (match_operand:V4SI 2 "register_operand" "v")))]
549 (define_expand "mulv4si3"
550   [(use (match_operand:V4SI 0 "register_operand" ""))
551    (use (match_operand:V4SI 1 "register_operand" ""))
552    (use (match_operand:V4SI 2 "register_operand" ""))]
553    "TARGET_ALTIVEC"
554    "
555  {
556    rtx zero;
557    rtx swap;
558    rtx small_swap;
559    rtx sixteen;
560    rtx one;
561    rtx two;
562    rtx low_product;
563    rtx high_product;
564        
565    zero = gen_reg_rtx (V4SImode);
566    emit_insn (gen_altivec_vspltisw (zero, const0_rtx));
567  
568    sixteen = gen_reg_rtx (V4SImode);   
569    emit_insn (gen_altivec_vspltisw (sixteen,  gen_rtx_CONST_INT (V4SImode, -16)));
570  
571    swap = gen_reg_rtx (V4SImode);
572    emit_insn (gen_vrotlv4si3 (swap, operands[2], sixteen));
573  
574    one = gen_reg_rtx (V8HImode);
575    convert_move (one, operands[1], 0);
576  
577    two = gen_reg_rtx (V8HImode);
578    convert_move (two, operands[2], 0);
579  
580    small_swap = gen_reg_rtx (V8HImode);
581    convert_move (small_swap, swap, 0);
582  
583    low_product = gen_reg_rtx (V4SImode);
584    emit_insn (gen_altivec_vmulouh (low_product, one, two));
585  
586    high_product = gen_reg_rtx (V4SImode);
587    emit_insn (gen_altivec_vmsumuhm (high_product, one, small_swap, zero));
588  
589    emit_insn (gen_vashlv4si3 (high_product, high_product, sixteen));
590  
591    emit_insn (gen_addv4si3 (operands[0], high_product, low_product));
592    
593    DONE;
594  }")
595  
596 (define_expand "mulv8hi3"
597   [(use (match_operand:V8HI 0 "register_operand" ""))
598    (use (match_operand:V8HI 1 "register_operand" ""))
599    (use (match_operand:V8HI 2 "register_operand" ""))]
600    "TARGET_ALTIVEC"
601    "
602 {
603    rtx odd = gen_reg_rtx (V4SImode);
604    rtx even = gen_reg_rtx (V4SImode);
605    rtx high = gen_reg_rtx (V4SImode);
606    rtx low = gen_reg_rtx (V4SImode);
607
608    emit_insn (gen_altivec_vmulesh (even, operands[1], operands[2]));
609    emit_insn (gen_altivec_vmulosh (odd, operands[1], operands[2]));
610
611    emit_insn (gen_altivec_vmrghw (high, even, odd));
612    emit_insn (gen_altivec_vmrglw (low, even, odd));
613
614    emit_insn (gen_altivec_vpkuwum (operands[0], high, low));
615
616    DONE;
617 }")
618
619 ;; Fused multiply subtract 
620 (define_insn "*altivec_vnmsubfp"
621   [(set (match_operand:V4SF 0 "register_operand" "=v")
622         (neg:V4SF
623          (fma:V4SF (match_operand:V4SF 1 "register_operand" "v")
624                    (match_operand:V4SF 2 "register_operand" "v")
625                    (neg:V4SF
626                     (match_operand:V4SF 3 "register_operand" "v")))))]
627   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
628   "vnmsubfp %0,%1,%2,%3"
629   [(set_attr "type" "vecfloat")])
630
631 (define_insn "altivec_vmsumu<VI_char>m"
632   [(set (match_operand:V4SI 0 "register_operand" "=v")
633         (unspec:V4SI [(match_operand:VIshort 1 "register_operand" "v")
634                       (match_operand:VIshort 2 "register_operand" "v")
635                       (match_operand:V4SI 3 "register_operand" "v")]
636                      UNSPEC_VMSUMU))]
637   "TARGET_ALTIVEC"
638   "vmsumu<VI_char>m %0,%1,%2,%3"
639   [(set_attr "type" "veccomplex")])
640
641 (define_insn "altivec_vmsumm<VI_char>m"
642   [(set (match_operand:V4SI 0 "register_operand" "=v")
643         (unspec:V4SI [(match_operand:VIshort 1 "register_operand" "v")
644                       (match_operand:VIshort 2 "register_operand" "v")
645                       (match_operand:V4SI 3 "register_operand" "v")]
646                      UNSPEC_VMSUMM))]
647   "TARGET_ALTIVEC"
648   "vmsumm<VI_char>m %0,%1,%2,%3"
649   [(set_attr "type" "veccomplex")])
650
651 (define_insn "altivec_vmsumshm"
652   [(set (match_operand:V4SI 0 "register_operand" "=v")
653         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
654                       (match_operand:V8HI 2 "register_operand" "v")
655                       (match_operand:V4SI 3 "register_operand" "v")]
656                      UNSPEC_VMSUMSHM))]
657   "TARGET_ALTIVEC"
658   "vmsumshm %0,%1,%2,%3"
659   [(set_attr "type" "veccomplex")])
660
661 (define_insn "altivec_vmsumuhs"
662   [(set (match_operand:V4SI 0 "register_operand" "=v")
663         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
664                       (match_operand:V8HI 2 "register_operand" "v")
665                       (match_operand:V4SI 3 "register_operand" "v")]
666                      UNSPEC_VMSUMUHS))
667    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
668   "TARGET_ALTIVEC"
669   "vmsumuhs %0,%1,%2,%3"
670   [(set_attr "type" "veccomplex")])
671
672 (define_insn "altivec_vmsumshs"
673   [(set (match_operand:V4SI 0 "register_operand" "=v")
674         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
675                       (match_operand:V8HI 2 "register_operand" "v")
676                       (match_operand:V4SI 3 "register_operand" "v")]
677                      UNSPEC_VMSUMSHS))
678    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
679   "TARGET_ALTIVEC"
680   "vmsumshs %0,%1,%2,%3"
681   [(set_attr "type" "veccomplex")])
682
683 ;; max
684
685 (define_insn "umax<mode>3"
686   [(set (match_operand:VI 0 "register_operand" "=v")
687         (umax:VI (match_operand:VI 1 "register_operand" "v")
688                  (match_operand:VI 2 "register_operand" "v")))]
689   "TARGET_ALTIVEC"
690   "vmaxu<VI_char> %0,%1,%2"
691   [(set_attr "type" "vecsimple")])
692
693 (define_insn "smax<mode>3"
694   [(set (match_operand:VI 0 "register_operand" "=v")
695         (smax:VI (match_operand:VI 1 "register_operand" "v")
696                  (match_operand:VI 2 "register_operand" "v")))]
697   "TARGET_ALTIVEC"
698   "vmaxs<VI_char> %0,%1,%2"
699   [(set_attr "type" "vecsimple")])
700
701 (define_insn "*altivec_smaxv4sf3"
702   [(set (match_operand:V4SF 0 "register_operand" "=v")
703         (smax:V4SF (match_operand:V4SF 1 "register_operand" "v")
704                    (match_operand:V4SF 2 "register_operand" "v")))]
705   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
706   "vmaxfp %0,%1,%2"
707   [(set_attr "type" "veccmp")])
708
709 (define_insn "umin<mode>3"
710   [(set (match_operand:VI 0 "register_operand" "=v")
711         (umin:VI (match_operand:VI 1 "register_operand" "v")
712                  (match_operand:VI 2 "register_operand" "v")))]
713   "TARGET_ALTIVEC"
714   "vminu<VI_char> %0,%1,%2"
715   [(set_attr "type" "vecsimple")])
716
717 (define_insn "smin<mode>3"
718   [(set (match_operand:VI 0 "register_operand" "=v")
719         (smin:VI (match_operand:VI 1 "register_operand" "v")
720                  (match_operand:VI 2 "register_operand" "v")))]
721   "TARGET_ALTIVEC"
722   "vmins<VI_char> %0,%1,%2"
723   [(set_attr "type" "vecsimple")])
724
725 (define_insn "*altivec_sminv4sf3"
726   [(set (match_operand:V4SF 0 "register_operand" "=v")
727         (smin:V4SF (match_operand:V4SF 1 "register_operand" "v")
728                    (match_operand:V4SF 2 "register_operand" "v")))]
729   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
730   "vminfp %0,%1,%2"
731   [(set_attr "type" "veccmp")])
732
733 (define_insn "altivec_vmhaddshs"
734   [(set (match_operand:V8HI 0 "register_operand" "=v")
735         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "v")
736                       (match_operand:V8HI 2 "register_operand" "v")
737                       (match_operand:V8HI 3 "register_operand" "v")]
738                      UNSPEC_VMHADDSHS))
739    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
740   "TARGET_ALTIVEC"
741   "vmhaddshs %0,%1,%2,%3"
742   [(set_attr "type" "veccomplex")])
743
744 (define_insn "altivec_vmhraddshs"
745   [(set (match_operand:V8HI 0 "register_operand" "=v")
746         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "v")
747                       (match_operand:V8HI 2 "register_operand" "v")
748                       (match_operand:V8HI 3 "register_operand" "v")]
749                      UNSPEC_VMHRADDSHS))
750    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
751   "TARGET_ALTIVEC"
752   "vmhraddshs %0,%1,%2,%3"
753   [(set_attr "type" "veccomplex")])
754
755 (define_insn "altivec_vmladduhm"
756   [(set (match_operand:V8HI 0 "register_operand" "=v")
757         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "v")
758                       (match_operand:V8HI 2 "register_operand" "v")
759                       (match_operand:V8HI 3 "register_operand" "v")]
760                      UNSPEC_VMLADDUHM))]
761   "TARGET_ALTIVEC"
762   "vmladduhm %0,%1,%2,%3"
763   [(set_attr "type" "veccomplex")])
764
765 (define_insn "altivec_vmrghb"
766   [(set (match_operand:V16QI 0 "register_operand" "=v")
767         (vec_merge:V16QI (vec_select:V16QI (match_operand:V16QI 1 "register_operand" "v")
768                                            (parallel [(const_int 0)
769                                                       (const_int 8)
770                                                       (const_int 1)
771                                                       (const_int 9)
772                                                       (const_int 2)
773                                                       (const_int 10)
774                                                       (const_int 3)
775                                                       (const_int 11)
776                                                       (const_int 4)
777                                                       (const_int 12)
778                                                       (const_int 5)
779                                                       (const_int 13)
780                                                       (const_int 6)
781                                                       (const_int 14)
782                                                       (const_int 7)
783                                                       (const_int 15)]))
784                         (vec_select:V16QI (match_operand:V16QI 2 "register_operand" "v")
785                                            (parallel [(const_int 8)
786                                                       (const_int 0)
787                                                       (const_int 9)
788                                                       (const_int 1)
789                                                       (const_int 10)
790                                                       (const_int 2)
791                                                       (const_int 11)
792                                                       (const_int 3)
793                                                       (const_int 12)
794                                                       (const_int 4)
795                                                       (const_int 13)
796                                                       (const_int 5)
797                                                       (const_int 14)
798                                                       (const_int 6)
799                                                       (const_int 15)
800                                                       (const_int 7)]))
801                       (const_int 21845)))]
802   "TARGET_ALTIVEC"
803   "vmrghb %0,%1,%2"
804   [(set_attr "type" "vecperm")])
805
806 (define_insn "altivec_vmrghh"
807   [(set (match_operand:V8HI 0 "register_operand" "=v")
808         (vec_merge:V8HI (vec_select:V8HI (match_operand:V8HI 1 "register_operand" "v")
809                                            (parallel [(const_int 0)
810                                                       (const_int 4)
811                                                       (const_int 1)
812                                                       (const_int 5)
813                                                       (const_int 2)
814                                                       (const_int 6)
815                                                       (const_int 3)
816                                                       (const_int 7)]))
817                         (vec_select:V8HI (match_operand:V8HI 2 "register_operand" "v")
818                                            (parallel [(const_int 4)
819                                                       (const_int 0)
820                                                       (const_int 5)
821                                                       (const_int 1)
822                                                       (const_int 6)
823                                                       (const_int 2)
824                                                       (const_int 7)
825                                                       (const_int 3)]))
826                       (const_int 85)))]
827   "TARGET_ALTIVEC"
828   "vmrghh %0,%1,%2"
829   [(set_attr "type" "vecperm")])
830
831 (define_insn "altivec_vmrghw"
832   [(set (match_operand:V4SI 0 "register_operand" "=v")
833         (vec_merge:V4SI (vec_select:V4SI (match_operand:V4SI 1 "register_operand" "v")
834                                          (parallel [(const_int 0)
835                                                     (const_int 2)
836                                                     (const_int 1)
837                                                     (const_int 3)]))
838                         (vec_select:V4SI (match_operand:V4SI 2 "register_operand" "v")
839                                          (parallel [(const_int 2)
840                                                     (const_int 0)
841                                                     (const_int 3)
842                                                     (const_int 1)]))
843                       (const_int 5)))]
844   "VECTOR_MEM_ALTIVEC_P (V4SImode)"
845   "vmrghw %0,%1,%2"
846   [(set_attr "type" "vecperm")])
847
848 (define_insn "*altivec_vmrghsf"
849   [(set (match_operand:V4SF 0 "register_operand" "=v")
850         (vec_merge:V4SF (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "v")
851                                          (parallel [(const_int 0)
852                                                     (const_int 2)
853                                                     (const_int 1)
854                                                     (const_int 3)]))
855                         (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "v")
856                                          (parallel [(const_int 2)
857                                                     (const_int 0)
858                                                     (const_int 3)
859                                                     (const_int 1)]))
860                       (const_int 5)))]
861   "VECTOR_MEM_ALTIVEC_P (V4SFmode)"
862   "vmrghw %0,%1,%2"
863   [(set_attr "type" "vecperm")])
864
865 (define_insn "altivec_vmrglb"
866   [(set (match_operand:V16QI 0 "register_operand" "=v")
867         (vec_merge:V16QI (vec_select:V16QI (match_operand:V16QI 1 "register_operand" "v")
868                                            (parallel [(const_int 8)
869                                                       (const_int 0)
870                                                       (const_int 9)
871                                                       (const_int 1)
872                                                       (const_int 10)
873                                                       (const_int 2)
874                                                       (const_int 11)
875                                                       (const_int 3)
876                                                       (const_int 12)
877                                                       (const_int 4)
878                                                       (const_int 13)
879                                                       (const_int 5)
880                                                       (const_int 14)
881                                                       (const_int 6)
882                                                       (const_int 15)
883                                                       (const_int 7)]))
884                       (vec_select:V16QI (match_operand:V16QI 2 "register_operand" "v")
885                                            (parallel [(const_int 0)
886                                                       (const_int 8)
887                                                       (const_int 1)
888                                                       (const_int 9)
889                                                       (const_int 2)
890                                                       (const_int 10)
891                                                       (const_int 3)
892                                                       (const_int 11)
893                                                       (const_int 4)
894                                                       (const_int 12)
895                                                       (const_int 5)
896                                                       (const_int 13)
897                                                       (const_int 6)
898                                                       (const_int 14)
899                                                       (const_int 7)
900                                                       (const_int 15)]))
901                       (const_int 21845)))]
902   "TARGET_ALTIVEC"
903   "vmrglb %0,%1,%2"
904   [(set_attr "type" "vecperm")])
905
906 (define_insn "altivec_vmrglh"
907   [(set (match_operand:V8HI 0 "register_operand" "=v")
908         (vec_merge:V8HI (vec_select:V8HI (match_operand:V8HI 1 "register_operand" "v")
909                                            (parallel [(const_int 4)
910                                                       (const_int 0)
911                                                       (const_int 5)
912                                                       (const_int 1)
913                                                       (const_int 6)
914                                                       (const_int 2)
915                                                       (const_int 7)
916                                                       (const_int 3)]))
917                         (vec_select:V8HI (match_operand:V8HI 2 "register_operand" "v")
918                                            (parallel [(const_int 0)
919                                                       (const_int 4)
920                                                       (const_int 1)
921                                                       (const_int 5)
922                                                       (const_int 2)
923                                                       (const_int 6)
924                                                       (const_int 3)
925                                                       (const_int 7)]))
926                       (const_int 85)))]
927   "TARGET_ALTIVEC"
928   "vmrglh %0,%1,%2"
929   [(set_attr "type" "vecperm")])
930
931 (define_insn "altivec_vmrglw"
932   [(set (match_operand:V4SI 0 "register_operand" "=v")
933         (vec_merge:V4SI
934          (vec_select:V4SI (match_operand:V4SI 1 "register_operand" "v")
935                           (parallel [(const_int 2)
936                                      (const_int 0)
937                                      (const_int 3)
938                                      (const_int 1)]))
939          (vec_select:V4SI (match_operand:V4SI 2 "register_operand" "v")
940                           (parallel [(const_int 0)
941                                      (const_int 2)
942                                      (const_int 1)
943                                      (const_int 3)]))
944          (const_int 5)))]
945   "VECTOR_MEM_ALTIVEC_P (V4SImode)"
946   "vmrglw %0,%1,%2"
947   [(set_attr "type" "vecperm")])
948
949 (define_insn "*altivec_vmrglsf"
950   [(set (match_operand:V4SF 0 "register_operand" "=v")
951         (vec_merge:V4SF
952          (vec_select:V4SF (match_operand:V4SF 1 "register_operand" "v")
953                           (parallel [(const_int 2)
954                                      (const_int 0)
955                                      (const_int 3)
956                                      (const_int 1)]))
957          (vec_select:V4SF (match_operand:V4SF 2 "register_operand" "v")
958                           (parallel [(const_int 0)
959                                      (const_int 2)
960                                      (const_int 1)
961                                      (const_int 3)]))
962          (const_int 5)))]
963   "VECTOR_MEM_ALTIVEC_P (V4SFmode)"
964   "vmrglw %0,%1,%2"
965   [(set_attr "type" "vecperm")])
966
967 (define_insn "altivec_vmuleub"
968   [(set (match_operand:V8HI 0 "register_operand" "=v")
969         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
970                       (match_operand:V16QI 2 "register_operand" "v")]
971                      UNSPEC_VMULEUB))]
972   "TARGET_ALTIVEC"
973   "vmuleub %0,%1,%2"
974   [(set_attr "type" "veccomplex")])
975
976 (define_insn "altivec_vmulesb"
977   [(set (match_operand:V8HI 0 "register_operand" "=v")
978         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
979                       (match_operand:V16QI 2 "register_operand" "v")]
980                      UNSPEC_VMULESB))]
981   "TARGET_ALTIVEC"
982   "vmulesb %0,%1,%2"
983   [(set_attr "type" "veccomplex")])
984
985 (define_insn "altivec_vmuleuh"
986   [(set (match_operand:V4SI 0 "register_operand" "=v")
987         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
988                       (match_operand:V8HI 2 "register_operand" "v")]
989                      UNSPEC_VMULEUH))]
990   "TARGET_ALTIVEC"
991   "vmuleuh %0,%1,%2"
992   [(set_attr "type" "veccomplex")])
993
994 (define_insn "altivec_vmulesh"
995   [(set (match_operand:V4SI 0 "register_operand" "=v")
996         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
997                       (match_operand:V8HI 2 "register_operand" "v")]
998                      UNSPEC_VMULESH))]
999   "TARGET_ALTIVEC"
1000   "vmulesh %0,%1,%2"
1001   [(set_attr "type" "veccomplex")])
1002
1003 (define_insn "altivec_vmuloub"
1004   [(set (match_operand:V8HI 0 "register_operand" "=v")
1005         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
1006                       (match_operand:V16QI 2 "register_operand" "v")]
1007                      UNSPEC_VMULOUB))]
1008   "TARGET_ALTIVEC"
1009   "vmuloub %0,%1,%2"
1010   [(set_attr "type" "veccomplex")])
1011
1012 (define_insn "altivec_vmulosb"
1013   [(set (match_operand:V8HI 0 "register_operand" "=v")
1014         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
1015                       (match_operand:V16QI 2 "register_operand" "v")]
1016                      UNSPEC_VMULOSB))]
1017   "TARGET_ALTIVEC"
1018   "vmulosb %0,%1,%2"
1019   [(set_attr "type" "veccomplex")])
1020
1021 (define_insn "altivec_vmulouh"
1022   [(set (match_operand:V4SI 0 "register_operand" "=v")
1023         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
1024                       (match_operand:V8HI 2 "register_operand" "v")]
1025                      UNSPEC_VMULOUH))]
1026   "TARGET_ALTIVEC"
1027   "vmulouh %0,%1,%2"
1028   [(set_attr "type" "veccomplex")])
1029
1030 (define_insn "altivec_vmulosh"
1031   [(set (match_operand:V4SI 0 "register_operand" "=v")
1032         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
1033                       (match_operand:V8HI 2 "register_operand" "v")]
1034                      UNSPEC_VMULOSH))]
1035   "TARGET_ALTIVEC"
1036   "vmulosh %0,%1,%2"
1037   [(set_attr "type" "veccomplex")])
1038
1039
1040 ;; logical ops.  Have the logical ops follow the memory ops in
1041 ;; terms of whether to prefer VSX or Altivec
1042
1043 (define_insn "*altivec_and<mode>3"
1044   [(set (match_operand:VM 0 "register_operand" "=v")
1045         (and:VM (match_operand:VM 1 "register_operand" "v")
1046                 (match_operand:VM 2 "register_operand" "v")))]
1047   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1048   "vand %0,%1,%2"
1049   [(set_attr "type" "vecsimple")])
1050
1051 (define_insn "*altivec_ior<mode>3"
1052   [(set (match_operand:VM 0 "register_operand" "=v")
1053         (ior:VM (match_operand:VM 1 "register_operand" "v")
1054                 (match_operand:VM 2 "register_operand" "v")))]
1055   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1056   "vor %0,%1,%2"
1057   [(set_attr "type" "vecsimple")])
1058
1059 (define_insn "*altivec_xor<mode>3"
1060   [(set (match_operand:VM 0 "register_operand" "=v")
1061         (xor:VM (match_operand:VM 1 "register_operand" "v")
1062                 (match_operand:VM 2 "register_operand" "v")))]
1063   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1064   "vxor %0,%1,%2"
1065   [(set_attr "type" "vecsimple")])
1066
1067 (define_insn "*altivec_one_cmpl<mode>2"
1068   [(set (match_operand:VM 0 "register_operand" "=v")
1069         (not:VM (match_operand:VM 1 "register_operand" "v")))]
1070   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1071   "vnor %0,%1,%1"
1072   [(set_attr "type" "vecsimple")])
1073   
1074 (define_insn "*altivec_nor<mode>3"
1075   [(set (match_operand:VM 0 "register_operand" "=v")
1076         (not:VM (ior:VM (match_operand:VM 1 "register_operand" "v")
1077                         (match_operand:VM 2 "register_operand" "v"))))]
1078   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1079   "vnor %0,%1,%2"
1080   [(set_attr "type" "vecsimple")])
1081
1082 (define_insn "*altivec_andc<mode>3"
1083   [(set (match_operand:VM 0 "register_operand" "=v")
1084         (and:VM (not:VM (match_operand:VM 2 "register_operand" "v"))
1085                 (match_operand:VM 1 "register_operand" "v")))]
1086   "VECTOR_MEM_ALTIVEC_P (<MODE>mode)"
1087   "vandc %0,%1,%2"
1088   [(set_attr "type" "vecsimple")])
1089
1090 (define_insn "altivec_vpkuhum"
1091   [(set (match_operand:V16QI 0 "register_operand" "=v")
1092         (unspec:V16QI [(match_operand:V8HI 1 "register_operand" "v")
1093                        (match_operand:V8HI 2 "register_operand" "v")]
1094                       UNSPEC_VPKUHUM))]
1095   "TARGET_ALTIVEC"
1096   "vpkuhum %0,%1,%2"
1097   [(set_attr "type" "vecperm")])
1098
1099 (define_insn "altivec_vpkuwum"
1100   [(set (match_operand:V8HI 0 "register_operand" "=v")
1101         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
1102                       (match_operand:V4SI 2 "register_operand" "v")]
1103                      UNSPEC_VPKUWUM))]
1104   "TARGET_ALTIVEC"
1105   "vpkuwum %0,%1,%2"
1106   [(set_attr "type" "vecperm")])
1107
1108 (define_insn "altivec_vpkpx"
1109   [(set (match_operand:V8HI 0 "register_operand" "=v")
1110         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
1111                       (match_operand:V4SI 2 "register_operand" "v")]
1112                      UNSPEC_VPKPX))]
1113   "TARGET_ALTIVEC"
1114   "vpkpx %0,%1,%2"
1115   [(set_attr "type" "vecperm")])
1116
1117 (define_insn "altivec_vpkshss"
1118   [(set (match_operand:V16QI 0 "register_operand" "=v")
1119         (unspec:V16QI [(match_operand:V8HI 1 "register_operand" "v")
1120                        (match_operand:V8HI 2 "register_operand" "v")]
1121                       UNSPEC_VPKSHSS))
1122    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1123   "TARGET_ALTIVEC"
1124   "vpkshss %0,%1,%2"
1125   [(set_attr "type" "vecperm")])
1126
1127 (define_insn "altivec_vpkswss"
1128   [(set (match_operand:V8HI 0 "register_operand" "=v")
1129         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
1130                       (match_operand:V4SI 2 "register_operand" "v")]
1131                      UNSPEC_VPKSWSS))
1132    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1133   "TARGET_ALTIVEC"
1134   "vpkswss %0,%1,%2"
1135   [(set_attr "type" "vecperm")])
1136
1137 (define_insn "altivec_vpkuhus"
1138   [(set (match_operand:V16QI 0 "register_operand" "=v")
1139         (unspec:V16QI [(match_operand:V8HI 1 "register_operand" "v")
1140                        (match_operand:V8HI 2 "register_operand" "v")]
1141                       UNSPEC_VPKUHUS))
1142    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1143   "TARGET_ALTIVEC"
1144   "vpkuhus %0,%1,%2"
1145   [(set_attr "type" "vecperm")])
1146
1147 (define_insn "altivec_vpkshus"
1148   [(set (match_operand:V16QI 0 "register_operand" "=v")
1149         (unspec:V16QI [(match_operand:V8HI 1 "register_operand" "v")
1150                        (match_operand:V8HI 2 "register_operand" "v")]
1151                       UNSPEC_VPKSHUS))
1152    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1153   "TARGET_ALTIVEC"
1154   "vpkshus %0,%1,%2"
1155   [(set_attr "type" "vecperm")])
1156
1157 (define_insn "altivec_vpkuwus"
1158   [(set (match_operand:V8HI 0 "register_operand" "=v")
1159         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
1160                       (match_operand:V4SI 2 "register_operand" "v")]
1161                      UNSPEC_VPKUWUS))
1162    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1163   "TARGET_ALTIVEC"
1164   "vpkuwus %0,%1,%2"
1165   [(set_attr "type" "vecperm")])
1166
1167 (define_insn "altivec_vpkswus"
1168   [(set (match_operand:V8HI 0 "register_operand" "=v")
1169         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
1170                       (match_operand:V4SI 2 "register_operand" "v")]
1171                      UNSPEC_VPKSWUS))
1172    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1173   "TARGET_ALTIVEC"
1174   "vpkswus %0,%1,%2"
1175   [(set_attr "type" "vecperm")])
1176
1177 (define_insn "*altivec_vrl<VI_char>"
1178   [(set (match_operand:VI 0 "register_operand" "=v")
1179         (rotate:VI (match_operand:VI 1 "register_operand" "v")
1180                    (match_operand:VI 2 "register_operand" "v")))]
1181   "TARGET_ALTIVEC"
1182   "vrl<VI_char> %0,%1,%2"
1183   [(set_attr "type" "vecsimple")])
1184
1185 (define_insn "altivec_vsl"
1186   [(set (match_operand:V4SI 0 "register_operand" "=v")
1187         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1188                       (match_operand:V4SI 2 "register_operand" "v")]
1189                      UNSPEC_VSLV4SI))]
1190   "TARGET_ALTIVEC"
1191   "vsl %0,%1,%2"
1192   [(set_attr "type" "vecperm")])
1193
1194 (define_insn "altivec_vslo"
1195   [(set (match_operand:V4SI 0 "register_operand" "=v")
1196         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1197                       (match_operand:V4SI 2 "register_operand" "v")]
1198                      UNSPEC_VSLO))]
1199   "TARGET_ALTIVEC"
1200   "vslo %0,%1,%2"
1201   [(set_attr "type" "vecperm")])
1202
1203 (define_insn "*altivec_vsl<VI_char>"
1204   [(set (match_operand:VI 0 "register_operand" "=v")
1205         (ashift:VI (match_operand:VI 1 "register_operand" "v")
1206                    (match_operand:VI 2 "register_operand" "v")))]
1207   "TARGET_ALTIVEC"
1208   "vsl<VI_char> %0,%1,%2"
1209   [(set_attr "type" "vecsimple")])
1210
1211 (define_insn "*altivec_vsr<VI_char>"
1212   [(set (match_operand:VI 0 "register_operand" "=v")
1213         (lshiftrt:VI (match_operand:VI 1 "register_operand" "v")
1214                      (match_operand:VI 2 "register_operand" "v")))]
1215   "TARGET_ALTIVEC"
1216   "vsr<VI_char> %0,%1,%2"
1217   [(set_attr "type" "vecsimple")])
1218
1219 (define_insn "*altivec_vsra<VI_char>"
1220   [(set (match_operand:VI 0 "register_operand" "=v")
1221         (ashiftrt:VI (match_operand:VI 1 "register_operand" "v")
1222                      (match_operand:VI 2 "register_operand" "v")))]
1223   "TARGET_ALTIVEC"
1224   "vsra<VI_char> %0,%1,%2"
1225   [(set_attr "type" "vecsimple")])
1226
1227 (define_insn "altivec_vsr"
1228   [(set (match_operand:V4SI 0 "register_operand" "=v")
1229         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1230                       (match_operand:V4SI 2 "register_operand" "v")]
1231                      UNSPEC_VSR))]
1232   "TARGET_ALTIVEC"
1233   "vsr %0,%1,%2"
1234   [(set_attr "type" "vecperm")])
1235
1236 (define_insn "altivec_vsro"
1237   [(set (match_operand:V4SI 0 "register_operand" "=v")
1238         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1239                       (match_operand:V4SI 2 "register_operand" "v")]
1240                      UNSPEC_VSRO))]
1241   "TARGET_ALTIVEC"
1242   "vsro %0,%1,%2"
1243   [(set_attr "type" "vecperm")])
1244
1245 (define_insn "altivec_vsum4ubs"
1246   [(set (match_operand:V4SI 0 "register_operand" "=v")
1247         (unspec:V4SI [(match_operand:V16QI 1 "register_operand" "v")
1248                       (match_operand:V4SI 2 "register_operand" "v")]
1249                      UNSPEC_VSUM4UBS))
1250    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1251   "TARGET_ALTIVEC"
1252   "vsum4ubs %0,%1,%2"
1253   [(set_attr "type" "veccomplex")])
1254
1255 (define_insn "altivec_vsum4s<VI_char>s"
1256   [(set (match_operand:V4SI 0 "register_operand" "=v")
1257         (unspec:V4SI [(match_operand:VIshort 1 "register_operand" "v")
1258                       (match_operand:V4SI 2 "register_operand" "v")]
1259                      UNSPEC_VSUM4S))
1260    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1261   "TARGET_ALTIVEC"
1262   "vsum4s<VI_char>s %0,%1,%2"
1263   [(set_attr "type" "veccomplex")])
1264
1265 (define_insn "altivec_vsum2sws"
1266   [(set (match_operand:V4SI 0 "register_operand" "=v")
1267         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1268                       (match_operand:V4SI 2 "register_operand" "v")]
1269                      UNSPEC_VSUM2SWS))
1270    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1271   "TARGET_ALTIVEC"
1272   "vsum2sws %0,%1,%2"
1273   [(set_attr "type" "veccomplex")])
1274
1275 (define_insn "altivec_vsumsws"
1276   [(set (match_operand:V4SI 0 "register_operand" "=v")
1277         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1278                       (match_operand:V4SI 2 "register_operand" "v")]
1279                      UNSPEC_VSUMSWS))
1280    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1281   "TARGET_ALTIVEC"
1282   "vsumsws %0,%1,%2"
1283   [(set_attr "type" "veccomplex")])
1284
1285 (define_insn "altivec_vspltb"
1286   [(set (match_operand:V16QI 0 "register_operand" "=v")
1287         (vec_duplicate:V16QI
1288          (vec_select:QI (match_operand:V16QI 1 "register_operand" "v")
1289                         (parallel
1290                          [(match_operand:QI 2 "u5bit_cint_operand" "")]))))]
1291   "TARGET_ALTIVEC"
1292   "vspltb %0,%1,%2"
1293   [(set_attr "type" "vecperm")])
1294
1295 (define_insn "altivec_vsplth"
1296   [(set (match_operand:V8HI 0 "register_operand" "=v")
1297         (vec_duplicate:V8HI
1298          (vec_select:HI (match_operand:V8HI 1 "register_operand" "v")
1299                         (parallel
1300                          [(match_operand:QI 2 "u5bit_cint_operand" "")]))))]
1301   "TARGET_ALTIVEC"
1302   "vsplth %0,%1,%2"
1303   [(set_attr "type" "vecperm")])
1304
1305 (define_insn "altivec_vspltw"
1306   [(set (match_operand:V4SI 0 "register_operand" "=v")
1307         (vec_duplicate:V4SI
1308          (vec_select:SI (match_operand:V4SI 1 "register_operand" "v")
1309                         (parallel
1310                          [(match_operand:QI 2 "u5bit_cint_operand" "i")]))))]
1311   "TARGET_ALTIVEC"
1312   "vspltw %0,%1,%2"
1313   [(set_attr "type" "vecperm")])
1314
1315 (define_insn "altivec_vspltsf"
1316   [(set (match_operand:V4SF 0 "register_operand" "=v")
1317         (vec_duplicate:V4SF
1318          (vec_select:SF (match_operand:V4SF 1 "register_operand" "v")
1319                         (parallel
1320                          [(match_operand:QI 2 "u5bit_cint_operand" "i")]))))]
1321   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1322   "vspltw %0,%1,%2"
1323   [(set_attr "type" "vecperm")])
1324
1325 (define_insn "altivec_vspltis<VI_char>"
1326   [(set (match_operand:VI 0 "register_operand" "=v")
1327         (vec_duplicate:VI
1328          (match_operand:QI 1 "s5bit_cint_operand" "i")))]
1329   "TARGET_ALTIVEC"
1330   "vspltis<VI_char> %0,%1"
1331   [(set_attr "type" "vecperm")])
1332
1333 (define_insn "*altivec_vrfiz"
1334   [(set (match_operand:V4SF 0 "register_operand" "=v")
1335         (fix:V4SF (match_operand:V4SF 1 "register_operand" "v")))]
1336   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1337   "vrfiz %0,%1"
1338   [(set_attr "type" "vecfloat")])
1339
1340 (define_insn "altivec_vperm_<mode>"
1341   [(set (match_operand:VM 0 "register_operand" "=v")
1342         (unspec:VM [(match_operand:VM 1 "register_operand" "v")
1343                     (match_operand:VM 2 "register_operand" "v")
1344                     (match_operand:V16QI 3 "register_operand" "v")]
1345                    UNSPEC_VPERM))]
1346   "TARGET_ALTIVEC"
1347   "vperm %0,%1,%2,%3"
1348   [(set_attr "type" "vecperm")])
1349
1350 (define_insn "altivec_vperm_<mode>_uns"
1351   [(set (match_operand:VM 0 "register_operand" "=v")
1352         (unspec:VM [(match_operand:VM 1 "register_operand" "v")
1353                     (match_operand:VM 2 "register_operand" "v")
1354                     (match_operand:V16QI 3 "register_operand" "v")]
1355                    UNSPEC_VPERM_UNS))]
1356   "TARGET_ALTIVEC"
1357   "vperm %0,%1,%2,%3"
1358   [(set_attr "type" "vecperm")])
1359
1360 (define_expand "vec_permv16qi"
1361   [(set (match_operand:V16QI 0 "register_operand" "")
1362         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "")
1363                        (match_operand:V16QI 2 "register_operand" "")
1364                        (match_operand:V16QI 3 "register_operand" "")]
1365                       UNSPEC_VPERM))]
1366   "TARGET_ALTIVEC"
1367   "")
1368
1369 (define_insn "altivec_vrfip"            ; ceil
1370   [(set (match_operand:V4SF 0 "register_operand" "=v")
1371         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1372                      UNSPEC_FRIP))]
1373   "TARGET_ALTIVEC"
1374   "vrfip %0,%1"
1375   [(set_attr "type" "vecfloat")])
1376
1377 (define_insn "altivec_vrfin"
1378   [(set (match_operand:V4SF 0 "register_operand" "=v")
1379         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1380                      UNSPEC_VRFIN))]
1381   "TARGET_ALTIVEC"
1382   "vrfin %0,%1"
1383   [(set_attr "type" "vecfloat")])
1384
1385 (define_insn "*altivec_vrfim"           ; floor
1386   [(set (match_operand:V4SF 0 "register_operand" "=v")
1387         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1388                      UNSPEC_FRIM))]
1389   "TARGET_ALTIVEC"
1390   "vrfim %0,%1"
1391   [(set_attr "type" "vecfloat")])
1392
1393 (define_insn "altivec_vcfux"
1394   [(set (match_operand:V4SF 0 "register_operand" "=v")
1395         (unspec:V4SF [(match_operand:V4SI 1 "register_operand" "v")
1396                       (match_operand:QI 2 "immediate_operand" "i")]
1397                      UNSPEC_VCFUX))]
1398   "TARGET_ALTIVEC"
1399   "vcfux %0,%1,%2"
1400   [(set_attr "type" "vecfloat")])
1401
1402 (define_insn "altivec_vcfsx"
1403   [(set (match_operand:V4SF 0 "register_operand" "=v")
1404         (unspec:V4SF [(match_operand:V4SI 1 "register_operand" "v")
1405                       (match_operand:QI 2 "immediate_operand" "i")]
1406                      UNSPEC_VCFSX))]
1407   "TARGET_ALTIVEC"
1408   "vcfsx %0,%1,%2"
1409   [(set_attr "type" "vecfloat")])
1410
1411 (define_insn "altivec_vctuxs"
1412   [(set (match_operand:V4SI 0 "register_operand" "=v")
1413         (unspec:V4SI [(match_operand:V4SF 1 "register_operand" "v")
1414                       (match_operand:QI 2 "immediate_operand" "i")]
1415                      UNSPEC_VCTUXS))
1416    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1417   "TARGET_ALTIVEC"
1418   "vctuxs %0,%1,%2"
1419   [(set_attr "type" "vecfloat")])
1420
1421 (define_insn "altivec_vctsxs"
1422   [(set (match_operand:V4SI 0 "register_operand" "=v")
1423         (unspec:V4SI [(match_operand:V4SF 1 "register_operand" "v")
1424                       (match_operand:QI 2 "immediate_operand" "i")]
1425                      UNSPEC_VCTSXS))
1426    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1427   "TARGET_ALTIVEC"
1428   "vctsxs %0,%1,%2"
1429   [(set_attr "type" "vecfloat")])
1430
1431 (define_insn "altivec_vlogefp"
1432   [(set (match_operand:V4SF 0 "register_operand" "=v")
1433         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1434                      UNSPEC_VLOGEFP))]
1435   "TARGET_ALTIVEC"
1436   "vlogefp %0,%1"
1437   [(set_attr "type" "vecfloat")])
1438
1439 (define_insn "altivec_vexptefp"
1440   [(set (match_operand:V4SF 0 "register_operand" "=v")
1441         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1442                      UNSPEC_VEXPTEFP))]
1443   "TARGET_ALTIVEC"
1444   "vexptefp %0,%1"
1445   [(set_attr "type" "vecfloat")])
1446
1447 (define_insn "*altivec_vrsqrtefp"
1448   [(set (match_operand:V4SF 0 "register_operand" "=v")
1449         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1450                      UNSPEC_RSQRT))]
1451   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1452   "vrsqrtefp %0,%1"
1453   [(set_attr "type" "vecfloat")])
1454
1455 (define_insn "altivec_vrefp"
1456   [(set (match_operand:V4SF 0 "register_operand" "=v")
1457         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "v")]
1458                      UNSPEC_FRES))]
1459   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1460   "vrefp %0,%1"
1461   [(set_attr "type" "vecfloat")])
1462
1463 (define_expand "altivec_copysign_v4sf3"
1464   [(use (match_operand:V4SF 0 "register_operand" ""))
1465    (use (match_operand:V4SF 1 "register_operand" ""))
1466    (use (match_operand:V4SF 2 "register_operand" ""))]
1467   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1468   "
1469 {
1470   rtx mask = gen_reg_rtx (V4SImode);
1471   rtvec v = rtvec_alloc (4);
1472   unsigned HOST_WIDE_INT mask_val = ((unsigned HOST_WIDE_INT)1) << 31;
1473
1474   RTVEC_ELT (v, 0) = GEN_INT (mask_val);
1475   RTVEC_ELT (v, 1) = GEN_INT (mask_val);
1476   RTVEC_ELT (v, 2) = GEN_INT (mask_val);
1477   RTVEC_ELT (v, 3) = GEN_INT (mask_val);
1478
1479   emit_insn (gen_vec_initv4si (mask, gen_rtx_PARALLEL (V4SImode, v)));
1480   emit_insn (gen_vector_select_v4sf (operands[0], operands[1], operands[2],
1481                                      gen_lowpart (V4SFmode, mask)));
1482   DONE;
1483 }")
1484
1485 (define_insn "altivec_vsldoi_<mode>"
1486   [(set (match_operand:VM 0 "register_operand" "=v")
1487         (unspec:VM [(match_operand:VM 1 "register_operand" "v")
1488                     (match_operand:VM 2 "register_operand" "v")
1489                     (match_operand:QI 3 "immediate_operand" "i")]
1490                   UNSPEC_VLSDOI))]
1491   "TARGET_ALTIVEC"
1492   "vsldoi %0,%1,%2,%3"
1493   [(set_attr "type" "vecperm")])
1494
1495 (define_insn "altivec_vupkhsb"
1496   [(set (match_operand:V8HI 0 "register_operand" "=v")
1497         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
1498                      UNSPEC_VUPKHSB))]
1499   "TARGET_ALTIVEC"
1500   "vupkhsb %0,%1"
1501   [(set_attr "type" "vecperm")])
1502
1503 (define_insn "altivec_vupkhpx"
1504   [(set (match_operand:V4SI 0 "register_operand" "=v")
1505         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1506                      UNSPEC_VUPKHPX))]
1507   "TARGET_ALTIVEC"
1508   "vupkhpx %0,%1"
1509   [(set_attr "type" "vecperm")])
1510
1511 (define_insn "altivec_vupkhsh"
1512   [(set (match_operand:V4SI 0 "register_operand" "=v")
1513         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1514                      UNSPEC_VUPKHSH))]
1515   "TARGET_ALTIVEC"
1516   "vupkhsh %0,%1"
1517   [(set_attr "type" "vecperm")])
1518
1519 (define_insn "altivec_vupklsb"
1520   [(set (match_operand:V8HI 0 "register_operand" "=v")
1521         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
1522                      UNSPEC_VUPKLSB))]
1523   "TARGET_ALTIVEC"
1524   "vupklsb %0,%1"
1525   [(set_attr "type" "vecperm")])
1526
1527 (define_insn "altivec_vupklpx"
1528   [(set (match_operand:V4SI 0 "register_operand" "=v")
1529         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1530                      UNSPEC_VUPKLPX))]
1531   "TARGET_ALTIVEC"
1532   "vupklpx %0,%1"
1533   [(set_attr "type" "vecperm")])
1534
1535 (define_insn "altivec_vupklsh"
1536   [(set (match_operand:V4SI 0 "register_operand" "=v")
1537         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1538                      UNSPEC_VUPKLSH))]
1539   "TARGET_ALTIVEC"
1540   "vupklsh %0,%1"
1541   [(set_attr "type" "vecperm")])
1542
1543 ;; Compare vectors producing a vector result and a predicate, setting CR6 to
1544 ;; indicate a combined status
1545 (define_insn "*altivec_vcmpequ<VI_char>_p"
1546   [(set (reg:CC 74)
1547         (unspec:CC [(eq:CC (match_operand:VI 1 "register_operand" "v")
1548                            (match_operand:VI 2 "register_operand" "v"))]
1549                    UNSPEC_PREDICATE))
1550    (set (match_operand:VI 0 "register_operand" "=v")
1551         (eq:VI (match_dup 1)
1552                (match_dup 2)))]
1553   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
1554   "vcmpequ<VI_char>. %0,%1,%2"
1555   [(set_attr "type" "veccmp")])
1556
1557 (define_insn "*altivec_vcmpgts<VI_char>_p"
1558   [(set (reg:CC 74)
1559         (unspec:CC [(gt:CC (match_operand:VI 1 "register_operand" "v")
1560                            (match_operand:VI 2 "register_operand" "v"))]
1561                    UNSPEC_PREDICATE))
1562    (set (match_operand:VI 0 "register_operand" "=v")
1563         (gt:VI (match_dup 1)
1564                (match_dup 2)))]
1565   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
1566   "vcmpgts<VI_char>. %0,%1,%2"
1567   [(set_attr "type" "veccmp")])
1568
1569 (define_insn "*altivec_vcmpgtu<VI_char>_p"
1570   [(set (reg:CC 74)
1571         (unspec:CC [(gtu:CC (match_operand:VI 1 "register_operand" "v")
1572                             (match_operand:VI 2 "register_operand" "v"))]
1573                    UNSPEC_PREDICATE))
1574    (set (match_operand:VI 0 "register_operand" "=v")
1575         (gtu:VI (match_dup 1)
1576                 (match_dup 2)))]
1577   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
1578   "vcmpgtu<VI_char>. %0,%1,%2"
1579   [(set_attr "type" "veccmp")])
1580
1581 (define_insn "*altivec_vcmpeqfp_p"
1582   [(set (reg:CC 74)
1583         (unspec:CC [(eq:CC (match_operand:V4SF 1 "register_operand" "v")
1584                            (match_operand:V4SF 2 "register_operand" "v"))]
1585                    UNSPEC_PREDICATE))
1586    (set (match_operand:V4SF 0 "register_operand" "=v")
1587         (eq:V4SF (match_dup 1)
1588                  (match_dup 2)))]
1589   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1590   "vcmpeqfp. %0,%1,%2"
1591   [(set_attr "type" "veccmp")])
1592
1593 (define_insn "*altivec_vcmpgtfp_p"
1594   [(set (reg:CC 74)
1595         (unspec:CC [(gt:CC (match_operand:V4SF 1 "register_operand" "v")
1596                            (match_operand:V4SF 2 "register_operand" "v"))]
1597                    UNSPEC_PREDICATE))
1598    (set (match_operand:V4SF 0 "register_operand" "=v")
1599         (gt:V4SF (match_dup 1)
1600                  (match_dup 2)))]
1601   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1602   "vcmpgtfp. %0,%1,%2"
1603   [(set_attr "type" "veccmp")])
1604
1605 (define_insn "*altivec_vcmpgefp_p"
1606   [(set (reg:CC 74)
1607         (unspec:CC [(ge:CC (match_operand:V4SF 1 "register_operand" "v")
1608                            (match_operand:V4SF 2 "register_operand" "v"))]
1609                    UNSPEC_PREDICATE))
1610    (set (match_operand:V4SF 0 "register_operand" "=v")
1611         (ge:V4SF (match_dup 1)
1612                  (match_dup 2)))]
1613   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
1614   "vcmpgefp. %0,%1,%2"
1615   [(set_attr "type" "veccmp")])
1616
1617 (define_insn "altivec_vcmpbfp_p"
1618   [(set (reg:CC 74)
1619         (unspec:CC [(match_operand:V4SF 1 "register_operand" "v")
1620                     (match_operand:V4SF 2 "register_operand" "v")]
1621                    UNSPEC_VCMPBFP))
1622    (set (match_operand:V4SF 0 "register_operand" "=v")
1623         (unspec:V4SF [(match_dup 1)
1624                       (match_dup 2)] 
1625                       UNSPEC_VCMPBFP))]
1626   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
1627   "vcmpbfp. %0,%1,%2"
1628   [(set_attr "type" "veccmp")])
1629
1630 (define_insn "altivec_mtvscr"
1631   [(set (reg:SI 110)
1632         (unspec_volatile:SI
1633          [(match_operand:V4SI 0 "register_operand" "v")] UNSPECV_MTVSCR))]
1634   "TARGET_ALTIVEC"
1635   "mtvscr %0"
1636   [(set_attr "type" "vecsimple")])
1637
1638 (define_insn "altivec_mfvscr"
1639   [(set (match_operand:V8HI 0 "register_operand" "=v")
1640         (unspec_volatile:V8HI [(reg:SI 110)] UNSPECV_MFVSCR))]
1641   "TARGET_ALTIVEC"
1642   "mfvscr %0"
1643   [(set_attr "type" "vecsimple")])
1644
1645 (define_insn "altivec_dssall"
1646   [(unspec_volatile [(const_int 0)] UNSPECV_DSSALL)]
1647   "TARGET_ALTIVEC"
1648   "dssall"
1649   [(set_attr "type" "vecsimple")])
1650
1651 (define_insn "altivec_dss"
1652   [(unspec_volatile [(match_operand:QI 0 "immediate_operand" "i")]
1653                     UNSPECV_DSS)]
1654   "TARGET_ALTIVEC"
1655   "dss %0"
1656   [(set_attr "type" "vecsimple")])
1657
1658 (define_insn "altivec_dst"
1659   [(unspec [(match_operand 0 "register_operand" "b")
1660             (match_operand:SI 1 "register_operand" "r")
1661             (match_operand:QI 2 "immediate_operand" "i")] UNSPEC_DST)]
1662   "TARGET_ALTIVEC && GET_MODE (operands[0]) == Pmode"
1663   "dst %0,%1,%2"
1664   [(set_attr "type" "vecsimple")])
1665
1666 (define_insn "altivec_dstt"
1667   [(unspec [(match_operand 0 "register_operand" "b")
1668             (match_operand:SI 1 "register_operand" "r")
1669             (match_operand:QI 2 "immediate_operand" "i")] UNSPEC_DSTT)]
1670   "TARGET_ALTIVEC && GET_MODE (operands[0]) == Pmode"
1671   "dstt %0,%1,%2"
1672   [(set_attr "type" "vecsimple")])
1673
1674 (define_insn "altivec_dstst"
1675   [(unspec [(match_operand 0 "register_operand" "b")
1676             (match_operand:SI 1 "register_operand" "r")
1677             (match_operand:QI 2 "immediate_operand" "i")] UNSPEC_DSTST)]
1678   "TARGET_ALTIVEC && GET_MODE (operands[0]) == Pmode"
1679   "dstst %0,%1,%2"
1680   [(set_attr "type" "vecsimple")])
1681
1682 (define_insn "altivec_dststt"
1683   [(unspec [(match_operand 0 "register_operand" "b")
1684             (match_operand:SI 1 "register_operand" "r")
1685             (match_operand:QI 2 "immediate_operand" "i")] UNSPEC_DSTSTT)]
1686   "TARGET_ALTIVEC && GET_MODE (operands[0]) == Pmode"
1687   "dststt %0,%1,%2"
1688   [(set_attr "type" "vecsimple")])
1689
1690 (define_insn "altivec_lvsl"
1691   [(set (match_operand:V16QI 0 "register_operand" "=v")
1692         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] UNSPEC_LVSL))]
1693   "TARGET_ALTIVEC"
1694   "lvsl %0,%y1"
1695   [(set_attr "type" "vecload")])
1696
1697 (define_insn "altivec_lvsr"
1698   [(set (match_operand:V16QI 0 "register_operand" "=v")
1699         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] UNSPEC_LVSR))]
1700   "TARGET_ALTIVEC"
1701   "lvsr %0,%y1"
1702   [(set_attr "type" "vecload")])
1703
1704 (define_expand "build_vector_mask_for_load"
1705   [(set (match_operand:V16QI 0 "register_operand" "")
1706         (unspec:V16QI [(match_operand 1 "memory_operand" "")] UNSPEC_LVSR))]
1707   "TARGET_ALTIVEC"
1708   "
1709
1710   rtx addr;
1711   rtx temp;
1712
1713   gcc_assert (GET_CODE (operands[1]) == MEM);
1714
1715   addr = XEXP (operands[1], 0);
1716   temp = gen_reg_rtx (GET_MODE (addr));
1717   emit_insn (gen_rtx_SET (VOIDmode, temp, 
1718                           gen_rtx_NEG (GET_MODE (addr), addr)));
1719   emit_insn (gen_altivec_lvsr (operands[0], 
1720                                replace_equiv_address (operands[1], temp)));
1721   DONE;
1722 }")
1723
1724 ;; Parallel some of the LVE* and STV*'s with unspecs because some have
1725 ;; identical rtl but different instructions-- and gcc gets confused.
1726
1727 (define_insn "altivec_lve<VI_char>x"
1728   [(parallel
1729     [(set (match_operand:VI 0 "register_operand" "=v")
1730           (match_operand:VI 1 "memory_operand" "Z"))
1731      (unspec [(const_int 0)] UNSPEC_LVE)])]
1732   "TARGET_ALTIVEC"
1733   "lve<VI_char>x %0,%y1"
1734   [(set_attr "type" "vecload")])
1735
1736 (define_insn "*altivec_lvesfx"
1737   [(parallel
1738     [(set (match_operand:V4SF 0 "register_operand" "=v")
1739           (match_operand:V4SF 1 "memory_operand" "Z"))
1740      (unspec [(const_int 0)] UNSPEC_LVE)])]
1741   "TARGET_ALTIVEC"
1742   "lvewx %0,%y1"
1743   [(set_attr "type" "vecload")])
1744
1745 (define_insn "altivec_lvxl"
1746   [(parallel
1747     [(set (match_operand:V4SI 0 "register_operand" "=v")
1748           (match_operand:V4SI 1 "memory_operand" "Z"))
1749      (unspec [(const_int 0)] UNSPEC_SET_VSCR)])]
1750   "TARGET_ALTIVEC"
1751   "lvxl %0,%y1"
1752   [(set_attr "type" "vecload")])
1753
1754 (define_insn "altivec_lvx_<mode>"
1755   [(parallel
1756     [(set (match_operand:VM2 0 "register_operand" "=v")
1757           (match_operand:VM2 1 "memory_operand" "Z"))
1758      (unspec [(const_int 0)] UNSPEC_LVX)])]
1759   "TARGET_ALTIVEC"
1760   "lvx %0,%y1"
1761   [(set_attr "type" "vecload")])
1762
1763 (define_insn "altivec_stvx_<mode>"
1764   [(parallel
1765     [(set (match_operand:VM2 0 "memory_operand" "=Z")
1766           (match_operand:VM2 1 "register_operand" "v"))
1767      (unspec [(const_int 0)] UNSPEC_STVX)])]
1768   "TARGET_ALTIVEC"
1769   "stvx %1,%y0"
1770   [(set_attr "type" "vecstore")])
1771
1772 (define_insn "altivec_stvxl"
1773   [(parallel
1774     [(set (match_operand:V4SI 0 "memory_operand" "=Z")
1775           (match_operand:V4SI 1 "register_operand" "v"))
1776      (unspec [(const_int 0)] UNSPEC_STVXL)])]
1777   "TARGET_ALTIVEC"
1778   "stvxl %1,%y0"
1779   [(set_attr "type" "vecstore")])
1780
1781 (define_insn "altivec_stve<VI_char>x"
1782   [(set (match_operand:<VI_scalar> 0 "memory_operand" "=Z")
1783         (unspec:<VI_scalar> [(match_operand:VI 1 "register_operand" "v")] UNSPEC_STVE))]
1784   "TARGET_ALTIVEC"
1785   "stve<VI_char>x %1,%y0"
1786   [(set_attr "type" "vecstore")])
1787
1788 (define_insn "*altivec_stvesfx"
1789   [(set (match_operand:SF 0 "memory_operand" "=Z")
1790         (unspec:SF [(match_operand:V4SF 1 "register_operand" "v")] UNSPEC_STVE))]
1791   "TARGET_ALTIVEC"
1792   "stvewx %1,%y0"
1793   [(set_attr "type" "vecstore")])
1794
1795 ;; Generate
1796 ;;    vspltis? SCRATCH0,0
1797 ;;    vsubu?m SCRATCH2,SCRATCH1,%1
1798 ;;    vmaxs? %0,%1,SCRATCH2"
1799 (define_expand "abs<mode>2"
1800   [(set (match_dup 2) (vec_duplicate:VI (const_int 0)))
1801    (set (match_dup 3)
1802         (minus:VI (match_dup 2)
1803                   (match_operand:VI 1 "register_operand" "v")))
1804    (set (match_operand:VI 0 "register_operand" "=v")
1805         (smax:VI (match_dup 1) (match_dup 3)))]
1806   "TARGET_ALTIVEC"
1807 {
1808   operands[2] = gen_reg_rtx (GET_MODE (operands[0]));
1809   operands[3] = gen_reg_rtx (GET_MODE (operands[0]));
1810 })
1811
1812 ;; Generate
1813 ;;    vspltisw SCRATCH1,-1
1814 ;;    vslw SCRATCH2,SCRATCH1,SCRATCH1
1815 ;;    vandc %0,%1,SCRATCH2
1816 (define_expand "altivec_absv4sf2"
1817   [(set (match_dup 2)
1818         (vec_duplicate:V4SI (const_int -1)))
1819    (set (match_dup 3)
1820         (ashift:V4SI (match_dup 2) (match_dup 2)))
1821    (set (match_operand:V4SF 0 "register_operand" "=v")
1822         (and:V4SF (not:V4SF (subreg:V4SF (match_dup 3) 0))
1823                   (match_operand:V4SF 1 "register_operand" "v")))]
1824   "TARGET_ALTIVEC"
1825 {
1826   operands[2] = gen_reg_rtx (V4SImode);
1827   operands[3] = gen_reg_rtx (V4SImode);
1828 })
1829
1830 ;; Generate
1831 ;;    vspltis? SCRATCH0,0
1832 ;;    vsubs?s SCRATCH2,SCRATCH1,%1
1833 ;;    vmaxs? %0,%1,SCRATCH2"
1834 (define_expand "altivec_abss_<mode>"
1835   [(set (match_dup 2) (vec_duplicate:VI (const_int 0)))
1836    (parallel [(set (match_dup 3)
1837                    (unspec:VI [(match_dup 2)
1838                                (match_operand:VI 1 "register_operand" "v")]
1839                               UNSPEC_VSUBS))
1840               (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))])
1841    (set (match_operand:VI 0 "register_operand" "=v")
1842         (smax:VI (match_dup 1) (match_dup 3)))]
1843   "TARGET_ALTIVEC"
1844 {
1845   operands[2] = gen_reg_rtx (GET_MODE (operands[0]));
1846   operands[3] = gen_reg_rtx (GET_MODE (operands[0]));
1847 })
1848
1849 (define_insn "altivec_vsumsws_nomode"
1850   [(set (match_operand 0 "register_operand" "=v")
1851         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "v")
1852                       (match_operand:V4SI 2 "register_operand" "v")]
1853                      UNSPEC_VSUMSWS))
1854    (set (reg:SI 110) (unspec:SI [(const_int 0)] UNSPEC_SET_VSCR))]
1855   "TARGET_ALTIVEC"
1856   "vsumsws %0,%1,%2"
1857   [(set_attr "type" "veccomplex")])
1858
1859 (define_expand "reduc_splus_<mode>"
1860   [(set (match_operand:VIshort 0 "register_operand" "=v")
1861         (unspec:VIshort [(match_operand:VIshort 1 "register_operand" "v")]
1862                         UNSPEC_REDUC_PLUS))]
1863   "TARGET_ALTIVEC"
1864   "
1865
1866   rtx vzero = gen_reg_rtx (V4SImode);
1867   rtx vtmp1 = gen_reg_rtx (V4SImode);
1868
1869   emit_insn (gen_altivec_vspltisw (vzero, const0_rtx));
1870   emit_insn (gen_altivec_vsum4s<VI_char>s (vtmp1, operands[1], vzero));
1871   emit_insn (gen_altivec_vsumsws_nomode (operands[0], vtmp1, vzero));
1872   DONE;
1873 }")
1874
1875 (define_expand "reduc_uplus_v16qi"
1876   [(set (match_operand:V16QI 0 "register_operand" "=v")
1877         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "v")]
1878                       UNSPEC_REDUC_PLUS))]
1879   "TARGET_ALTIVEC"
1880   "
1881 {
1882   rtx vzero = gen_reg_rtx (V4SImode);
1883   rtx vtmp1 = gen_reg_rtx (V4SImode);
1884
1885   emit_insn (gen_altivec_vspltisw (vzero, const0_rtx));
1886   emit_insn (gen_altivec_vsum4ubs (vtmp1, operands[1], vzero));
1887   emit_insn (gen_altivec_vsumsws_nomode (operands[0], vtmp1, vzero));
1888   DONE;
1889 }")
1890
1891 (define_expand "neg<mode>2"
1892   [(use (match_operand:VI 0 "register_operand" ""))
1893    (use (match_operand:VI 1 "register_operand" ""))]
1894   "TARGET_ALTIVEC"
1895   "
1896 {
1897   rtx vzero;
1898
1899   vzero = gen_reg_rtx (GET_MODE (operands[0]));
1900   emit_insn (gen_altivec_vspltis<VI_char> (vzero, const0_rtx));
1901   emit_insn (gen_sub<mode>3 (operands[0], vzero, operands[1])); 
1902   
1903   DONE;
1904 }")
1905
1906 (define_expand "udot_prod<mode>"
1907   [(set (match_operand:V4SI 0 "register_operand" "=v")
1908         (plus:V4SI (match_operand:V4SI 3 "register_operand" "v")
1909                    (unspec:V4SI [(match_operand:VIshort 1 "register_operand" "v")  
1910                                  (match_operand:VIshort 2 "register_operand" "v")] 
1911                                 UNSPEC_VMSUMU)))]
1912   "TARGET_ALTIVEC"
1913   "
1914 {  
1915   emit_insn (gen_altivec_vmsumu<VI_char>m (operands[0], operands[1], operands[2], operands[3]));
1916   DONE;
1917 }")
1918    
1919 (define_expand "sdot_prodv8hi"
1920   [(set (match_operand:V4SI 0 "register_operand" "=v")
1921         (plus:V4SI (match_operand:V4SI 3 "register_operand" "v")
1922                    (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
1923                                  (match_operand:V8HI 2 "register_operand" "v")]
1924                                 UNSPEC_VMSUMSHM)))]
1925   "TARGET_ALTIVEC"
1926   "
1927 {
1928   emit_insn (gen_altivec_vmsumshm (operands[0], operands[1], operands[2], operands[3]));
1929   DONE;
1930 }")
1931
1932 (define_expand "widen_usum<mode>3"
1933   [(set (match_operand:V4SI 0 "register_operand" "=v")
1934         (plus:V4SI (match_operand:V4SI 2 "register_operand" "v")
1935                    (unspec:V4SI [(match_operand:VIshort 1 "register_operand" "v")]
1936                                 UNSPEC_VMSUMU)))]
1937   "TARGET_ALTIVEC"
1938   "
1939 {
1940   rtx vones = gen_reg_rtx (GET_MODE (operands[1]));
1941
1942   emit_insn (gen_altivec_vspltis<VI_char> (vones, const1_rtx));
1943   emit_insn (gen_altivec_vmsumu<VI_char>m (operands[0], operands[1], vones, operands[2]));
1944   DONE;
1945 }")
1946
1947 (define_expand "widen_ssumv16qi3"
1948   [(set (match_operand:V4SI 0 "register_operand" "=v")
1949         (plus:V4SI (match_operand:V4SI 2 "register_operand" "v")
1950                    (unspec:V4SI [(match_operand:V16QI 1 "register_operand" "v")]
1951                                 UNSPEC_VMSUMM)))]
1952   "TARGET_ALTIVEC"
1953   "
1954 {
1955   rtx vones = gen_reg_rtx (V16QImode);
1956
1957   emit_insn (gen_altivec_vspltisb (vones, const1_rtx));
1958   emit_insn (gen_altivec_vmsummbm (operands[0], operands[1], vones, operands[2]));
1959   DONE;
1960 }")
1961
1962 (define_expand "widen_ssumv8hi3"
1963   [(set (match_operand:V4SI 0 "register_operand" "=v")
1964         (plus:V4SI (match_operand:V4SI 2 "register_operand" "v")
1965                    (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1966                                 UNSPEC_VMSUMSHM)))]
1967   "TARGET_ALTIVEC"
1968   "
1969 {
1970   rtx vones = gen_reg_rtx (V8HImode);
1971
1972   emit_insn (gen_altivec_vspltish (vones, const1_rtx));
1973   emit_insn (gen_altivec_vmsumshm (operands[0], operands[1], vones, operands[2]));
1974   DONE;
1975 }")
1976
1977 (define_expand "vec_unpacks_hi_v16qi"
1978   [(set (match_operand:V8HI 0 "register_operand" "=v")
1979         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
1980                      UNSPEC_VUPKHSB))]
1981   "TARGET_ALTIVEC"
1982   "
1983 {
1984   emit_insn (gen_altivec_vupkhsb (operands[0], operands[1]));
1985   DONE;
1986 }")
1987
1988 (define_expand "vec_unpacks_hi_v8hi"
1989   [(set (match_operand:V4SI 0 "register_operand" "=v")
1990         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
1991                      UNSPEC_VUPKHSH))]
1992   "TARGET_ALTIVEC"
1993   "
1994 {
1995   emit_insn (gen_altivec_vupkhsh (operands[0], operands[1]));
1996   DONE;
1997 }")
1998
1999 (define_expand "vec_unpacks_lo_v16qi"
2000   [(set (match_operand:V8HI 0 "register_operand" "=v")
2001         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
2002                      UNSPEC_VUPKLSB))]
2003   "TARGET_ALTIVEC"
2004   "
2005 {
2006   emit_insn (gen_altivec_vupklsb (operands[0], operands[1]));
2007   DONE;
2008 }")
2009
2010 (define_expand "vec_unpacks_lo_v8hi"
2011   [(set (match_operand:V4SI 0 "register_operand" "=v")
2012         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
2013                      UNSPEC_VUPKLSH))]
2014   "TARGET_ALTIVEC"
2015   "
2016 {
2017   emit_insn (gen_altivec_vupklsh (operands[0], operands[1]));
2018   DONE;
2019 }")
2020
2021 (define_insn "vperm_v8hiv4si"
2022   [(set (match_operand:V4SI 0 "register_operand" "=v")
2023         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
2024                    (match_operand:V4SI 2 "register_operand" "v")
2025                    (match_operand:V16QI 3 "register_operand" "v")]
2026                   UNSPEC_VPERMSI))]
2027   "TARGET_ALTIVEC"
2028   "vperm %0,%1,%2,%3"
2029   [(set_attr "type" "vecperm")])
2030
2031 (define_insn "vperm_v16qiv8hi"
2032   [(set (match_operand:V8HI 0 "register_operand" "=v")
2033         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
2034                    (match_operand:V8HI 2 "register_operand" "v")
2035                    (match_operand:V16QI 3 "register_operand" "v")]
2036                   UNSPEC_VPERMHI))]
2037   "TARGET_ALTIVEC"
2038   "vperm %0,%1,%2,%3"
2039   [(set_attr "type" "vecperm")])
2040
2041
2042 (define_expand "vec_unpacku_hi_v16qi"
2043   [(set (match_operand:V8HI 0 "register_operand" "=v")
2044         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
2045                      UNSPEC_VUPKHUB))]
2046   "TARGET_ALTIVEC"      
2047   "
2048 {  
2049   rtx vzero = gen_reg_rtx (V8HImode);
2050   rtx mask = gen_reg_rtx (V16QImode);
2051   rtvec v = rtvec_alloc (16);
2052    
2053   emit_insn (gen_altivec_vspltish (vzero, const0_rtx));
2054    
2055   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 16);
2056   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 0);
2057   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 16);
2058   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 1);
2059   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 16);
2060   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 2);
2061   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 16);
2062   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 3);
2063   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2064   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 4);
2065   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 16);
2066   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 5);
2067   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 16);
2068   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 6);
2069   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 16);
2070   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 7);
2071
2072   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2073   emit_insn (gen_vperm_v16qiv8hi (operands[0], operands[1], vzero, mask));
2074   DONE;
2075 }")
2076
2077 (define_expand "vec_unpacku_hi_v8hi"
2078   [(set (match_operand:V4SI 0 "register_operand" "=v")
2079         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
2080                      UNSPEC_VUPKHUH))]
2081   "TARGET_ALTIVEC"
2082   "
2083 {
2084   rtx vzero = gen_reg_rtx (V4SImode);
2085   rtx mask = gen_reg_rtx (V16QImode);
2086   rtvec v = rtvec_alloc (16);
2087
2088   emit_insn (gen_altivec_vspltisw (vzero, const0_rtx));
2089  
2090   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 16);
2091   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 17);
2092   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 0);
2093   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 1);
2094   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 16);
2095   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 17);
2096   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 2);
2097   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 3);
2098   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2099   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 17);
2100   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 4);
2101   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 5);
2102   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 16);
2103   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 17);
2104   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 6);
2105   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 7);
2106
2107   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2108   emit_insn (gen_vperm_v8hiv4si (operands[0], operands[1], vzero, mask));
2109   DONE;
2110 }")
2111
2112 (define_expand "vec_unpacku_lo_v16qi"
2113   [(set (match_operand:V8HI 0 "register_operand" "=v")
2114         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")]
2115                      UNSPEC_VUPKLUB))]
2116   "TARGET_ALTIVEC"
2117   "
2118 {
2119   rtx vzero = gen_reg_rtx (V8HImode);
2120   rtx mask = gen_reg_rtx (V16QImode);
2121   rtvec v = rtvec_alloc (16);
2122
2123   emit_insn (gen_altivec_vspltish (vzero, const0_rtx));
2124
2125   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 16);
2126   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 8);
2127   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 16);
2128   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 9);
2129   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 16);
2130   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 10);
2131   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 16);
2132   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 11);
2133   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2134   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 12);
2135   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 16);
2136   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 13);
2137   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 16);
2138   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 14);
2139   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 16);
2140   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 15);
2141
2142   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2143   emit_insn (gen_vperm_v16qiv8hi (operands[0], operands[1], vzero, mask));
2144   DONE;
2145 }")
2146
2147 (define_expand "vec_unpacku_lo_v8hi"
2148   [(set (match_operand:V4SI 0 "register_operand" "=v")
2149         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")]
2150                      UNSPEC_VUPKLUH))]
2151   "TARGET_ALTIVEC"
2152   "
2153 {
2154   rtx vzero = gen_reg_rtx (V4SImode);
2155   rtx mask = gen_reg_rtx (V16QImode);
2156   rtvec v = rtvec_alloc (16);
2157
2158   emit_insn (gen_altivec_vspltisw (vzero, const0_rtx));
2159  
2160   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 16);
2161   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 17);
2162   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 8);
2163   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 9);
2164   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 16);
2165   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 17);
2166   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 10);
2167   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 11);
2168   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2169   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 17);
2170   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 12);
2171   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 13);
2172   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 16);
2173   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 17);
2174   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 14);
2175   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 15);
2176
2177   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2178   emit_insn (gen_vperm_v8hiv4si (operands[0], operands[1], vzero, mask));
2179   DONE;
2180 }")
2181
2182 (define_expand "vec_widen_umult_hi_v16qi"
2183   [(set (match_operand:V8HI 0 "register_operand" "=v")
2184         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
2185                       (match_operand:V16QI 2 "register_operand" "v")]
2186                      UNSPEC_VMULWHUB))]
2187   "TARGET_ALTIVEC"
2188   "
2189 {
2190   rtx ve = gen_reg_rtx (V8HImode);
2191   rtx vo = gen_reg_rtx (V8HImode);
2192   
2193   emit_insn (gen_altivec_vmuleub (ve, operands[1], operands[2]));
2194   emit_insn (gen_altivec_vmuloub (vo, operands[1], operands[2]));
2195   emit_insn (gen_altivec_vmrghh (operands[0], ve, vo));
2196   DONE;
2197 }")
2198
2199 (define_expand "vec_widen_umult_lo_v16qi"
2200   [(set (match_operand:V8HI 0 "register_operand" "=v")
2201         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
2202                       (match_operand:V16QI 2 "register_operand" "v")]
2203                      UNSPEC_VMULWLUB))]
2204   "TARGET_ALTIVEC"
2205   "
2206 {
2207   rtx ve = gen_reg_rtx (V8HImode);
2208   rtx vo = gen_reg_rtx (V8HImode);
2209   
2210   emit_insn (gen_altivec_vmuleub (ve, operands[1], operands[2]));
2211   emit_insn (gen_altivec_vmuloub (vo, operands[1], operands[2]));
2212   emit_insn (gen_altivec_vmrglh (operands[0], ve, vo));
2213   DONE;
2214 }")
2215
2216 (define_expand "vec_widen_smult_hi_v16qi"
2217   [(set (match_operand:V8HI 0 "register_operand" "=v")
2218         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
2219                       (match_operand:V16QI 2 "register_operand" "v")]
2220                      UNSPEC_VMULWHSB))]
2221   "TARGET_ALTIVEC"
2222   "
2223 {
2224   rtx ve = gen_reg_rtx (V8HImode);
2225   rtx vo = gen_reg_rtx (V8HImode);
2226   
2227   emit_insn (gen_altivec_vmulesb (ve, operands[1], operands[2]));
2228   emit_insn (gen_altivec_vmulosb (vo, operands[1], operands[2]));
2229   emit_insn (gen_altivec_vmrghh (operands[0], ve, vo));
2230   DONE;
2231 }")
2232
2233 (define_expand "vec_widen_smult_lo_v16qi"
2234   [(set (match_operand:V8HI 0 "register_operand" "=v")
2235         (unspec:V8HI [(match_operand:V16QI 1 "register_operand" "v")
2236                       (match_operand:V16QI 2 "register_operand" "v")]
2237                      UNSPEC_VMULWLSB))]
2238   "TARGET_ALTIVEC"
2239   "
2240 {
2241   rtx ve = gen_reg_rtx (V8HImode);
2242   rtx vo = gen_reg_rtx (V8HImode);
2243   
2244   emit_insn (gen_altivec_vmulesb (ve, operands[1], operands[2]));
2245   emit_insn (gen_altivec_vmulosb (vo, operands[1], operands[2]));
2246   emit_insn (gen_altivec_vmrglh (operands[0], ve, vo));
2247   DONE;
2248 }")
2249
2250 (define_expand "vec_widen_umult_hi_v8hi"
2251   [(set (match_operand:V4SI 0 "register_operand" "=v")
2252         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
2253                       (match_operand:V8HI 2 "register_operand" "v")]
2254                      UNSPEC_VMULWHUH))]
2255   "TARGET_ALTIVEC"
2256   "
2257
2258   rtx ve = gen_reg_rtx (V4SImode);
2259   rtx vo = gen_reg_rtx (V4SImode);
2260   
2261   emit_insn (gen_altivec_vmuleuh (ve, operands[1], operands[2]));
2262   emit_insn (gen_altivec_vmulouh (vo, operands[1], operands[2]));
2263   emit_insn (gen_altivec_vmrghw (operands[0], ve, vo));
2264   DONE;
2265 }")
2266
2267 (define_expand "vec_widen_umult_lo_v8hi"
2268   [(set (match_operand:V4SI 0 "register_operand" "=v")
2269         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
2270                       (match_operand:V8HI 2 "register_operand" "v")]
2271                      UNSPEC_VMULWLUH))]
2272   "TARGET_ALTIVEC"
2273   "
2274
2275   rtx ve = gen_reg_rtx (V4SImode);
2276   rtx vo = gen_reg_rtx (V4SImode);
2277   
2278   emit_insn (gen_altivec_vmuleuh (ve, operands[1], operands[2]));
2279   emit_insn (gen_altivec_vmulouh (vo, operands[1], operands[2]));
2280   emit_insn (gen_altivec_vmrglw (operands[0], ve, vo));
2281   DONE;
2282 }")
2283
2284 (define_expand "vec_widen_smult_hi_v8hi"
2285   [(set (match_operand:V4SI 0 "register_operand" "=v")
2286         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
2287                       (match_operand:V8HI 2 "register_operand" "v")]
2288                      UNSPEC_VMULWHSH))]
2289   "TARGET_ALTIVEC"
2290   "
2291
2292   rtx ve = gen_reg_rtx (V4SImode);
2293   rtx vo = gen_reg_rtx (V4SImode);
2294   
2295   emit_insn (gen_altivec_vmulesh (ve, operands[1], operands[2]));
2296   emit_insn (gen_altivec_vmulosh (vo, operands[1], operands[2]));
2297   emit_insn (gen_altivec_vmrghw (operands[0], ve, vo));
2298   DONE;
2299 }")
2300
2301 (define_expand "vec_widen_smult_lo_v8hi"
2302   [(set (match_operand:V4SI 0 "register_operand" "=v")
2303         (unspec:V4SI [(match_operand:V8HI 1 "register_operand" "v")
2304                       (match_operand:V8HI 2 "register_operand" "v")]
2305                      UNSPEC_VMULWLSH))]
2306   "TARGET_ALTIVEC"
2307   "
2308
2309   rtx ve = gen_reg_rtx (V4SImode);
2310   rtx vo = gen_reg_rtx (V4SImode);
2311   
2312   emit_insn (gen_altivec_vmulesh (ve, operands[1], operands[2]));
2313   emit_insn (gen_altivec_vmulosh (vo, operands[1], operands[2]));
2314   emit_insn (gen_altivec_vmrglw (operands[0], ve, vo));
2315   DONE;
2316 }")
2317
2318 (define_expand "vec_pack_trunc_v8hi"
2319   [(set (match_operand:V16QI 0 "register_operand" "=v")
2320         (unspec:V16QI [(match_operand:V8HI 1 "register_operand" "v")
2321                        (match_operand:V8HI 2 "register_operand" "v")]
2322                       UNSPEC_VPKUHUM))]
2323   "TARGET_ALTIVEC"
2324   "
2325 {
2326   emit_insn (gen_altivec_vpkuhum (operands[0], operands[1], operands[2]));
2327   DONE;
2328 }")
2329                                                                                 
2330 (define_expand "vec_pack_trunc_v4si"
2331   [(set (match_operand:V8HI 0 "register_operand" "=v")
2332         (unspec:V8HI [(match_operand:V4SI 1 "register_operand" "v")
2333                       (match_operand:V4SI 2 "register_operand" "v")]
2334                      UNSPEC_VPKUWUM))]
2335   "TARGET_ALTIVEC"
2336   "
2337 {
2338   emit_insn (gen_altivec_vpkuwum (operands[0], operands[1], operands[2]));
2339   DONE;
2340 }")
2341
2342 (define_expand "altivec_negv4sf2"
2343   [(use (match_operand:V4SF 0 "register_operand" ""))
2344    (use (match_operand:V4SF 1 "register_operand" ""))]
2345   "TARGET_ALTIVEC"
2346   "
2347 {
2348   rtx neg0;
2349
2350   /* Generate [-0.0, -0.0, -0.0, -0.0].  */
2351   neg0 = gen_reg_rtx (V4SImode);
2352   emit_insn (gen_altivec_vspltisw (neg0, constm1_rtx));
2353   emit_insn (gen_vashlv4si3 (neg0, neg0, neg0));
2354
2355   /* XOR */
2356   emit_insn (gen_xorv4sf3 (operands[0],
2357                            gen_lowpart (V4SFmode, neg0), operands[1])); 
2358     
2359   DONE;
2360 }")
2361
2362 ;; Vector SIMD PEM v2.06c defines LVLX, LVLXL, LVRX, LVRXL,
2363 ;; STVLX, STVLXL, STVVRX, STVRXL are available only on Cell.
2364 (define_insn "altivec_lvlx"
2365   [(set (match_operand:V16QI 0 "register_operand" "=v")
2366         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] 
2367                       UNSPEC_LVLX))]
2368   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2369   "lvlx %0,%y1"
2370   [(set_attr "type" "vecload")])
2371
2372 (define_insn "altivec_lvlxl"
2373   [(set (match_operand:V16QI 0 "register_operand" "=v")
2374         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] 
2375                       UNSPEC_LVLXL))]
2376   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2377   "lvlxl %0,%y1"
2378   [(set_attr "type" "vecload")])
2379
2380 (define_insn "altivec_lvrx"
2381   [(set (match_operand:V16QI 0 "register_operand" "=v")
2382         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] 
2383                       UNSPEC_LVRX))]
2384   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2385   "lvrx %0,%y1"
2386   [(set_attr "type" "vecload")])
2387
2388 (define_insn "altivec_lvrxl"
2389   [(set (match_operand:V16QI 0 "register_operand" "=v")
2390         (unspec:V16QI [(match_operand 1 "memory_operand" "Z")] 
2391                       UNSPEC_LVRXL))]
2392   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2393   "lvrxl %0,%y1"
2394   [(set_attr "type" "vecload")])
2395
2396 (define_insn "altivec_stvlx"
2397   [(parallel
2398     [(set (match_operand:V4SI 0 "memory_operand" "=Z")
2399           (match_operand:V4SI 1 "register_operand" "v"))
2400      (unspec [(const_int 0)] UNSPEC_STVLX)])]
2401   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2402   "stvlx %1,%y0"
2403   [(set_attr "type" "vecstore")])
2404
2405 (define_insn "altivec_stvlxl"
2406   [(parallel
2407     [(set (match_operand:V4SI 0 "memory_operand" "=Z")
2408           (match_operand:V4SI 1 "register_operand" "v"))
2409      (unspec [(const_int 0)] UNSPEC_STVLXL)])]
2410   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2411   "stvlxl %1,%y0"
2412   [(set_attr "type" "vecstore")])
2413
2414 (define_insn "altivec_stvrx"
2415   [(parallel
2416     [(set (match_operand:V4SI 0 "memory_operand" "=Z")
2417           (match_operand:V4SI 1 "register_operand" "v"))
2418      (unspec [(const_int 0)] UNSPEC_STVRX)])]
2419   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2420   "stvrx %1,%y0"
2421   [(set_attr "type" "vecstore")])
2422
2423 (define_insn "altivec_stvrxl"
2424   [(parallel
2425     [(set (match_operand:V4SI 0 "memory_operand" "=Z")
2426           (match_operand:V4SI 1 "register_operand" "v"))
2427      (unspec [(const_int 0)] UNSPEC_STVRXL)])]
2428   "TARGET_ALTIVEC && rs6000_cpu == PROCESSOR_CELL"
2429   "stvrxl %1,%y0"
2430   [(set_attr "type" "vecstore")])
2431
2432 ;; ??? This is still used directly by vector.md
2433 (define_expand "vec_extract_evenv4si"
2434  [(set (match_operand:V4SI 0 "register_operand" "")
2435         (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "")
2436                       (match_operand:V4SI 2 "register_operand" "")]
2437                       UNSPEC_EXTEVEN_V4SI))]
2438   "TARGET_ALTIVEC"
2439   "
2440 {
2441   rtx mask = gen_reg_rtx (V16QImode);
2442   rtvec v = rtvec_alloc (16);
2443
2444   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 0);
2445   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 1);
2446   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 2);
2447   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 3);
2448   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 8);
2449   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 9);
2450   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 10);
2451   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 11);
2452   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2453   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 17);
2454   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 18);
2455   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 19);
2456   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 24);
2457   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 25);
2458   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 26);
2459   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 27);
2460   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2461   emit_insn (gen_altivec_vperm_v4si (operands[0], operands[1], operands[2], mask));
2462   
2463   DONE;
2464 }")
2465
2466 ;; ??? This is still used directly by vector.md
2467 (define_expand "vec_extract_evenv4sf"
2468  [(set (match_operand:V4SF 0 "register_operand" "")
2469         (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "")
2470                       (match_operand:V4SF 2 "register_operand" "")]
2471                       UNSPEC_EXTEVEN_V4SF))]
2472   "TARGET_ALTIVEC"
2473   "
2474
2475   rtx mask = gen_reg_rtx (V16QImode);
2476   rtvec v = rtvec_alloc (16);
2477   
2478   RTVEC_ELT (v, 0) = gen_rtx_CONST_INT (QImode, 0);
2479   RTVEC_ELT (v, 1) = gen_rtx_CONST_INT (QImode, 1);
2480   RTVEC_ELT (v, 2) = gen_rtx_CONST_INT (QImode, 2);
2481   RTVEC_ELT (v, 3) = gen_rtx_CONST_INT (QImode, 3);
2482   RTVEC_ELT (v, 4) = gen_rtx_CONST_INT (QImode, 8);
2483   RTVEC_ELT (v, 5) = gen_rtx_CONST_INT (QImode, 9);
2484   RTVEC_ELT (v, 6) = gen_rtx_CONST_INT (QImode, 10);
2485   RTVEC_ELT (v, 7) = gen_rtx_CONST_INT (QImode, 11);
2486   RTVEC_ELT (v, 8) = gen_rtx_CONST_INT (QImode, 16);
2487   RTVEC_ELT (v, 9) = gen_rtx_CONST_INT (QImode, 17);
2488   RTVEC_ELT (v, 10) = gen_rtx_CONST_INT (QImode, 18);
2489   RTVEC_ELT (v, 11) = gen_rtx_CONST_INT (QImode, 19);
2490   RTVEC_ELT (v, 12) = gen_rtx_CONST_INT (QImode, 24);
2491   RTVEC_ELT (v, 13) = gen_rtx_CONST_INT (QImode, 25);
2492   RTVEC_ELT (v, 14) = gen_rtx_CONST_INT (QImode, 26);
2493   RTVEC_ELT (v, 15) = gen_rtx_CONST_INT (QImode, 27);
2494   emit_insn (gen_vec_initv16qi (mask, gen_rtx_PARALLEL (V16QImode, v)));
2495   emit_insn (gen_altivec_vperm_v4sf (operands[0], operands[1], operands[2], mask));
2496   
2497   DONE;
2498 }")
2499
2500 (define_insn "vpkuhum_nomode"
2501   [(set (match_operand:V16QI 0 "register_operand" "=v")
2502         (unspec:V16QI [(match_operand 1 "register_operand" "v")
2503                        (match_operand 2 "register_operand" "v")]
2504                       UNSPEC_VPKUHUM))] 
2505   "TARGET_ALTIVEC"
2506   "vpkuhum %0,%1,%2"
2507   [(set_attr "type" "vecperm")])
2508
2509 (define_insn "vpkuwum_nomode"
2510   [(set (match_operand:V8HI 0 "register_operand" "=v")
2511         (unspec:V8HI [(match_operand 1 "register_operand" "v")
2512                       (match_operand 2 "register_operand" "v")]
2513                      UNSPEC_VPKUWUM))]
2514   "TARGET_ALTIVEC"
2515   "vpkuwum %0,%1,%2"
2516   [(set_attr "type" "vecperm")])
2517
2518 (define_expand "vec_extract_oddv8hi"
2519  [(set (match_operand:V8HI 0 "register_operand" "")
2520         (unspec:V8HI [(match_operand:V8HI 1 "register_operand" "")
2521                       (match_operand:V8HI 2 "register_operand" "")]
2522                       UNSPEC_EXTODD_V8HI))]
2523   "TARGET_ALTIVEC"
2524   "
2525 {
2526   emit_insn (gen_vpkuwum_nomode (operands[0], operands[1], operands[2]));
2527   DONE;
2528 }")
2529
2530 (define_expand "vec_extract_oddv16qi"
2531  [(set (match_operand:V16QI 0 "register_operand" "")
2532         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "")
2533                       (match_operand:V16QI 2 "register_operand" "")]
2534                       UNSPEC_EXTODD_V16QI))]
2535   "TARGET_ALTIVEC"
2536   "
2537 {
2538   emit_insn (gen_vpkuhum_nomode (operands[0], operands[1], operands[2]));
2539   DONE;
2540 }")
2541
2542 (define_expand "vec_interleave_high<mode>"
2543  [(set (match_operand:VI 0 "register_operand" "")
2544         (unspec:VI [(match_operand:VI 1 "register_operand" "")
2545                     (match_operand:VI 2 "register_operand" "")]
2546                      UNSPEC_INTERHI))]
2547   "TARGET_ALTIVEC"
2548   "
2549 {
2550   emit_insn (gen_altivec_vmrgh<VI_char> (operands[0], operands[1], operands[2]));
2551   DONE;
2552 }")
2553
2554 (define_expand "vec_interleave_low<mode>"
2555  [(set (match_operand:VI 0 "register_operand" "")
2556         (unspec:VI [(match_operand:VI 1 "register_operand" "")
2557                     (match_operand:VI 2 "register_operand" "")]
2558                      UNSPEC_INTERLO))]
2559   "TARGET_ALTIVEC"
2560   "
2561 {
2562   emit_insn (gen_altivec_vmrgl<VI_char> (operands[0], operands[1], operands[2]));
2563   DONE;
2564 }")
2565
2566 (define_expand "vec_unpacks_float_hi_v8hi"
2567  [(set (match_operand:V4SF 0 "register_operand" "")
2568         (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "")]
2569                      UNSPEC_VUPKHS_V4SF))]
2570   "TARGET_ALTIVEC"
2571   "
2572 {
2573   rtx tmp = gen_reg_rtx (V4SImode);
2574
2575   emit_insn (gen_vec_unpacks_hi_v8hi (tmp, operands[1]));
2576   emit_insn (gen_altivec_vcfsx (operands[0], tmp, const0_rtx));
2577   DONE;
2578 }")
2579
2580 (define_expand "vec_unpacks_float_lo_v8hi"
2581  [(set (match_operand:V4SF 0 "register_operand" "")
2582         (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "")]
2583                      UNSPEC_VUPKLS_V4SF))]
2584   "TARGET_ALTIVEC"
2585   "
2586 {
2587   rtx tmp = gen_reg_rtx (V4SImode);
2588
2589   emit_insn (gen_vec_unpacks_lo_v8hi (tmp, operands[1]));
2590   emit_insn (gen_altivec_vcfsx (operands[0], tmp, const0_rtx));
2591   DONE;
2592 }")
2593
2594 (define_expand "vec_unpacku_float_hi_v8hi"
2595  [(set (match_operand:V4SF 0 "register_operand" "")
2596         (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "")]
2597                      UNSPEC_VUPKHU_V4SF))]
2598   "TARGET_ALTIVEC"
2599   "
2600 {
2601   rtx tmp = gen_reg_rtx (V4SImode);
2602
2603   emit_insn (gen_vec_unpacku_hi_v8hi (tmp, operands[1]));
2604   emit_insn (gen_altivec_vcfux (operands[0], tmp, const0_rtx));
2605   DONE;
2606 }")
2607
2608 (define_expand "vec_unpacku_float_lo_v8hi"
2609  [(set (match_operand:V4SF 0 "register_operand" "")
2610         (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "")]
2611                      UNSPEC_VUPKLU_V4SF))]
2612   "TARGET_ALTIVEC"
2613   "
2614 {
2615   rtx tmp = gen_reg_rtx (V4SImode);
2616
2617   emit_insn (gen_vec_unpacku_lo_v8hi (tmp, operands[1]));
2618   emit_insn (gen_altivec_vcfux (operands[0], tmp, const0_rtx));
2619   DONE;
2620 }")