Merged revisions 195034,195219,195245,195357,195374,195428,195599,195673,195809 via...
[official-gcc.git] / main / gcc / config / rs6000 / vector.md
blob5a6e1fb302652fa3ad1ecdc46f2a800a6104187f
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])
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 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 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 DF 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.
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           && !easy_vector_constant (operands[1], <MODE>mode))
101         operands[1] = force_const_mem (<MODE>mode, operands[1]);
103       else if (!vlogical_operand (operands[0], <MODE>mode)
104                && !vlogical_operand (operands[1], <MODE>mode))
105         operands[1] = force_reg (<MODE>mode, operands[1]);
106     }
109 ;; Generic vector floating point load/store instructions.  These will match
110 ;; insns defined in vsx.md or altivec.md depending on the switches.
111 (define_expand "vector_load_<mode>"
112   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
113         (match_operand:VEC_M 1 "memory_operand" ""))]
114   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
115   "")
117 (define_expand "vector_store_<mode>"
118   [(set (match_operand:VEC_M 0 "memory_operand" "")
119         (match_operand:VEC_M 1 "vfloat_operand" ""))]
120   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
121   "")
123 ;; Splits if a GPR register was chosen for the move
124 (define_split
125   [(set (match_operand:VEC_L 0 "nonimmediate_operand" "")
126         (match_operand:VEC_L 1 "input_operand" ""))]
127   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
128    && reload_completed
129    && gpr_or_gpr_p (operands[0], operands[1])"
130   [(pc)]
132   rs6000_split_multireg_move (operands[0], operands[1]);
133   DONE;
136 ;; Vector floating point load/store instructions that uses the Altivec
137 ;; instructions even if we are compiling for VSX, since the Altivec
138 ;; instructions silently ignore the bottom 3 bits of the address, and VSX does
139 ;; not.
140 (define_expand "vector_altivec_load_<mode>"
141   [(set (match_operand:VEC_M 0 "vfloat_operand" "")
142         (match_operand:VEC_M 1 "memory_operand" ""))]
143   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
144   "
146   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
148   if (VECTOR_MEM_VSX_P (<MODE>mode))
149     {
150       operands[1] = rs6000_address_for_altivec (operands[1]);
151       emit_insn (gen_altivec_lvx_<mode> (operands[0], operands[1]));
152       DONE;
153     }
156 (define_expand "vector_altivec_store_<mode>"
157   [(set (match_operand:VEC_M 0 "memory_operand" "")
158         (match_operand:VEC_M 1 "vfloat_operand" ""))]
159   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
160   "
162   gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
164   if (VECTOR_MEM_VSX_P (<MODE>mode))
165     {
166       operands[0] = rs6000_address_for_altivec (operands[0]);
167       emit_insn (gen_altivec_stvx_<mode> (operands[0], operands[1]));
168       DONE;
169     }
174 ;; Reload patterns for vector operations.  We may need an additional base
175 ;; register to convert the reg+offset addressing to reg+reg for vector
176 ;; registers and reg+reg or (reg+reg)&(-16) addressing to just an index
177 ;; register for gpr registers.
178 (define_expand "reload_<VEC_R:mode>_<P:mptrsize>_store"
179   [(parallel [(match_operand:VEC_R 0 "memory_operand" "m")
180               (match_operand:VEC_R 1 "gpc_reg_operand" "r")
181               (match_operand:P 2 "register_operand" "=&b")])]
182   "<P:tptrsize>"
184   rs6000_secondary_reload_inner (operands[1], operands[0], operands[2], true);
185   DONE;
188 (define_expand "reload_<VEC_R:mode>_<P:mptrsize>_load"
189   [(parallel [(match_operand:VEC_R 0 "gpc_reg_operand" "=&r")
190               (match_operand:VEC_R 1 "memory_operand" "m")
191               (match_operand:P 2 "register_operand" "=&b")])]
192   "<P:tptrsize>"
194   rs6000_secondary_reload_inner (operands[0], operands[1], operands[2], false);
195   DONE;
198 ;; Reload sometimes tries to move the address to a GPR, and can generate
199 ;; invalid RTL for addresses involving AND -16.  Allow addresses involving
200 ;; reg+reg, reg+small constant, or just reg, all wrapped in an AND -16.
202 (define_insn_and_split "*vec_reload_and_plus_<mptrsize>"
203   [(set (match_operand:P 0 "gpc_reg_operand" "=b")
204         (and:P (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
205                        (match_operand:P 2 "reg_or_cint_operand" "rI"))
206                (const_int -16)))]
207   "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
208   "#"
209   "&& reload_completed"
210   [(set (match_dup 0)
211         (plus:P (match_dup 1)
212                 (match_dup 2)))
213    (parallel [(set (match_dup 0)
214                    (and:P (match_dup 0)
215                           (const_int -16)))
216               (clobber:CC (scratch:CC))])])
218 ;; The normal ANDSI3/ANDDI3 won't match if reload decides to move an AND -16
219 ;; address to a register because there is no clobber of a (scratch), so we add
220 ;; it here.
221 (define_insn_and_split "*vec_reload_and_reg_<mptrsize>"
222   [(set (match_operand:P 0 "gpc_reg_operand" "=b")
223         (and:P (match_operand:P 1 "gpc_reg_operand" "r")
224                (const_int -16)))]
225   "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
226   "#"
227   "&& reload_completed"
228   [(parallel [(set (match_dup 0)
229                    (and:P (match_dup 1)
230                           (const_int -16)))
231               (clobber:CC (scratch:CC))])])
233 ;; Generic floating point vector arithmetic support
234 (define_expand "add<mode>3"
235   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
236         (plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
237                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
238   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
239   "")
241 (define_expand "sub<mode>3"
242   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
243         (minus:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
244                      (match_operand:VEC_F 2 "vfloat_operand" "")))]
245   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
246   "")
248 (define_expand "mul<mode>3"
249   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
250         (mult:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
251                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
252   "VECTOR_UNIT_VSX_P (<MODE>mode) || VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
254   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
255     {
256       emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
257       DONE;
258     }
261 (define_expand "div<mode>3"
262   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
263         (div:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
264                    (match_operand:VEC_F 2 "vfloat_operand" "")))]
265   "VECTOR_UNIT_VSX_P (<MODE>mode)"
266   "")
268 (define_expand "neg<mode>2"
269   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
270         (neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
271   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
272   "
274   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
275     {
276       emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
277       DONE;
278     }
281 (define_expand "abs<mode>2"
282   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
283         (abs:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
284   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
285   "
287   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
288     {
289       emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
290       DONE;
291     }
294 (define_expand "smin<mode>3"
295   [(set (match_operand:VEC_F 0 "register_operand" "")
296         (smin:VEC_F (match_operand:VEC_F 1 "register_operand" "")
297                     (match_operand:VEC_F 2 "register_operand" "")))]
298   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
299   "")
301 (define_expand "smax<mode>3"
302   [(set (match_operand:VEC_F 0 "register_operand" "")
303         (smax:VEC_F (match_operand:VEC_F 1 "register_operand" "")
304                     (match_operand:VEC_F 2 "register_operand" "")))]
305   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
306   "")
309 (define_expand "sqrt<mode>2"
310   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
311         (sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
312   "VECTOR_UNIT_VSX_P (<MODE>mode)"
313   "")
315 (define_expand "rsqrte<mode>2"
316   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
317         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
318                       UNSPEC_RSQRT))]
319   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
320   "")
322 (define_expand "re<mode>2"
323   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
324         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "f")]
325                       UNSPEC_FRES))]
326   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
327   "")
329 (define_expand "ftrunc<mode>2"
330   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
331         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
332   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
333   "")
335 (define_expand "vector_ceil<mode>2"
336   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
337         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
338                       UNSPEC_FRIP))]
339   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
340   "")
342 (define_expand "vector_floor<mode>2"
343   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
344         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")]
345                       UNSPEC_FRIM))]
346   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
347   "")
349 (define_expand "vector_btrunc<mode>2"
350   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
351         (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")))]
352   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
353   "")
355 (define_expand "vector_copysign<mode>3"
356   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
357         (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand" "")
358                        (match_operand:VEC_F 2 "vfloat_operand" "")] UNSPEC_COPYSIGN))]
359   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
360   "
362   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
363     {
364       emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
365                                              operands[2]));
366       DONE;
367     }
371 ;; Vector comparisons
372 (define_expand "vcond<mode><mode>"
373   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
374         (if_then_else:VEC_F
375          (match_operator 3 "comparison_operator"
376                          [(match_operand:VEC_F 4 "vfloat_operand" "")
377                           (match_operand:VEC_F 5 "vfloat_operand" "")])
378          (match_operand:VEC_F 1 "vfloat_operand" "")
379          (match_operand:VEC_F 2 "vfloat_operand" "")))]
380   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
381   "
383   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
384                                     operands[3], operands[4], operands[5]))
385     DONE;
386   else
387     FAIL;
390 (define_expand "vcond<mode><mode>"
391   [(set (match_operand:VEC_I 0 "vint_operand" "")
392         (if_then_else:VEC_I
393          (match_operator 3 "comparison_operator"
394                          [(match_operand:VEC_I 4 "vint_operand" "")
395                           (match_operand:VEC_I 5 "vint_operand" "")])
396          (match_operand:VEC_I 1 "vint_operand" "")
397          (match_operand:VEC_I 2 "vint_operand" "")))]
398   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
399   "
401   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
402                                     operands[3], operands[4], operands[5]))
403     DONE;
404   else
405     FAIL;
408 (define_expand "vcondv4sfv4si"
409   [(set (match_operand:V4SF 0 "vfloat_operand" "")
410         (if_then_else:V4SF
411          (match_operator 3 "comparison_operator"
412                          [(match_operand:V4SI 4 "vint_operand" "")
413                           (match_operand:V4SI 5 "vint_operand" "")])
414          (match_operand:V4SF 1 "vfloat_operand" "")
415          (match_operand:V4SF 2 "vfloat_operand" "")))]
416   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
417    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
418   "
420   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
421                                     operands[3], operands[4], operands[5]))
422     DONE;
423   else
424     FAIL;
427 (define_expand "vcondv4siv4sf"
428   [(set (match_operand:V4SI 0 "vint_operand" "")
429         (if_then_else:V4SI
430          (match_operator 3 "comparison_operator"
431                          [(match_operand:V4SF 4 "vfloat_operand" "")
432                           (match_operand:V4SF 5 "vfloat_operand" "")])
433          (match_operand:V4SI 1 "vint_operand" "")
434          (match_operand:V4SI 2 "vint_operand" "")))]
435   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
436    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
437   "
439   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
440                                     operands[3], operands[4], operands[5]))
441     DONE;
442   else
443     FAIL;
446 (define_expand "vcondu<mode><mode>"
447   [(set (match_operand:VEC_I 0 "vint_operand" "")
448         (if_then_else:VEC_I
449          (match_operator 3 "comparison_operator"
450                          [(match_operand:VEC_I 4 "vint_operand" "")
451                           (match_operand:VEC_I 5 "vint_operand" "")])
452          (match_operand:VEC_I 1 "vint_operand" "")
453          (match_operand:VEC_I 2 "vint_operand" "")))]
454   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
455   "
457   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
458                                     operands[3], operands[4], operands[5]))
459     DONE;
460   else
461     FAIL;
464 (define_expand "vconduv4sfv4si"
465   [(set (match_operand:V4SF 0 "vfloat_operand" "")
466         (if_then_else:V4SF
467          (match_operator 3 "comparison_operator"
468                          [(match_operand:V4SI 4 "vint_operand" "")
469                           (match_operand:V4SI 5 "vint_operand" "")])
470          (match_operand:V4SF 1 "vfloat_operand" "")
471          (match_operand:V4SF 2 "vfloat_operand" "")))]
472   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
473    && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
474   "
476   if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
477                                     operands[3], operands[4], operands[5]))
478     DONE;
479   else
480     FAIL;
483 (define_expand "vector_eq<mode>"
484   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
485         (eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
486                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
487   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
488   "")
490 (define_expand "vector_gt<mode>"
491   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
492         (gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
493                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
494   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
495   "")
497 (define_expand "vector_ge<mode>"
498   [(set (match_operand:VEC_C 0 "vlogical_operand" "")
499         (ge:VEC_C (match_operand:VEC_C 1 "vlogical_operand" "")
500                   (match_operand:VEC_C 2 "vlogical_operand" "")))]
501   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
502   "")
504 (define_expand "vector_gtu<mode>"
505   [(set (match_operand:VEC_I 0 "vint_operand" "")
506         (gtu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
507                    (match_operand:VEC_I 2 "vint_operand" "")))]
508   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
509   "")
511 (define_expand "vector_geu<mode>"
512   [(set (match_operand:VEC_I 0 "vint_operand" "")
513         (geu:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
514                    (match_operand:VEC_I 2 "vint_operand" "")))]
515   "VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
516   "")
518 (define_insn_and_split "*vector_uneq<mode>"
519   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
520         (uneq:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
521                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
522   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
523   "#"
524   ""
525   [(set (match_dup 3)
526         (gt:VEC_F (match_dup 1)
527                   (match_dup 2)))
528    (set (match_dup 4)
529         (gt:VEC_F (match_dup 2)
530                   (match_dup 1)))
531    (set (match_dup 0)
532         (not:VEC_F (ior:VEC_F (match_dup 3)
533                               (match_dup 4))))]
534   "
536   operands[3] = gen_reg_rtx (<MODE>mode);
537   operands[4] = gen_reg_rtx (<MODE>mode);
540 (define_insn_and_split "*vector_ltgt<mode>"
541   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
542         (ltgt:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
543                     (match_operand:VEC_F 2 "vfloat_operand" "")))]
544   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
545   "#"
546   ""
547   [(set (match_dup 3)
548         (gt:VEC_F (match_dup 1)
549                   (match_dup 2)))
550    (set (match_dup 4)
551         (gt:VEC_F (match_dup 2)
552                   (match_dup 1)))
553    (set (match_dup 0)
554         (ior:VEC_F (match_dup 3)
555                    (match_dup 4)))]
556   "
558   operands[3] = gen_reg_rtx (<MODE>mode);
559   operands[4] = gen_reg_rtx (<MODE>mode);
562 (define_insn_and_split "*vector_ordered<mode>"
563   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
564         (ordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
565                        (match_operand:VEC_F 2 "vfloat_operand" "")))]
566   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
567   "#"
568   ""
569   [(set (match_dup 3)
570         (ge:VEC_F (match_dup 1)
571                   (match_dup 2)))
572    (set (match_dup 4)
573         (ge:VEC_F (match_dup 2)
574                   (match_dup 1)))
575    (set (match_dup 0)
576         (ior:VEC_F (match_dup 3)
577                    (match_dup 4)))]
578   "
580   operands[3] = gen_reg_rtx (<MODE>mode);
581   operands[4] = gen_reg_rtx (<MODE>mode);
584 (define_insn_and_split "*vector_unordered<mode>"
585   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
586         (unordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand" "")
587                          (match_operand:VEC_F 2 "vfloat_operand" "")))]
588   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
589   "#"
590   ""
591   [(set (match_dup 3)
592         (ge:VEC_F (match_dup 1)
593                   (match_dup 2)))
594    (set (match_dup 4)
595         (ge:VEC_F (match_dup 2)
596                   (match_dup 1)))
597    (set (match_dup 0)
598         (not:VEC_F (ior:VEC_F (match_dup 3)
599                               (match_dup 4))))]
600   "
602   operands[3] = gen_reg_rtx (<MODE>mode);
603   operands[4] = gen_reg_rtx (<MODE>mode);
606 ;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask
607 ;; which is in the reverse order that we want
608 (define_expand "vector_select_<mode>"
609   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
610         (if_then_else:VEC_L
611          (ne:CC (match_operand:VEC_L 3 "vlogical_operand" "")
612                 (match_dup 4))
613          (match_operand:VEC_L 2 "vlogical_operand" "")
614          (match_operand:VEC_L 1 "vlogical_operand" "")))]
615   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
616   "operands[4] = CONST0_RTX (<MODE>mode);")
618 (define_expand "vector_select_<mode>_uns"
619   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
620         (if_then_else:VEC_L
621          (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand" "")
622                    (match_dup 4))
623          (match_operand:VEC_L 2 "vlogical_operand" "")
624          (match_operand:VEC_L 1 "vlogical_operand" "")))]
625   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
626   "operands[4] = CONST0_RTX (<MODE>mode);")
628 ;; Expansions that compare vectors producing a vector result and a predicate,
629 ;; setting CR6 to indicate a combined status
630 (define_expand "vector_eq_<mode>_p"
631   [(parallel
632     [(set (reg:CC 74)
633           (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand" "")
634                              (match_operand:VEC_A 2 "vlogical_operand" ""))]
635                      UNSPEC_PREDICATE))
636      (set (match_operand:VEC_A 0 "vlogical_operand" "")
637           (eq:VEC_A (match_dup 1)
638                     (match_dup 2)))])]
639   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
640   "")
642 (define_expand "vector_gt_<mode>_p"
643   [(parallel
644     [(set (reg:CC 74)
645           (unspec:CC [(gt: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           (gt:VEC_A (match_dup 1)
650                     (match_dup 2)))])]
651   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
652   "")
654 (define_expand "vector_ge_<mode>_p"
655   [(parallel
656     [(set (reg:CC 74)
657           (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand" "")
658                              (match_operand:VEC_F 2 "vfloat_operand" ""))]
659                      UNSPEC_PREDICATE))
660      (set (match_operand:VEC_F 0 "vfloat_operand" "")
661           (ge:VEC_F (match_dup 1)
662                     (match_dup 2)))])]
663   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
664   "")
666 (define_expand "vector_gtu_<mode>_p"
667   [(parallel
668     [(set (reg:CC 74)
669           (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand" "")
670                               (match_operand:VEC_I 2 "vint_operand" ""))]
671                      UNSPEC_PREDICATE))
672      (set (match_operand:VEC_I 0 "vlogical_operand" "")
673           (gtu:VEC_I (match_dup 1)
674                      (match_dup 2)))])]
675   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
676   "")
678 ;; AltiVec/VSX predicates.
680 (define_expand "cr6_test_for_zero"
681   [(set (match_operand:SI 0 "register_operand" "=r")
682         (eq:SI (reg:CC 74)
683                (const_int 0)))]
684   "TARGET_ALTIVEC || TARGET_VSX"
685   "")
687 (define_expand "cr6_test_for_zero_reverse"
688   [(set (match_operand:SI 0 "register_operand" "=r")
689         (eq:SI (reg:CC 74)
690                (const_int 0)))
691    (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
692   "TARGET_ALTIVEC || TARGET_VSX"
693   "")
695 (define_expand "cr6_test_for_lt"
696   [(set (match_operand:SI 0 "register_operand" "=r")
697         (lt:SI (reg:CC 74)
698                (const_int 0)))]
699   "TARGET_ALTIVEC || TARGET_VSX"
700   "")
702 (define_expand "cr6_test_for_lt_reverse"
703   [(set (match_operand:SI 0 "register_operand" "=r")
704         (lt:SI (reg:CC 74)
705                (const_int 0)))
706    (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
707   "TARGET_ALTIVEC || TARGET_VSX"
708   "")
711 ;; Vector logical instructions
712 (define_expand "xor<mode>3"
713   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
714         (xor:VEC_L (match_operand:VEC_L 1 "vlogical_operand" "")
715                    (match_operand:VEC_L 2 "vlogical_operand" "")))]
716   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
717   "")
719 (define_expand "ior<mode>3"
720   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
721         (ior:VEC_L (match_operand:VEC_L 1 "vlogical_operand" "")
722                    (match_operand:VEC_L 2 "vlogical_operand" "")))]
723   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
724   "")
726 (define_expand "and<mode>3"
727   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
728         (and:VEC_L (match_operand:VEC_L 1 "vlogical_operand" "")
729                    (match_operand:VEC_L 2 "vlogical_operand" "")))]
730   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
731   "")
733 (define_expand "one_cmpl<mode>2"
734   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
735         (not:VEC_L (match_operand:VEC_L 1 "vlogical_operand" "")))]
736   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
737   "")
739 (define_expand "nor<mode>3"
740   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
741         (not:VEC_L (ior:VEC_L (match_operand:VEC_L 1 "vlogical_operand" "")
742                               (match_operand:VEC_L 2 "vlogical_operand" ""))))]
743   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
744   "")
746 (define_expand "andc<mode>3"
747   [(set (match_operand:VEC_L 0 "vlogical_operand" "")
748         (and:VEC_L (not:VEC_L (match_operand:VEC_L 2 "vlogical_operand" ""))
749                    (match_operand:VEC_L 1 "vlogical_operand" "")))]
750   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
751   "")
753 ;; Same size conversions
754 (define_expand "float<VEC_int><mode>2"
755   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
756         (float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
757   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
758   "
760   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
761     {
762       emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
763       DONE;
764     }
767 (define_expand "floatuns<VEC_int><mode>2"
768   [(set (match_operand:VEC_F 0 "vfloat_operand" "")
769         (unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand" "")))]
770   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
771   "
773   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
774     {
775       emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
776       DONE;
777     }
780 (define_expand "fix_trunc<mode><VEC_int>2"
781   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
782         (fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
783   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
784   "
786   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
787     {
788       emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
789       DONE;
790     }
793 (define_expand "fixuns_trunc<mode><VEC_int>2"
794   [(set (match_operand:<VEC_INT> 0 "vint_operand" "")
795         (unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand" "")))]
796   "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
797   "
799   if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
800     {
801       emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
802       DONE;
803     }
807 ;; Vector initialization, set, extract
808 (define_expand "vec_init<mode>"
809   [(match_operand:VEC_E 0 "vlogical_operand" "")
810    (match_operand:VEC_E 1 "" "")]
811   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
813   rs6000_expand_vector_init (operands[0], operands[1]);
814   DONE;
817 (define_expand "vec_set<mode>"
818   [(match_operand:VEC_E 0 "vlogical_operand" "")
819    (match_operand:<VEC_base> 1 "register_operand" "")
820    (match_operand 2 "const_int_operand" "")]
821   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
823   rs6000_expand_vector_set (operands[0], operands[1], INTVAL (operands[2]));
824   DONE;
827 (define_expand "vec_extract<mode>"
828   [(match_operand:<VEC_base> 0 "register_operand" "")
829    (match_operand:VEC_E 1 "vlogical_operand" "")
830    (match_operand 2 "const_int_operand" "")]
831   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
833   rs6000_expand_vector_extract (operands[0], operands[1],
834                                 INTVAL (operands[2]));
835   DONE;
838 ;; Convert double word types to single word types
839 (define_expand "vec_pack_trunc_v2df"
840   [(match_operand:V4SF 0 "vfloat_operand" "")
841    (match_operand:V2DF 1 "vfloat_operand" "")
842    (match_operand:V2DF 2 "vfloat_operand" "")]
843   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
845   rtx r1 = gen_reg_rtx (V4SFmode);
846   rtx r2 = gen_reg_rtx (V4SFmode);
848   emit_insn (gen_vsx_xvcvdpsp (r1, operands[1]));
849   emit_insn (gen_vsx_xvcvdpsp (r2, operands[2]));
850   rs6000_expand_extract_even (operands[0], r1, r2);
851   DONE;
854 (define_expand "vec_pack_sfix_trunc_v2df"
855   [(match_operand:V4SI 0 "vint_operand" "")
856    (match_operand:V2DF 1 "vfloat_operand" "")
857    (match_operand:V2DF 2 "vfloat_operand" "")]
858   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
860   rtx r1 = gen_reg_rtx (V4SImode);
861   rtx r2 = gen_reg_rtx (V4SImode);
863   emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1]));
864   emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2]));
865   rs6000_expand_extract_even (operands[0], r1, r2);
866   DONE;
869 (define_expand "vec_pack_ufix_trunc_v2df"
870   [(match_operand:V4SI 0 "vint_operand" "")
871    (match_operand:V2DF 1 "vfloat_operand" "")
872    (match_operand:V2DF 2 "vfloat_operand" "")]
873   "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
875   rtx r1 = gen_reg_rtx (V4SImode);
876   rtx r2 = gen_reg_rtx (V4SImode);
878   emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1]));
879   emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2]));
880   rs6000_expand_extract_even (operands[0], r1, r2);
881   DONE;
884 ;; Convert single word types to double word
885 (define_expand "vec_unpacks_hi_v4sf"
886   [(match_operand:V2DF 0 "vfloat_operand" "")
887    (match_operand:V4SF 1 "vfloat_operand" "")]
888   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
890   rtx reg = gen_reg_rtx (V4SFmode);
892   rs6000_expand_interleave (reg, operands[1], operands[1], true);
893   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
894   DONE;
897 (define_expand "vec_unpacks_lo_v4sf"
898   [(match_operand:V2DF 0 "vfloat_operand" "")
899    (match_operand:V4SF 1 "vfloat_operand" "")]
900   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
902   rtx reg = gen_reg_rtx (V4SFmode);
904   rs6000_expand_interleave (reg, operands[1], operands[1], false);
905   emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
906   DONE;
909 (define_expand "vec_unpacks_float_hi_v4si"
910   [(match_operand:V2DF 0 "vfloat_operand" "")
911    (match_operand:V4SI 1 "vint_operand" "")]
912   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
914   rtx reg = gen_reg_rtx (V4SImode);
916   rs6000_expand_interleave (reg, operands[1], operands[1], true);
917   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
918   DONE;
921 (define_expand "vec_unpacks_float_lo_v4si"
922   [(match_operand:V2DF 0 "vfloat_operand" "")
923    (match_operand:V4SI 1 "vint_operand" "")]
924   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
926   rtx reg = gen_reg_rtx (V4SImode);
928   rs6000_expand_interleave (reg, operands[1], operands[1], false);
929   emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
930   DONE;
933 (define_expand "vec_unpacku_float_hi_v4si"
934   [(match_operand:V2DF 0 "vfloat_operand" "")
935    (match_operand:V4SI 1 "vint_operand" "")]
936   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
938   rtx reg = gen_reg_rtx (V4SImode);
940   rs6000_expand_interleave (reg, operands[1], operands[1], true);
941   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
942   DONE;
945 (define_expand "vec_unpacku_float_lo_v4si"
946   [(match_operand:V2DF 0 "vfloat_operand" "")
947    (match_operand:V4SI 1 "vint_operand" "")]
948   "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
950   rtx reg = gen_reg_rtx (V4SImode);
952   rs6000_expand_interleave (reg, operands[1], operands[1], false);
953   emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
954   DONE;
958 ;; Align vector loads with a permute.
959 (define_expand "vec_realign_load_<mode>"
960   [(match_operand:VEC_K 0 "vlogical_operand" "")
961    (match_operand:VEC_K 1 "vlogical_operand" "")
962    (match_operand:VEC_K 2 "vlogical_operand" "")
963    (match_operand:V16QI 3 "vlogical_operand" "")]
964   "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
966   emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1], operands[2],
967                                        operands[3]));
968   DONE;
971 ;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned
972 ;; since the load already handles it.
973 (define_expand "movmisalign<mode>"
974  [(set (match_operand:VEC_N 0 "nonimmediate_operand" "")
975        (match_operand:VEC_N 1 "any_operand" ""))]
976  "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN"
977  "")
980 ;; Vector shift left in bits.  Currently supported ony for shift
981 ;; amounts that can be expressed as byte shifts (divisible by 8).
982 ;; General shift amounts can be supported using vslo + vsl. We're
983 ;; not expecting to see these yet (the vectorizer currently
984 ;; generates only shifts divisible by byte_size).
985 (define_expand "vec_shl_<mode>"
986   [(match_operand:VEC_L 0 "vlogical_operand" "")
987    (match_operand:VEC_L 1 "vlogical_operand" "")
988    (match_operand:QI 2 "reg_or_short_operand" "")]
989   "TARGET_ALTIVEC"
990   "
992   rtx bitshift = operands[2];
993   rtx shift;
994   rtx insn;
995   HOST_WIDE_INT bitshift_val;
996   HOST_WIDE_INT byteshift_val;
998   if (! CONSTANT_P (bitshift))
999     FAIL;
1000   bitshift_val = INTVAL (bitshift);
1001   if (bitshift_val & 0x7)
1002     FAIL;
1003   byteshift_val = bitshift_val >> 3;
1004   if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1005     {
1006       shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1007       insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
1008                                      shift);
1009     }
1010   else
1011     {
1012       shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1013       insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
1014                                         shift);
1015     }
1017   emit_insn (insn);
1018   DONE;
1021 ;; Vector shift right in bits. Currently supported ony for shift
1022 ;; amounts that can be expressed as byte shifts (divisible by 8).
1023 ;; General shift amounts can be supported using vsro + vsr. We're
1024 ;; not expecting to see these yet (the vectorizer currently
1025 ;; generates only shifts divisible by byte_size).
1026 (define_expand "vec_shr_<mode>"
1027   [(match_operand:VEC_L 0 "vlogical_operand" "")
1028    (match_operand:VEC_L 1 "vlogical_operand" "")
1029    (match_operand:QI 2 "reg_or_short_operand" "")]
1030   "TARGET_ALTIVEC"
1031   "
1033   rtx bitshift = operands[2];
1034   rtx shift;
1035   rtx insn;
1036   HOST_WIDE_INT bitshift_val;
1037   HOST_WIDE_INT byteshift_val;
1039   if (! CONSTANT_P (bitshift))
1040     FAIL;
1041   bitshift_val = INTVAL (bitshift);
1042   if (bitshift_val & 0x7)
1043     FAIL;
1044   byteshift_val = 16 - (bitshift_val >> 3);
1045   if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1046     {
1047       shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1048       insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
1049                                      shift);
1050     }
1051   else
1052     {
1053       shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1054       insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
1055                                         shift);
1056     }
1058   emit_insn (insn);
1059   DONE;
1062 ;; Expanders for rotate each element in a vector
1063 (define_expand "vrotl<mode>3"
1064   [(set (match_operand:VEC_I 0 "vint_operand" "")
1065         (rotate:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1066                       (match_operand:VEC_I 2 "vint_operand" "")))]
1067   "TARGET_ALTIVEC"
1068   "")
1070 ;; Expanders for arithmetic shift left on each vector element
1071 (define_expand "vashl<mode>3"
1072   [(set (match_operand:VEC_I 0 "vint_operand" "")
1073         (ashift:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1074                       (match_operand:VEC_I 2 "vint_operand" "")))]
1075   "TARGET_ALTIVEC"
1076   "")
1078 ;; Expanders for logical shift right on each vector element
1079 (define_expand "vlshr<mode>3"
1080   [(set (match_operand:VEC_I 0 "vint_operand" "")
1081         (lshiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1082                         (match_operand:VEC_I 2 "vint_operand" "")))]
1083   "TARGET_ALTIVEC"
1084   "")
1086 ;; Expanders for arithmetic shift right on each vector element
1087 (define_expand "vashr<mode>3"
1088   [(set (match_operand:VEC_I 0 "vint_operand" "")
1089         (ashiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand" "")
1090                         (match_operand:VEC_I 2 "vint_operand" "")))]
1091   "TARGET_ALTIVEC"
1092   "")
1094 ;; Vector reduction expanders for VSX
1096 (define_expand "reduc_<VEC_reduc_name>_v2df"
1097   [(parallel [(set (match_operand:V2DF 0 "vfloat_operand" "")
1098                    (VEC_reduc:V2DF
1099                     (vec_concat:V2DF
1100                      (vec_select:DF
1101                       (match_operand:V2DF 1 "vfloat_operand" "")
1102                       (parallel [(const_int 1)]))
1103                      (vec_select:DF
1104                       (match_dup 1)
1105                       (parallel [(const_int 0)])))
1106                     (match_dup 1)))
1107               (clobber (match_scratch:V2DF 2 ""))])]
1108   "VECTOR_UNIT_VSX_P (V2DFmode)"
1109   "")
1111 ; The (VEC_reduc:V4SF
1112 ;       (op1)
1113 ;       (unspec:V4SF [(const_int 0)] UNSPEC_REDUC))
1115 ; is to allow us to use a code iterator, but not completely list all of the
1116 ; vector rotates, etc. to prevent canonicalization
1118 (define_expand "reduc_<VEC_reduc_name>_v4sf"
1119   [(parallel [(set (match_operand:V4SF 0 "vfloat_operand" "")
1120                    (VEC_reduc:V4SF
1121                     (unspec:V4SF [(const_int 0)] UNSPEC_REDUC)
1122                     (match_operand:V4SF 1 "vfloat_operand" "")))
1123               (clobber (match_scratch:V4SF 2 ""))
1124               (clobber (match_scratch:V4SF 3 ""))])]
1125   "VECTOR_UNIT_VSX_P (V4SFmode)"
1126   "")
1129 ;;; Expanders for vector insn patterns shared between the SPE and TARGET_PAIRED systems.
1131 (define_expand "absv2sf2"
1132   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1133         (abs:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1134   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1135   "")
1137 (define_expand "negv2sf2"
1138   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1139         (neg:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")))]
1140   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1141   "")
1143 (define_expand "addv2sf3"
1144   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1145         (plus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1146                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1147   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1148   "
1150   if (TARGET_SPE)
1151     {
1152       /* We need to make a note that we clobber SPEFSCR.  */
1153       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1155       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1156                                          gen_rtx_PLUS (V2SFmode, operands[1], operands[2]));
1157       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1158       emit_insn (par);
1159       DONE;
1160     }
1163 (define_expand "subv2sf3"
1164   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1165         (minus:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1166                     (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1167   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1168   "
1170   if (TARGET_SPE)
1171     {
1172       /* We need to make a note that we clobber SPEFSCR.  */
1173       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1175       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1176                                          gen_rtx_MINUS (V2SFmode, operands[1], operands[2]));
1177       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1178       emit_insn (par);
1179       DONE;
1180     }
1183 (define_expand "mulv2sf3"
1184   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1185         (mult:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1186                    (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1187   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1188   "
1190   if (TARGET_SPE)
1191     {
1192       /* We need to make a note that we clobber SPEFSCR.  */
1193       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1195       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1196                                          gen_rtx_MULT (V2SFmode, operands[1], operands[2]));
1197       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1198       emit_insn (par);
1199       DONE;
1200     }
1203 (define_expand "divv2sf3"
1204   [(set (match_operand:V2SF 0 "gpc_reg_operand" "")
1205         (div:V2SF (match_operand:V2SF 1 "gpc_reg_operand" "")
1206                   (match_operand:V2SF 2 "gpc_reg_operand" "")))]
1207   "TARGET_PAIRED_FLOAT || TARGET_SPE"
1208   "
1210   if (TARGET_SPE)
1211     {
1212       /* We need to make a note that we clobber SPEFSCR.  */
1213       rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (2));
1215       XVECEXP (par, 0, 0) = gen_rtx_SET (VOIDmode, operands[0],
1216                                          gen_rtx_DIV (V2SFmode, operands[1], operands[2]));
1217       XVECEXP (par, 0, 1) = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, SPEFSCR_REGNO));
1218       emit_insn (par);
1219       DONE;
1220     }