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