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-2023 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 comparison, shift and rotation
30 (define_mode_iterator VEC_IC [V16QI V8HI V4SI V2DI (V1TI "TARGET_POWER10")])
33 (define_mode_iterator VEC_TI [V1TI TI])
35 ;; Vector int modes for parity
36 (define_mode_iterator VEC_IP [V8HI
43 (define_mode_iterator VEC_F [V4SF V2DF])
45 ;; Vector arithmetic modes
46 (define_mode_iterator VEC_A [V16QI V8HI V4SI V2DI V4SF V2DF])
48 ;; Vector modes that need alginment via permutes
49 (define_mode_iterator VEC_K [V16QI V8HI V4SI V4SF])
51 ;; Vector logical modes
52 (define_mode_iterator VEC_L [V16QI V8HI V4SI V2DI V4SF V2DF V1TI TI KF TF])
54 ;; Vector modes for moves. Don't do TImode or TFmode here, since their
55 ;; moves are handled elsewhere.
56 (define_mode_iterator VEC_M [V16QI V8HI V4SI V2DI V4SF V2DF V1TI KF])
58 ;; Vector modes for types that don't need a realignment under VSX
59 (define_mode_iterator VEC_N [V4SI V4SF V2DI V2DF V1TI KF TF])
61 ;; Vector comparison modes
62 (define_mode_iterator VEC_C [V16QI V8HI V4SI V2DI V4SF V2DF V1TI])
64 ;; Vector init/extract modes
65 (define_mode_iterator VEC_E [V16QI V8HI V4SI V2DI V4SF V2DF])
67 ;; Vector modes for 64-bit base types
68 (define_mode_iterator VEC_64 [V2DI V2DF])
70 ;; Vector integer modes
71 (define_mode_iterator VI [V4SI V8HI V16QI])
73 ;; Base type from vector mode
74 (define_mode_attr VEC_base [(V16QI "QI")
83 ;; As above, but in lower case
84 (define_mode_attr VEC_base_l [(V16QI "qi")
93 ;; Same size integer type for floating point data
94 (define_mode_attr VEC_int [(V4SF "v4si")
97 (define_mode_attr VEC_INT [(V4SF "V4SI")
100 ;; constants for unspec
101 (define_c_enum "unspec" [UNSPEC_PREDICATE
105 ;; Vector reduction code iterators
106 (define_code_iterator VEC_reduc [plus smin smax])
108 (define_code_attr VEC_reduc_name [(plus "plus")
112 (define_code_attr VEC_reduc_rtx [(plus "add")
116 ;; code iterators and attributes for vector FP comparison operators:
117 (define_code_iterator
118 vector_fp_comparison_simple [lt le ne ungt unge unlt unle])
119 (define_code_iterator
120 vector_fp_comparison_complex [ltgt uneq unordered ordered])
123 ;; Vector move instructions. Little-endian VSX loads and stores require
124 ;; special handling to circumvent "element endianness."
125 (define_expand "mov<mode>"
126 [(set (match_operand:VEC_M 0 "nonimmediate_operand")
127 (match_operand:VEC_M 1 "any_operand"))]
128 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
130 if (can_create_pseudo_p ())
132 if (CONSTANT_P (operands[1]))
134 if (FLOAT128_VECTOR_P (<MODE>mode))
136 if (!easy_fp_constant (operands[1], <MODE>mode))
137 operands[1] = force_const_mem (<MODE>mode, operands[1]);
139 else if (!easy_vector_constant (operands[1], <MODE>mode))
140 operands[1] = force_const_mem (<MODE>mode, operands[1]);
143 if (!vlogical_operand (operands[0], <MODE>mode)
144 && !vlogical_operand (operands[1], <MODE>mode))
145 operands[1] = force_reg (<MODE>mode, operands[1]);
147 /* When generating load/store instructions to/from VSX registers on
148 pre-power9 hardware in little endian mode, we need to emit register
149 permute instructions to byte swap the contents, since the VSX load/store
150 instructions do not include a byte swap as part of their operation.
151 Altivec loads and stores have no such problem, so we skip them below. */
152 if (!BYTES_BIG_ENDIAN
153 && VECTOR_MEM_VSX_P (<MODE>mode)
155 && !gpr_or_gpr_p (operands[0], operands[1])
156 && ((memory_operand (operands[0], <MODE>mode)
157 && !altivec_indexed_or_indirect_operand(operands[0], <MODE>mode))
158 ^ (memory_operand (operands[1], <MODE>mode)
159 && !altivec_indexed_or_indirect_operand(operands[1], <MODE>mode))))
161 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
166 ;; Generic vector floating point load/store instructions. These will match
167 ;; insns defined in vsx.md or altivec.md depending on the switches.
168 (define_expand "vector_load_<mode>"
169 [(set (match_operand:VEC_M 0 "vfloat_operand")
170 (match_operand:VEC_M 1 "memory_operand"))]
171 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
174 (define_expand "vector_store_<mode>"
175 [(set (match_operand:VEC_M 0 "memory_operand")
176 (match_operand:VEC_M 1 "vfloat_operand"))]
177 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
180 ;; Splits if a GPR register was chosen for the move
182 [(set (match_operand:VEC_L 0 "nonimmediate_operand")
183 (match_operand:VEC_L 1 "input_operand"))]
184 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
186 && gpr_or_gpr_p (operands[0], operands[1])
187 && !direct_move_p (operands[0], operands[1])
188 && !quad_load_store_p (operands[0], operands[1])"
191 rs6000_split_multireg_move (operands[0], operands[1]);
196 ;; Generic floating point vector arithmetic support
197 (define_expand "add<mode>3"
198 [(set (match_operand:VEC_F 0 "vfloat_operand")
199 (plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
200 (match_operand:VEC_F 2 "vfloat_operand")))]
201 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
204 (define_expand "sub<mode>3"
205 [(set (match_operand:VEC_F 0 "vfloat_operand")
206 (minus:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
207 (match_operand:VEC_F 2 "vfloat_operand")))]
208 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
211 (define_expand "mul<mode>3"
212 [(set (match_operand:VEC_F 0 "vfloat_operand")
213 (mult:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
214 (match_operand:VEC_F 2 "vfloat_operand")))]
215 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
217 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
219 emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2]));
224 (define_expand "div<mode>3"
225 [(set (match_operand:VEC_F 0 "vfloat_operand")
226 (div:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
227 (match_operand:VEC_F 2 "vfloat_operand")))]
228 "VECTOR_UNIT_VSX_P (<MODE>mode)"
230 if (RS6000_RECIP_AUTO_RE_P (<MODE>mode)
231 && can_create_pseudo_p () && flag_finite_math_only
232 && !flag_trapping_math && flag_reciprocal_math)
234 rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
239 (define_expand "neg<mode>2"
240 [(set (match_operand:VEC_F 0 "vfloat_operand")
241 (neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
242 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
244 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
246 emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1]));
251 (define_expand "abs<mode>2"
252 [(set (match_operand:VEC_F 0 "vfloat_operand")
253 (abs:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
254 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
256 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
258 emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1]));
263 (define_expand "smin<mode>3"
264 [(set (match_operand:VEC_F 0 "register_operand")
265 (smin:VEC_F (match_operand:VEC_F 1 "register_operand")
266 (match_operand:VEC_F 2 "register_operand")))]
267 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
270 (define_expand "smax<mode>3"
271 [(set (match_operand:VEC_F 0 "register_operand")
272 (smax:VEC_F (match_operand:VEC_F 1 "register_operand")
273 (match_operand:VEC_F 2 "register_operand")))]
274 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
278 (define_expand "sqrt<mode>2"
279 [(set (match_operand:VEC_F 0 "vfloat_operand")
280 (sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
281 "VECTOR_UNIT_VSX_P (<MODE>mode)"
283 if (<MODE>mode == V4SFmode
284 && !optimize_function_for_size_p (cfun)
285 && flag_finite_math_only && !flag_trapping_math
286 && flag_unsafe_math_optimizations)
288 rs6000_emit_swsqrt (operands[0], operands[1], 0);
293 (define_expand "rsqrte<mode>2"
294 [(set (match_operand:VEC_F 0 "vfloat_operand")
295 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
297 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
300 (define_expand "re<mode>2"
301 [(set (match_operand:VEC_F 0 "vfloat_operand")
302 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
304 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
307 (define_expand "ftrunc<mode>2"
308 [(set (match_operand:VEC_F 0 "vfloat_operand")
309 (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
310 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
313 (define_expand "vector_ceil<mode>2"
314 [(set (match_operand:VEC_F 0 "vfloat_operand")
315 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
317 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
320 (define_expand "vector_floor<mode>2"
321 [(set (match_operand:VEC_F 0 "vfloat_operand")
322 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")]
324 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
327 (define_expand "vector_btrunc<mode>2"
328 [(set (match_operand:VEC_F 0 "vfloat_operand")
329 (fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))]
330 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
333 (define_expand "vector_copysign<mode>3"
334 [(set (match_operand:VEC_F 0 "vfloat_operand")
335 (unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")
336 (match_operand:VEC_F 2 "vfloat_operand")] UNSPEC_COPYSIGN))]
337 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
339 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
341 emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1],
348 ;; Vector comparisons
349 (define_expand "vcond<mode><mode>"
350 [(set (match_operand:VEC_F 0 "vfloat_operand")
352 (match_operator 3 "comparison_operator"
353 [(match_operand:VEC_F 4 "vfloat_operand")
354 (match_operand:VEC_F 5 "vfloat_operand")])
355 (match_operand:VEC_F 1 "vfloat_operand")
356 (match_operand:VEC_F 2 "vfloat_operand")))]
357 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
359 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
360 operands[3], operands[4], operands[5]))
366 (define_expand "vcond<mode><mode>"
367 [(set (match_operand:VEC_I 0 "vint_operand")
369 (match_operator 3 "comparison_operator"
370 [(match_operand:VEC_I 4 "vint_operand")
371 (match_operand:VEC_I 5 "vint_operand")])
372 (match_operand:VEC_I 1 "vector_int_reg_or_same_bit")
373 (match_operand:VEC_I 2 "vector_int_reg_or_same_bit")))]
374 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
376 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
377 operands[3], operands[4], operands[5]))
383 (define_expand "vcondv4sfv4si"
384 [(set (match_operand:V4SF 0 "vfloat_operand")
386 (match_operator 3 "comparison_operator"
387 [(match_operand:V4SI 4 "vint_operand")
388 (match_operand:V4SI 5 "vint_operand")])
389 (match_operand:V4SF 1 "vfloat_operand")
390 (match_operand:V4SF 2 "vfloat_operand")))]
391 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
392 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
394 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
395 operands[3], operands[4], operands[5]))
401 (define_expand "vcondv4siv4sf"
402 [(set (match_operand:V4SI 0 "vint_operand")
404 (match_operator 3 "comparison_operator"
405 [(match_operand:V4SF 4 "vfloat_operand")
406 (match_operand:V4SF 5 "vfloat_operand")])
407 (match_operand:V4SI 1 "vint_operand")
408 (match_operand:V4SI 2 "vint_operand")))]
409 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
410 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
412 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
413 operands[3], operands[4], operands[5]))
419 (define_expand "vcondv2dfv2di"
420 [(set (match_operand:V2DF 0 "vfloat_operand")
422 (match_operator 3 "comparison_operator"
423 [(match_operand:V2DI 4 "vint_operand")
424 (match_operand:V2DI 5 "vint_operand")])
425 (match_operand:V2DF 1 "vfloat_operand")
426 (match_operand:V2DF 2 "vfloat_operand")))]
427 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
428 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
430 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
431 operands[3], operands[4], operands[5]))
437 (define_expand "vcondv2div2df"
438 [(set (match_operand:V2DI 0 "vint_operand")
440 (match_operator 3 "comparison_operator"
441 [(match_operand:V2DF 4 "vfloat_operand")
442 (match_operand:V2DF 5 "vfloat_operand")])
443 (match_operand:V2DI 1 "vint_operand")
444 (match_operand:V2DI 2 "vint_operand")))]
445 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
446 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
448 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
449 operands[3], operands[4], operands[5]))
455 (define_expand "vcondu<mode><mode>"
456 [(set (match_operand:VEC_I 0 "vint_operand")
458 (match_operator 3 "comparison_operator"
459 [(match_operand:VEC_I 4 "vint_operand")
460 (match_operand:VEC_I 5 "vint_operand")])
461 (match_operand:VEC_I 1 "vector_int_reg_or_same_bit")
462 (match_operand:VEC_I 2 "vector_int_reg_or_same_bit")))]
463 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
465 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
466 operands[3], operands[4], operands[5]))
472 (define_expand "vconduv4sfv4si"
473 [(set (match_operand:V4SF 0 "vfloat_operand")
475 (match_operator 3 "comparison_operator"
476 [(match_operand:V4SI 4 "vint_operand")
477 (match_operand:V4SI 5 "vint_operand")])
478 (match_operand:V4SF 1 "vfloat_operand")
479 (match_operand:V4SF 2 "vfloat_operand")))]
480 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
481 && VECTOR_UNIT_ALTIVEC_P (V4SImode)"
483 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
484 operands[3], operands[4], operands[5]))
490 (define_expand "vconduv2dfv2di"
491 [(set (match_operand:V2DF 0 "vfloat_operand")
493 (match_operator 3 "comparison_operator"
494 [(match_operand:V2DI 4 "vint_operand")
495 (match_operand:V2DI 5 "vint_operand")])
496 (match_operand:V2DF 1 "vfloat_operand")
497 (match_operand:V2DF 2 "vfloat_operand")))]
498 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)
499 && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DImode)"
501 if (rs6000_emit_vector_cond_expr (operands[0], operands[1], operands[2],
502 operands[3], operands[4], operands[5]))
508 ;; To support vector condition vectorization, define vcond_mask and vec_cmp.
510 ;; Same mode for condition true/false values and predicate operand.
511 (define_expand "vcond_mask_<mode><mode>"
512 [(match_operand:VEC_I 0 "vint_operand")
513 (match_operand:VEC_I 1 "vint_operand")
514 (match_operand:VEC_I 2 "vint_operand")
515 (match_operand:VEC_I 3 "vint_operand")]
516 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
518 emit_insn (gen_vector_select_<mode> (operands[0], operands[2], operands[1],
523 ;; Condition true/false values are float but predicate operand is of
524 ;; type integer vector with same element size.
525 (define_expand "vcond_mask_<mode><VEC_int>"
526 [(match_operand:VEC_F 0 "vfloat_operand")
527 (match_operand:VEC_F 1 "vfloat_operand")
528 (match_operand:VEC_F 2 "vfloat_operand")
529 (match_operand:<VEC_INT> 3 "vint_operand")]
530 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
532 emit_insn (gen_vector_select_<mode> (operands[0], operands[2], operands[1],
533 gen_lowpart (<MODE>mode, operands[3])));
537 ;; For signed integer vectors comparison.
538 (define_expand "vec_cmp<mode><mode>"
539 [(set (match_operand:VEC_IC 0 "vint_operand")
540 (match_operator 1 "signed_or_equality_comparison_operator"
541 [(match_operand:VEC_IC 2 "vint_operand")
542 (match_operand:VEC_IC 3 "vint_operand")]))]
543 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
545 enum rtx_code code = GET_CODE (operands[1]);
546 rtx tmp = gen_reg_rtx (<MODE>mode);
550 emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3]));
551 emit_insn (gen_one_cmpl<mode>2 (operands[0], operands[0]));
554 emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3]));
557 emit_insn (gen_vector_nlt<mode> (operands[0],operands[2], operands[3],
561 emit_insn (gen_vector_gt<mode> (operands[0], operands[2], operands[3]));
564 emit_insn (gen_vector_ngt<mode> (operands[0], operands[2], operands[3],
568 emit_insn (gen_vector_gt<mode> (operands[0], operands[3], operands[2]));
577 ;; For unsigned integer vectors comparison.
578 (define_expand "vec_cmpu<mode><mode>"
579 [(set (match_operand:VEC_IC 0 "vint_operand")
580 (match_operator 1 "unsigned_or_equality_comparison_operator"
581 [(match_operand:VEC_IC 2 "vint_operand")
582 (match_operand:VEC_IC 3 "vint_operand")]))]
583 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
585 enum rtx_code code = GET_CODE (operands[1]);
586 rtx tmp = gen_reg_rtx (<MODE>mode);
590 emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3]));
591 emit_insn (gen_one_cmpl<mode>2 (operands[0], operands[0]));
594 emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3]));
597 emit_insn (gen_vector_nltu<mode> (operands[0], operands[2], operands[3],
601 emit_insn (gen_vector_gtu<mode> (operands[0], operands[2], operands[3]));
604 emit_insn (gen_vector_ngtu<mode> (operands[0], operands[2], operands[3],
608 emit_insn (gen_vector_gtu<mode> (operands[0], operands[3], operands[2]));
617 ;; For float point vectors comparison.
618 (define_expand "vec_cmp<mode><VEC_int>"
619 [(set (match_operand:<VEC_INT> 0 "vint_operand")
620 (match_operator 1 "comparison_operator"
621 [(match_operand:VEC_F 2 "vfloat_operand")
622 (match_operand:VEC_F 3 "vfloat_operand")]))]
623 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
625 enum rtx_code code = GET_CODE (operands[1]);
626 rtx res = gen_reg_rtx (<MODE>mode);
630 emit_insn (gen_vector_ne<mode> (res, operands[2], operands[3]));
633 emit_insn (gen_vector_eq<mode> (res, operands[2], operands[3]));
636 emit_insn (gen_vector_ge<mode> (res, operands[2], operands[3]));
639 emit_insn (gen_vector_gt<mode> (res, operands[2], operands[3]));
642 emit_insn (gen_vector_le<mode> (res, operands[2], operands[3]));
645 emit_insn (gen_vector_lt<mode> (res, operands[2], operands[3]));
648 emit_insn (gen_vector_ltgt<mode> (res, operands[2], operands[3]));
651 emit_insn (gen_vector_unordered<mode> (res, operands[2], operands[3]));
654 emit_insn (gen_vector_ordered<mode> (res, operands[2], operands[3]));
657 emit_insn (gen_vector_uneq<mode> (res, operands[2], operands[3]));
660 emit_insn (gen_vector_unge<mode> (res, operands[2], operands[3]));
663 emit_insn (gen_vector_ungt<mode> (res, operands[2], operands[3]));
666 emit_insn (gen_vector_unle<mode> (res, operands[2], operands[3]));
669 emit_insn (gen_vector_unlt<mode> (res, operands[2], operands[3]));
676 emit_insn (gen_move_insn (operands[0], gen_lowpart (<VEC_INT>mode, res)));
680 (define_expand "vector_eq<mode>"
681 [(set (match_operand:VEC_C 0 "vlogical_operand")
682 (eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand")
683 (match_operand:VEC_C 2 "vlogical_operand")))]
684 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
687 (define_expand "vector_gt<mode>"
688 [(set (match_operand:VEC_C 0 "vlogical_operand")
689 (gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand")
690 (match_operand:VEC_C 2 "vlogical_operand")))]
691 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
694 ; >= for integer vectors: swap operands and apply not-greater-than
695 (define_expand "vector_nlt<mode>"
696 [(set (match_operand:VEC_IC 3 "vlogical_operand")
697 (gt:VEC_IC (match_operand:VEC_IC 2 "vlogical_operand")
698 (match_operand:VEC_IC 1 "vlogical_operand")))
699 (set (match_operand:VEC_IC 0 "vlogical_operand")
700 (not:VEC_IC (match_dup 3)))]
701 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
703 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
706 (define_expand "vector_gtu<mode>"
707 [(set (match_operand:VEC_IC 0 "vint_operand")
708 (gtu:VEC_IC (match_operand:VEC_IC 1 "vint_operand")
709 (match_operand:VEC_IC 2 "vint_operand")))]
710 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
713 ; >= for integer vectors: swap operands and apply not-greater-than
714 (define_expand "vector_nltu<mode>"
715 [(set (match_operand:VEC_IC 3 "vlogical_operand")
716 (gtu:VEC_IC (match_operand:VEC_IC 2 "vlogical_operand")
717 (match_operand:VEC_IC 1 "vlogical_operand")))
718 (set (match_operand:VEC_IC 0 "vlogical_operand")
719 (not:VEC_IC (match_dup 3)))]
720 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
722 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
725 (define_expand "vector_geu<mode>"
726 [(set (match_operand:VEC_IC 0 "vint_operand")
727 (geu:VEC_IC (match_operand:VEC_IC 1 "vint_operand")
728 (match_operand:VEC_IC 2 "vint_operand")))]
729 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
732 ; <= for integer vectors: apply not-greater-than
733 (define_expand "vector_ngt<mode>"
734 [(set (match_operand:VEC_IC 3 "vlogical_operand")
735 (gt:VEC_IC (match_operand:VEC_IC 1 "vlogical_operand")
736 (match_operand:VEC_IC 2 "vlogical_operand")))
737 (set (match_operand:VEC_IC 0 "vlogical_operand")
738 (not:VEC_IC (match_dup 3)))]
739 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
741 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
744 (define_expand "vector_ngtu<mode>"
745 [(set (match_operand:VEC_IC 3 "vlogical_operand")
746 (gtu:VEC_IC (match_operand:VEC_IC 1 "vlogical_operand")
747 (match_operand:VEC_IC 2 "vlogical_operand")))
748 (set (match_operand:VEC_IC 0 "vlogical_operand")
749 (not:VEC_IC (match_dup 3)))]
750 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
752 operands[3] = gen_reg_rtx_and_attrs (operands[0]);
755 ; There are 14 possible vector FP comparison operators, gt and eq of them have
756 ; been expanded above, so just support 12 remaining operators here.
759 (define_expand "vector_ge<mode>"
760 [(set (match_operand:VEC_F 0 "vlogical_operand")
761 (ge:VEC_F (match_operand:VEC_F 1 "vlogical_operand")
762 (match_operand:VEC_F 2 "vlogical_operand")))]
763 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
766 ; For lt/le/ne/ungt/unge/unlt/unle:
769 ; unge(a,b) = ~lt(a,b)
770 ; unle(a,b) = ~gt(a,b)
772 ; ungt(a,b) = ~le(a,b)
773 ; unlt(a,b) = ~ge(a,b)
774 (define_insn_and_split "vector_<code><mode>"
775 [(set (match_operand:VEC_F 0 "vfloat_operand")
776 (vector_fp_comparison_simple:VEC_F
777 (match_operand:VEC_F 1 "vfloat_operand")
778 (match_operand:VEC_F 2 "vfloat_operand")))]
779 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && can_create_pseudo_p ()"
781 "&& can_create_pseudo_p ()"
784 enum rtx_code cond = <CODE>;
785 bool need_invert = false;
787 if (cond == UNLE || cond == UNLT || cond == NE || cond == UNGE
790 cond = reverse_condition_maybe_unordered (cond);
794 if (cond == LT || cond == LE)
796 cond = swap_condition (cond);
797 std::swap (operands[1], operands[2]);
800 gcc_assert (cond == EQ || cond == GE || cond == GT);
802 rtx comp = gen_rtx_fmt_ee (cond, <MODE>mode, operands[1], operands[2]);
806 rtx res = gen_reg_rtx (<MODE>mode);
807 emit_insn (gen_rtx_SET (res, comp));
808 emit_insn (gen_one_cmpl<mode>2 (operands[0], res));
811 emit_insn (gen_rtx_SET (operands[0], comp));
816 ; For ltgt/uneq/ordered/unordered:
817 ; ltgt: gt(a,b) | gt(b,a)
818 ; uneq: ~(gt(a,b) | gt(b,a))
819 ; ordered: ge(a,b) | ge(b,a)
820 ; unordered: ~(ge(a,b) | ge(b,a))
821 (define_insn_and_split "vector_<code><mode>"
822 [(set (match_operand:VEC_F 0 "vfloat_operand")
823 (vector_fp_comparison_complex:VEC_F
824 (match_operand:VEC_F 1 "vfloat_operand")
825 (match_operand:VEC_F 2 "vfloat_operand")))]
826 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && can_create_pseudo_p ()"
828 "&& can_create_pseudo_p ()"
831 enum rtx_code cond = <CODE>;
832 bool need_invert = false;
834 if (cond == UNORDERED || cond == UNEQ)
836 cond = reverse_condition_maybe_unordered (cond);
842 else if (cond == ORDERED)
847 rtx comp1 = gen_rtx_fmt_ee (cond, <MODE>mode, operands[1], operands[2]);
848 rtx res1 = gen_reg_rtx (<MODE>mode);
849 emit_insn (gen_rtx_SET (res1, comp1));
850 rtx comp2 = gen_rtx_fmt_ee (cond, <MODE>mode, operands[2], operands[1]);
851 rtx res2 = gen_reg_rtx (<MODE>mode);
852 emit_insn (gen_rtx_SET (res2, comp2));
856 rtx not1 = gen_rtx_fmt_e (NOT, <MODE>mode, res1);
857 rtx not2 = gen_rtx_fmt_e (NOT, <MODE>mode, res2);
858 rtx comp3 = gen_rtx_fmt_ee (AND, <MODE>mode, not1, not2);
859 emit_insn (gen_rtx_SET (operands[0], comp3));
862 emit_insn (gen_ior<mode>3 (operands[0], res1, res2));
867 ;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask
868 ;; which is in the reverse order that we want
869 (define_expand "vector_select_<mode>"
870 [(set (match_operand:VEC_L 0 "vlogical_operand")
872 (and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand"))
873 (match_operand:VEC_L 1 "vlogical_operand"))
874 (and:VEC_L (match_dup 3)
875 (match_operand:VEC_L 2 "vlogical_operand"))))]
876 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)")
878 (define_expand "vector_select_<mode>_uns"
879 [(set (match_operand:VEC_L 0 "vlogical_operand")
881 (and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand"))
882 (match_operand:VEC_L 1 "vlogical_operand"))
883 (and:VEC_L (match_dup 3)
884 (match_operand:VEC_L 2 "vlogical_operand"))))]
885 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)")
887 ;; Expansions that compare vectors producing a vector result and a predicate,
888 ;; setting CR6 to indicate a combined status
889 (define_expand "vector_eq_<mode>_p"
891 [(set (reg:CC CR6_REGNO)
892 (unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand")
893 (match_operand:VEC_A 2 "vlogical_operand"))]
895 (set (match_operand:VEC_A 0 "vlogical_operand")
896 (eq:VEC_A (match_dup 1)
898 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
901 (define_expand "vector_eq_v1ti_p"
903 [(set (reg:CC CR6_REGNO)
904 (unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand")
905 (match_operand:V1TI 2 "altivec_register_operand"))]
907 (set (match_operand:V1TI 0 "vlogical_operand")
908 (eq:V1TI (match_dup 1)
913 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
914 ;; implementation of the vec_all_ne built-in functions on Power9.
915 (define_expand "vector_ne_<mode>_p"
917 [(set (reg:CC CR6_REGNO)
918 (unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand")
919 (match_operand:VI 2 "vlogical_operand"))]
924 (set (match_operand:SI 0 "register_operand" "=r")
925 (lt:SI (reg:CC CR6_REGNO)
929 operands[3] = gen_reg_rtx (<MODE>mode);
932 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
933 ;; implementation of the vec_any_eq built-in functions on Power9.
934 (define_expand "vector_ae_<mode>_p"
936 [(set (reg:CC CR6_REGNO)
937 (unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand")
938 (match_operand:VI 2 "vlogical_operand"))]
943 (set (match_operand:SI 0 "register_operand" "=r")
944 (lt:SI (reg:CC CR6_REGNO)
947 (xor:SI (match_dup 0)
951 operands[3] = gen_reg_rtx (<MODE>mode);
954 ;; This expansion handles the V16QI, V8HI, and V4SI modes in the
955 ;; implementation of the vec_all_nez and vec_any_eqz built-in
956 ;; functions on Power9.
957 (define_expand "vector_nez_<mode>_p"
959 [(set (reg:CC CR6_REGNO)
960 (unspec:CC [(unspec:VI
961 [(match_operand:VI 1 "vlogical_operand")
962 (match_operand:VI 2 "vlogical_operand")]
965 (set (match_operand:VI 0 "vlogical_operand")
966 (unspec:VI [(match_dup 1)
972 ;; This expansion handles the V2DI mode in the implementation of the
973 ;; vec_all_ne built-in function on Power9.
975 ;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode,
976 ;; this expands into the same rtl that would be used for the Power8
978 (define_expand "vector_ne_v2di_p"
980 [(set (reg:CC CR6_REGNO)
981 (unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand")
982 (match_operand:V2DI 2 "vlogical_operand"))]
985 (eq:V2DI (match_dup 1)
987 (set (match_operand:SI 0 "register_operand" "=r")
988 (eq:SI (reg:CC CR6_REGNO)
992 operands[3] = gen_reg_rtx (V2DImode);
995 (define_expand "vector_ne_v1ti_p"
997 [(set (reg:CC CR6_REGNO)
998 (unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand")
999 (match_operand:V1TI 2 "altivec_register_operand"))]
1002 (eq:V1TI (match_dup 1)
1004 (set (match_operand:SI 0 "register_operand" "=r")
1005 (eq:SI (reg:CC CR6_REGNO)
1009 operands[3] = gen_reg_rtx (V1TImode);
1012 ;; This expansion handles the V2DI mode in the implementation of the
1013 ;; vec_any_eq built-in function on Power9.
1015 ;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode,
1016 ;; this expands into the same rtl that would be used for the Power8
1018 (define_expand "vector_ae_v2di_p"
1020 [(set (reg:CC CR6_REGNO)
1021 (unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand")
1022 (match_operand:V2DI 2 "vlogical_operand"))]
1025 (eq:V2DI (match_dup 1)
1027 (set (match_operand:SI 0 "register_operand" "=r")
1028 (eq:SI (reg:CC CR6_REGNO)
1031 (xor:SI (match_dup 0)
1035 operands[3] = gen_reg_rtx (V2DImode);
1038 (define_expand "vector_ae_v1ti_p"
1040 [(set (reg:CC CR6_REGNO)
1041 (unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand")
1042 (match_operand:V1TI 2 "altivec_register_operand"))]
1045 (eq:V1TI (match_dup 1)
1047 (set (match_operand:SI 0 "register_operand" "=r")
1048 (eq:SI (reg:CC CR6_REGNO)
1051 (xor:SI (match_dup 0)
1055 operands[3] = gen_reg_rtx (V1TImode);
1058 ;; This expansion handles the V4SF and V2DF modes in the Power9
1059 ;; implementation of the vec_all_ne built-in functions. Note that the
1060 ;; expansions for this pattern with these modes makes no use of power9-
1061 ;; specific instructions since there are no new power9 instructions
1062 ;; for vector compare not equal with floating point arguments.
1063 (define_expand "vector_ne_<mode>_p"
1065 [(set (reg:CC CR6_REGNO)
1066 (unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand")
1067 (match_operand:VEC_F 2 "vlogical_operand"))]
1070 (eq:VEC_F (match_dup 1)
1072 (set (match_operand:SI 0 "register_operand" "=r")
1073 (eq:SI (reg:CC CR6_REGNO)
1077 operands[3] = gen_reg_rtx (<MODE>mode);
1080 ;; This expansion handles the V4SF and V2DF modes in the Power9
1081 ;; implementation of the vec_any_eq built-in functions. Note that the
1082 ;; expansions for this pattern with these modes makes no use of power9-
1083 ;; specific instructions since there are no new power9 instructions
1084 ;; for vector compare not equal with floating point arguments.
1085 (define_expand "vector_ae_<mode>_p"
1087 [(set (reg:CC CR6_REGNO)
1088 (unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand")
1089 (match_operand:VEC_F 2 "vlogical_operand"))]
1092 (eq:VEC_F (match_dup 1)
1094 (set (match_operand:SI 0 "register_operand" "=r")
1095 (eq:SI (reg:CC CR6_REGNO)
1098 (xor:SI (match_dup 0)
1102 operands[3] = gen_reg_rtx (<MODE>mode);
1105 (define_expand "vector_gt_<mode>_p"
1107 [(set (reg:CC CR6_REGNO)
1108 (unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand")
1109 (match_operand:VEC_A 2 "vlogical_operand"))]
1111 (set (match_operand:VEC_A 0 "vlogical_operand")
1112 (gt:VEC_A (match_dup 1)
1114 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1117 (define_expand "vector_gt_v1ti_p"
1119 [(set (reg:CC CR6_REGNO)
1120 (unspec:CC [(gt:CC (match_operand:V1TI 1 "vlogical_operand")
1121 (match_operand:V1TI 2 "vlogical_operand"))]
1123 (set (match_operand:V1TI 0 "vlogical_operand")
1124 (gt:V1TI (match_dup 1)
1129 (define_expand "vector_ge_<mode>_p"
1131 [(set (reg:CC CR6_REGNO)
1132 (unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand")
1133 (match_operand:VEC_F 2 "vfloat_operand"))]
1135 (set (match_operand:VEC_F 0 "vfloat_operand")
1136 (ge:VEC_F (match_dup 1)
1138 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1141 (define_expand "vector_gtu_<mode>_p"
1143 [(set (reg:CC CR6_REGNO)
1144 (unspec:CC [(gtu:CC (match_operand:VEC_IC 1 "vint_operand")
1145 (match_operand:VEC_IC 2 "vint_operand"))]
1147 (set (match_operand:VEC_IC 0 "vlogical_operand")
1148 (gtu:VEC_IC (match_dup 1)
1150 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1153 ;; AltiVec/VSX predicates.
1155 ;; This expansion is triggered during expansion of predicate built-in
1156 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
1157 ;; altivec_expand_predicate_builtin() function when the value of the
1158 ;; integer constant first argument equals zero (aka __CR6_EQ in altivec.h).
1159 (define_expand "cr6_test_for_zero"
1160 [(set (match_operand:SI 0 "register_operand" "=r")
1161 (eq:SI (reg:CC CR6_REGNO)
1163 "TARGET_ALTIVEC || TARGET_VSX"
1166 ;; This expansion is triggered during expansion of predicate built-in
1167 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
1168 ;; altivec_expand_predicate_builtin() function when the value of the
1169 ;; integer constant first argument equals one (aka __CR6_EQ_REV in altivec.h).
1170 (define_expand "cr6_test_for_zero_reverse"
1171 [(set (match_operand:SI 0 "register_operand" "=r")
1172 (eq:SI (reg:CC CR6_REGNO)
1175 (xor:SI (match_dup 0)
1177 "TARGET_ALTIVEC || TARGET_VSX"
1180 ;; This expansion is triggered during expansion of predicate built-in
1181 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
1182 ;; altivec_expand_predicate_builtin() function when the value of the
1183 ;; integer constant first argument equals two (aka __CR6_LT in altivec.h).
1184 (define_expand "cr6_test_for_lt"
1185 [(set (match_operand:SI 0 "register_operand" "=r")
1186 (lt:SI (reg:CC CR6_REGNO)
1188 "TARGET_ALTIVEC || TARGET_VSX"
1191 ;; This expansion is triggered during expansion of predicate built-in
1192 ;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the
1193 ;; altivec_expand_predicate_builtin() function when the value of the
1194 ;; integer constant first argument equals three
1195 ;; (aka __CR6_LT_REV in altivec.h).
1196 (define_expand "cr6_test_for_lt_reverse"
1197 [(set (match_operand:SI 0 "register_operand" "=r")
1198 (lt:SI (reg:CC CR6_REGNO)
1201 (xor:SI (match_dup 0)
1203 "TARGET_ALTIVEC || TARGET_VSX"
1207 ;; Vector count leading zeros
1208 (define_expand "clz<mode>2"
1209 [(set (match_operand:VEC_I 0 "register_operand")
1210 (clz:VEC_I (match_operand:VEC_I 1 "register_operand")))]
1213 ;; Vector count trailing zeros
1214 (define_expand "ctz<mode>2"
1215 [(set (match_operand:VEC_I 0 "register_operand")
1216 (ctz:VEC_I (match_operand:VEC_I 1 "register_operand")))]
1219 ;; Vector population count
1220 (define_expand "popcount<mode>2"
1221 [(set (match_operand:VEC_I 0 "register_operand")
1222 (popcount:VEC_I (match_operand:VEC_I 1 "register_operand")))]
1226 (define_expand "parity<mode>2"
1227 [(set (match_operand:VEC_IP 0 "register_operand")
1228 (parity:VEC_IP (match_operand:VEC_IP 1 "register_operand")))]
1232 ;; Same size conversions
1233 (define_expand "float<VEC_int><mode>2"
1234 [(set (match_operand:VEC_F 0 "vfloat_operand")
1235 (float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))]
1236 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1238 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1240 emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx));
1245 (define_expand "floatuns<VEC_int><mode>2"
1246 [(set (match_operand:VEC_F 0 "vfloat_operand")
1247 (unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))]
1248 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1250 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1252 emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx));
1257 (define_expand "fix_trunc<mode><VEC_int>2"
1258 [(set (match_operand:<VEC_INT> 0 "vint_operand")
1259 (fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))]
1260 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1262 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1264 emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx));
1269 (define_expand "fixuns_trunc<mode><VEC_int>2"
1270 [(set (match_operand:<VEC_INT> 0 "vint_operand")
1271 (unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))]
1272 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1274 if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode))
1276 emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx));
1282 ;; Vector initialization, set, extract
1283 (define_expand "vec_init<mode><VEC_base_l>"
1284 [(match_operand:VEC_E 0 "vlogical_operand")
1285 (match_operand:VEC_E 1 "")]
1286 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1288 rs6000_expand_vector_init (operands[0], operands[1]);
1292 (define_expand "vec_set<mode>"
1293 [(match_operand:VEC_E 0 "vlogical_operand")
1294 (match_operand:<VEC_base> 1 "register_operand")
1295 (match_operand 2 "vec_set_index_operand")]
1296 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1298 rs6000_expand_vector_set (operands[0], operands[1], operands[2]);
1302 (define_expand "vec_extract<mode><VEC_base_l>"
1303 [(match_operand:<VEC_base> 0 "register_operand")
1304 (match_operand:VEC_E 1 "vlogical_operand")
1305 (match_operand 2 "const_int_operand")]
1306 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1308 rs6000_expand_vector_extract (operands[0], operands[1], operands[2]);
1312 ;; Convert double word types to single word types
1313 (define_expand "vec_pack_trunc_v2df"
1314 [(match_operand:V4SF 0 "vfloat_operand")
1315 (match_operand:V2DF 1 "vfloat_operand")
1316 (match_operand:V2DF 2 "vfloat_operand")]
1317 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1319 rtx r1 = gen_reg_rtx (V4SFmode);
1320 rtx r2 = gen_reg_rtx (V4SFmode);
1322 emit_insn (gen_vsx_xvcvdpsp (r1, operands[1]));
1323 emit_insn (gen_vsx_xvcvdpsp (r2, operands[2]));
1324 rs6000_expand_extract_even (operands[0], r1, r2);
1328 (define_expand "vec_pack_sfix_trunc_v2df"
1329 [(match_operand:V4SI 0 "vint_operand")
1330 (match_operand:V2DF 1 "vfloat_operand")
1331 (match_operand:V2DF 2 "vfloat_operand")]
1332 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1334 rtx r1 = gen_reg_rtx (V4SImode);
1335 rtx r2 = gen_reg_rtx (V4SImode);
1337 emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1]));
1338 emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2]));
1339 rs6000_expand_extract_even (operands[0], r1, r2);
1343 (define_expand "vec_pack_ufix_trunc_v2df"
1344 [(match_operand:V4SI 0 "vint_operand")
1345 (match_operand:V2DF 1 "vfloat_operand")
1346 (match_operand:V2DF 2 "vfloat_operand")]
1347 "VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC"
1349 rtx r1 = gen_reg_rtx (V4SImode);
1350 rtx r2 = gen_reg_rtx (V4SImode);
1352 emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1]));
1353 emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2]));
1354 rs6000_expand_extract_even (operands[0], r1, r2);
1358 ;; Convert single word types to double word
1359 (define_expand "vec_unpacks_hi_v4sf"
1360 [(match_operand:V2DF 0 "vfloat_operand")
1361 (match_operand:V4SF 1 "vfloat_operand")]
1362 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
1364 rtx reg = gen_reg_rtx (V4SFmode);
1366 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1367 emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
1371 (define_expand "vec_unpacks_lo_v4sf"
1372 [(match_operand:V2DF 0 "vfloat_operand")
1373 (match_operand:V4SF 1 "vfloat_operand")]
1374 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)"
1376 rtx reg = gen_reg_rtx (V4SFmode);
1378 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1379 emit_insn (gen_vsx_xvcvspdp (operands[0], reg));
1383 (define_expand "vec_unpacks_float_hi_v4si"
1384 [(match_operand:V2DF 0 "vfloat_operand")
1385 (match_operand:V4SI 1 "vint_operand")]
1386 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1388 rtx reg = gen_reg_rtx (V4SImode);
1390 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1391 emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
1395 (define_expand "vec_unpacks_float_lo_v4si"
1396 [(match_operand:V2DF 0 "vfloat_operand")
1397 (match_operand:V4SI 1 "vint_operand")]
1398 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1400 rtx reg = gen_reg_rtx (V4SImode);
1402 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1403 emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg));
1407 (define_expand "vec_unpacku_float_hi_v4si"
1408 [(match_operand:V2DF 0 "vfloat_operand")
1409 (match_operand:V4SI 1 "vint_operand")]
1410 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1412 rtx reg = gen_reg_rtx (V4SImode);
1414 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
1415 emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
1419 (define_expand "vec_unpacku_float_lo_v4si"
1420 [(match_operand:V2DF 0 "vfloat_operand")
1421 (match_operand:V4SI 1 "vint_operand")]
1422 "VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)"
1424 rtx reg = gen_reg_rtx (V4SImode);
1426 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
1427 emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg));
1432 ;; Align vector loads with a permute.
1433 (define_expand "vec_realign_load_<mode>"
1434 [(match_operand:VEC_K 0 "vlogical_operand")
1435 (match_operand:VEC_K 1 "vlogical_operand")
1436 (match_operand:VEC_K 2 "vlogical_operand")
1437 (match_operand:V16QI 3 "vlogical_operand")]
1438 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
1440 if (BYTES_BIG_ENDIAN)
1441 emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1],
1442 operands[2], operands[3]));
1445 /* We have changed lvsr to lvsl, so to complete the transformation
1446 of vperm for LE, we must swap the inputs. */
1447 rtx unspec = gen_rtx_UNSPEC (<MODE>mode,
1448 gen_rtvec (3, operands[2],
1449 operands[1], operands[3]),
1451 emit_move_insn (operands[0], unspec);
1456 ;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned
1457 ;; since the load already handles it.
1458 (define_expand "movmisalign<mode>"
1459 [(set (match_operand:VEC_N 0 "nonimmediate_operand")
1460 (match_operand:VEC_N 1 "any_operand"))]
1461 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN"
1463 rs6000_emit_move (operands[0], operands[1], <MODE>mode);
1467 ;; Vector shift right in bits. Currently supported ony for shift
1468 ;; amounts that can be expressed as byte shifts (divisible by 8).
1469 ;; General shift amounts can be supported using vsro + vsr. We're
1470 ;; not expecting to see these yet (the vectorizer currently
1471 ;; generates only shifts by a whole number of vector elements).
1472 ;; Note that the vec_shr operation is actually defined as
1473 ;; 'shift toward element 0' so is a shr for LE and shl for BE.
1474 (define_expand "vec_shr_<mode>"
1475 [(match_operand:VEC_L 0 "vlogical_operand")
1476 (match_operand:VEC_L 1 "vlogical_operand")
1477 (match_operand:QI 2 "reg_or_short_operand")]
1478 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1480 rtx bitshift = operands[2];
1483 rtx zero_reg, op1, op2;
1484 HOST_WIDE_INT bitshift_val;
1485 HOST_WIDE_INT byteshift_val;
1487 if (! CONSTANT_P (bitshift))
1489 bitshift_val = INTVAL (bitshift);
1490 if (bitshift_val & 0x7)
1492 byteshift_val = (bitshift_val >> 3);
1493 zero_reg = gen_reg_rtx (<MODE>mode);
1494 emit_move_insn (zero_reg, CONST0_RTX (<MODE>mode));
1495 if (!BYTES_BIG_ENDIAN)
1497 /* Note, byteshift_val can be 0! */
1498 byteshift_val = -byteshift_val & 15;
1508 if (TARGET_VSX && (byteshift_val & 0x3) == 0)
1510 shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2);
1511 insn = gen_vsx_xxsldwi_<mode> (operands[0], op1, op2, shift);
1515 shift = gen_rtx_CONST_INT (QImode, byteshift_val);
1516 insn = gen_altivec_vsldoi_<mode> (operands[0], op1, op2, shift);
1523 ;; Expanders for rotate each element in a vector
1524 (define_expand "vrotl<mode>3"
1525 [(set (match_operand:VEC_IC 0 "vint_operand")
1526 (rotate:VEC_IC (match_operand:VEC_IC 1 "vint_operand")
1527 (match_operand:VEC_IC 2 "vint_operand")))]
1528 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1530 /* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */
1531 if (<MODE>mode == V1TImode)
1533 rtx tmp = gen_reg_rtx (V1TImode);
1535 emit_insn (gen_xxswapd_v1ti (tmp, operands[2]));
1536 emit_insn (gen_altivec_vrlq (operands[0], operands[1], tmp));
1541 ;; Expanders for rotatert to make use of vrotl
1542 (define_expand "vrotr<mode>3"
1543 [(set (match_operand:VEC_I 0 "vint_operand")
1544 (rotatert:VEC_I (match_operand:VEC_I 1 "vint_operand")
1545 (match_operand:VEC_I 2 "vint_operand")))]
1546 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1548 rtx rot_count = gen_reg_rtx (<MODE>mode);
1549 emit_insn (gen_neg<mode>2 (rot_count, operands[2]));
1550 emit_insn (gen_vrotl<mode>3 (operands[0], operands[1], rot_count));
1554 ;; Expanders for arithmetic shift left on each vector element
1555 (define_expand "vashl<mode>3"
1556 [(set (match_operand:VEC_I 0 "vint_operand")
1557 (ashift:VEC_I (match_operand:VEC_I 1 "vint_operand")
1558 (match_operand:VEC_I 2 "vint_operand")))]
1559 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1562 ;; No immediate version of this 128-bit instruction
1563 (define_expand "vashl<mode>3"
1564 [(set (match_operand:VEC_TI 0 "vsx_register_operand" "=v")
1565 (ashift:VEC_TI (match_operand:VEC_TI 1 "vsx_register_operand")
1566 (match_operand:VEC_TI 2 "vsx_register_operand")))]
1569 /* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */
1570 rtx tmp = gen_reg_rtx (<MODE>mode);
1572 emit_insn (gen_xxswapd_v1ti (tmp, operands[2]));
1573 emit_insn(gen_altivec_vslq_<mode> (operands[0], operands[1], tmp));
1577 ;; Expanders for logical shift right on each vector element
1578 (define_expand "vlshr<mode>3"
1579 [(set (match_operand:VEC_I 0 "vint_operand")
1580 (lshiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand")
1581 (match_operand:VEC_I 2 "vint_operand")))]
1582 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1585 ;; No immediate version of this 128-bit instruction
1586 (define_expand "vlshr<mode>3"
1587 [(set (match_operand:VEC_TI 0 "vsx_register_operand" "=v")
1588 (lshiftrt:VEC_TI (match_operand:VEC_TI 1 "vsx_register_operand")
1589 (match_operand:VEC_TI 2 "vsx_register_operand")))]
1592 /* Shift amount in needs to be put into bits[57:63] of 128-bit operand2. */
1593 rtx tmp = gen_reg_rtx (<MODE>mode);
1595 emit_insn (gen_xxswapd_v1ti (tmp, operands[2]));
1596 emit_insn(gen_altivec_vsrq_<mode> (operands[0], operands[1], tmp));
1600 ;; Expanders for arithmetic shift right on each vector element
1601 (define_expand "vashr<mode>3"
1602 [(set (match_operand:VEC_IC 0 "vint_operand")
1603 (ashiftrt:VEC_IC (match_operand:VEC_IC 1 "vint_operand")
1604 (match_operand:VEC_IC 2 "vint_operand")))]
1605 "VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)"
1607 /* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */
1608 if (<MODE>mode == V1TImode)
1610 rtx tmp = gen_reg_rtx (V1TImode);
1612 emit_insn (gen_xxswapd_v1ti (tmp, operands[2]));
1613 emit_insn (gen_altivec_vsraq (operands[0], operands[1], tmp));
1619 ;; Vector reduction expanders for VSX
1620 ; The (VEC_reduc:...
1622 ; (unspec:... [(const_int 0)] UNSPEC_REDUC))
1624 ; is to allow us to use a code iterator, but not completely list all of the
1625 ; vector rotates, etc. to prevent canonicalization
1628 (define_expand "reduc_<VEC_reduc:VEC_reduc_name>_scal_<VEC_F:mode>"
1629 [(match_operand:<VEC_base> 0 "register_operand")
1630 (VEC_reduc:VEC_F (match_operand:VEC_F 1 "vfloat_operand")
1631 (unspec:VEC_F [(const_int 0)] UNSPEC_REDUC))]
1632 "VECTOR_UNIT_VSX_P (<VEC_F:MODE>mode)"
1634 rtx vec = gen_reg_rtx (<VEC_F:MODE>mode);
1635 rtx elt = BYTES_BIG_ENDIAN
1636 ? gen_int_mode (GET_MODE_NUNITS (<VEC_F:MODE>mode) - 1, QImode)
1638 emit_insn (gen_vsx_reduc_<VEC_reduc:VEC_reduc_name>_<VEC_F:mode> (vec,
1640 emit_insn (gen_vsx_extract_<VEC_F:mode> (operand0, vec, elt));