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-2018 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])
29 ;; Vector int modes for parity
30 (define_mode_iterator VEC_IP [V8HI
37 (define_mode_iterator VEC_F [V4SF V2DF])
39 ;; Vector arithmetic modes
40 (define_mode_iterator VEC_A [V16QI V8HI V4SI V2DI V4SF V2DF])
42 ;; Vector modes that need alginment via permutes
43 (define_mode_iterator VEC_K [V16QI V8HI V4SI V4SF])
45 ;; Vector logical modes
46 (define_mode_iterator VEC_L [V16QI V8HI V4SI V2DI V4SF V2DF V1TI TI KF TF])
48 ;; Vector modes for moves. Don't do TImode or TFmode here, since their
49 ;; moves are handled elsewhere.
50 (define_mode_iterator VEC_M [V16QI V8HI V4SI V2DI V4SF V2DF V1TI KF])
52 ;; Vector modes for types that don't need a realignment under VSX
53 (define_mode_iterator VEC_N [V4SI V4SF V2DI V2DF V1TI KF TF])
55 ;; Vector comparison modes
56 (define_mode_iterator VEC_C [V16QI V8HI V4SI V2DI V4SF V2DF])
58 ;; Vector init/extract modes
59 (define_mode_iterator VEC_E [V16QI V8HI V4SI V2DI V4SF V2DF])
61 ;; Vector modes for 64-bit base types
62 (define_mode_iterator VEC_64 [V2DI V2DF])
64 ;; Vector integer modes
65 (define_mode_iterator VI [V4SI V8HI V16QI])
67 ;; Base type from vector mode
68 (define_mode_attr VEC_base [(V16QI "QI")
77 ;; As above, but in lower case
78 (define_mode_attr VEC_base_l [(V16QI "qi")
87 ;; Same size integer type for floating point data
88 (define_mode_attr VEC_int [(V4SF "v4si")
91 (define_mode_attr VEC_INT [(V4SF "V4SI")
94 ;; constants for unspec
95 (define_c_enum "unspec" [UNSPEC_PREDICATE
99 ;; Vector reduction code iterators
100 (define_code_iterator VEC_reduc [plus smin smax])
102 (define_code_attr VEC_reduc_name [(plus "plus")
106 (define_code_attr VEC_reduc_rtx [(plus "add")
111 ;; Vector move instructions. Little-endian VSX loads and stores require
112 ;; special handling to circumvent "element endianness."
113 (define_expand "mov<mode>"
114 [(set (match_operand:VEC_M 0 "nonimmediate_operand")
115 (match_operand:VEC_M 1 "any_operand"))]
116 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
118 if (can_create_pseudo_p ())
120 if (CONSTANT_P (operands[1]))
122 if (FLOAT128_VECTOR_P (<MODE>mode))
124 if (!easy_fp_constant (operands[1], <MODE>mode))
125 operands[1] = force_const_mem (<MODE>mode, operands[1]);
127 else if (!easy_vector_constant (operands[1], <MODE>mode))
128 operands[1] = force_const_mem (<MODE>mode, operands[1]);
131 if (!vlogical_operand (operands[0], <MODE>mode)
132 && !vlogical_operand (operands[1], <MODE>mode))
133 operands[1] = force_reg (<MODE>mode, operands[1]);
135 if (!BYTES_BIG_ENDIAN
136 && VECTOR_MEM_VSX_P (<MODE>mode)
138 && !gpr_or_gpr_p (operands[0], operands[1])
139 && (memory_operand (operands[0], <MODE>mode)
140 ^ memory_operand (operands[1], <MODE>mode)))
142 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
147 ;; Generic vector floating point load/store instructions. These will match
148 ;; insns defined in vsx.md or altivec.md depending on the switches.
149 (define_expand "vector_load_<mode>"
150 [(set (match_operand:VEC_M 0 "vfloat_operand")
151 (match_operand:VEC_M 1 "memory_operand"))]
152 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
155 (define_expand "vector_store_<mode>"
156 [(set (match_operand:VEC_M 0 "memory_operand")
157 (match_operand:VEC_M 1 "vfloat_operand"))]
158 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
161 ;; Splits if a GPR register was chosen for the move
163 [(set (match_operand:VEC_L 0 "nonimmediate_operand")
164 (match_operand:VEC_L 1 "input_operand"))]
165 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
167 && gpr_or_gpr_p (operands[0], operands[1])
168 && !direct_move_p (operands[0], operands[1])
169 && !quad_load_store_p (operands[0], operands[1])"
172 rs6000_split_multireg_move (operands[0], operands[1]);
176 ;; Vector floating point load/store instructions that uses the Altivec
177 ;; instructions even if we are compiling for VSX, since the Altivec
178 ;; instructions silently ignore the bottom 3 bits of the address, and VSX does
180 (define_expand "vector_altivec_load_<mode>"
181 [(set (match_operand:VEC_M 0 "vfloat_operand")
182 (match_operand:VEC_M 1 "memory_operand"))]
183 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
185 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
187 if (VECTOR_MEM_VSX_P (<MODE>mode))
189 operands[1] = rs6000_address_for_altivec (operands[1]);
190 rtx and_op = XEXP (operands[1], 0);
191 gcc_assert (GET_CODE (and_op) == AND);
192 rtx addr = XEXP (and_op, 0);
193 if (GET_CODE (addr) == PLUS)
194 emit_insn (gen_altivec_lvx_<mode>_2op (operands[0], XEXP (addr, 0),
197 emit_insn (gen_altivec_lvx_<mode>_1op (operands[0], operands[1]));
202 (define_expand "vector_altivec_store_<mode>"
203 [(set (match_operand:VEC_M 0 "memory_operand")
204 (match_operand:VEC_M 1 "vfloat_operand"))]
205 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
207 gcc_assert (VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode));
209 if (VECTOR_MEM_VSX_P (<MODE>mode))
211 operands[0] = rs6000_address_for_altivec (operands[0]);
212 rtx and_op = XEXP (operands[0], 0);
213 gcc_assert (GET_CODE (and_op) == AND);
214 rtx addr = XEXP (and_op, 0);
215 if (GET_CODE (addr) == PLUS)
216 emit_insn (gen_altivec_stvx_<mode>_2op (operands[1], XEXP (addr, 0),
219 emit_insn (gen_altivec_stvx_<mode>_1op (operands[1], operands[0]));
226 ;; Generic floating point vector arithmetic support
227 (define_expand "add<mode>3"
228 [(set (match_operand:VEC_F 0 "vfloat_operand")
229 (plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
230 (match_operand:VEC_F 2 "vfloat_operand")))]
231 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
234 (define_expand "sub<mode>3"
235 [(set (match_operand:VEC_F 0 "vfloat_operand")
236 (minus: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)"
241 (define_expand "mul<mode>3"
242 [(set (match_operand:VEC_F 0 "vfloat_operand")
243 (mult: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)"
247 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
249 emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
254 (define_expand "div<mode>3"
255 [(set (match_operand:VEC_F 0 "vfloat_operand")
256 (div:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
257 (match_operand:VEC_F 2 "vfloat_operand")))]
258 "VECTOR_UNIT_VSX_P (<MODE>mode)"
260 if (RS6000_RECIP_AUTO_RE_P (<MODE>mode)
261 && can_create_pseudo_p () && flag_finite_math_only
262 && !flag_trapping_math && flag_reciprocal_math)
264 rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
269 (define_expand "neg<mode>2"
270 [(set (match_operand:VEC_F 0 "vfloat_operand")
271 (neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
272 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
274 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
276 emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
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)"
286 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
288 emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
293 (define_expand "smin<mode>3"
294 [(set (match_operand:VEC_F 0 "register_operand")
295 (smin:VEC_F (match_operand:VEC_F 1 "register_operand")
296 (match_operand:VEC_F 2 "register_operand")))]
297 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
300 (define_expand "smax<mode>3"
301 [(set (match_operand:VEC_F 0 "register_operand")
302 (smax:VEC_F (match_operand:VEC_F 1 "register_operand")
303 (match_operand:VEC_F 2 "register_operand")))]
304 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
308 (define_expand "sqrt<mode>2"
309 [(set (match_operand:VEC_F 0 "vfloat_operand")
310 (sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
311 "VECTOR_UNIT_VSX_P (<MODE>mode)"
313 if (<MODE>mode == V4SFmode
314 && !optimize_function_for_size_p (cfun)
315 && flag_finite_math_only && !flag_trapping_math
316 && flag_unsafe_math_optimizations)
318 rs6000_emit_swsqrt (operands[0], operands[1], 0);
323 (define_expand "rsqrte<mode>2"
324 [(set (match_operand:VEC_F 0 "vfloat_operand")
325 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
327 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
330 (define_expand "re<mode>2"
331 [(set (match_operand:VEC_F 0 "vfloat_operand")
332 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
334 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
337 (define_expand "ftrunc<mode>2"
338 [(set (match_operand:VEC_F 0 "vfloat_operand")
339 (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
340 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
343 (define_expand "vector_ceil<mode>2"
344 [(set (match_operand:VEC_F 0 "vfloat_operand")
345 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
347 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
350 (define_expand "vector_floor<mode>2"
351 [(set (match_operand:VEC_F 0 "vfloat_operand")
352 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
354 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
357 (define_expand "vector_btrunc<mode>2"
358 [(set (match_operand:VEC_F 0 "vfloat_operand")
359 (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
360 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
363 (define_expand "vector_copysign<mode>3"
364 [(set (match_operand:VEC_F 0 "vfloat_operand")
365 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")
366 (match_operand:VEC_F 2 "vfloat_operand")] UNSPEC_COPYSIGN))]
367 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
369 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
371 emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
378 ;; Vector comparisons
379 (define_expand "vcond<mode><mode>"
380 [(set (match_operand:VEC_F 0 "vfloat_operand")
382 (match_operator 3 "comparison_operator"
383 [(match_operand:VEC_F 4 "vfloat_operand")
384 (match_operand:VEC_F 5 "vfloat_operand")])
385 (match_operand:VEC_F 1 "vfloat_operand")
386 (match_operand:VEC_F 2 "vfloat_operand")))]
387 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
389 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
390 operands[3], operands[4], operands[5]))
396 (define_expand "vcond<mode><mode>"
397 [(set (match_operand:VEC_I 0 "vint_operand")
399 (match_operator 3 "comparison_operator"
400 [(match_operand:VEC_I 4 "vint_operand")
401 (match_operand:VEC_I 5 "vint_operand")])
402 (match_operand:VEC_I 1 "vector_int_reg_or_same_bit")
403 (match_operand:VEC_I 2 "vector_int_reg_or_same_bit")))]
404 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
406 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
407 operands[3], operands[4], operands[5]))
413 (define_expand "vcondv4sfv4si"
414 [(set (match_operand:V4SF 0 "vfloat_operand")
416 (match_operator 3 "comparison_operator"
417 [(match_operand:V4SI 4 "vint_operand")
418 (match_operand:V4SI 5 "vint_operand")])
419 (match_operand:V4SF 1 "vfloat_operand")
420 (match_operand:V4SF 2 "vfloat_operand")))]
421 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
422 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
424 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
425 operands[3], operands[4], operands[5]))
431 (define_expand "vcondv4siv4sf"
432 [(set (match_operand:V4SI 0 "vint_operand")
434 (match_operator 3 "comparison_operator"
435 [(match_operand:V4SF 4 "vfloat_operand")
436 (match_operand:V4SF 5 "vfloat_operand")])
437 (match_operand:V4SI 1 "vint_operand")
438 (match_operand:V4SI 2 "vint_operand")))]
439 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
440 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
442 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
443 operands[3], operands[4], operands[5]))
449 (define_expand "vcondv2dfv2di"
450 [(set (match_operand:V2DF 0 "vfloat_operand")
452 (match_operator 3 "comparison_operator"
453 [(match_operand:V2DI 4 "vint_operand")
454 (match_operand:V2DI 5 "vint_operand")])
455 (match_operand:V2DF 1 "vfloat_operand")
456 (match_operand:V2DF 2 "vfloat_operand")))]
457 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
458 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
460 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
461 operands[3], operands[4], operands[5]))
467 (define_expand "vcondv2div2df"
468 [(set (match_operand:V2DI 0 "vint_operand")
470 (match_operator 3 "comparison_operator"
471 [(match_operand:V2DF 4 "vfloat_operand")
472 (match_operand:V2DF 5 "vfloat_operand")])
473 (match_operand:V2DI 1 "vint_operand")
474 (match_operand:V2DI 2 "vint_operand")))]
475 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
476 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
478 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
479 operands[3], operands[4], operands[5]))
485 (define_expand "vcondu<mode><mode>"
486 [(set (match_operand:VEC_I 0 "vint_operand")
488 (match_operator 3 "comparison_operator"
489 [(match_operand:VEC_I 4 "vint_operand")
490 (match_operand:VEC_I 5 "vint_operand")])
491 (match_operand:VEC_I 1 "vector_int_reg_or_same_bit")
492 (match_operand:VEC_I 2 "vector_int_reg_or_same_bit")))]
493 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
495 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
496 operands[3], operands[4], operands[5]))
502 (define_expand "vconduv4sfv4si"
503 [(set (match_operand:V4SF 0 "vfloat_operand")
505 (match_operator 3 "comparison_operator"
506 [(match_operand:V4SI 4 "vint_operand")
507 (match_operand:V4SI 5 "vint_operand")])
508 (match_operand:V4SF 1 "vfloat_operand")
509 (match_operand:V4SF 2 "vfloat_operand")))]
510 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
511 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
513 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
514 operands[3], operands[4], operands[5]))
520 (define_expand "vconduv2dfv2di"
521 [(set (match_operand:V2DF 0 "vfloat_operand")
523 (match_operator 3 "comparison_operator"
524 [(match_operand:V2DI 4 "vint_operand")
525 (match_operand:V2DI 5 "vint_operand")])
526 (match_operand:V2DF 1 "vfloat_operand")
527 (match_operand:V2DF 2 "vfloat_operand")))]
528 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
529 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
531 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
532 operands[3], operands[4], operands[5]))
538 (define_expand "vector_eq<mode>"
539 [(set (match_operand:VEC_C 0 "vlogical_operand")
540 (eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand")
541 (match_operand:VEC_C 2 "vlogical_operand")))]
542 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
545 (define_expand "vector_gt<mode>"
546 [(set (match_operand:VEC_C 0 "vlogical_operand")
547 (gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand")
548 (match_operand:VEC_C 2 "vlogical_operand")))]
549 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
552 (define_expand "vector_ge<mode>"
553 [(set (match_operand:VEC_F 0 "vlogical_operand")
554 (ge:VEC_F (match_operand:VEC_F 1 "vlogical_operand")
555 (match_operand:VEC_F 2 "vlogical_operand")))]
556 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
559 ; >= for integer vectors: swap operands and apply not-greater-than
560 (define_expand "vector_nlt<mode>"
561 [(set (match_operand:VEC_I 3 "vlogical_operand")
562 (gt:VEC_I (match_operand:VEC_I 2 "vlogical_operand")
563 (match_operand:VEC_I 1 "vlogical_operand")))
564 (set (match_operand:VEC_I 0 "vlogical_operand")
565 (not:VEC_I (match_dup 3)))]
566 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
568 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
571 (define_expand "vector_gtu<mode>"
572 [(set (match_operand:VEC_I 0 "vint_operand")
573 (gtu:VEC_I (match_operand:VEC_I 1 "vint_operand")
574 (match_operand:VEC_I 2 "vint_operand")))]
575 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
578 ; >= for integer vectors: swap operands and apply not-greater-than
579 (define_expand "vector_nltu<mode>"
580 [(set (match_operand:VEC_I 3 "vlogical_operand")
581 (gtu:VEC_I (match_operand:VEC_I 2 "vlogical_operand")
582 (match_operand:VEC_I 1 "vlogical_operand")))
583 (set (match_operand:VEC_I 0 "vlogical_operand")
584 (not:VEC_I (match_dup 3)))]
585 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
587 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
590 (define_expand "vector_geu<mode>"
591 [(set (match_operand:VEC_I 0 "vint_operand")
592 (geu:VEC_I (match_operand:VEC_I 1 "vint_operand")
593 (match_operand:VEC_I 2 "vint_operand")))]
594 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
597 ; <= for integer vectors: apply not-greater-than
598 (define_expand "vector_ngt<mode>"
599 [(set (match_operand:VEC_I 3 "vlogical_operand")
600 (gt:VEC_I (match_operand:VEC_I 1 "vlogical_operand")
601 (match_operand:VEC_I 2 "vlogical_operand")))
602 (set (match_operand:VEC_I 0 "vlogical_operand")
603 (not:VEC_I (match_dup 3)))]
604 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
606 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
609 (define_expand "vector_ngtu<mode>"
610 [(set (match_operand:VEC_I 3 "vlogical_operand")
611 (gtu:VEC_I (match_operand:VEC_I 1 "vlogical_operand")
612 (match_operand:VEC_I 2 "vlogical_operand")))
613 (set (match_operand:VEC_I 0 "vlogical_operand")
614 (not:VEC_I (match_dup 3)))]
615 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
617 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
620 (define_insn_and_split "*vector_uneq<mode>"
621 [(set (match_operand:VEC_F 0 "vfloat_operand")
622 (uneq:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
623 (match_operand:VEC_F 2 "vfloat_operand")))]
624 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
628 (gt:VEC_F (match_dup 1)
631 (gt:VEC_F (match_dup 2)
634 (and:VEC_F (not:VEC_F (match_dup 3))
635 (not:VEC_F (match_dup 4))))]
637 operands[3] = gen_reg_rtx (<MODE>mode);
638 operands[4] = gen_reg_rtx (<MODE>mode);
641 (define_insn_and_split "*vector_ltgt<mode>"
642 [(set (match_operand:VEC_F 0 "vfloat_operand")
643 (ltgt:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
644 (match_operand:VEC_F 2 "vfloat_operand")))]
645 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
649 (gt:VEC_F (match_dup 1)
652 (gt:VEC_F (match_dup 2)
655 (ior:VEC_F (match_dup 3)
658 operands[3] = gen_reg_rtx (<MODE>mode);
659 operands[4] = gen_reg_rtx (<MODE>mode);
662 (define_insn_and_split "*vector_ordered<mode>"
663 [(set (match_operand:VEC_F 0 "vfloat_operand")
664 (ordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
665 (match_operand:VEC_F 2 "vfloat_operand")))]
666 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
670 (ge:VEC_F (match_dup 1)
673 (ge:VEC_F (match_dup 2)
676 (ior:VEC_F (match_dup 3)
679 operands[3] = gen_reg_rtx (<MODE>mode);
680 operands[4] = gen_reg_rtx (<MODE>mode);
683 (define_insn_and_split "*vector_unordered<mode>"
684 [(set (match_operand:VEC_F 0 "vfloat_operand")
685 (unordered:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
686 (match_operand:VEC_F 2 "vfloat_operand")))]
687 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
691 (ge:VEC_F (match_dup 1)
694 (ge:VEC_F (match_dup 2)
697 (and:VEC_F (not:VEC_F (match_dup 3))
698 (not:VEC_F (match_dup 4))))]
700 operands[3] = gen_reg_rtx (<MODE>mode);
701 operands[4] = gen_reg_rtx (<MODE>mode);
704 ;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask
705 ;; which is in the reverse order that we want
706 (define_expand "vector_select_<mode>"
707 [(set (match_operand:VEC_L 0 "vlogical_operand")
709 (ne:CC (match_operand:VEC_L 3 "vlogical_operand")
711 (match_operand:VEC_L 2 "vlogical_operand")
712 (match_operand:VEC_L 1 "vlogical_operand")))]
713 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
714 "operands[4] = CONST0_RTX (<MODE>mode);")
716 (define_expand "vector_select_<mode>_uns"
717 [(set (match_operand:VEC_L 0 "vlogical_operand")
719 (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand")
721 (match_operand:VEC_L 2 "vlogical_operand")
722 (match_operand:VEC_L 1 "vlogical_operand")))]
723 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
724 "operands[4] = CONST0_RTX (<MODE>mode);")
726 ;; Expansions that compare vectors producing a vector result and a predicate,
727 ;; setting CR6 to indicate a combined status
728 (define_expand "vector_eq_<mode>_p"
730 [(set (reg:CC CR6_REGNO)
731 (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand")
732 (match_operand:VEC_A 2 "vlogical_operand"))]
734 (set (match_operand:VEC_A 0 "vlogical_operand")
735 (eq:VEC_A (match_dup 1)
737 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
740 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
741 ;; implementation of the vec_all_ne built-in functions on Power9.
742 (define_expand "vector_ne_<mode>_p"
744 [(set (reg:CC CR6_REGNO)
745 (unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand")
746 (match_operand:VI 2 "vlogical_operand"))]
751 (set (match_operand:SI 0 "register_operand" "=r")
752 (lt:SI (reg:CC CR6_REGNO)
756 operands[3] = gen_reg_rtx (<MODE>mode);
759 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
760 ;; implementation of the vec_any_eq built-in functions on Power9.
761 (define_expand "vector_ae_<mode>_p"
763 [(set (reg:CC CR6_REGNO)
764 (unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand")
765 (match_operand:VI 2 "vlogical_operand"))]
770 (set (match_operand:SI 0 "register_operand" "=r")
771 (lt:SI (reg:CC CR6_REGNO)
774 (xor:SI (match_dup 0)
778 operands[3] = gen_reg_rtx (<MODE>mode);
781 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
782 ;; implementation of the vec_all_nez and vec_any_eqz built-in
783 ;; functions on Power9.
784 (define_expand "vector_nez_<mode>_p"
786 [(set (reg:CC CR6_REGNO)
787 (unspec:CC [(unspec:VI
788 [(match_operand:VI 1 "vlogical_operand")
789 (match_operand:VI 2 "vlogical_operand")]
792 (set (match_operand:VI 0 "vlogical_operand")
793 (unspec:VI [(match_dup 1)
799 ;; This expansion handles the V2DI mode in the implementation of the
800 ;; vec_all_ne built-in function on Power9.
802 ;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode,
803 ;; this expands into the same rtl that would be used for the Power8
805 (define_expand "vector_ne_v2di_p"
807 [(set (reg:CC CR6_REGNO)
808 (unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand")
809 (match_operand:V2DI 2 "vlogical_operand"))]
812 (eq:V2DI (match_dup 1)
814 (set (match_operand:SI 0 "register_operand" "=r")
815 (eq:SI (reg:CC CR6_REGNO)
819 operands[3] = gen_reg_rtx (V2DImode);
822 ;; This expansion handles the V2DI mode in the implementation of the
823 ;; vec_any_eq built-in function on Power9.
825 ;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode,
826 ;; this expands into the same rtl that would be used for the Power8
828 (define_expand "vector_ae_v2di_p"
830 [(set (reg:CC CR6_REGNO)
831 (unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand")
832 (match_operand:V2DI 2 "vlogical_operand"))]
835 (eq:V2DI (match_dup 1)
837 (set (match_operand:SI 0 "register_operand" "=r")
838 (eq:SI (reg:CC CR6_REGNO)
841 (xor:SI (match_dup 0)
845 operands[3] = gen_reg_rtx (V2DImode);
848 ;; This expansion handles the V4SF and V2DF modes in the Power9
849 ;; implementation of the vec_all_ne built-in functions. Note that the
850 ;; expansions for this pattern with these modes makes no use of power9-
851 ;; specific instructions since there are no new power9 instructions
852 ;; for vector compare not equal with floating point arguments.
853 (define_expand "vector_ne_<mode>_p"
855 [(set (reg:CC CR6_REGNO)
856 (unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand")
857 (match_operand:VEC_F 2 "vlogical_operand"))]
860 (eq:VEC_F (match_dup 1)
862 (set (match_operand:SI 0 "register_operand" "=r")
863 (eq:SI (reg:CC CR6_REGNO)
867 operands[3] = gen_reg_rtx (<MODE>mode);
870 ;; This expansion handles the V4SF and V2DF modes in the Power9
871 ;; implementation of the vec_any_eq built-in functions. Note that the
872 ;; expansions for this pattern with these modes makes no use of power9-
873 ;; specific instructions since there are no new power9 instructions
874 ;; for vector compare not equal with floating point arguments.
875 (define_expand "vector_ae_<mode>_p"
877 [(set (reg:CC CR6_REGNO)
878 (unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand")
879 (match_operand:VEC_F 2 "vlogical_operand"))]
882 (eq:VEC_F (match_dup 1)
884 (set (match_operand:SI 0 "register_operand" "=r")
885 (eq:SI (reg:CC CR6_REGNO)
888 (xor:SI (match_dup 0)
892 operands[3] = gen_reg_rtx (<MODE>mode);
895 (define_expand "vector_gt_<mode>_p"
897 [(set (reg:CC CR6_REGNO)
898 (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand")
899 (match_operand:VEC_A 2 "vlogical_operand"))]
901 (set (match_operand:VEC_A 0 "vlogical_operand")
902 (gt:VEC_A (match_dup 1)
904 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
907 (define_expand "vector_ge_<mode>_p"
909 [(set (reg:CC CR6_REGNO)
910 (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand")
911 (match_operand:VEC_F 2 "vfloat_operand"))]
913 (set (match_operand:VEC_F 0 "vfloat_operand")
914 (ge:VEC_F (match_dup 1)
916 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
919 (define_expand "vector_gtu_<mode>_p"
921 [(set (reg:CC CR6_REGNO)
922 (unspec:CC [(gtu:CC (match_operand:VEC_I 1 "vint_operand")
923 (match_operand:VEC_I 2 "vint_operand"))]
925 (set (match_operand:VEC_I 0 "vlogical_operand")
926 (gtu:VEC_I (match_dup 1)
928 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
931 ;; AltiVec/VSX predicates.
933 ;; This expansion is triggered during expansion of predicate built-in
934 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
935 ;; altivec_expand_predicate_builtin() function when the value of the
936 ;; integer constant first argument equals zero (aka __CR6_EQ in altivec.h).
937 (define_expand "cr6_test_for_zero"
938 [(set (match_operand:SI 0 "register_operand" "=r")
939 (eq:SI (reg:CC CR6_REGNO)
941 "TARGET_ALTIVEC || TARGET_VSX"
944 ;; This expansion is triggered during expansion of predicate built-in
945 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
946 ;; altivec_expand_predicate_builtin() function when the value of the
947 ;; integer constant first argument equals one (aka __CR6_EQ_REV in altivec.h).
948 (define_expand "cr6_test_for_zero_reverse"
949 [(set (match_operand:SI 0 "register_operand" "=r")
950 (eq:SI (reg:CC CR6_REGNO)
953 (xor:SI (match_dup 0)
955 "TARGET_ALTIVEC || TARGET_VSX"
958 ;; This expansion is triggered during expansion of predicate built-in
959 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
960 ;; altivec_expand_predicate_builtin() function when the value of the
961 ;; integer constant first argument equals two (aka __CR6_LT in altivec.h).
962 (define_expand "cr6_test_for_lt"
963 [(set (match_operand:SI 0 "register_operand" "=r")
964 (lt:SI (reg:CC CR6_REGNO)
966 "TARGET_ALTIVEC || TARGET_VSX"
969 ;; This expansion is triggered during expansion of predicate built-in
970 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
971 ;; altivec_expand_predicate_builtin() function when the value of the
972 ;; integer constant first argument equals three
973 ;; (aka __CR6_LT_REV in altivec.h).
974 (define_expand "cr6_test_for_lt_reverse"
975 [(set (match_operand:SI 0 "register_operand" "=r")
976 (lt:SI (reg:CC CR6_REGNO)
979 (xor:SI (match_dup 0)
981 "TARGET_ALTIVEC || TARGET_VSX"
985 ;; Vector count leading zeros
986 (define_expand "clz<mode>2"
987 [(set (match_operand:VEC_I 0 "register_operand")
988 (clz:VEC_I (match_operand:VEC_I 1 "register_operand")))]
991 ;; Vector count trailing zeros
992 (define_expand "ctz<mode>2"
993 [(set (match_operand:VEC_I 0 "register_operand")
994 (ctz:VEC_I (match_operand:VEC_I 1 "register_operand")))]
997 ;; Vector population count
998 (define_expand "popcount<mode>2"
999 [(set (match_operand:VEC_I 0 "register_operand")
1000 (popcount:VEC_I (match_operand:VEC_I 1 "register_operand")))]
1004 (define_expand "parity<mode>2"
1005 [(set (match_operand:VEC_IP 0 "register_operand")
1006 (parity:VEC_IP (match_operand:VEC_IP 1 "register_operand")))]
1010 ;; Same size conversions
1011 (define_expand "float<VEC_int><mode>2"
1012 [(set (match_operand:VEC_F 0 "vfloat_operand")
1013 (float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))]
1014 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1016 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1018 emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
1023 (define_expand "floatuns<VEC_int><mode>2"
1024 [(set (match_operand:VEC_F 0 "vfloat_operand")
1025 (unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))]
1026 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1028 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1030 emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
1035 (define_expand "fix_trunc<mode><VEC_int>2"
1036 [(set (match_operand:<VEC_INT> 0 "vint_operand")
1037 (fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))]
1038 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1040 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1042 emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
1047 (define_expand "fixuns_trunc<mode><VEC_int>2"
1048 [(set (match_operand:<VEC_INT> 0 "vint_operand")
1049 (unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))]
1050 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1052 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1054 emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
1060 ;; Vector initialization, set, extract
1061 (define_expand "vec_init<mode><VEC_base_l>"
1062 [(match_operand:VEC_E 0 "vlogical_operand")
1063 (match_operand:VEC_E 1 "")]
1064 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1066 rs6000_expand_vector_init (operands[0], operands[1]);
1070 (define_expand "vec_set<mode>"
1071 [(match_operand:VEC_E 0 "vlogical_operand")
1072 (match_operand:<VEC_base> 1 "register_operand")
1073 (match_operand 2 "const_int_operand")]
1074 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1076 rs6000_expand_vector_set (operands[0], operands[1], INTVAL (operands[2]));
1080 (define_expand "vec_extract<mode><VEC_base_l>"
1081 [(match_operand:<VEC_base> 0 "register_operand")
1082 (match_operand:VEC_E 1 "vlogical_operand")
1083 (match_operand 2 "const_int_operand")]
1084 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1086 rs6000_expand_vector_extract (operands[0], operands[1], operands[2]);
1090 ;; Convert double word types to single word types
1091 (define_expand "vec_pack_trunc_v2df"
1092 [(match_operand:V4SF 0 "vfloat_operand")
1093 (match_operand:V2DF 1 "vfloat_operand")
1094 (match_operand:V2DF 2 "vfloat_operand")]
1095 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1097 rtx r1 = gen_reg_rtx (V4SFmode);
1098 rtx r2 = gen_reg_rtx (V4SFmode);
1100 emit_insn (gen_vsx_xvcvdpsp (r1, operands[1]));
1101 emit_insn (gen_vsx_xvcvdpsp (r2, operands[2]));
1102 rs6000_expand_extract_even (operands[0], r1, r2);
1106 (define_expand "vec_pack_sfix_trunc_v2df"
1107 [(match_operand:V4SI 0 "vint_operand")
1108 (match_operand:V2DF 1 "vfloat_operand")
1109 (match_operand:V2DF 2 "vfloat_operand")]
1110 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1112 rtx r1 = gen_reg_rtx (V4SImode);
1113 rtx r2 = gen_reg_rtx (V4SImode);
1115 emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1]));
1116 emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2]));
1117 rs6000_expand_extract_even (operands[0], r1, r2);
1121 (define_expand "vec_pack_ufix_trunc_v2df"
1122 [(match_operand:V4SI 0 "vint_operand")
1123 (match_operand:V2DF 1 "vfloat_operand")
1124 (match_operand:V2DF 2 "vfloat_operand")]
1125 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1127 rtx r1 = gen_reg_rtx (V4SImode);
1128 rtx r2 = gen_reg_rtx (V4SImode);
1130 emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1]));
1131 emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2]));
1132 rs6000_expand_extract_even (operands[0], r1, r2);
1136 ;; Convert single word types to double word
1137 (define_expand "vec_unpacks_hi_v4sf"
1138 [(match_operand:V2DF 0 "vfloat_operand")
1139 (match_operand:V4SF 1 "vfloat_operand")]
1140 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
1142 rtx reg = gen_reg_rtx (V4SFmode);
1144 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1145 emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
1149 (define_expand "vec_unpacks_lo_v4sf"
1150 [(match_operand:V2DF 0 "vfloat_operand")
1151 (match_operand:V4SF 1 "vfloat_operand")]
1152 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
1154 rtx reg = gen_reg_rtx (V4SFmode);
1156 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1157 emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
1161 (define_expand "vec_unpacks_float_hi_v4si"
1162 [(match_operand:V2DF 0 "vfloat_operand")
1163 (match_operand:V4SI 1 "vint_operand")]
1164 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1166 rtx reg = gen_reg_rtx (V4SImode);
1168 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1169 emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
1173 (define_expand "vec_unpacks_float_lo_v4si"
1174 [(match_operand:V2DF 0 "vfloat_operand")
1175 (match_operand:V4SI 1 "vint_operand")]
1176 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1178 rtx reg = gen_reg_rtx (V4SImode);
1180 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1181 emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
1185 (define_expand "vec_unpacku_float_hi_v4si"
1186 [(match_operand:V2DF 0 "vfloat_operand")
1187 (match_operand:V4SI 1 "vint_operand")]
1188 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1190 rtx reg = gen_reg_rtx (V4SImode);
1192 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1193 emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
1197 (define_expand "vec_unpacku_float_lo_v4si"
1198 [(match_operand:V2DF 0 "vfloat_operand")
1199 (match_operand:V4SI 1 "vint_operand")]
1200 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1202 rtx reg = gen_reg_rtx (V4SImode);
1204 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1205 emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
1210 ;; Align vector loads with a permute.
1211 (define_expand "vec_realign_load_<mode>"
1212 [(match_operand:VEC_K 0 "vlogical_operand")
1213 (match_operand:VEC_K 1 "vlogical_operand")
1214 (match_operand:VEC_K 2 "vlogical_operand")
1215 (match_operand:V16QI 3 "vlogical_operand")]
1216 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1218 if (BYTES_BIG_ENDIAN)
1219 emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1],
1220 operands[2], operands[3]));
1223 /* We have changed lvsr to lvsl, so to complete the transformation
1224 of vperm for LE, we must swap the inputs. */
1225 rtx unspec = gen_rtx_UNSPEC (<MODE>mode,
1226 gen_rtvec (3, operands[2],
1227 operands[1], operands[3]),
1229 emit_move_insn (operands[0], unspec);
1234 ;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned
1235 ;; since the load already handles it.
1236 (define_expand "movmisalign<mode>"
1237 [(set (match_operand:VEC_N 0 "nonimmediate_operand")
1238 (match_operand:VEC_N 1 "any_operand"))]
1239 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN"
1242 ;; Vector shift right in bits. Currently supported ony for shift
1243 ;; amounts that can be expressed as byte shifts (divisible by 8).
1244 ;; General shift amounts can be supported using vsro + vsr. We're
1245 ;; not expecting to see these yet (the vectorizer currently
1246 ;; generates only shifts by a whole number of vector elements).
1247 ;; Note that the vec_shr operation is actually defined as
1248 ;; 'shift toward element 0' so is a shr for LE and shl for BE.
1249 (define_expand "vec_shr_<mode>"
1250 [(match_operand:VEC_L 0 "vlogical_operand")
1251 (match_operand:VEC_L 1 "vlogical_operand")
1252 (match_operand:QI 2 "reg_or_short_operand")]
1255 rtx bitshift = operands[2];
1258 rtx zero_reg, op1, op2;
1259 HOST_WIDE_INT bitshift_val;
1260 HOST_WIDE_INT byteshift_val;
1262 if (! CONSTANT_P (bitshift))
1264 bitshift_val = INTVAL (bitshift);
1265 if (bitshift_val & 0x7)
1267 byteshift_val = (bitshift_val >> 3);
1268 zero_reg = gen_reg_rtx (<MODE>mode);
1269 emit_move_insn (zero_reg, CONST0_RTX (<MODE>mode));
1270 if (!BYTES_BIG_ENDIAN)
1272 byteshift_val = 16 - byteshift_val;
1282 if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1284 shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1285 insn = gen_vsx_xxsldwi_<mode> (operands[0], op1, op2, shift);
1289 shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1290 insn = gen_altivec_vsldoi_<mode> (operands[0], op1, op2, shift);
1297 ;; Expanders for rotate each element in a vector
1298 (define_expand "vrotl<mode>3"
1299 [(set (match_operand:VEC_I 0 "vint_operand")
1300 (rotate:VEC_I (match_operand:VEC_I 1 "vint_operand")
1301 (match_operand:VEC_I 2 "vint_operand")))]
1302 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1305 ;; Expanders for arithmetic shift left on each vector element
1306 (define_expand "vashl<mode>3"
1307 [(set (match_operand:VEC_I 0 "vint_operand")
1308 (ashift:VEC_I (match_operand:VEC_I 1 "vint_operand")
1309 (match_operand:VEC_I 2 "vint_operand")))]
1310 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1313 ;; Expanders for logical shift right on each vector element
1314 (define_expand "vlshr<mode>3"
1315 [(set (match_operand:VEC_I 0 "vint_operand")
1316 (lshiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand")
1317 (match_operand:VEC_I 2 "vint_operand")))]
1318 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1321 ;; Expanders for arithmetic shift right on each vector element
1322 (define_expand "vashr<mode>3"
1323 [(set (match_operand:VEC_I 0 "vint_operand")
1324 (ashiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand")
1325 (match_operand:VEC_I 2 "vint_operand")))]
1326 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1329 ;; Vector reduction expanders for VSX
1330 ; The (VEC_reduc:...
1332 ; (unspec:... [(const_int 0)] UNSPEC_REDUC))
1334 ; is to allow us to use a code iterator, but not completely list all of the
1335 ; vector rotates, etc. to prevent canonicalization
1338 (define_expand "reduc_<VEC_reduc:VEC_reduc_name>_scal_<VEC_F:mode>"
1339 [(match_operand:<VEC_base> 0 "register_operand")
1340 (VEC_reduc:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
1341 (unspec:VEC_F [(const_int 0)] UNSPEC_REDUC))]
1342 "VECTOR_UNIT_VSX_P (<VEC_F:MODE>mode)"
1344 rtx vec = gen_reg_rtx (<VEC_F:MODE>mode);
1345 rtx elt = BYTES_BIG_ENDIAN
1346 ? gen_int_mode (GET_MODE_NUNITS (<VEC_F:MODE>mode) - 1, QImode)
1348 emit_insn (gen_vsx_reduc_<VEC_reduc:VEC_reduc_name>_<VEC_F:mode> (vec,
1350 emit_insn (gen_vsx_extract_<VEC_F:mode> (operand0, vec, elt));