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-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/>.
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 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")
67 ;; Same size integer type for floating point data
68 (define_mode_attr VEC_int [(V4SF "v4si")
71 (define_mode_attr VEC_INT [(V4SF "V4SI")
74 ;; constants for unspec
75 (define_c_enum "unspec" [UNSPEC_PREDICATE
78 ;; Vector reduction code iterators
79 (define_code_iterator VEC_reduc [plus smin smax])
81 (define_code_attr VEC_reduc_name [(plus "plus")
85 (define_code_attr VEC_reduc_rtx [(plus "add")
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 ())
99 if (CONSTANT_P (operands[1]))
101 if (FLOAT128_VECTOR_P (<MODE>mode))
103 if (!easy_fp_constant (operands[1], <MODE>mode))
104 operands[1] = force_const_mem (<MODE>mode, operands[1]);
106 else if (!easy_vector_constant (operands[1], <MODE>mode))
107 operands[1] = force_const_mem (<MODE>mode, operands[1]);
110 if (!vlogical_operand (operands[0], <MODE>mode)
111 && !vlogical_operand (operands[1], <MODE>mode))
112 operands[1] = force_reg (<MODE>mode, operands[1]);
114 if (!BYTES_BIG_ENDIAN
115 && VECTOR_MEM_VSX_P (<MODE>mode)
117 && !gpr_or_gpr_p (operands[0], operands[1])
118 && (memory_operand (operands[0], <MODE>mode)
119 ^ memory_operand (operands[1], <MODE>mode)))
121 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
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)"
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)"
140 ;; Splits if a GPR register was chosen for the move
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)
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])"
151 rs6000_split_multireg_move (operands[0], operands[1]);
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
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)"
165 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
167 if (VECTOR_MEM_VSX_P (<MODE>mode))
169 operands[1] = rs6000_address_for_altivec (operands[1]);
170 emit_insn (gen_altivec_lvx_<mode> (operands[0], operands[1]));
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)"
181 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
183 if (VECTOR_MEM_VSX_P (<MODE>mode))
185 operands[0] = rs6000_address_for_altivec (operands[0]);
186 emit_insn (gen_altivec_stvx_<mode> (operands[0], operands[1]));
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)"
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)"
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))
216 emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
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)"
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)"
234 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
236 emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
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)"
247 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
249 emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
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)"
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)"
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)
279 rs6000_emit_swsqrt (operands[0], operands[1], 0);
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" "")]
288 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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")]
295 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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)"
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" "")]
308 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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" "")]
315 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
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)"
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)"
331 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
333 emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
340 ;; Vector comparisons
341 (define_expand "vcond<mode><mode>"
342 [(set (match_operand:VEC_F 0 "vfloat_operand" "")
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)"
352 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
353 operands[3], operands[4], operands[5]))
359 (define_expand "vcond<mode><mode>"
360 [(set (match_operand:VEC_I 0 "vint_operand" "")
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)"
370 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
371 operands[3], operands[4], operands[5]))
377 (define_expand "vcondv4sfv4si"
378 [(set (match_operand:V4SF 0 "vfloat_operand" "")
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)"
389 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
390 operands[3], operands[4], operands[5]))
396 (define_expand "vcondv4siv4sf"
397 [(set (match_operand:V4SI 0 "vint_operand" "")
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)"
408 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
409 operands[3], operands[4], operands[5]))
415 (define_expand "vcondu<mode><mode>"
416 [(set (match_operand:VEC_I 0 "vint_operand" "")
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)"
426 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
427 operands[3], operands[4], operands[5]))
433 (define_expand "vconduv4sfv4si"
434 [(set (match_operand:V4SF 0 "vfloat_operand" "")
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)"
445 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
446 operands[3], operands[4], operands[5]))
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
546 (gt:VEC_F (match_dup 1)
549 (gt:VEC_F (match_dup 2)
552 (not:VEC_F (ior:VEC_F (match_dup 3)
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)"
568 (gt:VEC_F (match_dup 1)
571 (gt:VEC_F (match_dup 2)
574 (ior:VEC_F (match_dup 3)
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)"
590 (ge:VEC_F (match_dup 1)
593 (ge:VEC_F (match_dup 2)
596 (ior:VEC_F (match_dup 3)
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)"
612 (ge:VEC_F (match_dup 1)
615 (ge:VEC_F (match_dup 2)
618 (and:VEC_F (not:VEC_F (match_dup 3))
619 (not:VEC_F (match_dup 4))))]
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" "")
631 (ne:CC (match_operand:VEC_L 3 "vlogical_operand" "")
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" "")
641 (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand" "")
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"
653 (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand" "")
654 (match_operand:VEC_A 2 "vlogical_operand" ""))]
656 (set (match_operand:VEC_A 0 "vlogical_operand" "")
657 (eq:VEC_A (match_dup 1)
659 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
662 (define_expand "vector_gt_<mode>_p"
665 (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand" "")
666 (match_operand:VEC_A 2 "vlogical_operand" ""))]
668 (set (match_operand:VEC_A 0 "vlogical_operand" "")
669 (gt:VEC_A (match_dup 1)
671 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
674 (define_expand "vector_ge_<mode>_p"
677 (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand" "")
678 (match_operand:VEC_F 2 "vfloat_operand" ""))]
680 (set (match_operand:VEC_F 0 "vfloat_operand" "")
681 (ge:VEC_F (match_dup 1)
683 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
686 (define_expand "vector_gtu_<mode>_p"
689 (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand" "")
690 (match_operand:VEC_I 2 "vint_operand" ""))]
692 (set (match_operand:VEC_I 0 "vlogical_operand" "")
693 (gtu:VEC_I (match_dup 1)
695 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
698 ;; AltiVec/VSX predicates.
700 (define_expand "cr6_test_for_zero"
701 [(set (match_operand:SI 0 "register_operand" "=r")
704 "TARGET_ALTIVEC || TARGET_VSX"
707 (define_expand "cr6_test_for_zero_reverse"
708 [(set (match_operand:SI 0 "register_operand" "=r")
712 (xor:SI (match_dup 0)
714 "TARGET_ALTIVEC || TARGET_VSX"
717 (define_expand "cr6_test_for_lt"
718 [(set (match_operand:SI 0 "register_operand" "=r")
721 "TARGET_ALTIVEC || TARGET_VSX"
724 (define_expand "cr6_test_for_lt_reverse"
725 [(set (match_operand:SI 0 "register_operand" "=r")
729 (xor:SI (match_dup 0)
731 "TARGET_ALTIVEC || TARGET_VSX"
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" "")))]
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" "")))]
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)"
755 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
757 emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
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)"
768 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
770 emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
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)"
781 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
783 emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
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)"
794 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
796 emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
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]);
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]));
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]));
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);
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);
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);
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));
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));
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));
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));
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));
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));
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]));
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]),
972 emit_move_insn (operands[0], unspec);
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"
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" "")]
999 rtx bitshift = operands[2];
1002 rtx zero_reg, op1, op2;
1003 HOST_WIDE_INT bitshift_val;
1004 HOST_WIDE_INT byteshift_val;
1006 if (! CONSTANT_P (bitshift))
1008 bitshift_val = INTVAL (bitshift);
1009 if (bitshift_val & 0x7)
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)
1016 byteshift_val = 16 - byteshift_val;
1026 if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1028 shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1029 insn = gen_vsx_xxsldwi_<mode> (operands[0], op1, op2, shift);
1033 shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1034 insn = gen_altivec_vsldoi_<mode> (operands[0], op1, op2, shift);
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)"
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)"
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)"
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)"
1073 ;; Vector reduction expanders for VSX
1074 ; The (VEC_reduc:...
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)"
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)
1092 emit_insn (gen_vsx_reduc_<VEC_reduc:VEC_reduc_name>_<VEC_F:mode> (vec,
1094 emit_insn (gen_vsx_extract_<VEC_F:mode> (operand0, vec, elt));
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"
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"
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"
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));
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"
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));
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"
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));
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"
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));