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
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/>.
27 (define_mode_iterator VEC_I [V16QI V8HI V4SI V2DI])
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")
68 ;; Same size integer type for floating point data
69 (define_mode_attr VEC_int [(V4SF "v4si")
72 (define_mode_attr VEC_INT [(V4SF "V4SI")
75 ;; constants for unspec
76 (define_c_enum "unspec" [UNSPEC_PREDICATE
79 ;; Vector reduction code iterators
80 (define_code_iterator VEC_reduc [plus smin smax])
82 (define_code_attr VEC_reduc_name [(plus "splus")
86 (define_code_attr VEC_reduc_rtx [(plus "add")
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 ())
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]);
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)))
114 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
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)"
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)"
133 ;; Splits if a GPR register was chosen for the move
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)
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])"
144 rs6000_split_multireg_move (operands[0], operands[1]);
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
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)"
158 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
160 if (VECTOR_MEM_VSX_P (<MODE>mode))
162 operands[1] = rs6000_address_for_altivec (operands[1]);
163 emit_insn (gen_altivec_lvx_<mode> (operands[0], operands[1]));
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)"
174 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
176 if (VECTOR_MEM_VSX_P (<MODE>mode))
178 operands[0] = rs6000_address_for_altivec (operands[0]);
179 emit_insn (gen_altivec_stvx_<mode> (operands[0], operands[1]));
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")])]
196 rs6000_secondary_reload_inner (operands[1], operands[0], operands[2], true);
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")])]
206 rs6000_secondary_reload_inner (operands[0], operands[1], operands[2], false);
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"))
219 "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
221 "&& reload_completed"
223 (plus:P (match_dup 1)
225 (parallel [(set (match_dup 0)
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
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")
237 "(TARGET_ALTIVEC || TARGET_VSX) && (reload_in_progress || reload_completed)"
239 "&& reload_completed"
240 [(parallel [(set (match_dup 0)
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)"
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)"
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))
268 emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
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)"
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)"
286 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
288 emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
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)"
299 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
301 emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
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)"
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)"
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)"
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" "")]
331 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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")]
338 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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)"
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" "")]
351 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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" "")]
358 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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)"
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)"
374 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
376 emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
383 ;; Vector comparisons
384 (define_expand "vcond<mode><mode>"
385 [(set (match_operand:VEC_F 0 "vfloat_operand" "")
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)"
395 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
396 operands[3], operands[4], operands[5]))
402 (define_expand "vcond<mode><mode>"
403 [(set (match_operand:VEC_I 0 "vint_operand" "")
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)"
413 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
414 operands[3], operands[4], operands[5]))
420 (define_expand "vcondv4sfv4si"
421 [(set (match_operand:V4SF 0 "vfloat_operand" "")
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)"
432 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
433 operands[3], operands[4], operands[5]))
439 (define_expand "vcondv4siv4sf"
440 [(set (match_operand:V4SI 0 "vint_operand" "")
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)"
451 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
452 operands[3], operands[4], operands[5]))
458 (define_expand "vcondu<mode><mode>"
459 [(set (match_operand:VEC_I 0 "vint_operand" "")
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)"
469 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
470 operands[3], operands[4], operands[5]))
476 (define_expand "vconduv4sfv4si"
477 [(set (match_operand:V4SF 0 "vfloat_operand" "")
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)"
488 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
489 operands[3], operands[4], operands[5]))
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)"
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)"
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)"
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)"
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)"
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)"
538 (gt:VEC_F (match_dup 1)
541 (gt:VEC_F (match_dup 2)
544 (not:VEC_F (ior:VEC_F (match_dup 3)
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)"
560 (gt:VEC_F (match_dup 1)
563 (gt:VEC_F (match_dup 2)
566 (ior:VEC_F (match_dup 3)
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)"
582 (ge:VEC_F (match_dup 1)
585 (ge:VEC_F (match_dup 2)
588 (ior:VEC_F (match_dup 3)
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)"
604 (ge:VEC_F (match_dup 1)
607 (ge:VEC_F (match_dup 2)
610 (not:VEC_F (ior:VEC_F (match_dup 3)
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" "")
623 (ne:CC (match_operand:VEC_L 3 "vlogical_operand" "")
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" "")
633 (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand" "")
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"
645 (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand" "")
646 (match_operand:VEC_A 2 "vlogical_operand" ""))]
648 (set (match_operand:VEC_A 0 "vlogical_operand" "")
649 (eq:VEC_A (match_dup 1)
651 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
654 (define_expand "vector_gt_<mode>_p"
657 (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand" "")
658 (match_operand:VEC_A 2 "vlogical_operand" ""))]
660 (set (match_operand:VEC_A 0 "vlogical_operand" "")
661 (gt:VEC_A (match_dup 1)
663 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
666 (define_expand "vector_ge_<mode>_p"
669 (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand" "")
670 (match_operand:VEC_F 2 "vfloat_operand" ""))]
672 (set (match_operand:VEC_F 0 "vfloat_operand" "")
673 (ge:VEC_F (match_dup 1)
675 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
678 (define_expand "vector_gtu_<mode>_p"
681 (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand" "")
682 (match_operand:VEC_I 2 "vint_operand" ""))]
684 (set (match_operand:VEC_I 0 "vlogical_operand" "")
685 (gtu:VEC_I (match_dup 1)
687 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
690 ;; AltiVec/VSX predicates.
692 (define_expand "cr6_test_for_zero"
693 [(set (match_operand:SI 0 "register_operand" "=r")
696 "TARGET_ALTIVEC || TARGET_VSX"
699 (define_expand "cr6_test_for_zero_reverse"
700 [(set (match_operand:SI 0 "register_operand" "=r")
703 (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
704 "TARGET_ALTIVEC || TARGET_VSX"
707 (define_expand "cr6_test_for_lt"
708 [(set (match_operand:SI 0 "register_operand" "=r")
711 "TARGET_ALTIVEC || TARGET_VSX"
714 (define_expand "cr6_test_for_lt_reverse"
715 [(set (match_operand:SI 0 "register_operand" "=r")
718 (set (match_dup 0) (minus:SI (const_int 1) (match_dup 0)))]
719 "TARGET_ALTIVEC || TARGET_VSX"
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" "")))]
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" "")))]
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)"
743 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
745 emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
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)"
756 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
758 emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
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)"
769 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
771 emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
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)"
782 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
784 emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
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]);
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]));
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]));
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);
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);
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);
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));
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));
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));
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));
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));
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));
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]));
953 emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[2],
954 operands[1], operands[3]));
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"
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" "")]
979 rtx bitshift = operands[2];
982 HOST_WIDE_INT bitshift_val;
983 HOST_WIDE_INT byteshift_val;
985 if (! CONSTANT_P (bitshift))
987 bitshift_val = INTVAL (bitshift);
988 if (bitshift_val & 0x7)
990 byteshift_val = bitshift_val >> 3;
991 if (TARGET_VSX && (byteshift_val & 0x3) == 0)
993 shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
994 insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
999 shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1000 insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
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" "")]
1020 rtx bitshift = operands[2];
1023 HOST_WIDE_INT bitshift_val;
1024 HOST_WIDE_INT byteshift_val;
1026 if (! CONSTANT_P (bitshift))
1028 bitshift_val = INTVAL (bitshift);
1029 if (bitshift_val & 0x7)
1031 byteshift_val = 16 - (bitshift_val >> 3);
1032 if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1034 shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1035 insn = gen_vsx_xxsldwi_<mode> (operands[0], operands[1], operands[1],
1040 shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1041 insn = gen_altivec_vsldoi_<mode> (operands[0], operands[1], operands[1],
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)"
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)"
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)"
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)"
1081 ;; Vector reduction expanders for VSX
1083 (define_expand "reduc_<VEC_reduc_name>_v2df"
1084 [(parallel [(set (match_operand:V2DF 0 "vfloat_operand" "")
1088 (match_operand:V2DF 1 "vfloat_operand" "")
1089 (parallel [(const_int 1)]))
1092 (parallel [(const_int 0)])))
1094 (clobber (match_scratch:V2DF 2 ""))])]
1095 "VECTOR_UNIT_VSX_P (V2DFmode)"
1098 ; The (VEC_reduc:V4SF
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" "")
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)"
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"
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"
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"
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));
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"
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));
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"
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));
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"
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));