PR target/68609
[official-gcc.git] / gcc / config / rs6000 / vector.md
blob02fb3e3d12fc94b2e9acf6eeedd4db6d32abd55d
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-2016 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 V1TI TI KF TF])
41 ;; Vector modes for moves.  Don't do TImode or TFmode here, since their
42 ;; moves are handled elsewhere.
43 (define_mode_iterator VEC_M [V16QI V8HI V4SI V2DI V4SF V2DF V1TI KF])
45 ;; Vector modes for types that don't need a realignment under VSX
46 (define_mode_iterator VEC_N [V4SI V4SF V2DI V2DF V1TI KF TF])
48 ;; Vector comparison modes
49 (define_mode_iterator VEC_C [V16QI V8HI V4SI V2DI V4SF V2DF])
51 ;; Vector init/extract modes
52 (define_mode_iterator VEC_E [V16QI V8HI V4SI V2DI V4SF V2DF])
54 ;; Vector modes for 64-bit base types
55 (define_mode_iterator VEC_64 [V2DI V2DF])
57 ;; Base type from vector mode
58 (define_mode_attr VEC_base [(V16QI "QI")
59                             (V8HI  "HI")
60                             (V4SI  "SI")
61                             (V2DI  "DI")
62                             (V4SF  "SF")
63                             (V2DF  "DF")
64                             (V1TI  "TI")
65                             (TI    "TI")])
67 ;; Same size integer type for floating point data
68 (define_mode_attr VEC_int [(V4SF  "v4si")
69                            (V2DF  "v2di")])
71 (define_mode_attr VEC_INT [(V4SF  "V4SI")
72                            (V2DF  "V2DI")])
74 ;; constants for unspec
75 (define_c_enum "unspec" [UNSPEC_PREDICATE
76                          UNSPEC_REDUC])
78 ;; Vector reduction code iterators
79 (define_code_iterator VEC_reduc [plus smin smax])
81 (define_code_attr VEC_reduc_name [(plus "plus")
82                                   (smin "smin")
83                                   (smax "smax")])
85 (define_code_attr VEC_reduc_rtx [(plus "add")
86                                  (smin "smin")
87                                  (smax "smax")])
90 ;; Vector move instructions.  Little-endian VSX loads and stores require
91 ;; special handling to circumvent "element endianness."
92 (define_expand "mov<mode>"
93   [(set (match_operand:VEC_M 0 "nonimmediate_operand" "")
94         (match_operand:VEC_M 1 "any_operand" ""))]
95   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
97   if (can_create_pseudo_p ())
98     {
99       if (CONSTANT_P (operands[1]))
100         {
101           if (FLOAT128_VECTOR_P (<MODE>mode))
102             {
103               if (!easy_fp_constant (operands[1], <MODE>mode))
104                 operands[1] = force_const_mem (<MODE>mode, operands[1]);
105             }
106           else if (!easy_vector_constant (operands[1], <MODE>mode))
107             operands[1] = force_const_mem (<MODE>mode, operands[1]);
108         }
110       if (!vlogical_operand (operands[0], <MODE>mode)
111           && !vlogical_operand (operands[1], <MODE>mode))
112         operands[1] = force_reg (<MODE>mode, operands[1]);
113     }
114   if (!BYTES_BIG_ENDIAN
115       && VECTOR_MEM_VSX_P (<MODE>mode)
116       && !TARGET_P9_VECTOR
117       && !gpr_or_gpr_p (operands[0], operands[1])
118       && (memory_operand (operands[0], <MODE>mode)
119           ^ memory_operand (operands[1], <MODE>mode)))
120     {
121       rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
122       DONE;
123     }
126 ;; Generic vector floating point load/store instructions.  These will match
127 ;; insns defined in vsx.md or altivec.md depending on the switches.
128 (define_expand "vector_load_<mode>"
129   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
130         (match_operand:VEC_M 1 "memory_operand" ""))]
131   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
132   "")
134 (define_expand "vector_store_<mode>"
135   [(set (match_operand:VEC_M 0 "memory_operand" "")
136         (match_operand:VEC_M 1 "vfloat_operand" ""))]
137   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
138   "")
140 ;; Splits if a GPR register was chosen for the move
141 (define_split
142   [(set (match_operand:VEC_L 0 "nonimmediate_operand" "")
143         (match_operand:VEC_L 1 "input_operand" ""))]
144   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
145    && reload_completed
146    && gpr_or_gpr_p (operands[0], operands[1])
147    && !direct_move_p (operands[0], operands[1])
148    && !quad_load_store_p (operands[0], operands[1])"
149   [(pc)]
151   rs6000_split_multireg_move (operands[0], operands[1]);
152   DONE;
155 ;; Vector floating point load/store instructions that uses the Altivec
156 ;; instructions even if we are compiling for VSX, since the Altivec
157 ;; instructions silently ignore the bottom 3 bits of the address, and VSX does
158 ;; not.
159 (define_expand "vector_altivec_load_<mode>"
160   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
161         (match_operand:VEC_M 1 "memory_operand" ""))]
162   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
163   "
165   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
167   if (VECTOR_MEM_VSX_P (<MODE>mode))
168     {
169       operands[1] = rs6000_address_for_altivec (operands[1]);
170       emit_insn (gen_altivec_lvx_<mode> (operands[0], operands[1]));
171       DONE;
172     }
175 (define_expand "vector_altivec_store_<mode>"
176   [(set (match_operand:VEC_M 0 "memory_operand" "")
177         (match_operand:VEC_M 1 "vfloat_operand" ""))]
178   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
179   "
181   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
183   if (VECTOR_MEM_VSX_P (<MODE>mode))
184     {
185       operands[0] = rs6000_address_for_altivec (operands[0]);
186       emit_insn (gen_altivec_stvx_<mode> (operands[0], operands[1]));
187       DONE;
188     }
193 ;; Generic floating point vector arithmetic support
194 (define_expand "add<mode>3"
195   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
196         (plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
197                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
198   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
199   "")
201 (define_expand "sub<mode>3"
202   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
203         (minus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
204                      (match_operand:VEC_F 2 "vfloat_operand" "")))]
205   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
206   "")
208 (define_expand "mul<mode>3"
209   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
210         (mult:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
211                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
212   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
214   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
215     {
216       emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
217       DONE;
218     }
221 (define_expand "div<mode>3"
222   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
223         (div:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
224                    (match_operand:VEC_F 2 "vfloat_operand" "")))]
225   "VECTOR_UNIT_VSX_P (<MODE>mode)"
226   "")
228 (define_expand "neg<mode>2"
229   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
230         (neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
231   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
232   "
234   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
235     {
236       emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
237       DONE;
238     }
241 (define_expand "abs<mode>2"
242   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
243         (abs:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
244   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
245   "
247   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
248     {
249       emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
250       DONE;
251     }
254 (define_expand "smin<mode>3"
255   [(set (match_operand:VEC_F 0 "register_operand" "")
256         (smin:VEC_F (match_operand:VEC_F 1 "register_operand" "")
257                     (match_operand:VEC_F 2 "register_operand" "")))]
258   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
259   "")
261 (define_expand "smax<mode>3"
262   [(set (match_operand:VEC_F 0 "register_operand" "")
263         (smax:VEC_F (match_operand:VEC_F 1 "register_operand" "")
264                     (match_operand:VEC_F 2 "register_operand" "")))]
265   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
266   "")
269 (define_expand "sqrt<mode>2"
270   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
271         (sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
272   "VECTOR_UNIT_VSX_P (<MODE>mode)"
274   if (<MODE>mode == V4SFmode
275       && !optimize_function_for_size_p (cfun)
276       && flag_finite_math_only && !flag_trapping_math
277       && flag_unsafe_math_optimizations)
278     {
279       rs6000_emit_swsqrt (operands[0], operands[1], 0);
280       DONE;
281     }
284 (define_expand "rsqrte<mode>2"
285   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
286         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
287                       UNSPEC_RSQRT))]
288   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
289   "")
291 (define_expand "re<mode>2"
292   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
293         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "f")]
294                       UNSPEC_FRES))]
295   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
296   "")
298 (define_expand "ftrunc<mode>2"
299   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
300         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
301   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
302   "")
304 (define_expand "vector_ceil<mode>2"
305   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
306         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
307                       UNSPEC_FRIP))]
308   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
309   "")
311 (define_expand "vector_floor<mode>2"
312   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
313         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
314                       UNSPEC_FRIM))]
315   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
316   "")
318 (define_expand "vector_btrunc<mode>2"
319   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
320         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
321   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
322   "")
324 (define_expand "vector_copysign<mode>3"
325   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
326         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")
327                        (match_operand:VEC_F 2 "vfloat_operand" "")] UNSPEC_COPYSIGN))]
328   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
329   "
331   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
332     {
333       emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
334                                              operands[2]));
335       DONE;
336     }
340 ;; Vector comparisons
341 (define_expand "vcond<mode><mode>"
342   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
343         (if_then_else:VEC_F
344          (match_operator 3 "comparison_operator"
345                          [(match_operand:VEC_F 4 "vfloat_operand" "")
346                           (match_operand:VEC_F 5 "vfloat_operand" "")])
347          (match_operand:VEC_F 1 "vfloat_operand" "")
348          (match_operand:VEC_F 2 "vfloat_operand" "")))]
349   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
350   "
352   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
353                                     operands[3], operands[4], operands[5]))
354     DONE;
355   else
356     FAIL;
359 (define_expand "vcond<mode><mode>"
360   [(set (match_operand:VEC_I 0 "vint_operand" "")
361         (if_then_else:VEC_I
362          (match_operator 3 "comparison_operator"
363                          [(match_operand:VEC_I 4 "vint_operand" "")
364                           (match_operand:VEC_I 5 "vint_operand" "")])
365          (match_operand:VEC_I 1 "vint_operand" "")
366          (match_operand:VEC_I 2 "vint_operand" "")))]
367   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
368   "
370   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
371                                     operands[3], operands[4], operands[5]))
372     DONE;
373   else
374     FAIL;
377 (define_expand "vcondv4sfv4si"
378   [(set (match_operand:V4SF 0 "vfloat_operand" "")
379         (if_then_else:V4SF
380          (match_operator 3 "comparison_operator"
381                          [(match_operand:V4SI 4 "vint_operand" "")
382                           (match_operand:V4SI 5 "vint_operand" "")])
383          (match_operand:V4SF 1 "vfloat_operand" "")
384          (match_operand:V4SF 2 "vfloat_operand" "")))]
385   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
386    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
387   "
389   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
390                                     operands[3], operands[4], operands[5]))
391     DONE;
392   else
393     FAIL;
396 (define_expand "vcondv4siv4sf"
397   [(set (match_operand:V4SI 0 "vint_operand" "")
398         (if_then_else:V4SI
399          (match_operator 3 "comparison_operator"
400                          [(match_operand:V4SF 4 "vfloat_operand" "")
401                           (match_operand:V4SF 5 "vfloat_operand" "")])
402          (match_operand:V4SI 1 "vint_operand" "")
403          (match_operand:V4SI 2 "vint_operand" "")))]
404   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
405    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
406   "
408   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
409                                     operands[3], operands[4], operands[5]))
410     DONE;
411   else
412     FAIL;
415 (define_expand "vcondu<mode><mode>"
416   [(set (match_operand:VEC_I 0 "vint_operand" "")
417         (if_then_else:VEC_I
418          (match_operator 3 "comparison_operator"
419                          [(match_operand:VEC_I 4 "vint_operand" "")
420                           (match_operand:VEC_I 5 "vint_operand" "")])
421          (match_operand:VEC_I 1 "vint_operand" "")
422          (match_operand:VEC_I 2 "vint_operand" "")))]
423   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
424   "
426   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
427                                     operands[3], operands[4], operands[5]))
428     DONE;
429   else
430     FAIL;
433 (define_expand "vconduv4sfv4si"
434   [(set (match_operand:V4SF 0 "vfloat_operand" "")
435         (if_then_else:V4SF
436          (match_operator 3 "comparison_operator"
437                          [(match_operand:V4SI 4 "vint_operand" "")
438                           (match_operand:V4SI 5 "vint_operand" "")])
439          (match_operand:V4SF 1 "vfloat_operand" "")
440          (match_operand:V4SF 2 "vfloat_operand" "")))]
441   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
442    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
443   "
445   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
446                                     operands[3], operands[4], operands[5]))
447     DONE;
448   else
449     FAIL;
452 (define_expand "vector_eq<mode>"
453   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
454         (eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
455                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
456   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
457   "")
459 (define_expand "vector_gt<mode>"
460   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
461         (gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
462                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
463   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
464   "")
466 (define_expand "vector_ge<mode>"
467   [(set (match_operand:VEC_F 0 "vlogical_operand" "")
468         (ge:VEC_F (match_operand:VEC_F 1 "vlogical_operand" "")
469                   (match_operand:VEC_F 2 "vlogical_operand" "")))]
470   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
471   "")
473 ; >= for integer vectors: swap operands and apply not-greater-than
474 (define_expand "vector_nlt<mode>"
475   [(set (match_operand:VEC_I 3 "vlogical_operand" "")
476         (gt:VEC_I (match_operand:VEC_I 2 "vlogical_operand" "")
477                   (match_operand:VEC_I 1 "vlogical_operand" "")))
478    (set (match_operand:VEC_I 0 "vlogical_operand" "")
479         (not:VEC_I (match_dup 3)))]
480   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
481   "
483   operands[3] = gen_reg_rtx_and_attrs (operands[0]);
486 (define_expand "vector_gtu<mode>"
487   [(set (match_operand:VEC_I 0 "vint_operand" "")
488         (gtu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
489                    (match_operand:VEC_I 2 "vint_operand" "")))]
490   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
491   "")
493 ; >= for integer vectors: swap operands and apply not-greater-than
494 (define_expand "vector_nltu<mode>"
495   [(set (match_operand:VEC_I 3 "vlogical_operand" "")
496         (gtu:VEC_I (match_operand:VEC_I 2 "vlogical_operand" "")
497                    (match_operand:VEC_I 1 "vlogical_operand" "")))
498    (set (match_operand:VEC_I 0 "vlogical_operand" "")
499         (not:VEC_I (match_dup 3)))]
500   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
501   "
503   operands[3] = gen_reg_rtx_and_attrs (operands[0]);
506 (define_expand "vector_geu<mode>"
507   [(set (match_operand:VEC_I 0 "vint_operand" "")
508         (geu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
509                    (match_operand:VEC_I 2 "vint_operand" "")))]
510   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
511   "")
513 ; <= for integer vectors: apply not-greater-than
514 (define_expand "vector_ngt<mode>"
515   [(set (match_operand:VEC_I 3 "vlogical_operand" "")
516         (gt:VEC_I (match_operand:VEC_I 1 "vlogical_operand" "")
517                   (match_operand:VEC_I 2 "vlogical_operand" "")))
518    (set (match_operand:VEC_I 0 "vlogical_operand" "")
519         (not:VEC_I (match_dup 3)))]
520   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
521   "
523   operands[3] = gen_reg_rtx_and_attrs (operands[0]);
526 (define_expand "vector_ngtu<mode>"
527   [(set (match_operand:VEC_I 3 "vlogical_operand" "")
528         (gtu:VEC_I (match_operand:VEC_I 1 "vlogical_operand" "")
529                    (match_operand:VEC_I 2 "vlogical_operand" "")))
530    (set (match_operand:VEC_I 0 "vlogical_operand" "")
531         (not:VEC_I (match_dup 3)))]
532   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
533   "
535   operands[3] = gen_reg_rtx_and_attrs (operands[0]);
538 (define_insn_and_split "*vector_uneq<mode>"
539   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
540         (uneq:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
541                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
542   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
543   "#"
544   ""
545   [(set (match_dup 3)
546         (gt:VEC_F (match_dup 1)
547                   (match_dup 2)))
548    (set (match_dup 4)
549         (gt:VEC_F (match_dup 2)
550                   (match_dup 1)))
551    (set (match_dup 0)
552         (not:VEC_F (ior:VEC_F (match_dup 3)
553                               (match_dup 4))))]
554   "
556   operands[3] = gen_reg_rtx (<MODE>mode);
557   operands[4] = gen_reg_rtx (<MODE>mode);
560 (define_insn_and_split "*vector_ltgt<mode>"
561   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
562         (ltgt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
563                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
564   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
565   "#"
566   ""
567   [(set (match_dup 3)
568         (gt:VEC_F (match_dup 1)
569                   (match_dup 2)))
570    (set (match_dup 4)
571         (gt:VEC_F (match_dup 2)
572                   (match_dup 1)))
573    (set (match_dup 0)
574         (ior:VEC_F (match_dup 3)
575                    (match_dup 4)))]
576   "
578   operands[3] = gen_reg_rtx (<MODE>mode);
579   operands[4] = gen_reg_rtx (<MODE>mode);
582 (define_insn_and_split "*vector_ordered<mode>"
583   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
584         (ordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
585                        (match_operand:VEC_F 2 "vfloat_operand" "")))]
586   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
587   "#"
588   ""
589   [(set (match_dup 3)
590         (ge:VEC_F (match_dup 1)
591                   (match_dup 2)))
592    (set (match_dup 4)
593         (ge:VEC_F (match_dup 2)
594                   (match_dup 1)))
595    (set (match_dup 0)
596         (ior:VEC_F (match_dup 3)
597                    (match_dup 4)))]
598   "
600   operands[3] = gen_reg_rtx (<MODE>mode);
601   operands[4] = gen_reg_rtx (<MODE>mode);
604 (define_insn_and_split "*vector_unordered<mode>"
605   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
606         (unordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
607                          (match_operand:VEC_F 2 "vfloat_operand" "")))]
608   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
609   "#"
610   ""
611   [(set (match_dup 3)
612         (ge:VEC_F (match_dup 1)
613                   (match_dup 2)))
614    (set (match_dup 4)
615         (ge:VEC_F (match_dup 2)
616                   (match_dup 1)))
617    (set (match_dup 0)
618         (and:VEC_F (not:VEC_F (match_dup 3))
619                    (not:VEC_F (match_dup 4))))]
620   "
622   operands[3] = gen_reg_rtx (<MODE>mode);
623   operands[4] = gen_reg_rtx (<MODE>mode);
626 ;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask
627 ;; which is in the reverse order that we want
628 (define_expand "vector_select_<mode>"
629   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
630         (if_then_else:VEC_L
631          (ne:CC (match_operand:VEC_L 3 "vlogical_operand" "")
632                 (match_dup 4))
633          (match_operand:VEC_L 2 "vlogical_operand" "")
634          (match_operand:VEC_L 1 "vlogical_operand" "")))]
635   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
636   "operands[4] = CONST0_RTX (<MODE>mode);")
638 (define_expand "vector_select_<mode>_uns"
639   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
640         (if_then_else:VEC_L
641          (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand" "")
642                    (match_dup 4))
643          (match_operand:VEC_L 2 "vlogical_operand" "")
644          (match_operand:VEC_L 1 "vlogical_operand" "")))]
645   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
646   "operands[4] = CONST0_RTX (<MODE>mode);")
648 ;; Expansions that compare vectors producing a vector result and a predicate,
649 ;; setting CR6 to indicate a combined status
650 (define_expand "vector_eq_<mode>_p"
651   [(parallel
652     [(set (reg:CC 74)
653           (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand" "")
654                              (match_operand:VEC_A 2 "vlogical_operand" ""))]
655                      UNSPEC_PREDICATE))
656      (set (match_operand:VEC_A 0 "vlogical_operand" "")
657           (eq:VEC_A (match_dup 1)
658                     (match_dup 2)))])]
659   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
660   "")
662 (define_expand "vector_gt_<mode>_p"
663   [(parallel
664     [(set (reg:CC 74)
665           (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand" "")
666                              (match_operand:VEC_A 2 "vlogical_operand" ""))]
667                      UNSPEC_PREDICATE))
668      (set (match_operand:VEC_A 0 "vlogical_operand" "")
669           (gt:VEC_A (match_dup 1)
670                     (match_dup 2)))])]
671   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
672   "")
674 (define_expand "vector_ge_<mode>_p"
675   [(parallel
676     [(set (reg:CC 74)
677           (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand" "")
678                              (match_operand:VEC_F 2 "vfloat_operand" ""))]
679                      UNSPEC_PREDICATE))
680      (set (match_operand:VEC_F 0 "vfloat_operand" "")
681           (ge:VEC_F (match_dup 1)
682                     (match_dup 2)))])]
683   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
684   "")
686 (define_expand "vector_gtu_<mode>_p"
687   [(parallel
688     [(set (reg:CC 74)
689           (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand" "")
690                               (match_operand:VEC_I 2 "vint_operand" ""))]
691                      UNSPEC_PREDICATE))
692      (set (match_operand:VEC_I 0 "vlogical_operand" "")
693           (gtu:VEC_I (match_dup 1)
694                      (match_dup 2)))])]
695   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
696   "")
698 ;; AltiVec/VSX predicates.
700 (define_expand "cr6_test_for_zero"
701   [(set (match_operand:SI 0 "register_operand" "=r")
702         (eq:SI (reg:CC 74)
703                (const_int 0)))]
704   "TARGET_ALTIVEC || TARGET_VSX"
705   "")
707 (define_expand "cr6_test_for_zero_reverse"
708   [(set (match_operand:SI 0 "register_operand" "=r")
709         (eq:SI (reg:CC 74)
710                (const_int 0)))
711    (set (match_dup 0)
712         (xor:SI (match_dup 0)
713                 (const_int 1)))]
714   "TARGET_ALTIVEC || TARGET_VSX"
715   "")
717 (define_expand "cr6_test_for_lt"
718   [(set (match_operand:SI 0 "register_operand" "=r")
719         (lt:SI (reg:CC 74)
720                (const_int 0)))]
721   "TARGET_ALTIVEC || TARGET_VSX"
722   "")
724 (define_expand "cr6_test_for_lt_reverse"
725   [(set (match_operand:SI 0 "register_operand" "=r")
726         (lt:SI (reg:CC 74)
727                (const_int 0)))
728    (set (match_dup 0)
729         (xor:SI (match_dup 0)
730                 (const_int 1)))]
731   "TARGET_ALTIVEC || TARGET_VSX"
732   "")
735 ;; Vector count leading zeros
736 (define_expand "clz<mode>2"
737   [(set (match_operand:VEC_I 0 "register_operand" "")
738         (clz:VEC_I (match_operand:VEC_I 1 "register_operand" "")))]
739   "TARGET_P8_VECTOR")
741 ;; Vector population count
742 (define_expand "popcount<mode>2"
743   [(set (match_operand:VEC_I 0 "register_operand" "")
744         (popcount:VEC_I (match_operand:VEC_I 1 "register_operand" "")))]
745   "TARGET_P8_VECTOR")
748 ;; Same size conversions
749 (define_expand "float<VEC_int><mode>2"
750   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
751         (float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
752   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
753   "
755   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
756     {
757       emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
758       DONE;
759     }
762 (define_expand "floatuns<VEC_int><mode>2"
763   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
764         (unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
765   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
766   "
768   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
769     {
770       emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
771       DONE;
772     }
775 (define_expand "fix_trunc<mode><VEC_int>2"
776   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
777         (fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
778   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
779   "
781   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
782     {
783       emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
784       DONE;
785     }
788 (define_expand "fixuns_trunc<mode><VEC_int>2"
789   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
790         (unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
791   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
792   "
794   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
795     {
796       emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
797       DONE;
798     }
802 ;; Vector initialization, set, extract
803 (define_expand "vec_init<mode>"
804   [(match_operand:VEC_E 0 "vlogical_operand" "")
805    (match_operand:VEC_E 1 "" "")]
806   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
808   rs6000_expand_vector_init (operands[0], operands[1]);
809   DONE;
812 (define_expand "vec_set<mode>"
813   [(match_operand:VEC_E 0 "vlogical_operand" "")
814    (match_operand:<VEC_base> 1 "register_operand" "")
815    (match_operand 2 "const_int_operand" "")]
816   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
818   rs6000_expand_vector_set (operands[0], operands[1], INTVAL (operands[2]));
819   DONE;
822 (define_expand "vec_extract<mode>"
823   [(match_operand:<VEC_base> 0 "register_operand" "")
824    (match_operand:VEC_E 1 "vlogical_operand" "")
825    (match_operand 2 "const_int_operand" "")]
826   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
828   rs6000_expand_vector_extract (operands[0], operands[1],
829                                 INTVAL (operands[2]));
830   DONE;
833 ;; Convert double word types to single word types
834 (define_expand "vec_pack_trunc_v2df"
835   [(match_operand:V4SF 0 "vfloat_operand" "")
836    (match_operand:V2DF 1 "vfloat_operand" "")
837    (match_operand:V2DF 2 "vfloat_operand" "")]
838   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
840   rtx r1 = gen_reg_rtx (V4SFmode);
841   rtx r2 = gen_reg_rtx (V4SFmode);
843   emit_insn (gen_vsx_xvcvdpsp (r1, operands[1]));
844   emit_insn (gen_vsx_xvcvdpsp (r2, operands[2]));
845   rs6000_expand_extract_even (operands[0], r1, r2);
846   DONE;
849 (define_expand "vec_pack_sfix_trunc_v2df"
850   [(match_operand:V4SI 0 "vint_operand" "")
851    (match_operand:V2DF 1 "vfloat_operand" "")
852    (match_operand:V2DF 2 "vfloat_operand" "")]
853   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
855   rtx r1 = gen_reg_rtx (V4SImode);
856   rtx r2 = gen_reg_rtx (V4SImode);
858   emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1]));
859   emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2]));
860   rs6000_expand_extract_even (operands[0], r1, r2);
861   DONE;
864 (define_expand "vec_pack_ufix_trunc_v2df"
865   [(match_operand:V4SI 0 "vint_operand" "")
866    (match_operand:V2DF 1 "vfloat_operand" "")
867    (match_operand:V2DF 2 "vfloat_operand" "")]
868   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
870   rtx r1 = gen_reg_rtx (V4SImode);
871   rtx r2 = gen_reg_rtx (V4SImode);
873   emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1]));
874   emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2]));
875   rs6000_expand_extract_even (operands[0], r1, r2);
876   DONE;
879 ;; Convert single word types to double word
880 (define_expand "vec_unpacks_hi_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], BYTES_BIG_ENDIAN);
888   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
889   DONE;
892 (define_expand "vec_unpacks_lo_v4sf"
893   [(match_operand:V2DF 0 "vfloat_operand" "")
894    (match_operand:V4SF 1 "vfloat_operand" "")]
895   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
897   rtx reg = gen_reg_rtx (V4SFmode);
899   rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
900   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
901   DONE;
904 (define_expand "vec_unpacks_float_hi_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], BYTES_BIG_ENDIAN);
912   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
913   DONE;
916 (define_expand "vec_unpacks_float_lo_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], !BYTES_BIG_ENDIAN);
924   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
925   DONE;
928 (define_expand "vec_unpacku_float_hi_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], BYTES_BIG_ENDIAN);
936   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
937   DONE;
940 (define_expand "vec_unpacku_float_lo_v4si"
941   [(match_operand:V2DF 0 "vfloat_operand" "")
942    (match_operand:V4SI 1 "vint_operand" "")]
943   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
945   rtx reg = gen_reg_rtx (V4SImode);
947   rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
948   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
949   DONE;
953 ;; Align vector loads with a permute.
954 (define_expand "vec_realign_load_<mode>"
955   [(match_operand:VEC_K 0 "vlogical_operand" "")
956    (match_operand:VEC_K 1 "vlogical_operand" "")
957    (match_operand:VEC_K 2 "vlogical_operand" "")
958    (match_operand:V16QI 3 "vlogical_operand" "")]
959   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
961   if (BYTES_BIG_ENDIAN)
962     emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1],
963                                          operands[2], operands[3]));
964   else
965     {
966       /* We have changed lvsr to lvsl, so to complete the transformation
967          of vperm for LE, we must swap the inputs.  */
968       rtx unspec = gen_rtx_UNSPEC (<MODE>mode,
969                                    gen_rtvec (3, operands[2],
970                                               operands[1], operands[3]),
971                                    UNSPEC_VPERM);
972       emit_move_insn (operands[0], unspec);
973     }
974   DONE;
977 ;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned
978 ;; since the load already handles it.
979 (define_expand "movmisalign<mode>"
980  [(set (match_operand:VEC_N 0 "nonimmediate_operand" "")
981        (match_operand:VEC_N 1 "any_operand" ""))]
982  "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN"
983  "")
985 ;; Vector shift right in bits. Currently supported ony for shift
986 ;; amounts that can be expressed as byte shifts (divisible by 8).
987 ;; General shift amounts can be supported using vsro + vsr. We're
988 ;; not expecting to see these yet (the vectorizer currently
989 ;; generates only shifts by a whole number of vector elements).
990 ;; Note that the vec_shr operation is actually defined as 
991 ;; 'shift toward element 0' so is a shr for LE and shl for BE.
992 (define_expand "vec_shr_<mode>"
993   [(match_operand:VEC_L 0 "vlogical_operand" "")
994    (match_operand:VEC_L 1 "vlogical_operand" "")
995    (match_operand:QI 2 "reg_or_short_operand" "")]
996   "TARGET_ALTIVEC"
997   "
999   rtx bitshift = operands[2];
1000   rtx shift;
1001   rtx insn;
1002   rtx zero_reg, op1, op2;
1003   HOST_WIDE_INT bitshift_val;
1004   HOST_WIDE_INT byteshift_val;
1006   if (! CONSTANT_P (bitshift))
1007     FAIL;
1008   bitshift_val = INTVAL (bitshift);
1009   if (bitshift_val & 0x7)
1010     FAIL;
1011   byteshift_val = (bitshift_val >> 3);
1012   zero_reg = gen_reg_rtx (<MODE>mode);
1013   emit_move_insn (zero_reg, CONST0_RTX (<MODE>mode));
1014   if (!BYTES_BIG_ENDIAN)
1015     {
1016       byteshift_val = 16 - byteshift_val;
1017       op1 = zero_reg;
1018       op2 = operands[1];
1019     }
1020   else
1021     {
1022       op1 = operands[1];
1023       op2 = zero_reg;
1024     }
1026   if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1027     {
1028       shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1029       insn = gen_vsx_xxsldwi_<mode> (operands[0], op1, op2, shift);
1030     }
1031   else
1032     {
1033       shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1034       insn = gen_altivec_vsldoi_<mode> (operands[0], op1, op2, shift);
1035     }
1037   emit_insn (insn);
1038   DONE;
1041 ;; Expanders for rotate each element in a vector
1042 (define_expand "vrotl<mode>3"
1043   [(set (match_operand:VEC_I 0 "vint_operand" "")
1044         (rotate:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1045                       (match_operand:VEC_I 2 "vint_operand" "")))]
1046   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1047   "")
1049 ;; Expanders for arithmetic shift left on each vector element
1050 (define_expand "vashl<mode>3"
1051   [(set (match_operand:VEC_I 0 "vint_operand" "")
1052         (ashift: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 logical shift right on each vector element
1058 (define_expand "vlshr<mode>3"
1059   [(set (match_operand:VEC_I 0 "vint_operand" "")
1060         (lshiftrt: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 arithmetic shift right on each vector element
1066 (define_expand "vashr<mode>3"
1067   [(set (match_operand:VEC_I 0 "vint_operand" "")
1068         (ashiftrt: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 ;; Vector reduction expanders for VSX
1074 ; The (VEC_reduc:...
1075 ;       (op1)
1076 ;       (unspec:... [(const_int 0)] UNSPEC_REDUC))
1078 ; is to allow us to use a code iterator, but not completely list all of the
1079 ; vector rotates, etc. to prevent canonicalization
1082 (define_expand "reduc_<VEC_reduc:VEC_reduc_name>_scal_<VEC_F:mode>"
1083   [(match_operand:<VEC_base> 0 "register_operand" "")
1084    (VEC_reduc:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
1085                     (unspec:VEC_F [(const_int 0)] UNSPEC_REDUC))]
1086   "VECTOR_UNIT_VSX_P (<VEC_F:MODE>mode)"
1087   {
1088     rtx vec = gen_reg_rtx (<VEC_F:MODE>mode);
1089     rtx elt = BYTES_BIG_ENDIAN
1090                 ? gen_int_mode (GET_MODE_NUNITS (<VEC_F:MODE>mode) - 1, QImode)
1091                 : const0_rtx;
1092     emit_insn (gen_vsx_reduc_<VEC_reduc:VEC_reduc_name>_<VEC_F:mode> (vec,
1093         operand1));
1094     emit_insn (gen_vsx_extract_<VEC_F:mode> (operand0, vec, elt));
1095     DONE;
1096   })
1099 ;;; Expanders for vector insn patterns shared between the SPE and TARGET_PAIRED systems.
1101 (define_expand "absv2sf2"
1102   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1103         (abs:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1104   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1105   "")
1107 (define_expand "negv2sf2"
1108   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1109         (neg:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1110   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1111   "")
1113 (define_expand "addv2sf3"
1114   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1115         (plus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1116                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1117   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1118   "
1120   if (TARGET_SPE)
1121     {
1122       /* We need to make a note that we clobber SPEFSCR.  */
1123       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1125       XVECEXP (par, 0, 0) = gen_rtx_SET (operands[0],
1126                                          gen_rtx_PLUS (V2SFmode, operands[1], operands[2]));
1127       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1128       emit_insn (par);
1129       DONE;
1130     }
1133 (define_expand "subv2sf3"
1134   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1135         (minus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1136                     (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1137   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1138   "
1140   if (TARGET_SPE)
1141     {
1142       /* We need to make a note that we clobber SPEFSCR.  */
1143       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1145       XVECEXP (par, 0, 0) = gen_rtx_SET (operands[0],
1146                                          gen_rtx_MINUS (V2SFmode, operands[1], operands[2]));
1147       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1148       emit_insn (par);
1149       DONE;
1150     }
1153 (define_expand "mulv2sf3"
1154   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1155         (mult:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1156                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1157   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1158   "
1160   if (TARGET_SPE)
1161     {
1162       /* We need to make a note that we clobber SPEFSCR.  */
1163       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1165       XVECEXP (par, 0, 0) = gen_rtx_SET (operands[0],
1166                                          gen_rtx_MULT (V2SFmode, operands[1], operands[2]));
1167       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1168       emit_insn (par);
1169       DONE;
1170     }
1173 (define_expand "divv2sf3"
1174   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1175         (div:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1176                   (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1177   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1178   "
1180   if (TARGET_SPE)
1181     {
1182       /* We need to make a note that we clobber SPEFSCR.  */
1183       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1185       XVECEXP (par, 0, 0) = gen_rtx_SET (operands[0],
1186                                          gen_rtx_DIV (V2SFmode, operands[1], operands[2]));
1187       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1188       emit_insn (par);
1189       DONE;
1190     }