gcc:
[official-gcc.git] / gcc / config / rs6000 / vector.md
blobcbb1f4f8e7246a6c142fa2503d3729a65189e5b3
1 ;; Expander definitions for vector support between altivec & vsx.  No
2 ;; instructions are in this file, this file provides the generic vector
3 ;; expander, and the actual vector instructions will be in altivec.md and
4 ;; vsx.md
6 ;; Copyright (C) 2009-2013 Free Software Foundation, Inc.
7 ;; Contributed by Michael Meissner <meissner@linux.vnet.ibm.com>
9 ;; This file is part of GCC.
11 ;; GCC is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 3, or (at your
14 ;; option) any later version.
16 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
19 ;; License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GCC; see the file COPYING3.  If not see
23 ;; <http://www.gnu.org/licenses/>.
26 ;; Vector int modes
27 (define_mode_iterator VEC_I [V16QI V8HI V4SI V2DI])
29 ;; Vector float modes
30 (define_mode_iterator VEC_F [V4SF V2DF])
32 ;; Vector arithmetic modes
33 (define_mode_iterator VEC_A [V16QI V8HI V4SI V2DI V4SF V2DF])
35 ;; Vector modes that need alginment via permutes
36 (define_mode_iterator VEC_K [V16QI V8HI V4SI V4SF])
38 ;; Vector logical modes
39 (define_mode_iterator VEC_L [V16QI V8HI V4SI V2DI V4SF V2DF TI])
41 ;; Vector modes for moves.  Don't do TImode here.
42 (define_mode_iterator VEC_M [V16QI V8HI V4SI V2DI V4SF V2DF])
44 ;; Vector modes for types that don't need a realignment under VSX
45 (define_mode_iterator VEC_N [V4SI V4SF V2DI V2DF])
47 ;; Vector comparison modes
48 (define_mode_iterator VEC_C [V16QI V8HI V4SI V2DI V4SF V2DF])
50 ;; Vector init/extract modes
51 (define_mode_iterator VEC_E [V16QI V8HI V4SI V2DI V4SF V2DF])
53 ;; Vector modes for 64-bit base types
54 (define_mode_iterator VEC_64 [V2DI V2DF])
56 ;; Vector reload iterator
57 (define_mode_iterator VEC_R [V16QI V8HI V4SI V2DI V4SF V2DF SF SD SI DF DD DI TI])
59 ;; Base type from vector mode
60 (define_mode_attr VEC_base [(V16QI "QI")
61                             (V8HI  "HI")
62                             (V4SI  "SI")
63                             (V2DI  "DI")
64                             (V4SF  "SF")
65                             (V2DF  "DF")
66                             (TI    "TI")])
68 ;; Same size integer type for floating point data
69 (define_mode_attr VEC_int [(V4SF  "v4si")
70                            (V2DF  "v2di")])
72 (define_mode_attr VEC_INT [(V4SF  "V4SI")
73                            (V2DF  "V2DI")])
75 ;; constants for unspec
76 (define_c_enum "unspec" [UNSPEC_PREDICATE
77                          UNSPEC_REDUC])
79 ;; Vector reduction code iterators
80 (define_code_iterator VEC_reduc [plus smin smax])
82 (define_code_attr VEC_reduc_name [(plus "splus")
83                                   (smin "smin")
84                                   (smax "smax")])
86 (define_code_attr VEC_reduc_rtx [(plus "add")
87                                  (smin "smin")
88                                  (smax "smax")])
91 ;; Vector move instructions.  Little-endian VSX loads and stores require
92 ;; special handling to circumvent "element endianness."
93 (define_expand "mov<mode>"
94   [(set (match_operand:VEC_M 0 "nonimmediate_operand" "")
95         (match_operand:VEC_M 1 "any_operand" ""))]
96   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
98   if (can_create_pseudo_p ())
99     {
100       if (CONSTANT_P (operands[1])
101           && !easy_vector_constant (operands[1], <MODE>mode))
102         operands[1] = force_const_mem (<MODE>mode, operands[1]);
104       else if (!vlogical_operand (operands[0], <MODE>mode)
105                && !vlogical_operand (operands[1], <MODE>mode))
106         operands[1] = force_reg (<MODE>mode, operands[1]);
107     }
108   if (!BYTES_BIG_ENDIAN
109       && VECTOR_MEM_VSX_P (<MODE>mode)
110       && <MODE>mode != TImode
111       && (memory_operand (operands[0], <MODE>mode)
112           ^ memory_operand (operands[1], <MODE>mode)))
113     {
114       rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
115       DONE;
116     }
119 ;; Generic vector floating point load/store instructions.  These will match
120 ;; insns defined in vsx.md or altivec.md depending on the switches.
121 (define_expand "vector_load_<mode>"
122   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
123         (match_operand:VEC_M 1 "memory_operand" ""))]
124   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
125   "")
127 (define_expand "vector_store_<mode>"
128   [(set (match_operand:VEC_M 0 "memory_operand" "")
129         (match_operand:VEC_M 1 "vfloat_operand" ""))]
130   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
131   "")
133 ;; Splits if a GPR register was chosen for the move
134 (define_split
135   [(set (match_operand:VEC_L 0 "nonimmediate_operand" "")
136         (match_operand:VEC_L 1 "input_operand" ""))]
137   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
138    && reload_completed
139    && gpr_or_gpr_p (operands[0], operands[1])
140    && !direct_move_p (operands[0], operands[1])
141    && !quad_load_store_p (operands[0], operands[1])"
142   [(pc)]
144   rs6000_split_multireg_move (operands[0], operands[1]);
145   DONE;
148 ;; Vector floating point load/store instructions that uses the Altivec
149 ;; instructions even if we are compiling for VSX, since the Altivec
150 ;; instructions silently ignore the bottom 3 bits of the address, and VSX does
151 ;; not.
152 (define_expand "vector_altivec_load_<mode>"
153   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
154         (match_operand:VEC_M 1 "memory_operand" ""))]
155   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
156   "
158   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
160   if (VECTOR_MEM_VSX_P (<MODE>mode))
161     {
162       operands[1] = rs6000_address_for_altivec (operands[1]);
163       emit_insn (gen_altivec_lvx_<mode> (operands[0], operands[1]));
164       DONE;
165     }
168 (define_expand "vector_altivec_store_<mode>"
169   [(set (match_operand:VEC_M 0 "memory_operand" "")
170         (match_operand:VEC_M 1 "vfloat_operand" ""))]
171   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
172   "
174   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
176   if (VECTOR_MEM_VSX_P (<MODE>mode))
177     {
178       operands[0] = rs6000_address_for_altivec (operands[0]);
179       emit_insn (gen_altivec_stvx_<mode> (operands[0], operands[1]));
180       DONE;
181     }
186 ;; Reload patterns for vector operations.  We may need an additional base
187 ;; register to convert the reg+offset addressing to reg+reg for vector
188 ;; registers and reg+reg or (reg+reg)&(-16) addressing to just an index
189 ;; register for gpr registers.
190 (define_expand "reload_<VEC_R:mode>_<P:mptrsize>_store"
191   [(parallel [(match_operand:VEC_R 0 "memory_operand" "m")
192               (match_operand:VEC_R 1 "gpc_reg_operand" "r")
193               (match_operand:P 2 "register_operand" "=&b")])]
194   "<P:tptrsize>"
196   rs6000_secondary_reload_inner (operands[1], operands[0], operands[2], true);
197   DONE;
200 (define_expand "reload_<VEC_R:mode>_<P:mptrsize>_load"
201   [(parallel [(match_operand:VEC_R 0 "gpc_reg_operand" "=&r")
202               (match_operand:VEC_R 1 "memory_operand" "m")
203               (match_operand:P 2 "register_operand" "=&b")])]
204   "<P:tptrsize>"
206   rs6000_secondary_reload_inner (operands[0], operands[1], operands[2], false);
207   DONE;
210 ;; Reload sometimes tries to move the address to a GPR, and can generate
211 ;; invalid RTL for addresses involving AND -16.  Allow addresses involving
212 ;; reg+reg, reg+small constant, or just reg, all wrapped in an AND -16.
214 (define_insn_and_split "*vec_reload_and_plus_<mptrsize>"
215   [(set (match_operand:P 0 "gpc_reg_operand" "=b")
216         (and:P (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
217                        (match_operand:P 2 "reg_or_cint_operand" "rI"))
218                (const_int -16)))]
219   "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
220   "#"
221   "&& reload_completed"
222   [(set (match_dup 0)
223         (plus:P (match_dup 1)
224                 (match_dup 2)))
225    (parallel [(set (match_dup 0)
226                    (and:P (match_dup 0)
227                           (const_int -16)))
228               (clobber:CC (scratch:CC))])])
230 ;; The normal ANDSI3/ANDDI3 won't match if reload decides to move an AND -16
231 ;; address to a register because there is no clobber of a (scratch), so we add
232 ;; it here.
233 (define_insn_and_split "*vec_reload_and_reg_<mptrsize>"
234   [(set (match_operand:P 0 "gpc_reg_operand" "=b")
235         (and:P (match_operand:P 1 "gpc_reg_operand" "r")
236                (const_int -16)))]
237   "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
238   "#"
239   "&& reload_completed"
240   [(parallel [(set (match_dup 0)
241                    (and:P (match_dup 1)
242                           (const_int -16)))
243               (clobber:CC (scratch:CC))])])
245 ;; Generic floating point vector arithmetic support
246 (define_expand "add<mode>3"
247   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
248         (plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
249                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
250   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
251   "")
253 (define_expand "sub<mode>3"
254   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
255         (minus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
256                      (match_operand:VEC_F 2 "vfloat_operand" "")))]
257   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
258   "")
260 (define_expand "mul<mode>3"
261   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
262         (mult:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
263                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
264   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
266   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
267     {
268       emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
269       DONE;
270     }
273 (define_expand "div<mode>3"
274   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
275         (div:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
276                    (match_operand:VEC_F 2 "vfloat_operand" "")))]
277   "VECTOR_UNIT_VSX_P (<MODE>mode)"
278   "")
280 (define_expand "neg<mode>2"
281   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
282         (neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
283   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
284   "
286   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
287     {
288       emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
289       DONE;
290     }
293 (define_expand "abs<mode>2"
294   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
295         (abs:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
296   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
297   "
299   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
300     {
301       emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
302       DONE;
303     }
306 (define_expand "smin<mode>3"
307   [(set (match_operand:VEC_F 0 "register_operand" "")
308         (smin:VEC_F (match_operand:VEC_F 1 "register_operand" "")
309                     (match_operand:VEC_F 2 "register_operand" "")))]
310   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
311   "")
313 (define_expand "smax<mode>3"
314   [(set (match_operand:VEC_F 0 "register_operand" "")
315         (smax:VEC_F (match_operand:VEC_F 1 "register_operand" "")
316                     (match_operand:VEC_F 2 "register_operand" "")))]
317   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
318   "")
321 (define_expand "sqrt<mode>2"
322   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
323         (sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
324   "VECTOR_UNIT_VSX_P (<MODE>mode)"
325   "")
327 (define_expand "rsqrte<mode>2"
328   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
329         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
330                       UNSPEC_RSQRT))]
331   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
332   "")
334 (define_expand "re<mode>2"
335   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
336         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "f")]
337                       UNSPEC_FRES))]
338   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
339   "")
341 (define_expand "ftrunc<mode>2"
342   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
343         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
344   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
345   "")
347 (define_expand "vector_ceil<mode>2"
348   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
349         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
350                       UNSPEC_FRIP))]
351   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
352   "")
354 (define_expand "vector_floor<mode>2"
355   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
356         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
357                       UNSPEC_FRIM))]
358   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
359   "")
361 (define_expand "vector_btrunc<mode>2"
362   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
363         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
364   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
365   "")
367 (define_expand "vector_copysign<mode>3"
368   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
369         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")
370                        (match_operand:VEC_F 2 "vfloat_operand" "")] UNSPEC_COPYSIGN))]
371   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
372   "
374   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
375     {
376       emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
377                                              operands[2]));
378       DONE;
379     }
383 ;; Vector comparisons
384 (define_expand "vcond<mode><mode>"
385   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
386         (if_then_else:VEC_F
387          (match_operator 3 "comparison_operator"
388                          [(match_operand:VEC_F 4 "vfloat_operand" "")
389                           (match_operand:VEC_F 5 "vfloat_operand" "")])
390          (match_operand:VEC_F 1 "vfloat_operand" "")
391          (match_operand:VEC_F 2 "vfloat_operand" "")))]
392   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
393   "
395   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
396                                     operands[3], operands[4], operands[5]))
397     DONE;
398   else
399     FAIL;
402 (define_expand "vcond<mode><mode>"
403   [(set (match_operand:VEC_I 0 "vint_operand" "")
404         (if_then_else:VEC_I
405          (match_operator 3 "comparison_operator"
406                          [(match_operand:VEC_I 4 "vint_operand" "")
407                           (match_operand:VEC_I 5 "vint_operand" "")])
408          (match_operand:VEC_I 1 "vint_operand" "")
409          (match_operand:VEC_I 2 "vint_operand" "")))]
410   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
411   "
413   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
414                                     operands[3], operands[4], operands[5]))
415     DONE;
416   else
417     FAIL;
420 (define_expand "vcondv4sfv4si"
421   [(set (match_operand:V4SF 0 "vfloat_operand" "")
422         (if_then_else:V4SF
423          (match_operator 3 "comparison_operator"
424                          [(match_operand:V4SI 4 "vint_operand" "")
425                           (match_operand:V4SI 5 "vint_operand" "")])
426          (match_operand:V4SF 1 "vfloat_operand" "")
427          (match_operand:V4SF 2 "vfloat_operand" "")))]
428   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
429    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
430   "
432   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
433                                     operands[3], operands[4], operands[5]))
434     DONE;
435   else
436     FAIL;
439 (define_expand "vcondv4siv4sf"
440   [(set (match_operand:V4SI 0 "vint_operand" "")
441         (if_then_else:V4SI
442          (match_operator 3 "comparison_operator"
443                          [(match_operand:V4SF 4 "vfloat_operand" "")
444                           (match_operand:V4SF 5 "vfloat_operand" "")])
445          (match_operand:V4SI 1 "vint_operand" "")
446          (match_operand:V4SI 2 "vint_operand" "")))]
447   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
448    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
449   "
451   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
452                                     operands[3], operands[4], operands[5]))
453     DONE;
454   else
455     FAIL;
458 (define_expand "vcondu<mode><mode>"
459   [(set (match_operand:VEC_I 0 "vint_operand" "")
460         (if_then_else:VEC_I
461          (match_operator 3 "comparison_operator"
462                          [(match_operand:VEC_I 4 "vint_operand" "")
463                           (match_operand:VEC_I 5 "vint_operand" "")])
464          (match_operand:VEC_I 1 "vint_operand" "")
465          (match_operand:VEC_I 2 "vint_operand" "")))]
466   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
467   "
469   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
470                                     operands[3], operands[4], operands[5]))
471     DONE;
472   else
473     FAIL;
476 (define_expand "vconduv4sfv4si"
477   [(set (match_operand:V4SF 0 "vfloat_operand" "")
478         (if_then_else:V4SF
479          (match_operator 3 "comparison_operator"
480                          [(match_operand:V4SI 4 "vint_operand" "")
481                           (match_operand:V4SI 5 "vint_operand" "")])
482          (match_operand:V4SF 1 "vfloat_operand" "")
483          (match_operand:V4SF 2 "vfloat_operand" "")))]
484   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
485    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
486   "
488   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
489                                     operands[3], operands[4], operands[5]))
490     DONE;
491   else
492     FAIL;
495 (define_expand "vector_eq<mode>"
496   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
497         (eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
498                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
499   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
500   "")
502 (define_expand "vector_gt<mode>"
503   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
504         (gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
505                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
506   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
507   "")
509 (define_expand "vector_ge<mode>"
510   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
511         (ge:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
512                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
513   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
514   "")
516 (define_expand "vector_gtu<mode>"
517   [(set (match_operand:VEC_I 0 "vint_operand" "")
518         (gtu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
519                    (match_operand:VEC_I 2 "vint_operand" "")))]
520   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
521   "")
523 (define_expand "vector_geu<mode>"
524   [(set (match_operand:VEC_I 0 "vint_operand" "")
525         (geu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
526                    (match_operand:VEC_I 2 "vint_operand" "")))]
527   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
528   "")
530 (define_insn_and_split "*vector_uneq<mode>"
531   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
532         (uneq:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
533                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
534   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
535   "#"
536   ""
537   [(set (match_dup 3)
538         (gt:VEC_F (match_dup 1)
539                   (match_dup 2)))
540    (set (match_dup 4)
541         (gt:VEC_F (match_dup 2)
542                   (match_dup 1)))
543    (set (match_dup 0)
544         (not:VEC_F (ior:VEC_F (match_dup 3)
545                               (match_dup 4))))]
546   "
548   operands[3] = gen_reg_rtx (<MODE>mode);
549   operands[4] = gen_reg_rtx (<MODE>mode);
552 (define_insn_and_split "*vector_ltgt<mode>"
553   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
554         (ltgt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
555                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
556   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
557   "#"
558   ""
559   [(set (match_dup 3)
560         (gt:VEC_F (match_dup 1)
561                   (match_dup 2)))
562    (set (match_dup 4)
563         (gt:VEC_F (match_dup 2)
564                   (match_dup 1)))
565    (set (match_dup 0)
566         (ior:VEC_F (match_dup 3)
567                    (match_dup 4)))]
568   "
570   operands[3] = gen_reg_rtx (<MODE>mode);
571   operands[4] = gen_reg_rtx (<MODE>mode);
574 (define_insn_and_split "*vector_ordered<mode>"
575   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
576         (ordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
577                        (match_operand:VEC_F 2 "vfloat_operand" "")))]
578   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
579   "#"
580   ""
581   [(set (match_dup 3)
582         (ge:VEC_F (match_dup 1)
583                   (match_dup 2)))
584    (set (match_dup 4)
585         (ge:VEC_F (match_dup 2)
586                   (match_dup 1)))
587    (set (match_dup 0)
588         (ior:VEC_F (match_dup 3)
589                    (match_dup 4)))]
590   "
592   operands[3] = gen_reg_rtx (<MODE>mode);
593   operands[4] = gen_reg_rtx (<MODE>mode);
596 (define_insn_and_split "*vector_unordered<mode>"
597   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
598         (unordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
599                          (match_operand:VEC_F 2 "vfloat_operand" "")))]
600   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
601   "#"
602   ""
603   [(set (match_dup 3)
604         (ge:VEC_F (match_dup 1)
605                   (match_dup 2)))
606    (set (match_dup 4)
607         (ge:VEC_F (match_dup 2)
608                   (match_dup 1)))
609    (set (match_dup 0)
610         (not:VEC_F (ior:VEC_F (match_dup 3)
611                               (match_dup 4))))]
612   "
614   operands[3] = gen_reg_rtx (<MODE>mode);
615   operands[4] = gen_reg_rtx (<MODE>mode);
618 ;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask
619 ;; which is in the reverse order that we want
620 (define_expand "vector_select_<mode>"
621   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
622         (if_then_else:VEC_L
623          (ne:CC (match_operand:VEC_L 3 "vlogical_operand" "")
624                 (match_dup 4))
625          (match_operand:VEC_L 2 "vlogical_operand" "")
626          (match_operand:VEC_L 1 "vlogical_operand" "")))]
627   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
628   "operands[4] = CONST0_RTX (<MODE>mode);")
630 (define_expand "vector_select_<mode>_uns"
631   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
632         (if_then_else:VEC_L
633          (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand" "")
634                    (match_dup 4))
635          (match_operand:VEC_L 2 "vlogical_operand" "")
636          (match_operand:VEC_L 1 "vlogical_operand" "")))]
637   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
638   "operands[4] = CONST0_RTX (<MODE>mode);")
640 ;; Expansions that compare vectors producing a vector result and a predicate,
641 ;; setting CR6 to indicate a combined status
642 (define_expand "vector_eq_<mode>_p"
643   [(parallel
644     [(set (reg:CC 74)
645           (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand" "")
646                              (match_operand:VEC_A 2 "vlogical_operand" ""))]
647                      UNSPEC_PREDICATE))
648      (set (match_operand:VEC_A 0 "vlogical_operand" "")
649           (eq:VEC_A (match_dup 1)
650                     (match_dup 2)))])]
651   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
652   "")
654 (define_expand "vector_gt_<mode>_p"
655   [(parallel
656     [(set (reg:CC 74)
657           (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand" "")
658                              (match_operand:VEC_A 2 "vlogical_operand" ""))]
659                      UNSPEC_PREDICATE))
660      (set (match_operand:VEC_A 0 "vlogical_operand" "")
661           (gt:VEC_A (match_dup 1)
662                     (match_dup 2)))])]
663   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
664   "")
666 (define_expand "vector_ge_<mode>_p"
667   [(parallel
668     [(set (reg:CC 74)
669           (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand" "")
670                              (match_operand:VEC_F 2 "vfloat_operand" ""))]
671                      UNSPEC_PREDICATE))
672      (set (match_operand:VEC_F 0 "vfloat_operand" "")
673           (ge:VEC_F (match_dup 1)
674                     (match_dup 2)))])]
675   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
676   "")
678 (define_expand "vector_gtu_<mode>_p"
679   [(parallel
680     [(set (reg:CC 74)
681           (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand" "")
682                               (match_operand:VEC_I 2 "vint_operand" ""))]
683                      UNSPEC_PREDICATE))
684      (set (match_operand:VEC_I 0 "vlogical_operand" "")
685           (gtu:VEC_I (match_dup 1)
686                      (match_dup 2)))])]
687   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
688   "")
690 ;; AltiVec/VSX predicates.
692 (define_expand "cr6_test_for_zero"
693   [(set (match_operand:SI 0 "register_operand" "=r")
694         (eq:SI (reg:CC 74)
695                (const_int 0)))]
696   "TARGET_ALTIVEC || TARGET_VSX"
697   "")
699 (define_expand "cr6_test_for_zero_reverse"
700   [(set (match_operand:SI 0 "register_operand" "=r")
701         (eq:SI (reg:CC 74)
702                (const_int 0)))
703    (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
704   "TARGET_ALTIVEC || TARGET_VSX"
705   "")
707 (define_expand "cr6_test_for_lt"
708   [(set (match_operand:SI 0 "register_operand" "=r")
709         (lt:SI (reg:CC 74)
710                (const_int 0)))]
711   "TARGET_ALTIVEC || TARGET_VSX"
712   "")
714 (define_expand "cr6_test_for_lt_reverse"
715   [(set (match_operand:SI 0 "register_operand" "=r")
716         (lt:SI (reg:CC 74)
717                (const_int 0)))
718    (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
719   "TARGET_ALTIVEC || TARGET_VSX"
720   "")
723 ;; Vector count leading zeros
724 (define_expand "clz<mode>2"
725   [(set (match_operand:VEC_I 0 "register_operand" "")
726         (clz:VEC_I (match_operand:VEC_I 1 "register_operand" "")))]
727   "TARGET_P8_VECTOR")
729 ;; Vector population count
730 (define_expand "popcount<mode>2"
731   [(set (match_operand:VEC_I 0 "register_operand" "")
732         (popcount:VEC_I (match_operand:VEC_I 1 "register_operand" "")))]
733   "TARGET_P8_VECTOR")
736 ;; Same size conversions
737 (define_expand "float<VEC_int><mode>2"
738   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
739         (float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
740   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
741   "
743   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
744     {
745       emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
746       DONE;
747     }
750 (define_expand "floatuns<VEC_int><mode>2"
751   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
752         (unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
753   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
754   "
756   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
757     {
758       emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
759       DONE;
760     }
763 (define_expand "fix_trunc<mode><VEC_int>2"
764   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
765         (fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
766   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
767   "
769   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
770     {
771       emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
772       DONE;
773     }
776 (define_expand "fixuns_trunc<mode><VEC_int>2"
777   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
778         (unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
779   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
780   "
782   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
783     {
784       emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
785       DONE;
786     }
790 ;; Vector initialization, set, extract
791 (define_expand "vec_init<mode>"
792   [(match_operand:VEC_E 0 "vlogical_operand" "")
793    (match_operand:VEC_E 1 "" "")]
794   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
796   rs6000_expand_vector_init (operands[0], operands[1]);
797   DONE;
800 (define_expand "vec_set<mode>"
801   [(match_operand:VEC_E 0 "vlogical_operand" "")
802    (match_operand:<VEC_base> 1 "register_operand" "")
803    (match_operand 2 "const_int_operand" "")]
804   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
806   rs6000_expand_vector_set (operands[0], operands[1], INTVAL (operands[2]));
807   DONE;
810 (define_expand "vec_extract<mode>"
811   [(match_operand:<VEC_base> 0 "register_operand" "")
812    (match_operand:VEC_E 1 "vlogical_operand" "")
813    (match_operand 2 "const_int_operand" "")]
814   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
816   rs6000_expand_vector_extract (operands[0], operands[1],
817                                 INTVAL (operands[2]));
818   DONE;
821 ;; Convert double word types to single word types
822 (define_expand "vec_pack_trunc_v2df"
823   [(match_operand:V4SF 0 "vfloat_operand" "")
824    (match_operand:V2DF 1 "vfloat_operand" "")
825    (match_operand:V2DF 2 "vfloat_operand" "")]
826   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
828   rtx r1 = gen_reg_rtx (V4SFmode);
829   rtx r2 = gen_reg_rtx (V4SFmode);
831   emit_insn (gen_vsx_xvcvdpsp (r1, operands[1]));
832   emit_insn (gen_vsx_xvcvdpsp (r2, operands[2]));
833   rs6000_expand_extract_even (operands[0], r1, r2);
834   DONE;
837 (define_expand "vec_pack_sfix_trunc_v2df"
838   [(match_operand:V4SI 0 "vint_operand" "")
839    (match_operand:V2DF 1 "vfloat_operand" "")
840    (match_operand:V2DF 2 "vfloat_operand" "")]
841   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
843   rtx r1 = gen_reg_rtx (V4SImode);
844   rtx r2 = gen_reg_rtx (V4SImode);
846   emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1]));
847   emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2]));
848   rs6000_expand_extract_even (operands[0], r1, r2);
849   DONE;
852 (define_expand "vec_pack_ufix_trunc_v2df"
853   [(match_operand:V4SI 0 "vint_operand" "")
854    (match_operand:V2DF 1 "vfloat_operand" "")
855    (match_operand:V2DF 2 "vfloat_operand" "")]
856   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
858   rtx r1 = gen_reg_rtx (V4SImode);
859   rtx r2 = gen_reg_rtx (V4SImode);
861   emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1]));
862   emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2]));
863   rs6000_expand_extract_even (operands[0], r1, r2);
864   DONE;
867 ;; Convert single word types to double word
868 (define_expand "vec_unpacks_hi_v4sf"
869   [(match_operand:V2DF 0 "vfloat_operand" "")
870    (match_operand:V4SF 1 "vfloat_operand" "")]
871   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
873   rtx reg = gen_reg_rtx (V4SFmode);
875   rs6000_expand_interleave (reg, operands[1], operands[1], true);
876   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
877   DONE;
880 (define_expand "vec_unpacks_lo_v4sf"
881   [(match_operand:V2DF 0 "vfloat_operand" "")
882    (match_operand:V4SF 1 "vfloat_operand" "")]
883   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
885   rtx reg = gen_reg_rtx (V4SFmode);
887   rs6000_expand_interleave (reg, operands[1], operands[1], false);
888   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
889   DONE;
892 (define_expand "vec_unpacks_float_hi_v4si"
893   [(match_operand:V2DF 0 "vfloat_operand" "")
894    (match_operand:V4SI 1 "vint_operand" "")]
895   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
897   rtx reg = gen_reg_rtx (V4SImode);
899   rs6000_expand_interleave (reg, operands[1], operands[1], true);
900   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
901   DONE;
904 (define_expand "vec_unpacks_float_lo_v4si"
905   [(match_operand:V2DF 0 "vfloat_operand" "")
906    (match_operand:V4SI 1 "vint_operand" "")]
907   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
909   rtx reg = gen_reg_rtx (V4SImode);
911   rs6000_expand_interleave (reg, operands[1], operands[1], false);
912   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
913   DONE;
916 (define_expand "vec_unpacku_float_hi_v4si"
917   [(match_operand:V2DF 0 "vfloat_operand" "")
918    (match_operand:V4SI 1 "vint_operand" "")]
919   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
921   rtx reg = gen_reg_rtx (V4SImode);
923   rs6000_expand_interleave (reg, operands[1], operands[1], true);
924   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
925   DONE;
928 (define_expand "vec_unpacku_float_lo_v4si"
929   [(match_operand:V2DF 0 "vfloat_operand" "")
930    (match_operand:V4SI 1 "vint_operand" "")]
931   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
933   rtx reg = gen_reg_rtx (V4SImode);
935   rs6000_expand_interleave (reg, operands[1], operands[1], false);
936   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
937   DONE;
941 ;; Align vector loads with a permute.
942 (define_expand "vec_realign_load_<mode>"
943   [(match_operand:VEC_K 0 "vlogical_operand" "")
944    (match_operand:VEC_K 1 "vlogical_operand" "")
945    (match_operand:VEC_K 2 "vlogical_operand" "")
946    (match_operand:V16QI 3 "vlogical_operand" "")]
947   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
949   if (BYTES_BIG_ENDIAN)
950     emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1],
951                                          operands[2], operands[3]));
952   else
953     emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[2],
954                                          operands[1], operands[3]));
955   DONE;
958 ;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned
959 ;; since the load already handles it.
960 (define_expand "movmisalign<mode>"
961  [(set (match_operand:VEC_N 0 "nonimmediate_operand" "")
962        (match_operand:VEC_N 1 "any_operand" ""))]
963  "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN"
964  "")
967 ;; Vector shift left in bits.  Currently supported ony for shift
968 ;; amounts that can be expressed as byte shifts (divisible by 8).
969 ;; General shift amounts can be supported using vslo + vsl. We're
970 ;; not expecting to see these yet (the vectorizer currently
971 ;; generates only shifts divisible by byte_size).
972 (define_expand "vec_shl_<mode>"
973   [(match_operand:VEC_L 0 "vlogical_operand" "")
974    (match_operand:VEC_L 1 "vlogical_operand" "")
975    (match_operand:QI 2 "reg_or_short_operand" "")]
976   "TARGET_ALTIVEC"
977   "
979   rtx bitshift = operands[2];
980   rtx shift;
981   rtx insn;
982   HOST_WIDE_INT bitshift_val;
983   HOST_WIDE_INT byteshift_val;
985   if (! CONSTANT_P (bitshift))
986     FAIL;
987   bitshift_val = INTVAL (bitshift);
988   if (bitshift_val & 0x7)
989     FAIL;
990   byteshift_val = bitshift_val >> 3;
991   if (TARGET_VSX && (byteshift_val & 0x3) == 0)
992     {
993       shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
994       insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
995                                      shift);
996     }
997   else
998     {
999       shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1000       insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
1001                                         shift);
1002     }
1004   emit_insn (insn);
1005   DONE;
1008 ;; Vector shift right in bits. Currently supported ony for shift
1009 ;; amounts that can be expressed as byte shifts (divisible by 8).
1010 ;; General shift amounts can be supported using vsro + vsr. We're
1011 ;; not expecting to see these yet (the vectorizer currently
1012 ;; generates only shifts divisible by byte_size).
1013 (define_expand "vec_shr_<mode>"
1014   [(match_operand:VEC_L 0 "vlogical_operand" "")
1015    (match_operand:VEC_L 1 "vlogical_operand" "")
1016    (match_operand:QI 2 "reg_or_short_operand" "")]
1017   "TARGET_ALTIVEC"
1018   "
1020   rtx bitshift = operands[2];
1021   rtx shift;
1022   rtx insn;
1023   HOST_WIDE_INT bitshift_val;
1024   HOST_WIDE_INT byteshift_val;
1026   if (! CONSTANT_P (bitshift))
1027     FAIL;
1028   bitshift_val = INTVAL (bitshift);
1029   if (bitshift_val & 0x7)
1030     FAIL;
1031   byteshift_val = 16 - (bitshift_val >> 3);
1032   if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1033     {
1034       shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1035       insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
1036                                      shift);
1037     }
1038   else
1039     {
1040       shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1041       insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
1042                                         shift);
1043     }
1045   emit_insn (insn);
1046   DONE;
1049 ;; Expanders for rotate each element in a vector
1050 (define_expand "vrotl<mode>3"
1051   [(set (match_operand:VEC_I 0 "vint_operand" "")
1052         (rotate:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1053                       (match_operand:VEC_I 2 "vint_operand" "")))]
1054   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1055   "")
1057 ;; Expanders for arithmetic shift left on each vector element
1058 (define_expand "vashl<mode>3"
1059   [(set (match_operand:VEC_I 0 "vint_operand" "")
1060         (ashift:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1061                       (match_operand:VEC_I 2 "vint_operand" "")))]
1062   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1063   "")
1065 ;; Expanders for logical shift right on each vector element
1066 (define_expand "vlshr<mode>3"
1067   [(set (match_operand:VEC_I 0 "vint_operand" "")
1068         (lshiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1069                         (match_operand:VEC_I 2 "vint_operand" "")))]
1070   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1071   "")
1073 ;; Expanders for arithmetic shift right on each vector element
1074 (define_expand "vashr<mode>3"
1075   [(set (match_operand:VEC_I 0 "vint_operand" "")
1076         (ashiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1077                         (match_operand:VEC_I 2 "vint_operand" "")))]
1078   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1079   "")
1081 ;; Vector reduction expanders for VSX
1083 (define_expand "reduc_<VEC_reduc_name>_v2df"
1084   [(parallel [(set (match_operand:V2DF 0 "vfloat_operand" "")
1085                    (VEC_reduc:V2DF
1086                     (vec_concat:V2DF
1087                      (vec_select:DF
1088                       (match_operand:V2DF 1 "vfloat_operand" "")
1089                       (parallel [(const_int 1)]))
1090                      (vec_select:DF
1091                       (match_dup 1)
1092                       (parallel [(const_int 0)])))
1093                     (match_dup 1)))
1094               (clobber (match_scratch:V2DF 2 ""))])]
1095   "VECTOR_UNIT_VSX_P (V2DFmode)"
1096   "")
1098 ; The (VEC_reduc:V4SF
1099 ;       (op1)
1100 ;       (unspec:V4SF [(const_int 0)] UNSPEC_REDUC))
1102 ; is to allow us to use a code iterator, but not completely list all of the
1103 ; vector rotates, etc. to prevent canonicalization
1105 (define_expand "reduc_<VEC_reduc_name>_v4sf"
1106   [(parallel [(set (match_operand:V4SF 0 "vfloat_operand" "")
1107                    (VEC_reduc:V4SF
1108                     (unspec:V4SF [(const_int 0)] UNSPEC_REDUC)
1109                     (match_operand:V4SF 1 "vfloat_operand" "")))
1110               (clobber (match_scratch:V4SF 2 ""))
1111               (clobber (match_scratch:V4SF 3 ""))])]
1112   "VECTOR_UNIT_VSX_P (V4SFmode)"
1113   "")
1116 ;;; Expanders for vector insn patterns shared between the SPE and TARGET_PAIRED systems.
1118 (define_expand "absv2sf2"
1119   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1120         (abs:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1121   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1122   "")
1124 (define_expand "negv2sf2"
1125   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1126         (neg:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1127   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1128   "")
1130 (define_expand "addv2sf3"
1131   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1132         (plus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1133                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1134   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1135   "
1137   if (TARGET_SPE)
1138     {
1139       /* We need to make a note that we clobber SPEFSCR.  */
1140       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1142       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1143                                          gen_rtx_PLUS (V2SFmode, operands[1], operands[2]));
1144       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1145       emit_insn (par);
1146       DONE;
1147     }
1150 (define_expand "subv2sf3"
1151   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1152         (minus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1153                     (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1154   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1155   "
1157   if (TARGET_SPE)
1158     {
1159       /* We need to make a note that we clobber SPEFSCR.  */
1160       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1162       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1163                                          gen_rtx_MINUS (V2SFmode, operands[1], operands[2]));
1164       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1165       emit_insn (par);
1166       DONE;
1167     }
1170 (define_expand "mulv2sf3"
1171   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1172         (mult:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1173                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1174   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1175   "
1177   if (TARGET_SPE)
1178     {
1179       /* We need to make a note that we clobber SPEFSCR.  */
1180       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1182       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1183                                          gen_rtx_MULT (V2SFmode, operands[1], operands[2]));
1184       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1185       emit_insn (par);
1186       DONE;
1187     }
1190 (define_expand "divv2sf3"
1191   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1192         (div:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1193                   (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1194   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1195   "
1197   if (TARGET_SPE)
1198     {
1199       /* We need to make a note that we clobber SPEFSCR.  */
1200       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1202       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1203                                          gen_rtx_DIV (V2SFmode, operands[1], operands[2]));
1204       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1205       emit_insn (par);
1206       DONE;
1207     }