Debian Codegraph @

gcc/config/rs6000/vsx.md

raw
1 ;; VSX patterns.
2 ;; Copyright (C) 2009-2025 Free Software Foundation, Inc.
3 ;; Contributed by Michael Meissner <[email protected]>
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;; Iterator for comparison types
22 (define_code_iterator CMP_TEST [eq lt gt unordered])
23
24 ;; Mode attribute for vector floate and floato conversions
25 (define_mode_attr VF_sxddp [(V2DI "sxd") (V2DF "dp")])
26
27 ;; Iterator for both scalar and vector floating point types supported by VSX
28 (define_mode_iterator VSX_B [DF V4SF V2DF])
29
30 ;; Iterator for the 2 64-bit vector types
31 (define_mode_iterator VSX_D [V2DF V2DI])
32
33 ;; Mode iterator to handle swapping words on little endian for the 128-bit
34 ;; types that goes in a single vector register.
35 (define_mode_iterator VSX_LE_128 [(KF "FLOAT128_VECTOR_P (KFmode)")
36 (TF "FLOAT128_VECTOR_P (TFmode)")
37 TI
38 V1TI])
39
40 ;; Iterator for the 2 32-bit vector types
41 (define_mode_iterator VSX_W [V4SF V4SI])
42
43 ;; Iterator for the DF types
44 (define_mode_iterator VSX_DF [V2DF DF])
45
46 ;; Iterator for vector floating point types supported by VSX
47 (define_mode_iterator VSX_F [V4SF V2DF])
48
49 ;; Iterator for logical types supported by VSX
50 (define_mode_iterator VSX_L [V16QI
51 V8HI
52 V4SI
53 V2DI
54 V4SF
55 V2DF
56 V1TI
57 TI
58 (KF "FLOAT128_VECTOR_P (KFmode)")
59 (TF "FLOAT128_VECTOR_P (TFmode)")])
60
61 ;; Iterator for memory moves.
62 (define_mode_iterator VSX_M [V16QI
63 V8HI
64 V4SI
65 V2DI
66 V4SF
67 V2DF
68 V1TI
69 (KF "FLOAT128_VECTOR_P (KFmode)")
70 (TF "FLOAT128_VECTOR_P (TFmode)")
71 TI])
72
73 (define_mode_attr VSX_XXBR [(V8HI "h")
74 (V4SI "w")
75 (V4SF "w")
76 (V2DF "d")
77 (V2DI "d")
78 (V1TI "q")])
79
80 ;; Map into the appropriate load/store name based on the type
81 (define_mode_attr VSm [(V16QI "vw4")
82 (V8HI "vw4")
83 (V4SI "vw4")
84 (V4SF "vw4")
85 (V2DF "vd2")
86 (V2DI "vd2")
87 (DF "d")
88 (TF "vd2")
89 (KF "vd2")
90 (V1TI "vd2")
91 (TI "vd2")])
92
93 ;; Map the register class used
94 (define_mode_attr VSr [(V16QI "v")
95 (V8HI "v")
96 (V4SI "v")
97 (V4SF "wa")
98 (V2DI "wa")
99 (V2DF "wa")
100 (DI "wa")
101 (DF "wa")
102 (SF "wa")
103 (TF "wa")
104 (KF "wa")
105 (V1TI "v")
106 (TI "wa")])
107
108 ;; What value we need in the "isa" field, to make the IEEE QP float work.
109 (define_mode_attr VSisa [(V16QI "*")
110 (V8HI "*")
111 (V4SI "*")
112 (V4SF "*")
113 (V2DI "*")
114 (V2DF "*")
115 (DI "*")
116 (DF "*")
117 (SF "*")
118 (V1TI "*")
119 (TI "*")
120 (TF "p9tf")
121 (KF "p9kf")])
122
123 ;; A mode attribute to disparage use of GPR registers, except for scalar
124 ;; integer modes.
125 (define_mode_attr ??r [(V16QI "??r")
126 (V8HI "??r")
127 (V4SI "??r")
128 (V4SF "??r")
129 (V2DI "??r")
130 (V2DF "??r")
131 (V1TI "??r")
132 (KF "??r")
133 (TF "??r")
134 (TI "r")])
135
136 ;; A mode attribute used for 128-bit constant values.
137 (define_mode_attr nW [(V16QI "W")
138 (V8HI "W")
139 (V4SI "W")
140 (V4SF "W")
141 (V2DI "W")
142 (V2DF "W")
143 (V1TI "W")
144 (KF "W")
145 (TF "W")
146 (TI "n")])
147
148 ;; Same size integer type for floating point data
149 (define_mode_attr VSi [(V4SF "v4si")
150 (V2DF "v2di")
151 (DF "di")])
152
153 (define_mode_attr VSI [(V4SF "V4SI")
154 (V2DF "V2DI")
155 (DF "DI")])
156
157 ;; Word size for same size conversion
158 (define_mode_attr VSc [(V4SF "w")
159 (V2DF "d")
160 (DF "d")])
161
162 ;; Map into either s or v, depending on whether this is a scalar or vector
163 ;; operation
164 (define_mode_attr VSv [(V16QI "v")
165 (V8HI "v")
166 (V4SI "v")
167 (V4SF "v")
168 (V2DI "v")
169 (V2DF "v")
170 (V1TI "v")
171 (DF "s")
172 (KF "v")])
173
174 ;; Appropriate type for add ops (and other simple FP ops)
175 (define_mode_attr VStype_simple [(V2DF "vecdouble")
176 (V4SF "vecfloat")
177 (DF "fp")])
178
179 ;; Appropriate type for multiply ops
180 (define_mode_attr VStype_mul [(V2DF "vecdouble")
181 (V4SF "vecfloat")
182 (DF "dmul")])
183
184 ;; Appropriate type for divide ops.
185 (define_mode_attr VStype_div [(V2DF "vecdiv")
186 (V4SF "vecfdiv")
187 (DF "ddiv")])
188
189 ;; Map to a double-sized vector mode
190 (define_mode_attr VS_double [(V4SI "V8SI")
191 (V4SF "V8SF")
192 (V2DI "V4DI")
193 (V2DF "V4DF")
194 (V1TI "V2TI")])
195
196 ;; Iterators for loading constants with xxspltib
197 (define_mode_iterator VSINT_84 [V4SI V2DI DI SI])
198 (define_mode_iterator VSINT_842 [V8HI V4SI V2DI])
199
200 ;; Vector reverse byte modes
201 (define_mode_iterator VEC_REVB [V8HI V4SI V2DI V4SF V2DF V1TI])
202
203 ;; Iterator for ISA 3.0 vector extract/insert of small integer vectors.
204 ;; VSX_EXTRACT_I2 doesn't include V4SImode because SI extracts can be
205 ;; done on ISA 2.07 and not just ISA 3.0.
206 (define_mode_iterator VSX_EXTRACT_I [V16QI V8HI V4SI])
207 (define_mode_iterator VSX_EXTRACT_I2 [V16QI V8HI])
208 (define_mode_iterator VSX_EXTRACT_I4 [V16QI V8HI V4SI V2DI])
209
210 (define_mode_attr VSX_EXTRACT_WIDTH [(V16QI "b")
211 (V8HI "h")
212 (V4SI "w")])
213
214 ;; Mode attribute to give the correct predicate for ISA 3.0 vector extract and
215 ;; insert to validate the operand number.
216 (define_mode_attr VSX_EXTRACT_PREDICATE [(V16QI "const_0_to_15_operand")
217 (V8HI "const_0_to_7_operand")
218 (V4SI "const_0_to_3_operand")])
219
220 ;; Mode attribute to give the constraint for vector extract and insert
221 ;; operations.
222 (define_mode_attr VSX_EX [(V16QI "v")
223 (V8HI "v")
224 (V4SI "wa")])
225
226 ;; Mode iterator for binary floating types other than double to
227 ;; optimize convert to that floating point type from an extract
228 ;; of an integer type
229 (define_mode_iterator VSX_EXTRACT_FL [SF
230 (IF "FLOAT128_2REG_P (IFmode)")
231 (KF "TARGET_FLOAT128_HW")
232 (TF "FLOAT128_2REG_P (TFmode)
233 || (FLOAT128_IEEE_P (TFmode)
234 && TARGET_FLOAT128_HW)")])
235
236 ;; Mode iterator for binary floating types that have a direct conversion
237 ;; from 64-bit integer to floating point
238 (define_mode_iterator FL_CONV [SF
239 DF
240 (KF "TARGET_FLOAT128_HW")
241 (TF "TARGET_FLOAT128_HW
242 && FLOAT128_IEEE_P (TFmode)")])
243
244 ;; Iterator for the 2 short vector types to do a splat from an integer
245 (define_mode_iterator VSX_SPLAT_I [V16QI V8HI])
246
247 ;; Mode attribute to give the count for the splat instruction to splat
248 ;; the value in the 64-bit integer slot
249 (define_mode_attr VSX_SPLAT_COUNT [(V16QI "7") (V8HI "3")])
250
251 ;; Mode attribute to give the suffix for the splat instruction
252 (define_mode_attr VSX_SPLAT_SUFFIX [(V16QI "b") (V8HI "h")])
253
254 ;; Iterator for the move to mask instructions
255 (define_mode_iterator VSX_MM [V16QI V8HI V4SI V2DI V1TI])
256 (define_mode_iterator VSX_MM4 [V16QI V8HI V4SI V2DI])
257
258 ;; Longer vec int modes for rotate/mask ops
259 ;; and Vector Integer Multiply/Divide/Modulo Instructions
260 (define_mode_iterator VIlong [V2DI V4SI])
261
262 ;; Constants for creating unspecs
263 (define_c_enum "unspec"
264 [UNSPEC_VSX_CONCAT
265 UNSPEC_VSX_CVDPSXWS
266 UNSPEC_VSX_CVDPUXWS
267 UNSPEC_VSX_CVSPDP
268 UNSPEC_VSX_CVHPSP
269 UNSPEC_VSX_CVSPDPN
270 UNSPEC_VSX_CVDPSPN
271 UNSPEC_VSX_CVSXWDP
272 UNSPEC_VSX_CVUXWDP
273 UNSPEC_VSX_CVSXDSP
274 UNSPEC_VSX_CVUXDSP
275 UNSPEC_VSX_FLOAT2
276 UNSPEC_VSX_UNS_FLOAT2
277 UNSPEC_VSX_FLOATE
278 UNSPEC_VSX_UNS_FLOATE
279 UNSPEC_VSX_FLOATO
280 UNSPEC_VSX_UNS_FLOATO
281 UNSPEC_VSX_TDIV
282 UNSPEC_VSX_TSQRT
283 UNSPEC_VSX_SET
284 UNSPEC_VSX_ROUND_I
285 UNSPEC_VSX_ROUND_IC
286 UNSPEC_VSX_SLDWI
287 UNSPEC_VSX_XXPERM
288
289 UNSPEC_VSX_XXSPLTW
290 UNSPEC_VSX_XXSPLTD
291 UNSPEC_VSX_DIVSD
292 UNSPEC_VSX_DIVUD
293 UNSPEC_VSX_DIVSQ
294 UNSPEC_VSX_DIVUQ
295 UNSPEC_VSX_DIVESQ
296 UNSPEC_VSX_DIVEUQ
297 UNSPEC_VSX_MODSQ
298 UNSPEC_VSX_MODUQ
299 UNSPEC_VSX_MULSD
300 UNSPEC_VSX_SIGN_EXTEND
301 UNSPEC_VSX_XVCVBF16SPN
302 UNSPEC_VSX_XVCVSPBF16
303 UNSPEC_VSX_XVCVSPSXDS
304 UNSPEC_VSX_XVCVSPHP
305 UNSPEC_VSX_VSLO
306 UNSPEC_VSX_EXTRACT
307 UNSPEC_VSX_SXEXPDP
308 UNSPEC_VSX_SXSIG
309 UNSPEC_VSX_SIEXPDP
310 UNSPEC_VSX_SIEXPQP
311 UNSPEC_VSX_SCMPEXPDP
312 UNSPEC_VSX_SCMPEXPQP
313 UNSPEC_VSX_STSTDC
314 UNSPEC_VSX_VEXTRACT_FP_FROM_SHORTH
315 UNSPEC_VSX_VEXTRACT_FP_FROM_SHORTL
316 UNSPEC_VSX_VXEXP
317 UNSPEC_VSX_VXSIG
318 UNSPEC_VSX_VIEXP
319 UNSPEC_VSX_VTSTDC
320 UNSPEC_VSX_VSIGNED2
321
322 UNSPEC_LXVL
323 UNSPEC_LXVLL
324 UNSPEC_LVSL_REG
325 UNSPEC_LVSR_REG
326 UNSPEC_STXVL
327 UNSPEC_STXVLL
328 UNSPEC_XL_LEN_R
329 UNSPEC_XST_LEN_R
330
331 UNSPEC_VCLZLSBB
332 UNSPEC_VCTZLSBB
333 UNSPEC_VEXTUBLX
334 UNSPEC_VEXTUHLX
335 UNSPEC_VEXTUWLX
336 UNSPEC_VEXTUBRX
337 UNSPEC_VEXTUHRX
338 UNSPEC_VEXTUWRX
339 UNSPEC_VCMPNEB
340 UNSPEC_VCMPNEZB
341 UNSPEC_VCMPNEH
342 UNSPEC_VCMPNEZH
343 UNSPEC_VCMPNEW
344 UNSPEC_VCMPNEZW
345 UNSPEC_XXEXTRACTUW
346 UNSPEC_XXINSERTW
347 UNSPEC_VSX_FIRST_MATCH_INDEX
348 UNSPEC_VSX_FIRST_MATCH_EOS_INDEX
349 UNSPEC_VSX_FIRST_MISMATCH_INDEX
350 UNSPEC_VSX_FIRST_MISMATCH_EOS_INDEX
351 UNSPEC_XXGENPCV
352 UNSPEC_MTVSBM
353 UNSPEC_EXTENDDITI2
354 UNSPEC_VCNTMB
355 UNSPEC_VEXPAND
356 UNSPEC_VEXTRACT
357 UNSPEC_EXTRACTL
358 UNSPEC_EXTRACTR
359 UNSPEC_INSERTL
360 UNSPEC_INSERTR
361 UNSPEC_REPLACE_ELT
362 UNSPEC_REPLACE_UN
363 UNSPEC_VDIVES
364 UNSPEC_VDIVEU
365 UNSPEC_VMSUMCUD
366 UNSPEC_XXEVAL
367 UNSPEC_XXSPLTIW
368 UNSPEC_XXSPLTIDP
369 UNSPEC_XXSPLTI32DX
370 UNSPEC_XXBLEND
371 UNSPEC_XXPERMX
372 ])
373
374 (define_int_iterator XVCVBF16 [UNSPEC_VSX_XVCVSPBF16
375 UNSPEC_VSX_XVCVBF16SPN])
376
377 (define_int_attr xvcvbf16 [(UNSPEC_VSX_XVCVSPBF16 "xvcvspbf16")
378 (UNSPEC_VSX_XVCVBF16SPN "xvcvbf16spn")])
379
380 ;; Like VI, defined in vector.md, but add ISA 2.07 integer vector ops
381 (define_mode_iterator VI2 [V4SI V8HI V16QI V2DI])
382
383 ;; Aligned and unaligned vector replace iterator/attr for 32-bit and
384 ;; 64-bit elements
385 (define_mode_iterator REPLACE_ELT_V [V4SI V4SF V2DI V2DF])
386 (define_mode_iterator REPLACE_ELT [SI SF DI DF])
387 (define_mode_attr REPLACE_ELT_char [(V4SI "w") (V4SF "w")
388 (V2DI "d") (V2DF "d")
389 (SI "w") (SF "w")
390 (DI "d") (DF "d")])
391 (define_mode_attr REPLACE_ELT_sh [(V4SI "2") (V4SF "2")
392 (V2DI "3") (V2DF "3")])
393 (define_mode_attr REPLACE_ELT_max [(V4SI "12") (V4SF "12")
394 (V2DI "8") (V2DF "8")])
395
396 ;; Like VM2 in altivec.md, just do char, short, int, long, float and double
397 (define_mode_iterator VM3 [V4SI
398 V8HI
399 V16QI
400 V4SF
401 V2DF
402 V2DI])
403 (define_mode_iterator V2DI_DI [V2DI DI])
404 (define_mode_attr DI_to_TI [(V2DI "V1TI")
405 (DI "TI")])
406
407 (define_mode_attr VM3_char [(V2DI "d")
408 (V4SI "w")
409 (V8HI "h")
410 (V16QI "b")
411 (V2DF "d")
412 (V4SF "w")])
413
414 ;; Iterator and attribute for vector count leading/trailing
415 ;; zero least-significant bits byte
416 (define_int_iterator VCZLSBB [UNSPEC_VCLZLSBB
417 UNSPEC_VCTZLSBB])
418 (define_int_attr vczlsbb_char [(UNSPEC_VCLZLSBB "l")
419 (UNSPEC_VCTZLSBB "t")])
420
421 ;; VSX moves
422
423 ;; TImode memory to memory move optimization on LE with p8vector
424 (define_insn_and_split "*vsx_le_mem_to_mem_mov_ti"
425 [(set (match_operand:TI 0 "indexed_or_indirect_operand" "=Z")
426 (match_operand:TI 1 "indexed_or_indirect_operand" "Z"))]
427 "!BYTES_BIG_ENDIAN
428 && TARGET_VSX
429 && !TARGET_P9_VECTOR
430 && can_create_pseudo_p ()"
431 "#"
432 "&& 1"
433 [(const_int 0)]
434 {
435 rtx tmp = gen_reg_rtx (V2DImode);
436 rtx src = adjust_address (operands[1], V2DImode, 0);
437 emit_insn (gen_vsx_ld_elemrev_v2di (tmp, src));
438 rtx dest = adjust_address (operands[0], V2DImode, 0);
439 emit_insn (gen_vsx_st_elemrev_v2di (dest, tmp));
440 DONE;
441 }
442 [(set_attr "length" "16")])
443
444 ;; The patterns for LE permuted loads and stores come before the general
445 ;; VSX moves so they match first.
446 (define_insn_and_split "*vsx_le_perm_load_<mode>"
447 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
448 (match_operand:VSX_D 1 "indexed_or_indirect_operand" "Z"))]
449 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
450 "#"
451 "&& 1"
452 [(set (match_dup 2)
453 (vec_select:<MODE>
454 (match_dup 1)
455 (parallel [(const_int 1) (const_int 0)])))
456 (set (match_dup 0)
457 (vec_select:<MODE>
458 (match_dup 2)
459 (parallel [(const_int 1) (const_int 0)])))]
460 {
461 rtx mem = operands[1];
462
463 /* Don't apply the swap optimization if we've already performed register
464 allocation and the hard register destination is not in the altivec
465 range. */
466 if ((MEM_ALIGN (mem) >= 128)
467 && (!HARD_REGISTER_NUM_P (reg_or_subregno (operands[0]))
468 || ALTIVEC_REGNO_P (reg_or_subregno (operands[0]))))
469 {
470 rtx mem_address = XEXP (mem, 0);
471 enum machine_mode mode = GET_MODE (mem);
472
473 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
474 {
475 /* Replace the source memory address with masked address. */
476 rtx lvx_set_expr = rs6000_gen_lvx (mode, operands[0], mem);
477 emit_insn (lvx_set_expr);
478 DONE;
479 }
480 else if (rs6000_quadword_masked_address_p (mem_address))
481 {
482 /* This rtl is already in the form that matches lvx
483 instruction, so leave it alone. */
484 DONE;
485 }
486 /* Otherwise, fall through to transform into a swapping load. */
487 }
488 operands[2] = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (operands[0])
489 : operands[0];
490 }
491 [(set_attr "type" "vecload")
492 (set_attr "length" "8")])
493
494 (define_insn_and_split "*vsx_le_perm_load_<mode>"
495 [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
496 (match_operand:VSX_W 1 "indexed_or_indirect_operand" "Z"))]
497 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
498 "#"
499 "&& 1"
500 [(set (match_dup 2)
501 (vec_select:<MODE>
502 (match_dup 1)
503 (parallel [(const_int 2) (const_int 3)
504 (const_int 0) (const_int 1)])))
505 (set (match_dup 0)
506 (vec_select:<MODE>
507 (match_dup 2)
508 (parallel [(const_int 2) (const_int 3)
509 (const_int 0) (const_int 1)])))]
510 {
511 rtx mem = operands[1];
512
513 /* Don't apply the swap optimization if we've already performed register
514 allocation and the hard register destination is not in the altivec
515 range. */
516 if ((MEM_ALIGN (mem) >= 128)
517 && (!HARD_REGISTER_P (operands[0])
518 || ALTIVEC_REGNO_P (REGNO(operands[0]))))
519 {
520 rtx mem_address = XEXP (mem, 0);
521 enum machine_mode mode = GET_MODE (mem);
522
523 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
524 {
525 /* Replace the source memory address with masked address. */
526 rtx lvx_set_expr = rs6000_gen_lvx (mode, operands[0], mem);
527 emit_insn (lvx_set_expr);
528 DONE;
529 }
530 else if (rs6000_quadword_masked_address_p (mem_address))
531 {
532 /* This rtl is already in the form that matches lvx
533 instruction, so leave it alone. */
534 DONE;
535 }
536 /* Otherwise, fall through to transform into a swapping load. */
537 }
538 operands[2] = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (operands[0])
539 : operands[0];
540 }
541 [(set_attr "type" "vecload")
542 (set_attr "length" "8")])
543
544 (define_insn_and_split "*vsx_le_perm_load_v8hi"
545 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
546 (match_operand:V8HI 1 "indexed_or_indirect_operand" "Z"))]
547 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
548 "#"
549 "&& 1"
550 [(set (match_dup 2)
551 (vec_select:V8HI
552 (match_dup 1)
553 (parallel [(const_int 4) (const_int 5)
554 (const_int 6) (const_int 7)
555 (const_int 0) (const_int 1)
556 (const_int 2) (const_int 3)])))
557 (set (match_dup 0)
558 (vec_select:V8HI
559 (match_dup 2)
560 (parallel [(const_int 4) (const_int 5)
561 (const_int 6) (const_int 7)
562 (const_int 0) (const_int 1)
563 (const_int 2) (const_int 3)])))]
564 {
565 rtx mem = operands[1];
566
567 /* Don't apply the swap optimization if we've already performed register
568 allocation and the hard register destination is not in the altivec
569 range. */
570 if ((MEM_ALIGN (mem) >= 128)
571 && (!HARD_REGISTER_P (operands[0])
572 || ALTIVEC_REGNO_P (REGNO(operands[0]))))
573 {
574 rtx mem_address = XEXP (mem, 0);
575 enum machine_mode mode = GET_MODE (mem);
576
577 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
578 {
579 /* Replace the source memory address with masked address. */
580 rtx lvx_set_expr = rs6000_gen_lvx (mode, operands[0], mem);
581 emit_insn (lvx_set_expr);
582 DONE;
583 }
584 else if (rs6000_quadword_masked_address_p (mem_address))
585 {
586 /* This rtl is already in the form that matches lvx
587 instruction, so leave it alone. */
588 DONE;
589 }
590 /* Otherwise, fall through to transform into a swapping load. */
591 }
592 operands[2] = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (operands[0])
593 : operands[0];
594 }
595 [(set_attr "type" "vecload")
596 (set_attr "length" "8")])
597
598 (define_insn_and_split "*vsx_le_perm_load_v16qi"
599 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
600 (match_operand:V16QI 1 "indexed_or_indirect_operand" "Z"))]
601 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
602 "#"
603 "&& 1"
604 [(set (match_dup 2)
605 (vec_select:V16QI
606 (match_dup 1)
607 (parallel [(const_int 8) (const_int 9)
608 (const_int 10) (const_int 11)
609 (const_int 12) (const_int 13)
610 (const_int 14) (const_int 15)
611 (const_int 0) (const_int 1)
612 (const_int 2) (const_int 3)
613 (const_int 4) (const_int 5)
614 (const_int 6) (const_int 7)])))
615 (set (match_dup 0)
616 (vec_select:V16QI
617 (match_dup 2)
618 (parallel [(const_int 8) (const_int 9)
619 (const_int 10) (const_int 11)
620 (const_int 12) (const_int 13)
621 (const_int 14) (const_int 15)
622 (const_int 0) (const_int 1)
623 (const_int 2) (const_int 3)
624 (const_int 4) (const_int 5)
625 (const_int 6) (const_int 7)])))]
626 {
627 rtx mem = operands[1];
628
629 /* Don't apply the swap optimization if we've already performed register
630 allocation and the hard register destination is not in the altivec
631 range. */
632 if ((MEM_ALIGN (mem) >= 128)
633 && (!HARD_REGISTER_P (operands[0])
634 || ALTIVEC_REGNO_P (REGNO(operands[0]))))
635 {
636 rtx mem_address = XEXP (mem, 0);
637 enum machine_mode mode = GET_MODE (mem);
638
639 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
640 {
641 /* Replace the source memory address with masked address. */
642 rtx lvx_set_expr = rs6000_gen_lvx (mode, operands[0], mem);
643 emit_insn (lvx_set_expr);
644 DONE;
645 }
646 else if (rs6000_quadword_masked_address_p (mem_address))
647 {
648 /* This rtl is already in the form that matches lvx
649 instruction, so leave it alone. */
650 DONE;
651 }
652 /* Otherwise, fall through to transform into a swapping load. */
653 }
654 operands[2] = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (operands[0])
655 : operands[0];
656 }
657 [(set_attr "type" "vecload")
658 (set_attr "length" "8")])
659
660 (define_insn "*vsx_le_perm_store_<mode>"
661 [(set (match_operand:VSX_D 0 "indexed_or_indirect_operand" "=Z")
662 (match_operand:VSX_D 1 "vsx_register_operand" "wa"))]
663 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
664 "#"
665 [(set_attr "type" "vecstore")
666 (set_attr "length" "12")])
667
668 (define_split
669 [(set (match_operand:VSX_D 0 "indexed_or_indirect_operand")
670 (match_operand:VSX_D 1 "vsx_register_operand"))]
671 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && !reload_completed"
672 [(set (match_dup 2)
673 (vec_select:<MODE>
674 (match_dup 1)
675 (parallel [(const_int 1) (const_int 0)])))
676 (set (match_dup 0)
677 (vec_select:<MODE>
678 (match_dup 2)
679 (parallel [(const_int 1) (const_int 0)])))]
680 {
681 rtx mem = operands[0];
682
683 /* Don't apply the swap optimization if we've already performed register
684 allocation and the hard register source is not in the altivec range. */
685 if ((MEM_ALIGN (mem) >= 128)
686 && (!HARD_REGISTER_NUM_P (reg_or_subregno (operands[1]))
687 || ALTIVEC_REGNO_P (reg_or_subregno (operands[1]))))
688 {
689 rtx mem_address = XEXP (mem, 0);
690 enum machine_mode mode = GET_MODE (mem);
691 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
692 {
693 rtx stvx_set_expr = rs6000_gen_stvx (mode, mem, operands[1]);
694 emit_insn (stvx_set_expr);
695 DONE;
696 }
697 else if (rs6000_quadword_masked_address_p (mem_address))
698 {
699 /* This rtl is already in the form that matches stvx instruction,
700 so leave it alone. */
701 DONE;
702 }
703 /* Otherwise, fall through to transform into a swapping store. */
704 }
705
706 gcc_assert (can_create_pseudo_p ());
707 operands[2] = gen_reg_rtx_and_attrs (operands[1]);
708 })
709
710 ;; The post-reload split requires that we re-permute the source
711 ;; register in case it is still live.
712 (define_split
713 [(set (match_operand:VSX_D 0 "indexed_or_indirect_operand")
714 (match_operand:VSX_D 1 "vsx_register_operand"))]
715 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && reload_completed"
716 [(set (match_dup 1)
717 (vec_select:<MODE>
718 (match_dup 1)
719 (parallel [(const_int 1) (const_int 0)])))
720 (set (match_dup 0)
721 (vec_select:<MODE>
722 (match_dup 1)
723 (parallel [(const_int 1) (const_int 0)])))
724 (set (match_dup 1)
725 (vec_select:<MODE>
726 (match_dup 1)
727 (parallel [(const_int 1) (const_int 0)])))]
728 "")
729
730 (define_insn "*vsx_le_perm_store_<mode>"
731 [(set (match_operand:VSX_W 0 "indexed_or_indirect_operand" "=Z")
732 (match_operand:VSX_W 1 "vsx_register_operand" "wa"))]
733 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
734 "#"
735 [(set_attr "type" "vecstore")
736 (set_attr "length" "12")])
737
738 (define_split
739 [(set (match_operand:VSX_W 0 "indexed_or_indirect_operand")
740 (match_operand:VSX_W 1 "vsx_register_operand"))]
741 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && !reload_completed"
742 [(set (match_dup 2)
743 (vec_select:<MODE>
744 (match_dup 1)
745 (parallel [(const_int 2) (const_int 3)
746 (const_int 0) (const_int 1)])))
747 (set (match_dup 0)
748 (vec_select:<MODE>
749 (match_dup 2)
750 (parallel [(const_int 2) (const_int 3)
751 (const_int 0) (const_int 1)])))]
752 {
753 rtx mem = operands[0];
754
755 /* Don't apply the swap optimization if we've already performed register
756 allocation and the hard register source is not in the altivec range. */
757 if ((MEM_ALIGN (mem) >= 128)
758 && (!HARD_REGISTER_NUM_P (reg_or_subregno (operands[1]))
759 || ALTIVEC_REGNO_P (reg_or_subregno (operands[1]))))
760 {
761 rtx mem_address = XEXP (mem, 0);
762 enum machine_mode mode = GET_MODE (mem);
763 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
764 {
765 rtx stvx_set_expr = rs6000_gen_stvx (mode, mem, operands[1]);
766 emit_insn (stvx_set_expr);
767 DONE;
768 }
769 else if (rs6000_quadword_masked_address_p (mem_address))
770 {
771 /* This rtl is already in the form that matches stvx instruction,
772 so leave it alone. */
773 DONE;
774 }
775 /* Otherwise, fall through to transform into a swapping store. */
776 }
777
778 gcc_assert (can_create_pseudo_p ());
779 operands[2] = gen_reg_rtx_and_attrs (operands[1]);
780 })
781
782 ;; The post-reload split requires that we re-permute the source
783 ;; register in case it is still live.
784 (define_split
785 [(set (match_operand:VSX_W 0 "indexed_or_indirect_operand")
786 (match_operand:VSX_W 1 "vsx_register_operand"))]
787 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && reload_completed"
788 [(set (match_dup 1)
789 (vec_select:<MODE>
790 (match_dup 1)
791 (parallel [(const_int 2) (const_int 3)
792 (const_int 0) (const_int 1)])))
793 (set (match_dup 0)
794 (vec_select:<MODE>
795 (match_dup 1)
796 (parallel [(const_int 2) (const_int 3)
797 (const_int 0) (const_int 1)])))
798 (set (match_dup 1)
799 (vec_select:<MODE>
800 (match_dup 1)
801 (parallel [(const_int 2) (const_int 3)
802 (const_int 0) (const_int 1)])))]
803 "")
804
805 (define_insn "*vsx_le_perm_store_v8hi"
806 [(set (match_operand:V8HI 0 "indexed_or_indirect_operand" "=Z")
807 (match_operand:V8HI 1 "vsx_register_operand" "wa"))]
808 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
809 "#"
810 [(set_attr "type" "vecstore")
811 (set_attr "length" "12")])
812
813 (define_split
814 [(set (match_operand:V8HI 0 "indexed_or_indirect_operand")
815 (match_operand:V8HI 1 "vsx_register_operand"))]
816 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && !reload_completed"
817 [(set (match_dup 2)
818 (vec_select:V8HI
819 (match_dup 1)
820 (parallel [(const_int 4) (const_int 5)
821 (const_int 6) (const_int 7)
822 (const_int 0) (const_int 1)
823 (const_int 2) (const_int 3)])))
824 (set (match_dup 0)
825 (vec_select:V8HI
826 (match_dup 2)
827 (parallel [(const_int 4) (const_int 5)
828 (const_int 6) (const_int 7)
829 (const_int 0) (const_int 1)
830 (const_int 2) (const_int 3)])))]
831 {
832 rtx mem = operands[0];
833
834 /* Don't apply the swap optimization if we've already performed register
835 allocation and the hard register source is not in the altivec range. */
836 if ((MEM_ALIGN (mem) >= 128)
837 && (!HARD_REGISTER_NUM_P (reg_or_subregno (operands[1]))
838 || ALTIVEC_REGNO_P (reg_or_subregno (operands[1]))))
839 {
840 rtx mem_address = XEXP (mem, 0);
841 enum machine_mode mode = GET_MODE (mem);
842 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
843 {
844 rtx stvx_set_expr = rs6000_gen_stvx (mode, mem, operands[1]);
845 emit_insn (stvx_set_expr);
846 DONE;
847 }
848 else if (rs6000_quadword_masked_address_p (mem_address))
849 {
850 /* This rtl is already in the form that matches stvx instruction,
851 so leave it alone. */
852 DONE;
853 }
854 /* Otherwise, fall through to transform into a swapping store. */
855 }
856
857 gcc_assert (can_create_pseudo_p ());
858 operands[2] = gen_reg_rtx_and_attrs (operands[1]);
859 })
860
861 ;; The post-reload split requires that we re-permute the source
862 ;; register in case it is still live.
863 (define_split
864 [(set (match_operand:V8HI 0 "indexed_or_indirect_operand")
865 (match_operand:V8HI 1 "vsx_register_operand"))]
866 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && reload_completed"
867 [(set (match_dup 1)
868 (vec_select:V8HI
869 (match_dup 1)
870 (parallel [(const_int 4) (const_int 5)
871 (const_int 6) (const_int 7)
872 (const_int 0) (const_int 1)
873 (const_int 2) (const_int 3)])))
874 (set (match_dup 0)
875 (vec_select:V8HI
876 (match_dup 1)
877 (parallel [(const_int 4) (const_int 5)
878 (const_int 6) (const_int 7)
879 (const_int 0) (const_int 1)
880 (const_int 2) (const_int 3)])))
881 (set (match_dup 1)
882 (vec_select:V8HI
883 (match_dup 1)
884 (parallel [(const_int 4) (const_int 5)
885 (const_int 6) (const_int 7)
886 (const_int 0) (const_int 1)
887 (const_int 2) (const_int 3)])))]
888 "")
889
890 (define_insn "*vsx_le_perm_store_v16qi"
891 [(set (match_operand:V16QI 0 "indexed_or_indirect_operand" "=Z")
892 (match_operand:V16QI 1 "vsx_register_operand" "wa"))]
893 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
894 "#"
895 [(set_attr "type" "vecstore")
896 (set_attr "length" "12")])
897
898 (define_split
899 [(set (match_operand:V16QI 0 "indexed_or_indirect_operand")
900 (match_operand:V16QI 1 "vsx_register_operand"))]
901 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && !reload_completed"
902 [(set (match_dup 2)
903 (vec_select:V16QI
904 (match_dup 1)
905 (parallel [(const_int 8) (const_int 9)
906 (const_int 10) (const_int 11)
907 (const_int 12) (const_int 13)
908 (const_int 14) (const_int 15)
909 (const_int 0) (const_int 1)
910 (const_int 2) (const_int 3)
911 (const_int 4) (const_int 5)
912 (const_int 6) (const_int 7)])))
913 (set (match_dup 0)
914 (vec_select:V16QI
915 (match_dup 2)
916 (parallel [(const_int 8) (const_int 9)
917 (const_int 10) (const_int 11)
918 (const_int 12) (const_int 13)
919 (const_int 14) (const_int 15)
920 (const_int 0) (const_int 1)
921 (const_int 2) (const_int 3)
922 (const_int 4) (const_int 5)
923 (const_int 6) (const_int 7)])))]
924 {
925 rtx mem = operands[0];
926
927 /* Don't apply the swap optimization if we've already performed register
928 allocation and the hard register source is not in the altivec range. */
929 if ((MEM_ALIGN (mem) >= 128)
930 && (!HARD_REGISTER_NUM_P (reg_or_subregno (operands[1]))
931 || ALTIVEC_REGNO_P (reg_or_subregno (operands[1]))))
932 {
933 rtx mem_address = XEXP (mem, 0);
934 enum machine_mode mode = GET_MODE (mem);
935 if (REG_P (mem_address) || rs6000_sum_of_two_registers_p (mem_address))
936 {
937 rtx stvx_set_expr = rs6000_gen_stvx (mode, mem, operands[1]);
938 emit_insn (stvx_set_expr);
939 DONE;
940 }
941 else if (rs6000_quadword_masked_address_p (mem_address))
942 {
943 /* This rtl is already in the form that matches stvx instruction,
944 so leave it alone. */
945 DONE;
946 }
947 /* Otherwise, fall through to transform into a swapping store. */
948 }
949
950 gcc_assert (can_create_pseudo_p ());
951 operands[2] = gen_reg_rtx_and_attrs (operands[1]);
952 })
953
954 ;; The post-reload split requires that we re-permute the source
955 ;; register in case it is still live.
956 (define_split
957 [(set (match_operand:V16QI 0 "indexed_or_indirect_operand")
958 (match_operand:V16QI 1 "vsx_register_operand"))]
959 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && reload_completed"
960 [(set (match_dup 1)
961 (vec_select:V16QI
962 (match_dup 1)
963 (parallel [(const_int 8) (const_int 9)
964 (const_int 10) (const_int 11)
965 (const_int 12) (const_int 13)
966 (const_int 14) (const_int 15)
967 (const_int 0) (const_int 1)
968 (const_int 2) (const_int 3)
969 (const_int 4) (const_int 5)
970 (const_int 6) (const_int 7)])))
971 (set (match_dup 0)
972 (vec_select:V16QI
973 (match_dup 1)
974 (parallel [(const_int 8) (const_int 9)
975 (const_int 10) (const_int 11)
976 (const_int 12) (const_int 13)
977 (const_int 14) (const_int 15)
978 (const_int 0) (const_int 1)
979 (const_int 2) (const_int 3)
980 (const_int 4) (const_int 5)
981 (const_int 6) (const_int 7)])))
982 (set (match_dup 1)
983 (vec_select:V16QI
984 (match_dup 1)
985 (parallel [(const_int 8) (const_int 9)
986 (const_int 10) (const_int 11)
987 (const_int 12) (const_int 13)
988 (const_int 14) (const_int 15)
989 (const_int 0) (const_int 1)
990 (const_int 2) (const_int 3)
991 (const_int 4) (const_int 5)
992 (const_int 6) (const_int 7)])))]
993 "")
994
995 ;; Little endian word swapping for 128-bit types that are either scalars or the
996 ;; special V1TI container class, which it is not appropriate to use vec_select
997 ;; for the type.
998 (define_insn "*vsx_le_permute_<mode>"
999 [(set (match_operand:VEC_TI 0 "nonimmediate_operand" "=wa,wa,Z,&r,&r,Q")
1000 (rotate:VEC_TI
1001 (match_operand:VEC_TI 1 "input_operand" "wa,Z,wa,r,Q,r")
1002 (const_int 64)))]
1003 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR"
1004 "@
1005 xxpermdi %x0,%x1,%x1,2
1006 lxvd2x %x0,%y1
1007 stxvd2x %x1,%y0
1008 mr %0,%L1\;mr %L0,%1
1009 ld%U1%X1 %0,%L1\;ld%U1%X1 %L0,%1
1010 std%U0%X0 %L1,%0\;std%U0%X0 %1,%L0"
1011 [(set_attr "length" "*,*,*,8,8,8")
1012 (set_attr "type" "vecperm,vecload,vecstore,*,load,store")])
1013
1014 (define_insn_and_split "*vsx_le_undo_permute_<mode>"
1015 [(set (match_operand:VEC_TI 0 "vsx_register_operand" "=wa,wa")
1016 (rotate:VEC_TI
1017 (rotate:VEC_TI
1018 (match_operand:VEC_TI 1 "vsx_register_operand" "0,wa")
1019 (const_int 64))
1020 (const_int 64)))]
1021 "!BYTES_BIG_ENDIAN && TARGET_VSX"
1022 "@
1023 #
1024 xxlor %x0,%x1"
1025 "&& 1"
1026 [(set (match_dup 0) (match_dup 1))]
1027 {
1028 if (reload_completed && REGNO (operands[0]) == REGNO (operands[1]))
1029 {
1030 emit_note (NOTE_INSN_DELETED);
1031 DONE;
1032 }
1033 }
1034 [(set_attr "length" "0,4")
1035 (set_attr "type" "veclogical")])
1036
1037 (define_insn_and_split "*vsx_le_perm_load_<mode>"
1038 [(set (match_operand:VSX_LE_128 0 "vsx_register_operand" "=wa,r")
1039 (match_operand:VSX_LE_128 1 "memory_operand" "Z,Q"))]
1040 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1041 && !altivec_indexed_or_indirect_operand (operands[1], <MODE>mode)"
1042 "@
1043 #
1044 #"
1045 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1046 && !altivec_indexed_or_indirect_operand (operands[1], <MODE>mode)"
1047 [(const_int 0)]
1048 {
1049 rtx tmp = (can_create_pseudo_p ()
1050 ? gen_reg_rtx_and_attrs (operands[0])
1051 : operands[0]);
1052 rs6000_emit_le_vsx_permute (tmp, operands[1], <MODE>mode);
1053 rs6000_emit_le_vsx_permute (operands[0], tmp, <MODE>mode);
1054 DONE;
1055 }
1056 [(set_attr "type" "vecload,load")
1057 (set_attr "length" "8,8")
1058 (set_attr "isa" "<VSisa>,*")])
1059
1060 (define_insn "*vsx_le_perm_store_<mode>"
1061 [(set (match_operand:VSX_LE_128 0 "memory_operand" "=Z,Q")
1062 (match_operand:VSX_LE_128 1 "vsx_register_operand" "wa,r"))]
1063 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1064 && !altivec_indexed_or_indirect_operand (operands[0], <MODE>mode)"
1065 "@
1066 #
1067 #"
1068 [(set_attr "type" "vecstore,store")
1069 (set_attr "length" "12,8")
1070 (set_attr "isa" "<VSisa>,*")])
1071
1072 (define_split
1073 [(set (match_operand:VSX_LE_128 0 "memory_operand")
1074 (match_operand:VSX_LE_128 1 "vsx_register_operand"))]
1075 "!BYTES_BIG_ENDIAN && TARGET_VSX && !reload_completed && !TARGET_P9_VECTOR
1076 && !altivec_indexed_or_indirect_operand (operands[0], <MODE>mode)"
1077 [(const_int 0)]
1078 {
1079 gcc_assert (can_create_pseudo_p ());
1080 rtx tmp = gen_reg_rtx_and_attrs (operands[1]);
1081 rs6000_emit_le_vsx_permute (tmp, operands[1], <MODE>mode);
1082 rs6000_emit_le_vsx_permute (operands[0], tmp, <MODE>mode);
1083 DONE;
1084 })
1085
1086 ;; Peepholes to catch loads and stores for TImode if TImode landed in
1087 ;; GPR registers on a little endian system.
1088 (define_peephole2
1089 [(set (match_operand:VEC_TI 0 "int_reg_operand")
1090 (rotate:VEC_TI (match_operand:VEC_TI 1 "memory_operand")
1091 (const_int 64)))
1092 (set (match_operand:VEC_TI 2 "int_reg_operand")
1093 (rotate:VEC_TI (match_dup 0)
1094 (const_int 64)))]
1095 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1096 && (rtx_equal_p (operands[0], operands[2])
1097 || peep2_reg_dead_p (2, operands[0]))"
1098 [(set (match_dup 2) (match_dup 1))])
1099
1100 (define_peephole2
1101 [(set (match_operand:VEC_TI 0 "int_reg_operand")
1102 (rotate:VEC_TI (match_operand:VEC_TI 1 "int_reg_operand")
1103 (const_int 64)))
1104 (set (match_operand:VEC_TI 2 "memory_operand")
1105 (rotate:VEC_TI (match_dup 0)
1106 (const_int 64)))]
1107 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1108 && peep2_reg_dead_p (2, operands[0])"
1109 [(set (match_dup 2) (match_dup 1))])
1110
1111 ;; Peephole to catch memory to memory transfers for TImode if TImode landed in
1112 ;; VSX registers on a little endian system. The vector types and IEEE 128-bit
1113 ;; floating point are handled by the more generic swap elimination pass.
1114 (define_peephole2
1115 [(set (match_operand:TI 0 "vsx_register_operand")
1116 (rotate:TI (match_operand:TI 1 "vsx_register_operand")
1117 (const_int 64)))
1118 (set (match_operand:TI 2 "vsx_register_operand")
1119 (rotate:TI (match_dup 0)
1120 (const_int 64)))]
1121 "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR
1122 && (rtx_equal_p (operands[0], operands[2])
1123 || peep2_reg_dead_p (2, operands[0]))"
1124 [(set (match_dup 2) (match_dup 1))])
1125
1126 ;; The post-reload split requires that we re-permute the source
1127 ;; register in case it is still live.
1128 (define_split
1129 [(set (match_operand:VSX_LE_128 0 "memory_operand")
1130 (match_operand:VSX_LE_128 1 "vsx_register_operand"))]
1131 "!BYTES_BIG_ENDIAN && TARGET_VSX && reload_completed && !TARGET_P9_VECTOR
1132 && !altivec_indexed_or_indirect_operand (operands[0], <MODE>mode)"
1133 [(const_int 0)]
1134 {
1135 rs6000_emit_le_vsx_permute (operands[1], operands[1], <MODE>mode);
1136 rs6000_emit_le_vsx_permute (operands[0], operands[1], <MODE>mode);
1137 rs6000_emit_le_vsx_permute (operands[1], operands[1], <MODE>mode);
1138 DONE;
1139 })
1140
1141 ;; Vector constants that can be generated with XXSPLTIB that was added in ISA
1142 ;; 3.0. Both (const_vector [..]) and (vec_duplicate ...) forms are recognized.
1143 (define_insn "xxspltib_v16qi"
1144 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
1145 (vec_duplicate:V16QI (match_operand:SI 1 "s8bit_cint_operand" "n")))]
1146 "TARGET_P9_VECTOR"
1147 {
1148 operands[2] = GEN_INT (INTVAL (operands[1]) & 0xff);
1149 return "xxspltib %x0,%2";
1150 }
1151 [(set_attr "type" "vecperm")])
1152
1153 (define_insn "xxspltib_<mode>_nosplit"
1154 [(set (match_operand:VSINT_842 0 "vsx_register_operand" "=wa,wa")
1155 (match_operand:VSINT_842 1 "xxspltib_constant_nosplit" "jwM,wE"))]
1156 "TARGET_P9_VECTOR"
1157 {
1158 rtx op1 = operands[1];
1159 int value = 256;
1160 int num_insns = -1;
1161
1162 if (!xxspltib_constant_p (op1, <MODE>mode, &num_insns, &value)
1163 || num_insns != 1)
1164 gcc_unreachable ();
1165
1166 operands[2] = GEN_INT (value & 0xff);
1167 return "xxspltib %x0,%2";
1168 }
1169 [(set_attr "type" "vecperm")])
1170
1171 (define_insn_and_split "*xxspltib_<mode>_split"
1172 [(set (match_operand:VSINT_842 0 "altivec_register_operand" "=v")
1173 (match_operand:VSINT_842 1 "xxspltib_constant_split" "wS"))]
1174 "TARGET_P9_VECTOR"
1175 "#"
1176 "&& 1"
1177 [(const_int 0)]
1178 {
1179 int value = 256;
1180 int num_insns = -1;
1181 rtx op0 = operands[0];
1182 rtx op1 = operands[1];
1183 rtx tmp = ((can_create_pseudo_p ())
1184 ? gen_reg_rtx (V16QImode)
1185 : gen_lowpart (V16QImode, op0));
1186
1187 if (!xxspltib_constant_p (op1, <MODE>mode, &num_insns, &value)
1188 || num_insns != 2)
1189 gcc_unreachable ();
1190
1191 emit_insn (gen_xxspltib_v16qi (tmp, GEN_INT (value)));
1192
1193 if (<MODE>mode == V2DImode)
1194 emit_insn (gen_vsx_sign_extend_v16qi_v2di (op0, tmp));
1195
1196 else if (<MODE>mode == V4SImode)
1197 emit_insn (gen_vsx_sign_extend_v16qi_v4si (op0, tmp));
1198
1199 else if (<MODE>mode == V8HImode)
1200 emit_insn (gen_altivec_vupkhsb (op0, tmp));
1201
1202 else
1203 gcc_unreachable ();
1204
1205 DONE;
1206 }
1207 [(set_attr "type" "vecperm")
1208 (set_attr "length" "8")])
1209
1210 (define_insn_and_split "*vspltisw_v2di_split"
1211 [(set (match_operand:V2DI 0 "altivec_register_operand" "=v")
1212 (match_operand:V2DI 1 "vspltisw_vupkhsw_constant_split" "W"))]
1213 "TARGET_P8_VECTOR && vspltisw_vupkhsw_constant_split (operands[1], V2DImode)"
1214 "#"
1215 "&& 1"
1216 [(const_int 0)]
1217 {
1218 rtx op0 = operands[0];
1219 rtx op1 = operands[1];
1220 rtx tmp = can_create_pseudo_p ()
1221 ? gen_reg_rtx (V4SImode)
1222 : gen_lowpart (V4SImode, op0);
1223 int value;
1224
1225 vspltisw_vupkhsw_constant_p (op1, V2DImode, &value);
1226 emit_insn (gen_altivec_vspltisw (tmp, GEN_INT (value)));
1227 emit_insn (gen_altivec_vupkhsw_direct (op0, tmp));
1228
1229 DONE;
1230 }
1231 [(set_attr "type" "vecperm")
1232 (set_attr "length" "8")])
1233
1234
1235 ;; Prefer using vector registers over GPRs. Prefer using ISA 3.0's XXSPLTISB
1236 ;; or Altivec VSPLITW 0/-1 over XXLXOR/XXLORC to set a register to all 0's or
1237 ;; all 1's, since the machine does not have to wait for the previous
1238 ;; instruction using the register being set (such as a store waiting on a slow
1239 ;; instruction). But generate XXLXOR/XXLORC if it will avoid a register move.
1240
1241 ;; VSX store VSX load VSX move VSX->GPR GPR->VSX LQ (GPR)
1242 ;; STQ (GPR) GPR load GPR store GPR move XXSPLTIB VSPLTISW
1243 ;; LXVKQ XXSPLTI*
1244 ;; VSX 0/-1 VMX const GPR const LVX (VMX) STVX (VMX)
1245 (define_insn "vsx_mov<mode>_64bit"
1246 [(set (match_operand:VSX_M 0 "nonimmediate_operand"
1247 "=ZwO, wa, wa, r, we, ?wQ,
1248 ?&r, ??r, ??Y, <??r>, wa, v,
1249 wa, wa,
1250 ?wa, v, <??r>, wZ, v")
1251
1252 (match_operand:VSX_M 1 "input_operand"
1253 "wa, ZwO, wa, we, r, r,
1254 wQ, Y, r, r, wE, jwM,
1255 eQ, eP,
1256 ?jwM, W, <nW>, v, wZ"))]
1257
1258 "TARGET_POWERPC64 && VECTOR_MEM_VSX_P (<MODE>mode)
1259 && (register_operand (operands[0], <MODE>mode)
1260 || register_operand (operands[1], <MODE>mode))"
1261 {
1262 return rs6000_output_move_128bit (operands);
1263 }
1264 [(set_attr "type"
1265 "vecstore, vecload, vecsimple, mtvsr, mfvsr, load,
1266 store, load, store, *, vecsimple, vecsimple,
1267 vecperm, vecperm,
1268 vecsimple, *, *, vecstore, vecload")
1269 (set_attr "num_insns"
1270 "*, *, *, 2, *, 2,
1271 2, 2, 2, 2, *, *,
1272 *, *,
1273 *, 5, 2, *, *")
1274 (set_attr "max_prefixed_insns"
1275 "*, *, *, *, *, 2,
1276 2, 2, 2, 2, *, *,
1277 *, *,
1278 *, *, *, *, *")
1279 (set_attr "length"
1280 "*, *, *, 8, *, 8,
1281 8, 8, 8, 8, *, *,
1282 *, *,
1283 *, 20, 8, *, *")
1284 (set_attr "isa"
1285 "<VSisa>, <VSisa>, <VSisa>, *, *, *,
1286 *, *, *, *, p9v, *,
1287 p10, p10,
1288 <VSisa>, *, *, *, *")
1289 (set_attr "prefixed"
1290 "*, *, *, *, *, *,
1291 *, *, *, *, *, *,
1292 *, yes,
1293 *, *, *, *, *")])
1294
1295 ;; VSX store VSX load VSX move GPR load GPR store GPR move
1296 ;; LXVKQ XXSPLTI*
1297 ;; XXSPLTIB VSPLTISW VSX 0/-1 VMX const GPR const
1298 ;; LVX (VMX) STVX (VMX)
1299 (define_insn "*vsx_mov<mode>_32bit"
1300 [(set (match_operand:VSX_M 0 "nonimmediate_operand"
1301 "=ZwO, wa, wa, ??r, ??Y, <??r>,
1302 wa, wa,
1303 wa, v, ?wa, v, <??r>,
1304 wZ, v")
1305
1306 (match_operand:VSX_M 1 "input_operand"
1307 "wa, ZwO, wa, Y, r, r,
1308 eQ, eP,
1309 wE, jwM, ?jwM, W, <nW>,
1310 v, wZ"))]
1311
1312 "!TARGET_POWERPC64 && VECTOR_MEM_VSX_P (<MODE>mode)
1313 && (register_operand (operands[0], <MODE>mode)
1314 || register_operand (operands[1], <MODE>mode))"
1315 {
1316 return rs6000_output_move_128bit (operands);
1317 }
1318 [(set_attr "type"
1319 "vecstore, vecload, vecsimple, load, store, *,
1320 vecperm, vecperm,
1321 vecsimple, vecsimple, vecsimple, *, *,
1322 vecstore, vecload")
1323 (set_attr "length"
1324 "*, *, *, 16, 16, 16,
1325 *, *,
1326 *, *, *, 20, 16,
1327 *, *")
1328 (set_attr "isa"
1329 "<VSisa>, <VSisa>, <VSisa>, *, *, *,
1330 p10, p10,
1331 p9v, *, <VSisa>, *, *,
1332 *, *")
1333 (set_attr "prefixed"
1334 "*, *, *, *, *, *,
1335 *, yes,
1336 *, *, *, *, *,
1337 *, *")])
1338
1339 ;; Explicit load/store expanders for the builtin functions
1340 (define_expand "vsx_load_<mode>"
1341 [(set (match_operand:VSX_M 0 "vsx_register_operand")
1342 (match_operand:VSX_M 1 "memory_operand"))]
1343 "VECTOR_MEM_VSX_P (<MODE>mode)"
1344 {
1345 /* Expand to swaps if needed, prior to swap optimization. */
1346 if (!BYTES_BIG_ENDIAN && !TARGET_P9_VECTOR
1347 && !altivec_indexed_or_indirect_operand(operands[1], <MODE>mode))
1348 {
1349 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
1350 DONE;
1351 }
1352 })
1353
1354 (define_expand "vsx_store_<mode>"
1355 [(set (match_operand:VSX_M 0 "memory_operand")
1356 (match_operand:VSX_M 1 "vsx_register_operand"))]
1357 "VECTOR_MEM_VSX_P (<MODE>mode)"
1358 {
1359 /* Expand to swaps if needed, prior to swap optimization. */
1360 if (!BYTES_BIG_ENDIAN && !TARGET_P9_VECTOR
1361 && !altivec_indexed_or_indirect_operand(operands[0], <MODE>mode))
1362 {
1363 rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode);
1364 DONE;
1365 }
1366 })
1367
1368 ;; Load rightmost element from load_data
1369 ;; using lxvrbx, lxvrhx, lxvrwx, lxvrdx.
1370 (define_insn "vsx_lxvr<wd>x"
1371 [(set (match_operand:TI 0 "vsx_register_operand" "=wa")
1372 (zero_extend:TI (match_operand:INT_ISA3 1 "memory_operand" "Z")))]
1373 "TARGET_POWER10"
1374 "lxvr<wd>x %x0,%y1"
1375 [(set_attr "type" "vecload")])
1376
1377 ;; Store rightmost element into store_data
1378 ;; using stxvrbx, stxvrhx, strvxwx, strvxdx.
1379 (define_insn "vsx_stxvr<wd>x"
1380 [(set (match_operand:INT_ISA3 0 "memory_operand" "=Z")
1381 (truncate:INT_ISA3 (match_operand:TI 1 "vsx_register_operand" "wa")))]
1382 "TARGET_POWER10"
1383 "stxvr<wd>x %x1,%y0"
1384 [(set_attr "type" "vecstore")])
1385
1386 ;; Explicit load/store expanders for the builtin functions for lxvd2x, etc.,
1387 ;; when you really want their element-reversing behavior.
1388 (define_insn "vsx_ld_elemrev_v2di"
1389 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
1390 (vec_select:V2DI
1391 (match_operand:V2DI 1 "memory_operand" "Z")
1392 (parallel [(const_int 1) (const_int 0)])))]
1393 "VECTOR_MEM_VSX_P (V2DImode) && !BYTES_BIG_ENDIAN"
1394 "lxvd2x %x0,%y1"
1395 [(set_attr "type" "vecload")])
1396
1397 (define_insn "vsx_ld_elemrev_v1ti"
1398 [(set (match_operand:V1TI 0 "vsx_register_operand" "=wa")
1399 (vec_select:V1TI
1400 (match_operand:V1TI 1 "memory_operand" "Z")
1401 (parallel [(const_int 0)])))]
1402 "VECTOR_MEM_VSX_P (V1TImode) && !BYTES_BIG_ENDIAN"
1403 {
1404 return "lxvd2x %x0,%y1\;xxpermdi %x0,%x0,%x0,2";
1405 }
1406 [(set_attr "type" "vecload")])
1407
1408 (define_insn "vsx_ld_elemrev_v2df"
1409 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa")
1410 (vec_select:V2DF
1411 (match_operand:V2DF 1 "memory_operand" "Z")
1412 (parallel [(const_int 1) (const_int 0)])))]
1413 "VECTOR_MEM_VSX_P (V2DFmode) && !BYTES_BIG_ENDIAN"
1414 "lxvd2x %x0,%y1"
1415 [(set_attr "type" "vecload")])
1416
1417 (define_insn "vsx_ld_elemrev_v4si"
1418 [(set (match_operand:V4SI 0 "vsx_register_operand" "=wa")
1419 (vec_select:V4SI
1420 (match_operand:V4SI 1 "memory_operand" "Z")
1421 (parallel [(const_int 3) (const_int 2)
1422 (const_int 1) (const_int 0)])))]
1423 "VECTOR_MEM_VSX_P (V4SImode) && !BYTES_BIG_ENDIAN"
1424 "lxvw4x %x0,%y1"
1425 [(set_attr "type" "vecload")])
1426
1427 (define_insn "vsx_ld_elemrev_v4sf"
1428 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
1429 (vec_select:V4SF
1430 (match_operand:V4SF 1 "memory_operand" "Z")
1431 (parallel [(const_int 3) (const_int 2)
1432 (const_int 1) (const_int 0)])))]
1433 "VECTOR_MEM_VSX_P (V4SFmode) && !BYTES_BIG_ENDIAN"
1434 "lxvw4x %x0,%y1"
1435 [(set_attr "type" "vecload")])
1436
1437 (define_expand "vsx_ld_elemrev_v8hi"
1438 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
1439 (vec_select:V8HI
1440 (match_operand:V8HI 1 "memory_operand" "Z")
1441 (parallel [(const_int 7) (const_int 6)
1442 (const_int 5) (const_int 4)
1443 (const_int 3) (const_int 2)
1444 (const_int 1) (const_int 0)])))]
1445 "VECTOR_MEM_VSX_P (V8HImode) && !BYTES_BIG_ENDIAN"
1446 {
1447 if (!TARGET_P9_VECTOR)
1448 {
1449 rtx tmp = gen_reg_rtx (V4SImode);
1450 rtx subreg, subreg2, perm[16], pcv;
1451 /* 2 is leftmost element in register */
1452 unsigned int reorder[16] = {13,12,15,14,9,8,11,10,5,4,7,6,1,0,3,2};
1453 int i;
1454
1455 subreg = simplify_gen_subreg (V4SImode, operands[1], V8HImode, 0);
1456 emit_insn (gen_vsx_ld_elemrev_v4si (tmp, subreg));
1457 subreg2 = simplify_gen_subreg (V8HImode, tmp, V4SImode, 0);
1458
1459 for (i = 0; i < 16; ++i)
1460 perm[i] = GEN_INT (reorder[i]);
1461
1462 pcv = force_reg (V16QImode,
1463 gen_rtx_CONST_VECTOR (V16QImode,
1464 gen_rtvec_v (16, perm)));
1465 emit_insn (gen_altivec_vperm_v8hi_direct (operands[0], subreg2,
1466 subreg2, pcv));
1467 DONE;
1468 }
1469 })
1470
1471 (define_insn "*vsx_ld_elemrev_v8hi_internal"
1472 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
1473 (vec_select:V8HI
1474 (match_operand:V8HI 1 "memory_operand" "Z")
1475 (parallel [(const_int 7) (const_int 6)
1476 (const_int 5) (const_int 4)
1477 (const_int 3) (const_int 2)
1478 (const_int 1) (const_int 0)])))]
1479 "VECTOR_MEM_VSX_P (V8HImode) && !BYTES_BIG_ENDIAN && TARGET_P9_VECTOR"
1480 "lxvh8x %x0,%y1"
1481 [(set_attr "type" "vecload")])
1482
1483 (define_expand "vsx_ld_elemrev_v16qi"
1484 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
1485 (vec_select:V16QI
1486 (match_operand:V16QI 1 "memory_operand" "Z")
1487 (parallel [(const_int 15) (const_int 14)
1488 (const_int 13) (const_int 12)
1489 (const_int 11) (const_int 10)
1490 (const_int 9) (const_int 8)
1491 (const_int 7) (const_int 6)
1492 (const_int 5) (const_int 4)
1493 (const_int 3) (const_int 2)
1494 (const_int 1) (const_int 0)])))]
1495 "VECTOR_MEM_VSX_P (V16QImode) && !BYTES_BIG_ENDIAN"
1496 {
1497 if (!TARGET_P9_VECTOR)
1498 {
1499 rtx tmp = gen_reg_rtx (V4SImode);
1500 rtx subreg, subreg2, perm[16], pcv;
1501 /* 3 is leftmost element in register */
1502 unsigned int reorder[16] = {12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3};
1503 int i;
1504
1505 subreg = simplify_gen_subreg (V4SImode, operands[1], V16QImode, 0);
1506 emit_insn (gen_vsx_ld_elemrev_v4si (tmp, subreg));
1507 subreg2 = simplify_gen_subreg (V16QImode, tmp, V4SImode, 0);
1508
1509 for (i = 0; i < 16; ++i)
1510 perm[i] = GEN_INT (reorder[i]);
1511
1512 pcv = force_reg (V16QImode,
1513 gen_rtx_CONST_VECTOR (V16QImode,
1514 gen_rtvec_v (16, perm)));
1515 emit_insn (gen_altivec_vperm_v16qi_direct (operands[0], subreg2,
1516 subreg2, pcv));
1517 DONE;
1518 }
1519 })
1520
1521 (define_insn "vsx_ld_elemrev_v16qi_internal"
1522 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
1523 (vec_select:V16QI
1524 (match_operand:V16QI 1 "memory_operand" "Z")
1525 (parallel [(const_int 15) (const_int 14)
1526 (const_int 13) (const_int 12)
1527 (const_int 11) (const_int 10)
1528 (const_int 9) (const_int 8)
1529 (const_int 7) (const_int 6)
1530 (const_int 5) (const_int 4)
1531 (const_int 3) (const_int 2)
1532 (const_int 1) (const_int 0)])))]
1533 "VECTOR_MEM_VSX_P (V16QImode) && !BYTES_BIG_ENDIAN && TARGET_P9_VECTOR"
1534 "lxvb16x %x0,%y1"
1535 [(set_attr "type" "vecload")])
1536
1537 (define_insn "vsx_st_elemrev_v1ti"
1538 [(set (match_operand:V1TI 0 "memory_operand" "=Z")
1539 (vec_select:V1TI
1540 (match_operand:V1TI 1 "vsx_register_operand" "+wa")
1541 (parallel [(const_int 0)])))
1542 (clobber (match_dup 1))]
1543 "VECTOR_MEM_VSX_P (V2DImode) && !BYTES_BIG_ENDIAN"
1544 {
1545 return "xxpermdi %x1,%x1,%x1,2\;stxvd2x %x1,%y0";
1546 }
1547 [(set_attr "type" "vecstore")])
1548
1549 (define_insn "vsx_st_elemrev_v2df"
1550 [(set (match_operand:V2DF 0 "memory_operand" "=Z")
1551 (vec_select:V2DF
1552 (match_operand:V2DF 1 "vsx_register_operand" "wa")
1553 (parallel [(const_int 1) (const_int 0)])))]
1554 "VECTOR_MEM_VSX_P (V2DFmode) && !BYTES_BIG_ENDIAN"
1555 "stxvd2x %x1,%y0"
1556 [(set_attr "type" "vecstore")])
1557
1558 (define_insn "vsx_st_elemrev_v2di"
1559 [(set (match_operand:V2DI 0 "memory_operand" "=Z")
1560 (vec_select:V2DI
1561 (match_operand:V2DI 1 "vsx_register_operand" "wa")
1562 (parallel [(const_int 1) (const_int 0)])))]
1563 "VECTOR_MEM_VSX_P (V2DImode) && !BYTES_BIG_ENDIAN"
1564 "stxvd2x %x1,%y0"
1565 [(set_attr "type" "vecstore")])
1566
1567 (define_insn "vsx_st_elemrev_v4sf"
1568 [(set (match_operand:V4SF 0 "memory_operand" "=Z")
1569 (vec_select:V4SF
1570 (match_operand:V4SF 1 "vsx_register_operand" "wa")
1571 (parallel [(const_int 3) (const_int 2)
1572 (const_int 1) (const_int 0)])))]
1573 "VECTOR_MEM_VSX_P (V4SFmode) && !BYTES_BIG_ENDIAN"
1574 "stxvw4x %x1,%y0"
1575 [(set_attr "type" "vecstore")])
1576
1577 (define_insn "vsx_st_elemrev_v4si"
1578 [(set (match_operand:V4SI 0 "memory_operand" "=Z")
1579 (vec_select:V4SI
1580 (match_operand:V4SI 1 "vsx_register_operand" "wa")
1581 (parallel [(const_int 3) (const_int 2)
1582 (const_int 1) (const_int 0)])))]
1583 "VECTOR_MEM_VSX_P (V4SImode) && !BYTES_BIG_ENDIAN"
1584 "stxvw4x %x1,%y0"
1585 [(set_attr "type" "vecstore")])
1586
1587 (define_expand "vsx_st_elemrev_v8hi"
1588 [(set (match_operand:V8HI 0 "memory_operand" "=Z")
1589 (vec_select:V8HI
1590 (match_operand:V8HI 1 "vsx_register_operand" "wa")
1591 (parallel [(const_int 7) (const_int 6)
1592 (const_int 5) (const_int 4)
1593 (const_int 3) (const_int 2)
1594 (const_int 1) (const_int 0)])))]
1595 "VECTOR_MEM_VSX_P (V8HImode) && !BYTES_BIG_ENDIAN"
1596 {
1597 if (!TARGET_P9_VECTOR)
1598 {
1599 rtx mem_subreg, subreg, perm[16], pcv;
1600 rtx tmp = gen_reg_rtx (V8HImode);
1601 /* 2 is leftmost element in register */
1602 unsigned int reorder[16] = {13,12,15,14,9,8,11,10,5,4,7,6,1,0,3,2};
1603 int i;
1604
1605 for (i = 0; i < 16; ++i)
1606 perm[i] = GEN_INT (reorder[i]);
1607
1608 pcv = force_reg (V16QImode,
1609 gen_rtx_CONST_VECTOR (V16QImode,
1610 gen_rtvec_v (16, perm)));
1611 emit_insn (gen_altivec_vperm_v8hi_direct (tmp, operands[1],
1612 operands[1], pcv));
1613 subreg = simplify_gen_subreg (V4SImode, tmp, V8HImode, 0);
1614 mem_subreg = simplify_gen_subreg (V4SImode, operands[0], V8HImode, 0);
1615 emit_insn (gen_vsx_st_elemrev_v4si (mem_subreg, subreg));
1616 DONE;
1617 }
1618 })
1619
1620 (define_insn "*vsx_st_elemrev_v2di_internal"
1621 [(set (match_operand:V2DI 0 "memory_operand" "=Z")
1622 (vec_select:V2DI
1623 (match_operand:V2DI 1 "vsx_register_operand" "wa")
1624 (parallel [(const_int 1) (const_int 0)])))]
1625 "VECTOR_MEM_VSX_P (V2DImode) && !BYTES_BIG_ENDIAN && TARGET_P9_VECTOR"
1626 "stxvd2x %x1,%y0"
1627 [(set_attr "type" "vecstore")])
1628
1629 (define_insn "*vsx_st_elemrev_v8hi_internal"
1630 [(set (match_operand:V8HI 0 "memory_operand" "=Z")
1631 (vec_select:V8HI
1632 (match_operand:V8HI 1 "vsx_register_operand" "wa")
1633 (parallel [(const_int 7) (const_int 6)
1634 (const_int 5) (const_int 4)
1635 (const_int 3) (const_int 2)
1636 (const_int 1) (const_int 0)])))]
1637 "VECTOR_MEM_VSX_P (V8HImode) && !BYTES_BIG_ENDIAN && TARGET_P9_VECTOR"
1638 "stxvh8x %x1,%y0"
1639 [(set_attr "type" "vecstore")])
1640
1641 (define_expand "vsx_st_elemrev_v16qi"
1642 [(set (match_operand:V16QI 0 "memory_operand" "=Z")
1643 (vec_select:V16QI
1644 (match_operand:V16QI 1 "vsx_register_operand" "wa")
1645 (parallel [(const_int 15) (const_int 14)
1646 (const_int 13) (const_int 12)
1647 (const_int 11) (const_int 10)
1648 (const_int 9) (const_int 8)
1649 (const_int 7) (const_int 6)
1650 (const_int 5) (const_int 4)
1651 (const_int 3) (const_int 2)
1652 (const_int 1) (const_int 0)])))]
1653 "VECTOR_MEM_VSX_P (V16QImode) && !BYTES_BIG_ENDIAN"
1654 {
1655 if (!TARGET_P9_VECTOR)
1656 {
1657 rtx mem_subreg, subreg, perm[16], pcv;
1658 rtx tmp = gen_reg_rtx (V16QImode);
1659 /* 3 is leftmost element in register */
1660 unsigned int reorder[16] = {12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3};
1661 int i;
1662
1663 for (i = 0; i < 16; ++i)
1664 perm[i] = GEN_INT (reorder[i]);
1665
1666 pcv = force_reg (V16QImode,
1667 gen_rtx_CONST_VECTOR (V16QImode,
1668 gen_rtvec_v (16, perm)));
1669 emit_insn (gen_altivec_vperm_v16qi_direct (tmp, operands[1],
1670 operands[1], pcv));
1671 subreg = simplify_gen_subreg (V4SImode, tmp, V16QImode, 0);
1672 mem_subreg = simplify_gen_subreg (V4SImode, operands[0], V16QImode, 0);
1673 emit_insn (gen_vsx_st_elemrev_v4si (mem_subreg, subreg));
1674 DONE;
1675 }
1676 })
1677
1678 (define_insn "*vsx_st_elemrev_v16qi_internal"
1679 [(set (match_operand:V16QI 0 "memory_operand" "=Z")
1680 (vec_select:V16QI
1681 (match_operand:V16QI 1 "vsx_register_operand" "wa")
1682 (parallel [(const_int 15) (const_int 14)
1683 (const_int 13) (const_int 12)
1684 (const_int 11) (const_int 10)
1685 (const_int 9) (const_int 8)
1686 (const_int 7) (const_int 6)
1687 (const_int 5) (const_int 4)
1688 (const_int 3) (const_int 2)
1689 (const_int 1) (const_int 0)])))]
1690 "VECTOR_MEM_VSX_P (V16QImode) && !BYTES_BIG_ENDIAN && TARGET_P9_VECTOR"
1691 "stxvb16x %x1,%y0"
1692 [(set_attr "type" "vecstore")])
1693
1694
1695 ;; VSX vector floating point arithmetic instructions. The VSX scalar
1696 ;; instructions are now combined with the insn for the traditional floating
1697 ;; point unit.
1698 (define_insn "*vsx_add<mode>3"
1699 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1700 (plus:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
1701 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
1702 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1703 "xvadd<sd>p %x0,%x1,%x2"
1704 [(set_attr "type" "<VStype_simple>")])
1705
1706 (define_insn "*vsx_sub<mode>3"
1707 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa>")
1708 (minus:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
1709 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
1710 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1711 "xvsub<sd>p %x0,%x1,%x2"
1712 [(set_attr "type" "<VStype_simple>")])
1713
1714 (define_insn "*vsx_mul<mode>3"
1715 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1716 (mult:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
1717 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
1718 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1719 "xvmul<sd>p %x0,%x1,%x2"
1720 [(set_attr "type" "<VStype_simple>")])
1721
1722 ; Emulate vector with scalar for vec_mul in V2DImode
1723 (define_insn_and_split "vsx_mul_v2di"
1724 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
1725 (unspec:V2DI [(match_operand:V2DI 1 "vsx_register_operand" "wa")
1726 (match_operand:V2DI 2 "vsx_register_operand" "wa")]
1727 UNSPEC_VSX_MULSD))]
1728 "VECTOR_MEM_VSX_P (V2DImode)"
1729 "#"
1730 "VECTOR_MEM_VSX_P (V2DImode) && !reload_completed"
1731 [(const_int 0)]
1732 {
1733 rtx op0 = operands[0];
1734 rtx op1 = operands[1];
1735 rtx op2 = operands[2];
1736
1737 if (TARGET_POWER10)
1738 emit_insn (gen_mulv2di3 (op0, op1, op2) );
1739
1740 else
1741 {
1742 rtx op3 = gen_reg_rtx (DImode);
1743 rtx op4 = gen_reg_rtx (DImode);
1744 rtx op5 = gen_reg_rtx (DImode);
1745 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (0)));
1746 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (0)));
1747 if (TARGET_POWERPC64)
1748 emit_insn (gen_muldi3 (op5, op3, op4));
1749 else
1750 {
1751 rtx ret = expand_mult (DImode, op3, op4, NULL, 0, false);
1752 emit_move_insn (op5, ret);
1753 }
1754 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (1)));
1755 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (1)));
1756 if (TARGET_POWERPC64)
1757 emit_insn (gen_muldi3 (op3, op3, op4));
1758 else
1759 {
1760 rtx ret = expand_mult (DImode, op3, op4, NULL, 0, false);
1761 emit_move_insn (op3, ret);
1762 }
1763 emit_insn (gen_vsx_concat_v2di (op0, op5, op3));
1764 }
1765 DONE;
1766 }
1767 [(set_attr "type" "mul")])
1768
1769 (define_insn "*vsx_div<mode>3"
1770 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1771 (div:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
1772 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
1773 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1774 "xvdiv<sd>p %x0,%x1,%x2"
1775 [(set_attr "type" "<VStype_div>")])
1776
1777 ; Emulate vector with scalar for vec_div in V2DImode
1778 (define_insn_and_split "vsx_div_v2di"
1779 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
1780 (unspec:V2DI [(match_operand:V2DI 1 "vsx_register_operand" "wa")
1781 (match_operand:V2DI 2 "vsx_register_operand" "wa")]
1782 UNSPEC_VSX_DIVSD))]
1783 "VECTOR_MEM_VSX_P (V2DImode)"
1784 "#"
1785 "VECTOR_MEM_VSX_P (V2DImode) && !reload_completed"
1786 [(const_int 0)]
1787 {
1788 rtx op0 = operands[0];
1789 rtx op1 = operands[1];
1790 rtx op2 = operands[2];
1791 rtx op3 = gen_reg_rtx (DImode);
1792 rtx op4 = gen_reg_rtx (DImode);
1793 rtx op5 = gen_reg_rtx (DImode);
1794 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (0)));
1795 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (0)));
1796 if (TARGET_POWERPC64)
1797 emit_insn (gen_divdi3 (op5, op3, op4));
1798 else
1799 {
1800 rtx libfunc = optab_libfunc (sdiv_optab, DImode);
1801 rtx target = emit_library_call_value (libfunc,
1802 op5, LCT_NORMAL, DImode,
1803 op3, DImode,
1804 op4, DImode);
1805 emit_move_insn (op5, target);
1806 }
1807 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (1)));
1808 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (1)));
1809 if (TARGET_POWERPC64)
1810 emit_insn (gen_divdi3 (op3, op3, op4));
1811 else
1812 {
1813 rtx libfunc = optab_libfunc (sdiv_optab, DImode);
1814 rtx target = emit_library_call_value (libfunc,
1815 op3, LCT_NORMAL, DImode,
1816 op3, DImode,
1817 op4, DImode);
1818 emit_move_insn (op3, target);
1819 }
1820 emit_insn (gen_vsx_concat_v2di (op0, op5, op3));
1821 DONE;
1822 }
1823 [(set_attr "type" "div")])
1824
1825 (define_insn_and_split "vsx_udiv_v2di"
1826 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
1827 (unspec:V2DI [(match_operand:V2DI 1 "vsx_register_operand" "wa")
1828 (match_operand:V2DI 2 "vsx_register_operand" "wa")]
1829 UNSPEC_VSX_DIVUD))]
1830 "VECTOR_MEM_VSX_P (V2DImode)"
1831 "#"
1832 "VECTOR_MEM_VSX_P (V2DImode) && !reload_completed"
1833 [(const_int 0)]
1834 {
1835 rtx op0 = operands[0];
1836 rtx op1 = operands[1];
1837 rtx op2 = operands[2];
1838
1839 if (TARGET_POWER10)
1840 emit_insn (gen_udivv2di3 (op0, op1, op2) );
1841 else
1842 {
1843 rtx op3 = gen_reg_rtx (DImode);
1844 rtx op4 = gen_reg_rtx (DImode);
1845 rtx op5 = gen_reg_rtx (DImode);
1846
1847 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (0)));
1848 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (0)));
1849
1850 if (TARGET_POWERPC64)
1851 emit_insn (gen_udivdi3 (op5, op3, op4));
1852 else
1853 {
1854 rtx libfunc = optab_libfunc (udiv_optab, DImode);
1855 rtx target = emit_library_call_value (libfunc,
1856 op5, LCT_NORMAL, DImode,
1857 op3, DImode,
1858 op4, DImode);
1859 emit_move_insn (op5, target);
1860 }
1861 emit_insn (gen_vsx_extract_v2di (op3, op1, GEN_INT (1)));
1862 emit_insn (gen_vsx_extract_v2di (op4, op2, GEN_INT (1)));
1863
1864 if (TARGET_POWERPC64)
1865 emit_insn (gen_udivdi3 (op3, op3, op4));
1866 else
1867 {
1868 rtx libfunc = optab_libfunc (udiv_optab, DImode);
1869 rtx target = emit_library_call_value (libfunc,
1870 op3, LCT_NORMAL, DImode,
1871 op3, DImode,
1872 op4, DImode);
1873 emit_move_insn (op3, target);
1874 }
1875 emit_insn (gen_vsx_concat_v2di (op0, op5, op3));
1876 }
1877 DONE;
1878 }
1879 [(set_attr "type" "div")])
1880
1881 ;; Vector integer signed/unsigned divide
1882 (define_insn "vsx_div_v1ti"
1883 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1884 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1885 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1886 UNSPEC_VSX_DIVSQ))]
1887 "TARGET_POWER10"
1888 "vdivsq %0,%1,%2"
1889 [(set_attr "type" "div")])
1890
1891 (define_insn "vsx_udiv_v1ti"
1892 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1893 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1894 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1895 UNSPEC_VSX_DIVUQ))]
1896 "TARGET_POWER10"
1897 "vdivuq %0,%1,%2"
1898 [(set_attr "type" "div")])
1899
1900 (define_insn "vsx_dives_v1ti"
1901 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1902 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1903 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1904 UNSPEC_VSX_DIVESQ))]
1905 "TARGET_POWER10"
1906 "vdivesq %0,%1,%2"
1907 [(set_attr "type" "div")])
1908
1909 (define_insn "vsx_diveu_v1ti"
1910 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1911 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1912 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1913 UNSPEC_VSX_DIVEUQ))]
1914 "TARGET_POWER10"
1915 "vdiveuq %0,%1,%2"
1916 [(set_attr "type" "div")])
1917
1918 (define_insn "vsx_mods_v1ti"
1919 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1920 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1921 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1922 UNSPEC_VSX_MODSQ))]
1923 "TARGET_POWER10"
1924 "vmodsq %0,%1,%2"
1925 [(set_attr "type" "div")])
1926
1927 (define_insn "vsx_modu_v1ti"
1928 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
1929 (unspec:V1TI [(match_operand:V1TI 1 "vsx_register_operand" "v")
1930 (match_operand:V1TI 2 "vsx_register_operand" "v")]
1931 UNSPEC_VSX_MODUQ))]
1932 "TARGET_POWER10"
1933 "vmoduq %0,%1,%2"
1934 [(set_attr "type" "div")])
1935
1936 ;; *tdiv* instruction returning the FG flag
1937 (define_expand "vsx_tdiv<mode>3_fg"
1938 [(set (match_dup 3)
1939 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand")
1940 (match_operand:VSX_B 2 "vsx_register_operand")]
1941 UNSPEC_VSX_TDIV))
1942 (set (match_operand:SI 0 "gpc_reg_operand")
1943 (gt:SI (match_dup 3)
1944 (const_int 0)))]
1945 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1946 {
1947 operands[3] = gen_reg_rtx (CCFPmode);
1948 })
1949
1950 ;; *tdiv* instruction returning the FE flag
1951 (define_expand "vsx_tdiv<mode>3_fe"
1952 [(set (match_dup 3)
1953 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand")
1954 (match_operand:VSX_B 2 "vsx_register_operand")]
1955 UNSPEC_VSX_TDIV))
1956 (set (match_operand:SI 0 "gpc_reg_operand")
1957 (eq:SI (match_dup 3)
1958 (const_int 0)))]
1959 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1960 {
1961 operands[3] = gen_reg_rtx (CCFPmode);
1962 })
1963
1964 (define_insn "*vsx_tdiv<mode>3_internal"
1965 [(set (match_operand:CCFP 0 "cc_reg_operand" "=x")
1966 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand" "wa")
1967 (match_operand:VSX_B 2 "vsx_register_operand" "wa")]
1968 UNSPEC_VSX_TDIV))]
1969 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1970 "x<VSv>tdiv<sd>p %0,%x1,%x2"
1971 [(set_attr "type" "<VStype_simple>")])
1972
1973 (define_insn "vsx_fre<mode>2"
1974 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1975 (unspec:VSX_F [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
1976 UNSPEC_FRES))]
1977 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1978 "xvre<sd>p %x0,%x1"
1979 [(set_attr "type" "<VStype_simple>")])
1980
1981 (define_insn "*vsx_neg<mode>2"
1982 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1983 (neg:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")))]
1984 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1985 "xvneg<sd>p %x0,%x1"
1986 [(set_attr "type" "<VStype_simple>")])
1987
1988 (define_insn "*vsx_abs<mode>2"
1989 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1990 (abs:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")))]
1991 "VECTOR_UNIT_VSX_P (<MODE>mode)"
1992 "xvabs<sd>p %x0,%x1"
1993 [(set_attr "type" "<VStype_simple>")])
1994
1995 (define_insn "vsx_nabs<mode>2"
1996 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
1997 (neg:VSX_F
1998 (abs:VSX_F
1999 (match_operand:VSX_F 1 "vsx_register_operand" "wa"))))]
2000 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2001 "xvnabs<sd>p %x0,%x1"
2002 [(set_attr "type" "<VStype_simple>")])
2003
2004 (define_insn "vsx_smax<mode>3"
2005 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2006 (smax:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2007 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2008 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2009 "xvmax<sd>p %x0,%x1,%x2"
2010 [(set_attr "type" "<VStype_simple>")])
2011
2012 (define_insn "*vsx_smin<mode>3"
2013 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2014 (smin:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2015 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2016 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2017 "xvmin<sd>p %x0,%x1,%x2"
2018 [(set_attr "type" "<VStype_simple>")])
2019
2020 (define_insn "*vsx_sqrt<mode>2"
2021 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2022 (sqrt:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")))]
2023 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2024 "xvsqrt<sd>p %x0,%x1"
2025 [(set_attr "type" "<sd>sqrt")])
2026
2027 (define_insn "*vsx_rsqrte<mode>2"
2028 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2029 (unspec:VSX_F [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
2030 UNSPEC_RSQRT))]
2031 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2032 "xvrsqrte<sd>p %x0,%x1"
2033 [(set_attr "type" "<VStype_simple>")])
2034
2035 ;; *tsqrt* returning the fg flag
2036 (define_expand "vsx_tsqrt<mode>2_fg"
2037 [(set (match_dup 2)
2038 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand")]
2039 UNSPEC_VSX_TSQRT))
2040 (set (match_operand:SI 0 "gpc_reg_operand")
2041 (gt:SI (match_dup 2)
2042 (const_int 0)))]
2043 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2044 {
2045 operands[2] = gen_reg_rtx (CCFPmode);
2046 })
2047
2048 ;; *tsqrt* returning the fe flag
2049 (define_expand "vsx_tsqrt<mode>2_fe"
2050 [(set (match_dup 2)
2051 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand")]
2052 UNSPEC_VSX_TSQRT))
2053 (set (match_operand:SI 0 "gpc_reg_operand")
2054 (eq:SI (match_dup 2)
2055 (const_int 0)))]
2056 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2057 {
2058 operands[2] = gen_reg_rtx (CCFPmode);
2059 })
2060
2061 (define_insn "*vsx_tsqrt<mode>2_internal"
2062 [(set (match_operand:CCFP 0 "cc_reg_operand" "=x")
2063 (unspec:CCFP [(match_operand:VSX_B 1 "vsx_register_operand" "wa")]
2064 UNSPEC_VSX_TSQRT))]
2065 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2066 "x<VSv>tsqrt<sd>p %0,%x1"
2067 [(set_attr "type" "<VStype_simple>")])
2068
2069 ;; Fused vector multiply/add instructions. Do not generate the Altivec versions
2070 ;; of fma (vmaddfp and vnmsubfp). These instructions allows the target to be a
2071 ;; separate register from the 3 inputs, which can possibly save an extra move
2072 ;; being generated (assuming all registers are AltiVec registers). However,
2073 ;; vmaddfp and vnmsubfp can have different behaviors than the VSX instructions
2074 ;; in some corner cases due to VSCR[NJ] being set or if the addend is +0.0
2075 ;; instead of -0.0.
2076 (define_insn "*vsx_fmav4sf4"
2077 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa,wa")
2078 (fma:V4SF
2079 (match_operand:V4SF 1 "vsx_register_operand" "%wa,wa")
2080 (match_operand:V4SF 2 "vsx_register_operand" "wa,0")
2081 (match_operand:V4SF 3 "vsx_register_operand" "0,wa")))]
2082 "VECTOR_UNIT_VSX_P (V4SFmode)"
2083 "@
2084 xvmaddasp %x0,%x1,%x2
2085 xvmaddmsp %x0,%x1,%x3"
2086 [(set_attr "type" "vecfloat")])
2087
2088 (define_insn "*vsx_fmav2df4"
2089 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa,wa")
2090 (fma:V2DF
2091 (match_operand:V2DF 1 "vsx_register_operand" "%wa,wa")
2092 (match_operand:V2DF 2 "vsx_register_operand" "wa,0")
2093 (match_operand:V2DF 3 "vsx_register_operand" "0,wa")))]
2094 "VECTOR_UNIT_VSX_P (V2DFmode)"
2095 "@
2096 xvmaddadp %x0,%x1,%x2
2097 xvmaddmdp %x0,%x1,%x3"
2098 [(set_attr "type" "vecdouble")])
2099
2100 (define_insn "*vsx_fms<mode>4"
2101 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa,wa")
2102 (fma:VSX_F
2103 (match_operand:VSX_F 1 "vsx_register_operand" "%wa,wa")
2104 (match_operand:VSX_F 2 "vsx_register_operand" "wa,0")
2105 (neg:VSX_F
2106 (match_operand:VSX_F 3 "vsx_register_operand" "0,wa"))))]
2107 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2108 "@
2109 xvmsuba<sd>p %x0,%x1,%x2
2110 xvmsubm<sd>p %x0,%x1,%x3"
2111 [(set_attr "type" "<VStype_mul>")])
2112
2113 (define_insn "*vsx_nfma<mode>4"
2114 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa,wa")
2115 (neg:VSX_F
2116 (fma:VSX_F
2117 (match_operand:VSX_F 1 "vsx_register_operand" "wa,wa")
2118 (match_operand:VSX_F 2 "vsx_register_operand" "wa,0")
2119 (match_operand:VSX_F 3 "vsx_register_operand" "0,wa"))))]
2120 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2121 "@
2122 xvnmadda<sd>p %x0,%x1,%x2
2123 xvnmaddm<sd>p %x0,%x1,%x3"
2124 [(set_attr "type" "<VStype_mul>")])
2125
2126 (define_insn "*vsx_nfmsv4sf4"
2127 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa,wa")
2128 (neg:V4SF
2129 (fma:V4SF
2130 (match_operand:V4SF 1 "vsx_register_operand" "%wa,wa")
2131 (match_operand:V4SF 2 "vsx_register_operand" "wa,0")
2132 (neg:V4SF
2133 (match_operand:V4SF 3 "vsx_register_operand" "0,wa")))))]
2134 "VECTOR_UNIT_VSX_P (V4SFmode)"
2135 "@
2136 xvnmsubasp %x0,%x1,%x2
2137 xvnmsubmsp %x0,%x1,%x3"
2138 [(set_attr "type" "vecfloat")])
2139
2140 (define_insn "*vsx_nfmsv2df4"
2141 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa,wa")
2142 (neg:V2DF
2143 (fma:V2DF
2144 (match_operand:V2DF 1 "vsx_register_operand" "%wa,wa")
2145 (match_operand:V2DF 2 "vsx_register_operand" "wa,0")
2146 (neg:V2DF
2147 (match_operand:V2DF 3 "vsx_register_operand" "0,wa")))))]
2148 "VECTOR_UNIT_VSX_P (V2DFmode)"
2149 "@
2150 xvnmsubadp %x0,%x1,%x2
2151 xvnmsubmdp %x0,%x1,%x3"
2152 [(set_attr "type" "vecdouble")])
2153
2154 ;; Vector conditional expressions (no scalar version for these instructions)
2155 (define_insn "vsx_eq<mode>"
2156 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2157 (eq:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2158 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2159 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2160 "xvcmpeq<sd>p %x0,%x1,%x2"
2161 [(set_attr "type" "<VStype_simple>")])
2162
2163 (define_insn "vsx_gt<mode>"
2164 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2165 (gt:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2166 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2167 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2168 "xvcmpgt<sd>p %x0,%x1,%x2"
2169 [(set_attr "type" "<VStype_simple>")])
2170
2171 (define_insn "*vsx_ge<mode>"
2172 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2173 (ge:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2174 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2175 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2176 "xvcmpge<sd>p %x0,%x1,%x2"
2177 [(set_attr "type" "<VStype_simple>")])
2178
2179 ;; Compare vectors producing a vector result and a predicate, setting CR6 to
2180 ;; indicate a combined status
2181 (define_insn "*vsx_eq_<mode>_p"
2182 [(set (reg:CC CR6_REGNO)
2183 (unspec:CC
2184 [(eq:CC (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2185 (match_operand:VSX_F 2 "vsx_register_operand" "wa"))]
2186 UNSPEC_PREDICATE))
2187 (set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2188 (eq:VSX_F (match_dup 1)
2189 (match_dup 2)))]
2190 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2191 "xvcmpeq<sd>p. %x0,%x1,%x2"
2192 [(set_attr "type" "<VStype_simple>")])
2193
2194 (define_insn "*vsx_gt_<mode>_p"
2195 [(set (reg:CC CR6_REGNO)
2196 (unspec:CC
2197 [(gt:CC (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2198 (match_operand:VSX_F 2 "vsx_register_operand" "wa"))]
2199 UNSPEC_PREDICATE))
2200 (set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2201 (gt:VSX_F (match_dup 1)
2202 (match_dup 2)))]
2203 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2204 "xvcmpgt<sd>p. %x0,%x1,%x2"
2205 [(set_attr "type" "<VStype_simple>")])
2206
2207 ;; xvtlsbb BF,XB
2208 ;; Set the CR field BF to indicate if the lowest bit (bit 7) of every byte
2209 ;; element in VSR[XB] is equal to 1 (ALL_TRUE) or equal to 0 (ALL_FALSE).
2210 (define_insn "*xvtlsbb_internal"
2211 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
2212 (unspec:CC [(match_operand:V16QI 1 "vsx_register_operand" "wa")]
2213 UNSPEC_XVTLSBB))]
2214 "TARGET_POWER10"
2215 "xvtlsbb %0,%x1"
2216 [(set_attr "type" "logical")])
2217
2218 ;; Vector Test Least Significant Bit by Byte
2219 ;; for the implementation of the builtin
2220 ;; __builtin_vec_test_lsbb_all_ones
2221 ;; int vec_test_lsbb_all_ones (vector unsigned char);
2222 ;; and
2223 ;; __builtin_vec_test_lsbb_all_zeros
2224 ;; int vec_test_lsbb_all_zeros (vector unsigned char);
2225 (define_expand "xvtlsbbo"
2226 [(set (match_dup 2)
2227 (unspec:CC [(match_operand:V16QI 1 "vsx_register_operand" "v")]
2228 UNSPEC_XVTLSBB))
2229 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2230 (lt:SI (match_dup 2) (const_int 0)))]
2231 "TARGET_POWER10"
2232 {
2233 operands[2] = gen_reg_rtx (CCmode);
2234 })
2235 (define_expand "xvtlsbbz"
2236 [(set (match_dup 2)
2237 (unspec:CC [(match_operand:V16QI 1 "vsx_register_operand" "v")]
2238 UNSPEC_XVTLSBB))
2239 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2240 (eq:SI (match_dup 2) (const_int 0)))]
2241 "TARGET_POWER10"
2242 {
2243 operands[2] = gen_reg_rtx (CCmode);
2244 })
2245
2246 (define_insn "*vsx_ge_<mode>_p"
2247 [(set (reg:CC CR6_REGNO)
2248 (unspec:CC
2249 [(ge:CC (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2250 (match_operand:VSX_F 2 "vsx_register_operand" "wa"))]
2251 UNSPEC_PREDICATE))
2252 (set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2253 (ge:VSX_F (match_dup 1)
2254 (match_dup 2)))]
2255 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2256 "xvcmpge<sd>p. %x0,%x1,%x2"
2257 [(set_attr "type" "<VStype_simple>")])
2258
2259 ;; Copy sign
2260 (define_insn "vsx_copysign<mode>3"
2261 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2262 (copysign:VSX_F
2263 (match_operand:VSX_F 1 "vsx_register_operand" "wa")
2264 (match_operand:VSX_F 2 "vsx_register_operand" "wa")))]
2265 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2266 "xvcpsgn<sd>p %x0,%x2,%x1"
2267 [(set_attr "type" "<VStype_simple>")])
2268
2269 ;; For the conversions, limit the register class for the integer value to be
2270 ;; the fprs because we don't want to add the altivec registers to movdi/movsi.
2271 ;; For the unsigned tests, there isn't a generic double -> unsigned conversion
2272 ;; in rs6000.md so don't test VECTOR_UNIT_VSX_P, just test against VSX.
2273 ;; Don't use vsx_register_operand here, use gpc_reg_operand to match rs6000.md
2274 ;; in allowing virtual registers.
2275 (define_insn "vsx_float<VSi><mode>2"
2276 [(set (match_operand:VSX_F 0 "gpc_reg_operand" "=wa")
2277 (float:VSX_F (match_operand:<VSI> 1 "gpc_reg_operand" "wa")))]
2278 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2279 "xvcvsx<VSc><sd>p %x0,%x1"
2280 [(set_attr "type" "<VStype_simple>")])
2281
2282 (define_insn "vsx_floatuns<VSi><mode>2"
2283 [(set (match_operand:VSX_F 0 "gpc_reg_operand" "=wa")
2284 (unsigned_float:VSX_F (match_operand:<VSI> 1 "gpc_reg_operand" "wa")))]
2285 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2286 "xvcvux<VSc><sd>p %x0,%x1"
2287 [(set_attr "type" "<VStype_simple>")])
2288
2289 (define_insn "vsx_fix_trunc<mode><VSi>2"
2290 [(set (match_operand:<VSI> 0 "gpc_reg_operand" "=wa")
2291 (fix:<VSI> (match_operand:VSX_F 1 "gpc_reg_operand" "wa")))]
2292 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2293 "x<VSv>cv<sd>psx<VSc>s %x0,%x1"
2294 [(set_attr "type" "<VStype_simple>")])
2295
2296 (define_insn "vsx_fixuns_trunc<mode><VSi>2"
2297 [(set (match_operand:<VSI> 0 "gpc_reg_operand" "=wa")
2298 (unsigned_fix:<VSI> (match_operand:VSX_F 1 "gpc_reg_operand" "wa")))]
2299 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2300 "x<VSv>cv<sd>pux<VSc>s %x0,%x1"
2301 [(set_attr "type" "<VStype_simple>")])
2302
2303 ;; Math rounding functions
2304 (define_insn "vsx_x<VSv>r<sd>pi"
2305 [(set (match_operand:VSX_B 0 "vsx_register_operand" "=wa")
2306 (unspec:VSX_B [(match_operand:VSX_B 1 "vsx_register_operand" "wa")]
2307 UNSPEC_VSX_ROUND_I))]
2308 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2309 "x<VSv>r<sd>pi %x0,%x1"
2310 [(set_attr "type" "<VStype_simple>")])
2311
2312 (define_insn "vsx_x<VSv>r<sd>pic"
2313 [(set (match_operand:VSX_B 0 "vsx_register_operand" "=wa")
2314 (unspec:VSX_B [(match_operand:VSX_B 1 "vsx_register_operand" "wa")]
2315 UNSPEC_VSX_ROUND_IC))]
2316 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2317 "x<VSv>r<sd>pic %x0,%x1"
2318 [(set_attr "type" "<VStype_simple>")])
2319
2320 (define_insn "vsx_btrunc<mode>2"
2321 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2322 (fix:VSX_F (match_operand:VSX_F 1 "vsx_register_operand" "wa")))]
2323 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2324 "xvr<sd>piz %x0,%x1"
2325 [(set_attr "type" "<VStype_simple>")])
2326
2327 (define_insn "*vsx_b2trunc<mode>2"
2328 [(set (match_operand:VSX_B 0 "vsx_register_operand" "=wa")
2329 (unspec:VSX_B [(match_operand:VSX_B 1 "vsx_register_operand" "wa")]
2330 UNSPEC_FRIZ))]
2331 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2332 "x<VSv>r<sd>piz %x0,%x1"
2333 [(set_attr "type" "<VStype_simple>")])
2334
2335 (define_insn "vsx_floor<mode>2"
2336 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2337 (unspec:VSX_F [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
2338 UNSPEC_FRIM))]
2339 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2340 "xvr<sd>pim %x0,%x1"
2341 [(set_attr "type" "<VStype_simple>")])
2342
2343 (define_insn "vsx_ceil<mode>2"
2344 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
2345 (unspec:VSX_F [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
2346 UNSPEC_FRIP))]
2347 "VECTOR_UNIT_VSX_P (<MODE>mode)"
2348 "xvr<sd>pip %x0,%x1"
2349 [(set_attr "type" "<VStype_simple>")])
2350
2351
2352 ;; VSX convert to/from double vector
2353
2354 ;; Convert between single and double precision
2355 ;; Don't use xscvspdp and xscvdpsp for scalar conversions, since the normal
2356 ;; scalar single precision instructions internally use the double format.
2357 ;; Prefer the altivec registers, since we likely will need to do a vperm
2358 (define_insn "vsx_xscvdpsp"
2359 [(set (match_operand:V4SF 0 "vsx_register_operand" "=f,?wa")
2360 (unspec:V4SF [(match_operand:DF 1 "vsx_register_operand" "f,wa")]
2361 UNSPEC_VSX_CVSPDP))]
2362 "VECTOR_UNIT_VSX_P (DFmode)"
2363 "xscvdpsp %x0,%x1"
2364 [(set_attr "type" "fp")])
2365
2366 (define_insn "vsx_xvcvspdp_be"
2367 [(set (match_operand:V2DF 0 "vsx_register_operand" "=v,?wa")
2368 (float_extend:V2DF
2369 (vec_select:V2SF (match_operand:V4SF 1 "vsx_register_operand" "wa,wa")
2370 (parallel [(const_int 0) (const_int 2)]))))]
2371 "VECTOR_UNIT_VSX_P (V4SFmode) && BYTES_BIG_ENDIAN"
2372 "xvcvspdp %x0,%x1"
2373 [(set_attr "type" "vecdouble")])
2374
2375 (define_insn "vsx_xvcvspdp_le"
2376 [(set (match_operand:V2DF 0 "vsx_register_operand" "=v,?wa")
2377 (float_extend:V2DF
2378 (vec_select:V2SF (match_operand:V4SF 1 "vsx_register_operand" "wa,wa")
2379 (parallel [(const_int 1) (const_int 3)]))))]
2380 "VECTOR_UNIT_VSX_P (V4SFmode) && !BYTES_BIG_ENDIAN"
2381 "xvcvspdp %x0,%x1"
2382 [(set_attr "type" "vecdouble")])
2383
2384 (define_expand "vsx_xvcvspdp"
2385 [(match_operand:V2DF 0 "vsx_register_operand")
2386 (match_operand:V4SF 1 "vsx_register_operand")]
2387 "VECTOR_UNIT_VSX_P (V4SFmode)"
2388 {
2389 if (BYTES_BIG_ENDIAN)
2390 emit_insn (gen_vsx_xvcvspdp_be (operands[0], operands[1]));
2391 else
2392 emit_insn (gen_vsx_xvcvspdp_le (operands[0], operands[1]));
2393 DONE;
2394 })
2395
2396 (define_insn "vsx_xvcvdpsp"
2397 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa,?wa")
2398 (unspec:V4SF [(match_operand:V2DF 1 "vsx_register_operand" "v,wa")]
2399 UNSPEC_VSX_CVSPDP))]
2400 "VECTOR_UNIT_VSX_P (V2DFmode)"
2401 "xvcvdpsp %x0,%x1"
2402 [(set_attr "type" "vecdouble")])
2403
2404 ;; xscvspdp, represent the scalar SF type as V4SF
2405 (define_insn "vsx_xscvspdp"
2406 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
2407 (unspec:DF [(match_operand:V4SF 1 "vsx_register_operand" "wa")]
2408 UNSPEC_VSX_CVSPDP))]
2409 "VECTOR_UNIT_VSX_P (V4SFmode)"
2410 "xscvspdp %x0,%x1"
2411 [(set_attr "type" "fp")])
2412
2413 ;; Same as vsx_xscvspdp, but use SF as the type
2414 (define_insn "vsx_xscvspdp_scalar2"
2415 [(set (match_operand:SF 0 "vsx_register_operand" "=wa")
2416 (unspec:SF [(match_operand:V4SF 1 "vsx_register_operand" "wa")]
2417 UNSPEC_VSX_CVSPDP))]
2418 "VECTOR_UNIT_VSX_P (V4SFmode)"
2419 "xscvspdp %x0,%x1"
2420 [(set_attr "type" "fp")])
2421
2422 ;; Generate xvcvhpsp instruction
2423 (define_insn "vsx_xvcvhpsp"
2424 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2425 (unspec:V4SF [(match_operand: V16QI 1 "vsx_register_operand" "wa")]
2426 UNSPEC_VSX_CVHPSP))]
2427 "TARGET_P9_VECTOR"
2428 "xvcvhpsp %x0,%x1"
2429 [(set_attr "type" "vecfloat")])
2430
2431 ;; Generate xvcvsphp
2432 (define_insn "vsx_xvcvsphp"
2433 [(set (match_operand:V4SI 0 "register_operand" "=wa")
2434 (unspec:V4SI [(match_operand:V4SF 1 "vsx_register_operand" "wa")]
2435 UNSPEC_VSX_XVCVSPHP))]
2436 "TARGET_P9_VECTOR"
2437 "xvcvsphp %x0,%x1"
2438 [(set_attr "type" "vecfloat")])
2439
2440 ;; xscvdpsp used for splat'ing a scalar to V4SF, knowing that the internal SF
2441 ;; format of scalars is actually DF.
2442 (define_insn "vsx_xscvdpsp_scalar"
2443 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2444 (unspec:V4SF [(match_operand:SF 1 "vsx_register_operand" "wa")]
2445 UNSPEC_VSX_CVSPDP))]
2446 "VECTOR_UNIT_VSX_P (V4SFmode)"
2447 "xscvdpsp %x0,%x1"
2448 [(set_attr "type" "fp")])
2449
2450 ;; ISA 2.07 xscvdpspn/xscvspdpn that does not raise an error on signalling NaNs
2451 (define_insn "vsx_xscvdpspn"
2452 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2453 (unspec:V4SF [(match_operand:DF 1 "vsx_register_operand" "wa")]
2454 UNSPEC_VSX_CVDPSPN))]
2455 "TARGET_XSCVDPSPN"
2456 "xscvdpspn %x0,%x1"
2457 [(set_attr "type" "fp")])
2458
2459 (define_insn "vsx_xscvspdpn"
2460 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
2461 (unspec:DF [(match_operand:V4SF 1 "vsx_register_operand" "wa")]
2462 UNSPEC_VSX_CVSPDPN))]
2463 "TARGET_XSCVSPDPN"
2464 "xscvspdpn %x0,%x1"
2465 [(set_attr "type" "fp")])
2466
2467 (define_insn "vsx_xscvdpspn_scalar"
2468 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2469 (unspec:V4SF [(match_operand:SF 1 "vsx_register_operand" "wa")]
2470 UNSPEC_VSX_CVDPSPN))]
2471 "TARGET_XSCVDPSPN"
2472 "xscvdpspn %x0,%x1"
2473 [(set_attr "type" "fp")])
2474
2475 ;; Used by direct move to move a SFmode value from GPR to VSX register
2476 (define_insn "vsx_xscvspdpn_directmove"
2477 [(set (match_operand:SF 0 "vsx_register_operand" "=wa")
2478 (unspec:SF [(match_operand:SF 1 "vsx_register_operand" "wa")]
2479 UNSPEC_VSX_CVSPDPN))]
2480 "TARGET_XSCVSPDPN"
2481 "xscvspdpn %x0,%x1"
2482 [(set_attr "type" "fp")])
2483
2484 ;; Convert and scale (used by vec_ctf, vec_cts, vec_ctu for double/long long)
2485
2486 (define_insn "vsx_xvcv<su>xwsp"
2487 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2488 (any_float:V4SF (match_operand:V4SI 1 "vsx_register_operand" "wa")))]
2489 "VECTOR_UNIT_VSX_P (V4SFmode)"
2490 "xvcv<su>xwsp %x0,%x1"
2491 [(set_attr "type" "vecfloat")])
2492
2493 (define_insn "vsx_xvcv<su>xddp"
2494 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa")
2495 (any_float:V2DF (match_operand:V2DI 1 "vsx_register_operand" "wa")))]
2496 "VECTOR_UNIT_VSX_P (V2DFmode)"
2497 "xvcv<su>xddp %x0,%x1"
2498 [(set_attr "type" "vecdouble")])
2499
2500 (define_insn "vsx_xvcvsp<su>xws"
2501 [(set (match_operand:V4SI 0 "vsx_register_operand" "=wa")
2502 (any_fix:V4SI (match_operand:V4SF 1 "vsx_register_operand" "wa")))]
2503 "VECTOR_UNIT_VSX_P (V4SFmode)"
2504 "xvcvsp<su>xws %x0,%x1"
2505 [(set_attr "type" "vecfloat")])
2506
2507 (define_insn "vsx_xvcvdp<su>xds"
2508 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
2509 (any_fix:V2DI (match_operand:V2DF 1 "vsx_register_operand" "wa")))]
2510 "VECTOR_UNIT_VSX_P (V2DFmode)"
2511 "xvcvdp<su>xds %x0,%x1"
2512 [(set_attr "type" "vecdouble")])
2513
2514 (define_expand "vsx_xvcvsxddp_scale"
2515 [(match_operand:V2DF 0 "vsx_register_operand")
2516 (match_operand:V2DI 1 "vsx_register_operand")
2517 (match_operand:QI 2 "immediate_operand")]
2518 "VECTOR_UNIT_VSX_P (V2DFmode)"
2519 {
2520 rtx op0 = operands[0];
2521 rtx op1 = operands[1];
2522 int scale = INTVAL(operands[2]);
2523 emit_insn (gen_vsx_xvcvsxddp (op0, op1));
2524 if (scale != 0)
2525 rs6000_scale_v2df (op0, op0, -scale);
2526 DONE;
2527 })
2528
2529 (define_expand "vsx_xvcvuxddp_scale"
2530 [(match_operand:V2DF 0 "vsx_register_operand")
2531 (match_operand:V2DI 1 "vsx_register_operand")
2532 (match_operand:QI 2 "immediate_operand")]
2533 "VECTOR_UNIT_VSX_P (V2DFmode)"
2534 {
2535 rtx op0 = operands[0];
2536 rtx op1 = operands[1];
2537 int scale = INTVAL(operands[2]);
2538 emit_insn (gen_vsx_xvcvuxddp (op0, op1));
2539 if (scale != 0)
2540 rs6000_scale_v2df (op0, op0, -scale);
2541 DONE;
2542 })
2543
2544 (define_expand "vsx_xvcvdpsxds_scale"
2545 [(match_operand:V2DI 0 "vsx_register_operand")
2546 (match_operand:V2DF 1 "vsx_register_operand")
2547 (match_operand:QI 2 "immediate_operand")]
2548 "VECTOR_UNIT_VSX_P (V2DFmode)"
2549 {
2550 rtx op0 = operands[0];
2551 rtx op1 = operands[1];
2552 rtx tmp;
2553 int scale = INTVAL (operands[2]);
2554 if (scale == 0)
2555 tmp = op1;
2556 else
2557 {
2558 tmp = gen_reg_rtx (V2DFmode);
2559 rs6000_scale_v2df (tmp, op1, scale);
2560 }
2561 emit_insn (gen_vsx_xvcvdpsxds (op0, tmp));
2562 DONE;
2563 })
2564
2565 ;; convert vector of 64-bit floating point numbers to vector of
2566 ;; 64-bit unsigned integer
2567 (define_expand "vsx_xvcvdpuxds_scale"
2568 [(match_operand:V2DI 0 "vsx_register_operand")
2569 (match_operand:V2DF 1 "vsx_register_operand")
2570 (match_operand:QI 2 "immediate_operand")]
2571 "VECTOR_UNIT_VSX_P (V2DFmode)"
2572 {
2573 rtx op0 = operands[0];
2574 rtx op1 = operands[1];
2575 rtx tmp;
2576 int scale = INTVAL (operands[2]);
2577 if (scale == 0)
2578 tmp = op1;
2579 else
2580 {
2581 tmp = gen_reg_rtx (V2DFmode);
2582 rs6000_scale_v2df (tmp, op1, scale);
2583 }
2584 emit_insn (gen_vsx_xvcvdpuxds (op0, tmp));
2585 DONE;
2586 })
2587
2588 ;; Convert from 64-bit to 32-bit types
2589 ;; Note, favor the Altivec registers since the usual use of these instructions
2590 ;; is in vector converts and we need to use the Altivec vperm instruction.
2591
2592 (define_insn "vsx_xvcvdpsxws"
2593 [(set (match_operand:V4SI 0 "vsx_register_operand" "=v,?wa")
2594 (unspec:V4SI [(match_operand:V2DF 1 "vsx_register_operand" "wa,wa")]
2595 UNSPEC_VSX_CVDPSXWS))]
2596 "VECTOR_UNIT_VSX_P (V2DFmode)"
2597 "xvcvdpsxws %x0,%x1"
2598 [(set_attr "type" "vecdouble")])
2599
2600 (define_insn "vsx_xvcvdpuxws"
2601 [(set (match_operand:V4SI 0 "vsx_register_operand" "=v,?wa")
2602 (unspec:V4SI [(match_operand:V2DF 1 "vsx_register_operand" "wa,wa")]
2603 UNSPEC_VSX_CVDPUXWS))]
2604 "VECTOR_UNIT_VSX_P (V2DFmode)"
2605 "xvcvdpuxws %x0,%x1"
2606 [(set_attr "type" "vecdouble")])
2607
2608 (define_insn "vsx_xvcvsxdsp"
2609 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2610 (unspec:V4SF [(match_operand:V2DI 1 "vsx_register_operand" "wa")]
2611 UNSPEC_VSX_CVSXDSP))]
2612 "VECTOR_UNIT_VSX_P (V2DFmode)"
2613 "xvcvsxdsp %x0,%x1"
2614 [(set_attr "type" "vecfloat")])
2615
2616 (define_insn "vsx_xvcvuxdsp"
2617 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa")
2618 (unspec:V4SF [(match_operand:V2DI 1 "vsx_register_operand" "wa")]
2619 UNSPEC_VSX_CVUXDSP))]
2620 "VECTOR_UNIT_VSX_P (V2DFmode)"
2621 "xvcvuxdsp %x0,%x1"
2622 [(set_attr "type" "vecdouble")])
2623
2624 ;; Convert vector of 32-bit signed/unsigned integers to vector of
2625 ;; 64-bit floating point numbers.
2626 (define_insn "vsx_xvcv<su>xwdp_be"
2627 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa")
2628 (any_float:V2DF
2629 (vec_select:V2SI (match_operand:V4SI 1 "vsx_register_operand" "wa")
2630 (parallel [(const_int 0) (const_int 2)]))))]
2631 "VECTOR_UNIT_VSX_P (V2DFmode) && BYTES_BIG_ENDIAN"
2632 "xvcv<su>xwdp %x0,%x1"
2633 [(set_attr "type" "vecdouble")])
2634
2635 (define_insn "vsx_xvcv<su>xwdp_le"
2636 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa")
2637 (any_float:V2DF
2638 (vec_select:V2SI (match_operand:V4SI 1 "vsx_register_operand" "wa")
2639 (parallel [(const_int 1) (const_int 3)]))))]
2640 "VECTOR_UNIT_VSX_P (V2DFmode) && !BYTES_BIG_ENDIAN"
2641 "xvcv<su>xwdp %x0,%x1"
2642 [(set_attr "type" "vecdouble")])
2643
2644 (define_expand "vsx_xvcv<su>xwdp"
2645 [(match_operand:V2DF 0 "vsx_register_operand")
2646 (match_operand:V4SI 1 "vsx_register_operand")
2647 (any_float (pc))]
2648 "VECTOR_UNIT_VSX_P (V2DFmode)"
2649 {
2650 if (BYTES_BIG_ENDIAN)
2651 emit_insn (gen_vsx_xvcv<su>xwdp_be (operands[0], operands[1]));
2652 else
2653 emit_insn (gen_vsx_xvcv<su>xwdp_le (operands[0], operands[1]));
2654 DONE;
2655 })
2656
2657 (define_insn "vsx_xvcvsxwdp_df"
2658 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
2659 (unspec:DF [(match_operand:V4SI 1 "vsx_register_operand" "wa")]
2660 UNSPEC_VSX_CVSXWDP))]
2661 "TARGET_VSX"
2662 "xvcvsxwdp %x0,%x1"
2663 [(set_attr "type" "vecdouble")])
2664
2665 (define_insn "vsx_xvcvuxwdp_df"
2666 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
2667 (unspec:DF [(match_operand:V4SI 1 "vsx_register_operand" "wa")]
2668 UNSPEC_VSX_CVUXWDP))]
2669 "TARGET_VSX"
2670 "xvcvuxwdp %x0,%x1"
2671 [(set_attr "type" "vecdouble")])
2672
2673 ;; Convert vector of 32-bit floating point numbers to vector of
2674 ;; 64-bit signed/unsigned integers.
2675 (define_insn "vsx_xvcvsp<su>xds_be"
2676 [(set (match_operand:V2DI 0 "vsx_register_operand" "=v,?wa")
2677 (any_fix:V2DI
2678 (vec_select:V2SF (match_operand:V4SF 1 "vsx_register_operand" "wa,wa")
2679 (parallel [(const_int 0) (const_int 2)]))))]
2680 "VECTOR_UNIT_VSX_P (V2DFmode) && BYTES_BIG_ENDIAN"
2681 "xvcvsp<su>xds %x0,%x1"
2682 [(set_attr "type" "vecdouble")])
2683
2684 (define_insn "vsx_xvcvsp<su>xds_le"
2685 [(set (match_operand:V2DI 0 "vsx_register_operand" "=v,?wa")
2686 (any_fix:V2DI
2687 (vec_select:V2SF (match_operand:V4SF 1 "vsx_register_operand" "wa,wa")
2688 (parallel [(const_int 1) (const_int 3)]))))]
2689 "VECTOR_UNIT_VSX_P (V2DFmode) && !BYTES_BIG_ENDIAN"
2690 "xvcvsp<su>xds %x0,%x1"
2691 [(set_attr "type" "vecdouble")])
2692
2693 (define_expand "vsx_xvcvsp<su>xds"
2694 [(match_operand:V2DI 0 "vsx_register_operand")
2695 (match_operand:V4SF 1 "vsx_register_operand")
2696 (any_fix (pc))]
2697 "VECTOR_UNIT_VSX_P (V2DFmode)"
2698 {
2699 if (BYTES_BIG_ENDIAN)
2700 emit_insn (gen_vsx_xvcvsp<su>xds_be (operands[0], operands[1]));
2701 else
2702 emit_insn (gen_vsx_xvcvsp<su>xds_le (operands[0], operands[1]));
2703 DONE;
2704 })
2705
2706 ;; Convert float vector even elements to signed long long vector
2707 (define_expand "vsignede_v4sf"
2708 [(match_operand:V2DI 0 "vsx_register_operand")
2709 (match_operand:V4SF 1 "vsx_register_operand")]
2710 "VECTOR_UNIT_VSX_P (V2DFmode)"
2711 {
2712 if (BYTES_BIG_ENDIAN)
2713 emit_insn (gen_vsx_xvcvspsxds_be (operands[0], operands[1]));
2714 else
2715 {
2716 /* Shift left one word to put even word in correct location. */
2717 rtx rtx_tmp = gen_reg_rtx (V4SFmode);
2718 rtx rtx_val = GEN_INT (4);
2719 emit_insn (gen_altivec_vsldoi_v4sf (rtx_tmp, operands[1], operands[1],
2720 rtx_val));
2721 emit_insn (gen_vsx_xvcvspsxds_le (operands[0], rtx_tmp));
2722 }
2723
2724 DONE;
2725 })
2726
2727 ;; Convert float vector odd elements to signed long long vector
2728 (define_expand "vsignedo_v4sf"
2729 [(match_operand:V2DI 0 "vsx_register_operand")
2730 (match_operand:V4SF 1 "vsx_register_operand")]
2731 "VECTOR_UNIT_VSX_P (V2DFmode)"
2732 {
2733 if (BYTES_BIG_ENDIAN)
2734 {
2735 /* Shift left one word to put even word in correct location. */
2736 rtx rtx_tmp = gen_reg_rtx (V4SFmode);
2737 rtx rtx_val = GEN_INT (4);
2738 emit_insn (gen_altivec_vsldoi_v4sf (rtx_tmp, operands[1], operands[1],
2739 rtx_val));
2740 emit_insn (gen_vsx_xvcvspsxds_be (operands[0], rtx_tmp));
2741 }
2742 else
2743 emit_insn (gen_vsx_xvcvspsxds_le (operands[0], operands[1]));
2744
2745 DONE;
2746 })
2747
2748 ;; Convert float vector of even vector elements to unsigned long long vector
2749 (define_expand "vunsignede_v4sf"
2750 [(match_operand:V2DI 0 "vsx_register_operand")
2751 (match_operand:V4SF 1 "vsx_register_operand")]
2752 "VECTOR_UNIT_VSX_P (V2DFmode)"
2753 {
2754 if (BYTES_BIG_ENDIAN)
2755 emit_insn (gen_vsx_xvcvspuxds_be (operands[0], operands[1]));
2756 else
2757 {
2758 /* Shift left one word to put even word in correct location. */
2759 rtx rtx_tmp = gen_reg_rtx (V4SFmode);
2760 rtx rtx_val = GEN_INT (4);
2761 emit_insn (gen_altivec_vsldoi_v4sf (rtx_tmp, operands[1], operands[1],
2762 rtx_val));
2763 emit_insn (gen_vsx_xvcvspuxds_le (operands[0], rtx_tmp));
2764 }
2765
2766 DONE;
2767 })
2768
2769 ;; Convert float vector of odd elements to unsigned long long vector
2770 (define_expand "vunsignedo_v4sf"
2771 [(match_operand:V2DI 0 "vsx_register_operand")
2772 (match_operand:V4SF 1 "vsx_register_operand")]
2773 "VECTOR_UNIT_VSX_P (V2DFmode)"
2774 {
2775 if (BYTES_BIG_ENDIAN)
2776 {
2777 /* Shift left one word to put even word in correct location. */
2778 rtx rtx_tmp = gen_reg_rtx (V4SFmode);
2779 rtx rtx_val = GEN_INT (4);
2780 emit_insn (gen_altivec_vsldoi_v4sf (rtx_tmp, operands[1], operands[1],
2781 rtx_val));
2782 emit_insn (gen_vsx_xvcvspuxds_be (operands[0], rtx_tmp));
2783 }
2784 else
2785 emit_insn (gen_vsx_xvcvspuxds_le (operands[0], operands[1]));
2786
2787 DONE;
2788 })
2789
2790 ;; Generate float2 double
2791 ;; convert two double to float
2792 (define_expand "float2_v2df"
2793 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2794 (use (match_operand:V2DF 1 "register_operand" "wa"))
2795 (use (match_operand:V2DF 2 "register_operand" "wa"))]
2796 "VECTOR_UNIT_VSX_P (V4SFmode)"
2797 {
2798 rtx rtx_src1, rtx_src2, rtx_dst;
2799
2800 rtx_dst = operands[0];
2801 rtx_src1 = operands[1];
2802 rtx_src2 = operands[2];
2803
2804 rs6000_generate_float2_double_code (rtx_dst, rtx_src1, rtx_src2);
2805 DONE;
2806 })
2807
2808 ;; Generate float2
2809 ;; convert two long long signed ints to float
2810 (define_expand "float2_v2di"
2811 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2812 (use (match_operand:V2DI 1 "register_operand" "wa"))
2813 (use (match_operand:V2DI 2 "register_operand" "wa"))]
2814 "VECTOR_UNIT_VSX_P (V4SFmode)"
2815 {
2816 rtx rtx_src1, rtx_src2, rtx_dst;
2817
2818 rtx_dst = operands[0];
2819 rtx_src1 = operands[1];
2820 rtx_src2 = operands[2];
2821
2822 rs6000_generate_float2_code (true, rtx_dst, rtx_src1, rtx_src2);
2823 DONE;
2824 })
2825
2826 ;; Generate uns_float2
2827 ;; convert two long long unsigned ints to float
2828 (define_expand "uns_float2_v2di"
2829 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2830 (use (match_operand:V2DI 1 "register_operand" "wa"))
2831 (use (match_operand:V2DI 2 "register_operand" "wa"))]
2832 "VECTOR_UNIT_VSX_P (V4SFmode)"
2833 {
2834 rtx rtx_src1, rtx_src2, rtx_dst;
2835
2836 rtx_dst = operands[0];
2837 rtx_src1 = operands[1];
2838 rtx_src2 = operands[2];
2839
2840 rs6000_generate_float2_code (true, rtx_dst, rtx_src1, rtx_src2);
2841 DONE;
2842 })
2843
2844 ;; Generate floate
2845 ;; convert double or long long signed to float
2846 ;; (Only even words are valid, BE numbering)
2847 (define_expand "floate<mode>"
2848 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2849 (use (match_operand:VSX_D 1 "register_operand" "wa"))]
2850 "VECTOR_UNIT_VSX_P (V4SFmode)"
2851 {
2852 if (BYTES_BIG_ENDIAN)
2853 {
2854 /* Shift left one word to put even word correct location */
2855 rtx rtx_tmp;
2856 rtx rtx_val = GEN_INT (4);
2857
2858 rtx_tmp = gen_reg_rtx (V4SFmode);
2859 emit_insn (gen_vsx_xvcv<VF_sxddp>sp (rtx_tmp, operands[1]));
2860 emit_insn (gen_altivec_vsldoi_v4sf (operands[0],
2861 rtx_tmp, rtx_tmp, rtx_val));
2862 }
2863 else
2864 emit_insn (gen_vsx_xvcv<VF_sxddp>sp (operands[0], operands[1]));
2865
2866 DONE;
2867 })
2868
2869 ;; Generate uns_floate
2870 ;; convert long long unsigned to float
2871 ;; (Only even words are valid, BE numbering)
2872 (define_expand "unsfloatev2di"
2873 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2874 (use (match_operand:V2DI 1 "register_operand" "wa"))]
2875 "VECTOR_UNIT_VSX_P (V4SFmode)"
2876 {
2877 if (BYTES_BIG_ENDIAN)
2878 {
2879 /* Shift left one word to put even word correct location */
2880 rtx rtx_tmp;
2881 rtx rtx_val = GEN_INT (4);
2882
2883 rtx_tmp = gen_reg_rtx (V4SFmode);
2884 emit_insn (gen_vsx_xvcvuxdsp (rtx_tmp, operands[1]));
2885 emit_insn (gen_altivec_vsldoi_v4sf (operands[0],
2886 rtx_tmp, rtx_tmp, rtx_val));
2887 }
2888 else
2889 emit_insn (gen_vsx_xvcvuxdsp (operands[0], operands[1]));
2890
2891 DONE;
2892 })
2893
2894 ;; Generate floato
2895 ;; convert double or long long signed to float
2896 ;; Only odd words are valid, BE numbering)
2897 (define_expand "floato<mode>"
2898 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2899 (use (match_operand:VSX_D 1 "register_operand" "wa"))]
2900 "VECTOR_UNIT_VSX_P (V4SFmode)"
2901 {
2902 if (BYTES_BIG_ENDIAN)
2903 emit_insn (gen_vsx_xvcv<VF_sxddp>sp (operands[0], operands[1]));
2904 else
2905 {
2906 /* Shift left one word to put odd word correct location */
2907 rtx rtx_tmp;
2908 rtx rtx_val = GEN_INT (4);
2909
2910 rtx_tmp = gen_reg_rtx (V4SFmode);
2911 emit_insn (gen_vsx_xvcv<VF_sxddp>sp (rtx_tmp, operands[1]));
2912 emit_insn (gen_altivec_vsldoi_v4sf (operands[0],
2913 rtx_tmp, rtx_tmp, rtx_val));
2914 }
2915 DONE;
2916 })
2917
2918 ;; Generate uns_floato
2919 ;; convert long long unsigned to float
2920 ;; (Only odd words are valid, BE numbering)
2921 (define_expand "unsfloatov2di"
2922 [(use (match_operand:V4SF 0 "register_operand" "=wa"))
2923 (use (match_operand:V2DI 1 "register_operand" "wa"))]
2924 "VECTOR_UNIT_VSX_P (V4SFmode)"
2925 {
2926 if (BYTES_BIG_ENDIAN)
2927 emit_insn (gen_vsx_xvcvuxdsp (operands[0], operands[1]));
2928 else
2929 {
2930 /* Shift left one word to put odd word correct location */
2931 rtx rtx_tmp;
2932 rtx rtx_val = GEN_INT (4);
2933
2934 rtx_tmp = gen_reg_rtx (V4SFmode);
2935 emit_insn (gen_vsx_xvcvuxdsp (rtx_tmp, operands[1]));
2936 emit_insn (gen_altivec_vsldoi_v4sf (operands[0],
2937 rtx_tmp, rtx_tmp, rtx_val));
2938 }
2939 DONE;
2940 })
2941
2942 ;; Generate vsigned2
2943 ;; convert two double float vectors to a vector of single precision ints
2944 (define_expand "vsigned2_v2df"
2945 [(match_operand:V4SI 0 "register_operand" "=wa")
2946 (unspec:V4SI [(match_operand:V2DF 1 "register_operand" "wa")
2947 (match_operand:V2DF 2 "register_operand" "wa")]
2948 UNSPEC_VSX_VSIGNED2)]
2949 "TARGET_VSX"
2950 {
2951 rtx rtx_src1, rtx_src2, rtx_dst;
2952 bool signed_convert=true;
2953
2954 rtx_dst = operands[0];
2955 rtx_src1 = operands[1];
2956 rtx_src2 = operands[2];
2957
2958 rs6000_generate_vsigned2_code (signed_convert, rtx_dst, rtx_src1, rtx_src2);
2959 DONE;
2960 })
2961
2962 ;; Generate vsignedo_v2df
2963 ;; signed double float to int convert odd word
2964 (define_expand "vsignedo_v2df"
2965 [(set (match_operand:V4SI 0 "register_operand" "=wa")
2966 (match_operand:V2DF 1 "register_operand" "wa"))]
2967 "TARGET_VSX"
2968 {
2969 if (BYTES_BIG_ENDIAN)
2970 {
2971 rtx rtx_tmp;
2972 rtx rtx_val = GEN_INT (12);
2973 rtx_tmp = gen_reg_rtx (V4SImode);
2974
2975 emit_insn (gen_vsx_xvcvdpsxws (rtx_tmp, operands[1]));
2976
2977 /* Big endian word numbering for words in operand is 0 1 2 3.
2978 take (operand[1] operand[1]) and shift left one word
2979 0 1 2 3 0 1 2 3 => 1 2 3 0
2980 Words 1 and 3 are now are now where they need to be for result. */
2981
2982 emit_insn (gen_altivec_vsldoi_v4si (operands[0], rtx_tmp,
2983 rtx_tmp, rtx_val));
2984 }
2985 else
2986 /* Little endian word numbering for operand is 3 2 1 0.
2987 Result words 3 and 1 are where they need to be. */
2988 emit_insn (gen_vsx_xvcvdpsxws (operands[0], operands[1]));
2989
2990 DONE;
2991 }
2992 [(set_attr "type" "veccomplex")])
2993
2994 ;; Generate vsignede_v2df
2995 ;; signed double float to int even word
2996 (define_expand "vsignede_v2df"
2997 [(set (match_operand:V4SI 0 "register_operand" "=v")
2998 (match_operand:V2DF 1 "register_operand" "v"))]
2999 "TARGET_VSX"
3000 {
3001 if (BYTES_BIG_ENDIAN)
3002 /* Big endian word numbering for words in operand is 0 1
3003 Result words 0 is where they need to be. */
3004 emit_insn (gen_vsx_xvcvdpsxws (operands[0], operands[1]));
3005
3006 else
3007 {
3008 rtx rtx_tmp;
3009 rtx rtx_val = GEN_INT (12);
3010 rtx_tmp = gen_reg_rtx (V4SImode);
3011
3012 emit_insn (gen_vsx_xvcvdpsxws (rtx_tmp, operands[1]));
3013
3014 /* Little endian word numbering for operand is 3 2 1 0.
3015 take (operand[1] operand[1]) and shift left three words
3016 0 1 2 3 0 1 2 3 => 3 0 1 2
3017 Words 0 and 2 are now where they need to be for the result. */
3018 emit_insn (gen_altivec_vsldoi_v4si (operands[0], rtx_tmp,
3019 rtx_tmp, rtx_val));
3020 }
3021 DONE;
3022 }
3023 [(set_attr "type" "veccomplex")])
3024
3025 ;; Generate unsigned2
3026 ;; convert two double float vectors to a vector of single precision
3027 ;; unsigned ints
3028 (define_expand "vunsigned2_v2df"
3029 [(match_operand:V4SI 0 "register_operand" "=v")
3030 (unspec:V4SI [(match_operand:V2DF 1 "register_operand" "v")
3031 (match_operand:V2DF 2 "register_operand" "v")]
3032 UNSPEC_VSX_VSIGNED2)]
3033 "TARGET_VSX"
3034 {
3035 rtx rtx_src1, rtx_src2, rtx_dst;
3036 bool signed_convert=false;
3037
3038 rtx_dst = operands[0];
3039 rtx_src1 = operands[1];
3040 rtx_src2 = operands[2];
3041
3042 rs6000_generate_vsigned2_code (signed_convert, rtx_dst, rtx_src1, rtx_src2);
3043 DONE;
3044 })
3045
3046 ;; Generate vunsignedo_v2df
3047 ;; unsigned double float to int convert odd word
3048 (define_expand "vunsignedo_v2df"
3049 [(set (match_operand:V4SI 0 "register_operand" "=v")
3050 (match_operand:V2DF 1 "register_operand" "v"))]
3051 "TARGET_VSX"
3052 {
3053 if (BYTES_BIG_ENDIAN)
3054 {
3055 rtx rtx_tmp;
3056 rtx rtx_val = GEN_INT (12);
3057 rtx_tmp = gen_reg_rtx (V4SImode);
3058
3059 emit_insn (gen_vsx_xvcvdpuxws (rtx_tmp, operands[1]));
3060
3061 /* Big endian word numbering for words in operand is 0 1 2 3.
3062 take (operand[1] operand[1]) and shift left one word
3063 0 1 2 3 0 1 2 3 => 1 2 3 0
3064 Words 1 and 3 are now are now where they need to be for result. */
3065
3066 emit_insn (gen_altivec_vsldoi_v4si (operands[0], rtx_tmp,
3067 rtx_tmp, rtx_val));
3068 }
3069 else
3070 /* Little endian word numbering for operand is 3 2 1 0.
3071 Result words 3 and 1 are where they need to be. */
3072 emit_insn (gen_vsx_xvcvdpuxws (operands[0], operands[1]));
3073
3074 DONE;
3075 }
3076 [(set_attr "type" "veccomplex")])
3077
3078 ;; Generate vunsignede_v2df
3079 ;; unsigned double float to int even word
3080 (define_expand "vunsignede_v2df"
3081 [(set (match_operand:V4SI 0 "register_operand" "=v")
3082 (match_operand:V2DF 1 "register_operand" "v"))]
3083 "TARGET_VSX"
3084 {
3085 if (BYTES_BIG_ENDIAN)
3086 /* Big endian word numbering for words in operand is 0 1
3087 Result words 0 is where they need to be. */
3088 emit_insn (gen_vsx_xvcvdpuxws (operands[0], operands[1]));
3089
3090 else
3091 {
3092 rtx rtx_tmp;
3093 rtx rtx_val = GEN_INT (12);
3094 rtx_tmp = gen_reg_rtx (V4SImode);
3095
3096 emit_insn (gen_vsx_xvcvdpuxws (rtx_tmp, operands[1]));
3097
3098 /* Little endian word numbering for operand is 3 2 1 0.
3099 take (operand[1] operand[1]) and shift left three words
3100 0 1 2 3 0 1 2 3 => 3 0 1 2
3101 Words 0 and 2 are now where they need to be for the result. */
3102 emit_insn (gen_altivec_vsldoi_v4si (operands[0], rtx_tmp,
3103 rtx_tmp, rtx_val));
3104 }
3105 DONE;
3106 }
3107 [(set_attr "type" "veccomplex")])
3108
3109 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
3110 ;; since the xvrdpiz instruction does not truncate the value if the floating
3111 ;; point value is < LONG_MIN or > LONG_MAX.
3112 (define_insn "*vsx_float_fix_v2df2"
3113 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa,?wa")
3114 (float:V2DF
3115 (fix:V2DI
3116 (match_operand:V2DF 1 "vsx_register_operand" "wa,?wa"))))]
3117 "TARGET_HARD_FLOAT
3118 && VECTOR_UNIT_VSX_P (V2DFmode) && flag_unsafe_math_optimizations
3119 && !flag_trapping_math && TARGET_FRIZ"
3120 "xvrdpiz %x0,%x1"
3121 [(set_attr "type" "vecdouble")])
3122
3123
3124 ;; Permute operations
3125
3126 ;; Build a V2DF/V2DI vector from two scalars
3127 (define_insn "vsx_concat_<mode>"
3128 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa,we")
3129 (vec_concat:VSX_D
3130 (match_operand:<VEC_base> 1 "gpc_reg_operand" "wa,b")
3131 (match_operand:<VEC_base> 2 "gpc_reg_operand" "wa,b")))]
3132 "VECTOR_MEM_VSX_P (<MODE>mode)"
3133 {
3134 if (which_alternative == 0)
3135 return (BYTES_BIG_ENDIAN
3136 ? "xxpermdi %x0,%x1,%x2,0"
3137 : "xxpermdi %x0,%x2,%x1,0");
3138
3139 else if (which_alternative == 1)
3140 return (BYTES_BIG_ENDIAN
3141 ? "mtvsrdd %x0,%1,%2"
3142 : "mtvsrdd %x0,%2,%1");
3143
3144 else
3145 gcc_unreachable ();
3146 }
3147 [(set_attr "type" "vecperm,vecmove")])
3148
3149 ;; Combiner patterns to allow creating XXPERMDI's to access either double
3150 ;; word element in a vector register.
3151 (define_insn "*vsx_concat_<mode>_1"
3152 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3153 (vec_concat:VSX_D
3154 (vec_select:<VEC_base>
3155 (match_operand:VSX_D 1 "gpc_reg_operand" "wa")
3156 (parallel [(match_operand:QI 2 "const_0_to_1_operand" "n")]))
3157 (match_operand:<VEC_base> 3 "gpc_reg_operand" "wa")))]
3158 "VECTOR_MEM_VSX_P (<MODE>mode)"
3159 {
3160 HOST_WIDE_INT dword = INTVAL (operands[2]);
3161 if (BYTES_BIG_ENDIAN)
3162 {
3163 operands[4] = GEN_INT (2*dword);
3164 return "xxpermdi %x0,%x1,%x3,%4";
3165 }
3166 else
3167 {
3168 operands[4] = GEN_INT (!dword);
3169 return "xxpermdi %x0,%x3,%x1,%4";
3170 }
3171 }
3172 [(set_attr "type" "vecperm")])
3173
3174 (define_insn "*vsx_concat_<mode>_2"
3175 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3176 (vec_concat:VSX_D
3177 (match_operand:<VEC_base> 1 "gpc_reg_operand" "wa")
3178 (vec_select:<VEC_base>
3179 (match_operand:VSX_D 2 "gpc_reg_operand" "wa")
3180 (parallel [(match_operand:QI 3 "const_0_to_1_operand" "n")]))))]
3181 "VECTOR_MEM_VSX_P (<MODE>mode)"
3182 {
3183 HOST_WIDE_INT dword = INTVAL (operands[3]);
3184 if (BYTES_BIG_ENDIAN)
3185 {
3186 operands[4] = GEN_INT (dword);
3187 return "xxpermdi %x0,%x1,%x2,%4";
3188 }
3189 else
3190 {
3191 operands[4] = GEN_INT (2 * !dword);
3192 return "xxpermdi %x0,%x2,%x1,%4";
3193 }
3194 }
3195 [(set_attr "type" "vecperm")])
3196
3197 (define_insn "*vsx_concat_<mode>_3"
3198 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3199 (vec_concat:VSX_D
3200 (vec_select:<VEC_base>
3201 (match_operand:VSX_D 1 "gpc_reg_operand" "wa")
3202 (parallel [(match_operand:QI 2 "const_0_to_1_operand" "n")]))
3203 (vec_select:<VEC_base>
3204 (match_operand:VSX_D 3 "gpc_reg_operand" "wa")
3205 (parallel [(match_operand:QI 4 "const_0_to_1_operand" "n")]))))]
3206 "VECTOR_MEM_VSX_P (<MODE>mode)"
3207 {
3208 HOST_WIDE_INT dword1 = INTVAL (operands[2]);
3209 HOST_WIDE_INT dword2 = INTVAL (operands[4]);
3210 if (BYTES_BIG_ENDIAN)
3211 {
3212 operands[5] = GEN_INT ((2 * dword1) + dword2);
3213 return "xxpermdi %x0,%x1,%x3,%5";
3214 }
3215 else
3216 {
3217 operands[5] = GEN_INT ((2 * !dword2) + !dword1);
3218 return "xxpermdi %x0,%x3,%x1,%5";
3219 }
3220 }
3221 [(set_attr "type" "vecperm")])
3222
3223 ;; Special purpose concat using xxpermdi to glue two single precision values
3224 ;; together, relying on the fact that internally scalar floats are represented
3225 ;; as doubles. This is used to initialize a V4SF vector with 4 floats
3226 (define_insn "vsx_concat_v2sf"
3227 [(set (match_operand:V2DF 0 "vsx_register_operand" "=wa")
3228 (unspec:V2DF
3229 [(match_operand:SF 1 "vsx_register_operand" "wa")
3230 (match_operand:SF 2 "vsx_register_operand" "wa")]
3231 UNSPEC_VSX_CONCAT))]
3232 "VECTOR_MEM_VSX_P (V2DFmode)"
3233 {
3234 if (BYTES_BIG_ENDIAN)
3235 return "xxpermdi %x0,%x1,%x2,0";
3236 else
3237 return "xxpermdi %x0,%x2,%x1,0";
3238 }
3239 [(set_attr "type" "vecperm")])
3240
3241 ;; Concatenate 4 SImode elements into a V4SImode reg.
3242 (define_expand "vsx_init_v4si"
3243 [(use (match_operand:V4SI 0 "gpc_reg_operand"))
3244 (use (match_operand:SI 1 "gpc_reg_operand"))
3245 (use (match_operand:SI 2 "gpc_reg_operand"))
3246 (use (match_operand:SI 3 "gpc_reg_operand"))
3247 (use (match_operand:SI 4 "gpc_reg_operand"))]
3248 "VECTOR_MEM_VSX_P (V4SImode) && TARGET_DIRECT_MOVE_64BIT"
3249 {
3250 rtx a = gen_lowpart_SUBREG (DImode, operands[1]);
3251 rtx b = gen_lowpart_SUBREG (DImode, operands[2]);
3252 rtx c = gen_lowpart_SUBREG (DImode, operands[3]);
3253 rtx d = gen_lowpart_SUBREG (DImode, operands[4]);
3254 if (!BYTES_BIG_ENDIAN)
3255 {
3256 std::swap (a, b);
3257 std::swap (c, d);
3258 }
3259
3260 rtx ab = gen_reg_rtx (DImode);
3261 rtx cd = gen_reg_rtx (DImode);
3262 emit_insn (gen_rotldi3_insert_3 (ab, a, GEN_INT (32), b,
3263 GEN_INT (0xffffffff)));
3264 emit_insn (gen_rotldi3_insert_3 (cd, c, GEN_INT (32), d,
3265 GEN_INT (0xffffffff)));
3266
3267 rtx abcd = gen_reg_rtx (V2DImode);
3268 emit_insn (gen_vsx_concat_v2di (abcd, ab, cd));
3269 emit_move_insn (operands[0], gen_lowpart (V4SImode, abcd));
3270 DONE;
3271 })
3272
3273 ;; xxpermdi for little endian loads and stores. We need several of
3274 ;; these since the form of the PARALLEL differs by mode.
3275 (define_insn "*vsx_xxpermdi2_le_<mode>"
3276 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3277 (vec_select:VSX_D
3278 (match_operand:VSX_D 1 "vsx_register_operand" "wa")
3279 (parallel [(const_int 1) (const_int 0)])))]
3280 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (<MODE>mode)"
3281 "xxpermdi %x0,%x1,%x1,2"
3282 [(set_attr "type" "vecperm")])
3283
3284 (define_insn "xxswapd_v16qi"
3285 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
3286 (vec_select:V16QI
3287 (match_operand:V16QI 1 "vsx_register_operand" "wa")
3288 (parallel [(const_int 8) (const_int 9)
3289 (const_int 10) (const_int 11)
3290 (const_int 12) (const_int 13)
3291 (const_int 14) (const_int 15)
3292 (const_int 0) (const_int 1)
3293 (const_int 2) (const_int 3)
3294 (const_int 4) (const_int 5)
3295 (const_int 6) (const_int 7)])))]
3296 "TARGET_VSX"
3297 ;; AIX does not support the extended mnemonic xxswapd. Use the basic
3298 ;; mnemonic xxpermdi instead.
3299 "xxpermdi %x0,%x1,%x1,2"
3300 [(set_attr "type" "vecperm")])
3301
3302 (define_insn "xxswapd_v8hi"
3303 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
3304 (vec_select:V8HI
3305 (match_operand:V8HI 1 "vsx_register_operand" "wa")
3306 (parallel [(const_int 4) (const_int 5)
3307 (const_int 6) (const_int 7)
3308 (const_int 0) (const_int 1)
3309 (const_int 2) (const_int 3)])))]
3310 "TARGET_VSX"
3311 ;; AIX does not support the extended mnemonic xxswapd. Use the basic
3312 ;; mnemonic xxpermdi instead.
3313 "xxpermdi %x0,%x1,%x1,2"
3314 [(set_attr "type" "vecperm")])
3315
3316 (define_insn "xxswapd_<mode>"
3317 [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
3318 (vec_select:VSX_W
3319 (match_operand:VSX_W 1 "vsx_register_operand" "wa")
3320 (parallel [(const_int 2) (const_int 3)
3321 (const_int 0) (const_int 1)])))]
3322 "TARGET_VSX"
3323 ;; AIX does not support extended mnemonic xxswapd. Use the basic
3324 ;; mnemonic xxpermdi instead.
3325 "xxpermdi %x0,%x1,%x1,2"
3326 [(set_attr "type" "vecperm")])
3327
3328 (define_insn "xxswapd_<mode>"
3329 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3330 (vec_select:VSX_D
3331 (match_operand:VSX_D 1 "vsx_register_operand" "wa")
3332 (parallel [(const_int 1) (const_int 0)])))]
3333 "TARGET_VSX"
3334 ;; AIX does not support extended mnemonic xxswapd. Use the basic
3335 ;; mnemonic xxpermdi instead.
3336 "xxpermdi %x0,%x1,%x1,2"
3337 [(set_attr "type" "vecperm")])
3338
3339 ;; Swap upper/lower 64-bit values in a 128-bit vector
3340 (define_insn "xxswapd_v1ti"
3341 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
3342 (subreg:V1TI
3343 (vec_select:V2DI
3344 (subreg:V2DI
3345 (match_operand:V1TI 1 "vsx_register_operand" "v") 0 )
3346 (parallel [(const_int 1)(const_int 0)]))
3347 0))]
3348 "TARGET_POWER10"
3349 ;; AIX does not support extended mnemonic xxswapd. Use the basic
3350 ;; mnemonic xxpermdi instead.
3351 "xxpermdi %x0,%x1,%x1,2"
3352 [(set_attr "type" "vecperm")])
3353
3354 (define_insn "xxgenpcvm_<mode>_internal"
3355 [(set (match_operand:VSX_EXTRACT_I4 0 "altivec_register_operand" "=wa")
3356 (unspec:VSX_EXTRACT_I4
3357 [(match_operand:VSX_EXTRACT_I4 1 "altivec_register_operand" "v")
3358 (match_operand:QI 2 "const_0_to_3_operand" "n")]
3359 UNSPEC_XXGENPCV))]
3360 "TARGET_POWER10"
3361 "xxgenpcv<wd>m %x0,%1,%2"
3362 [(set_attr "type" "vecsimple")])
3363
3364 (define_expand "xxgenpcvm_<mode>"
3365 [(use (match_operand:VSX_EXTRACT_I4 0 "register_operand"))
3366 (use (match_operand:VSX_EXTRACT_I4 1 "register_operand"))
3367 (use (match_operand:QI 2 "immediate_operand"))]
3368 "TARGET_POWER10"
3369 {
3370 if (!BYTES_BIG_ENDIAN)
3371 {
3372 /* gen_xxgenpcvm assumes Big Endian order. If LE,
3373 change swap upper and lower double words. */
3374 rtx tmp = gen_reg_rtx (<MODE>mode);
3375
3376 emit_insn (gen_xxswapd_<mode> (tmp, operands[1]));
3377 operands[1] = tmp;
3378 }
3379 emit_insn (gen_xxgenpcvm_<mode>_internal (operands[0], operands[1],
3380 operands[2]));
3381 DONE;
3382 })
3383
3384 ;; lxvd2x for little endian loads. We need several of
3385 ;; these since the form of the PARALLEL differs by mode.
3386 (define_insn "*vsx_lxvd2x2_le_<mode>"
3387 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3388 (vec_select:VSX_D
3389 (match_operand:VSX_D 1 "memory_operand" "Z")
3390 (parallel [(const_int 1) (const_int 0)])))]
3391 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (<MODE>mode) && !TARGET_P9_VECTOR"
3392 "lxvd2x %x0,%y1"
3393 [(set_attr "type" "vecload")])
3394
3395 (define_insn "*vsx_lxvd2x4_le_<mode>"
3396 [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
3397 (vec_select:VSX_W
3398 (match_operand:VSX_W 1 "memory_operand" "Z")
3399 (parallel [(const_int 2) (const_int 3)
3400 (const_int 0) (const_int 1)])))]
3401 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (<MODE>mode) && !TARGET_P9_VECTOR"
3402 "lxvd2x %x0,%y1"
3403 [(set_attr "type" "vecload")])
3404
3405 (define_insn "*vsx_lxvd2x8_le_V8HI"
3406 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
3407 (vec_select:V8HI
3408 (match_operand:V8HI 1 "memory_operand" "Z")
3409 (parallel [(const_int 4) (const_int 5)
3410 (const_int 6) (const_int 7)
3411 (const_int 0) (const_int 1)
3412 (const_int 2) (const_int 3)])))]
3413 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V8HImode) && !TARGET_P9_VECTOR"
3414 "lxvd2x %x0,%y1"
3415 [(set_attr "type" "vecload")])
3416
3417 (define_insn "*vsx_lxvd2x16_le_V16QI"
3418 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
3419 (vec_select:V16QI
3420 (match_operand:V16QI 1 "memory_operand" "Z")
3421 (parallel [(const_int 8) (const_int 9)
3422 (const_int 10) (const_int 11)
3423 (const_int 12) (const_int 13)
3424 (const_int 14) (const_int 15)
3425 (const_int 0) (const_int 1)
3426 (const_int 2) (const_int 3)
3427 (const_int 4) (const_int 5)
3428 (const_int 6) (const_int 7)])))]
3429 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V16QImode) && !TARGET_P9_VECTOR"
3430 "lxvd2x %x0,%y1"
3431 [(set_attr "type" "vecload")])
3432
3433 ;; stxvd2x for little endian stores. We need several of
3434 ;; these since the form of the PARALLEL differs by mode.
3435 (define_insn "*vsx_stxvd2x2_le_<mode>"
3436 [(set (match_operand:VSX_D 0 "memory_operand" "=Z")
3437 (vec_select:VSX_D
3438 (match_operand:VSX_D 1 "vsx_register_operand" "wa")
3439 (parallel [(const_int 1) (const_int 0)])))]
3440 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (<MODE>mode) && !TARGET_P9_VECTOR"
3441 "stxvd2x %x1,%y0"
3442 [(set_attr "type" "vecstore")])
3443
3444 (define_insn "*vsx_stxvd2x4_le_<mode>"
3445 [(set (match_operand:VSX_W 0 "memory_operand" "=Z")
3446 (vec_select:VSX_W
3447 (match_operand:VSX_W 1 "vsx_register_operand" "wa")
3448 (parallel [(const_int 2) (const_int 3)
3449 (const_int 0) (const_int 1)])))]
3450 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (<MODE>mode) && !TARGET_P9_VECTOR"
3451 "stxvd2x %x1,%y0"
3452 [(set_attr "type" "vecstore")])
3453
3454 (define_insn_and_split "vsx_stxvd2x4_le_const_<mode>"
3455 [(set (match_operand:VSX_W 0 "memory_operand" "=Z")
3456 (match_operand:VSX_W 1 "immediate_operand" "W"))
3457 (clobber (match_scratch:VSX_W 2 "=wa"))]
3458 "!BYTES_BIG_ENDIAN
3459 && VECTOR_MEM_VSX_P (<MODE>mode)
3460 && !TARGET_P9_VECTOR
3461 && !altivec_indexed_or_indirect_operand (operands[0], <MODE>mode)
3462 && const_vec_duplicate_p (operands[1])"
3463 "#"
3464 "&& 1"
3465 [(set (match_dup 2)
3466 (match_dup 1))
3467 (set (match_dup 0)
3468 (vec_select:VSX_W
3469 (match_dup 2)
3470 (parallel [(const_int 2) (const_int 3)
3471 (const_int 0) (const_int 1)])))]
3472 {
3473 /* Here all the constants must be loaded without memory. */
3474 gcc_assert (easy_altivec_constant (operands[1], <MODE>mode));
3475 if (GET_CODE (operands[2]) == SCRATCH)
3476 operands[2] = gen_reg_rtx (<MODE>mode);
3477 }
3478 [(set_attr "type" "vecstore")
3479 (set_attr "length" "8")])
3480
3481 (define_insn "*vsx_stxvd2x8_le_V8HI"
3482 [(set (match_operand:V8HI 0 "memory_operand" "=Z")
3483 (vec_select:V8HI
3484 (match_operand:V8HI 1 "vsx_register_operand" "wa")
3485 (parallel [(const_int 4) (const_int 5)
3486 (const_int 6) (const_int 7)
3487 (const_int 0) (const_int 1)
3488 (const_int 2) (const_int 3)])))]
3489 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V8HImode) && !TARGET_P9_VECTOR"
3490 "stxvd2x %x1,%y0"
3491 [(set_attr "type" "vecstore")])
3492
3493 (define_insn "*vsx_stxvd2x16_le_V16QI"
3494 [(set (match_operand:V16QI 0 "memory_operand" "=Z")
3495 (vec_select:V16QI
3496 (match_operand:V16QI 1 "vsx_register_operand" "wa")
3497 (parallel [(const_int 8) (const_int 9)
3498 (const_int 10) (const_int 11)
3499 (const_int 12) (const_int 13)
3500 (const_int 14) (const_int 15)
3501 (const_int 0) (const_int 1)
3502 (const_int 2) (const_int 3)
3503 (const_int 4) (const_int 5)
3504 (const_int 6) (const_int 7)])))]
3505 "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V16QImode) && !TARGET_P9_VECTOR"
3506 "stxvd2x %x1,%y0"
3507 [(set_attr "type" "vecstore")])
3508
3509 ;; Convert a TImode value into V1TImode
3510 (define_expand "vsx_set_v1ti"
3511 [(match_operand:V1TI 0 "nonimmediate_operand")
3512 (match_operand:V1TI 1 "nonimmediate_operand")
3513 (match_operand:TI 2 "input_operand")
3514 (match_operand:QI 3 "u5bit_cint_operand")]
3515 "VECTOR_MEM_VSX_P (V1TImode)"
3516 {
3517 if (operands[3] != const0_rtx)
3518 gcc_unreachable ();
3519
3520 emit_move_insn (operands[0], gen_lowpart (V1TImode, operands[1]));
3521 DONE;
3522 })
3523
3524 ;; Rewrite V2DF/V2DI set in terms of VEC_CONCAT
3525 (define_expand "vsx_set_<mode>"
3526 [(use (match_operand:VSX_D 0 "vsx_register_operand"))
3527 (use (match_operand:VSX_D 1 "vsx_register_operand"))
3528 (use (match_operand:<VEC_base> 2 "gpc_reg_operand"))
3529 (use (match_operand:QI 3 "const_0_to_1_operand"))]
3530 "VECTOR_MEM_VSX_P (<MODE>mode)"
3531 {
3532 rtx dest = operands[0];
3533 rtx vec_reg = operands[1];
3534 rtx value = operands[2];
3535 rtx ele = operands[3];
3536 rtx tmp = gen_reg_rtx (<VEC_base>mode);
3537
3538 if (ele == const0_rtx)
3539 {
3540 emit_insn (gen_vsx_extract_<mode> (tmp, vec_reg, const1_rtx));
3541 emit_insn (gen_vsx_concat_<mode> (dest, value, tmp));
3542 DONE;
3543 }
3544 else if (ele == const1_rtx)
3545 {
3546 emit_insn (gen_vsx_extract_<mode> (tmp, vec_reg, const0_rtx));
3547 emit_insn (gen_vsx_concat_<mode> (dest, tmp, value));
3548 DONE;
3549 }
3550 else
3551 gcc_unreachable ();
3552 })
3553
3554 ;; Extract a DF/DI element from V2DF/V2DI
3555 ;; Optimize cases were we can do a simple or direct move.
3556 ;; Or see if we can avoid doing the move at all
3557
3558 (define_expand "vsx_extract_<mode>"
3559 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand")
3560 (vec_select:<VEC_base>
3561 (match_operand:VSX_D 1 "gpc_reg_operand")
3562 (parallel
3563 [(match_operand:QI 2 "const_0_to_1_operand")])))]
3564 "VECTOR_MEM_VSX_P (<MODE>mode)"
3565 "")
3566
3567 (define_insn "*vsx_extract_<mode>_0"
3568 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=wa,wa,wr")
3569 (vec_select:<VEC_base>
3570 (match_operand:VSX_D 1 "gpc_reg_operand" "0,wa,wa")
3571 (parallel
3572 [(match_operand:QI 2 "const_0_to_1_operand" "n,n,n")])))]
3573 "VECTOR_MEM_VSX_P (<MODE>mode)
3574 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 0 : 1)"
3575 {
3576 if (which_alternative == 0)
3577 return ASM_COMMENT_START " vec_extract to same register";
3578
3579 if (which_alternative == 2)
3580 return "mfvsrd %0,%x1";
3581
3582 return "xxlor %x0,%x1,%x1";
3583 }
3584 [(set_attr "type" "*,veclogical,mfvsr")
3585 (set_attr "isa" "*,*,p8v")
3586 (set_attr "length" "0,*,*")])
3587
3588 (define_insn "*vsx_extract_<mode>_1"
3589 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=wa,wr")
3590 (vec_select:<VEC_base>
3591 (match_operand:VSX_D 1 "gpc_reg_operand" "wa,wa")
3592 (parallel
3593 [(match_operand:QI 2 "const_0_to_1_operand" "n,n")])))]
3594 "VECTOR_MEM_VSX_P (<MODE>mode)
3595 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 1 : 0)"
3596 {
3597 if (which_alternative == 1)
3598 return "mfvsrld %0,%x1";
3599
3600 operands[3] = GEN_INT (BYTES_BIG_ENDIAN ? 2 : 3);
3601 return "xxpermdi %x0,%x1,%x1,%3";
3602 }
3603 [(set_attr "type" "mfvsr,vecperm")
3604 (set_attr "isa" "*,p9v")])
3605
3606 ;; Optimize extracting a single scalar element from memory.
3607 (define_insn_and_split "*vsx_extract_<P:mode>_<VSX_D:mode>_load"
3608 [(set (match_operand:<VEC_base> 0 "register_operand" "=wa,wr")
3609 (vec_select:<VSX_D:VEC_base>
3610 (match_operand:VSX_D 1 "memory_operand" "m,m")
3611 (parallel [(match_operand:QI 2 "const_0_to_1_operand" "n,n")])))
3612 (clobber (match_scratch:P 3 "=&b,&b"))]
3613 "TARGET_POWERPC64 && VECTOR_MEM_VSX_P (<VSX_D:MODE>mode)"
3614 "#"
3615 "&& reload_completed"
3616 [(set (match_dup 0) (match_dup 4))]
3617 {
3618 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
3619 operands[3], <VSX_D:VEC_base>mode);
3620 }
3621 [(set_attr "type" "fpload,load")
3622 (set_attr "length" "8")])
3623
3624 ;; Optimize storing a single scalar element that is the right location to
3625 ;; memory
3626 (define_insn "*vsx_extract_<mode>_store"
3627 [(set (match_operand:<VEC_base> 0 "memory_operand" "=m,Z,wY")
3628 (vec_select:<VEC_base>
3629 (match_operand:VSX_D 1 "register_operand" "d,v,v")
3630 (parallel [(match_operand:QI 2 "vsx_scalar_64bit" "n,n,n")])))]
3631 "VECTOR_MEM_VSX_P (<MODE>mode)
3632 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 0 : 1)"
3633 "@
3634 stfd%U0%X0 %1,%0
3635 stxsdx %x1,%y0
3636 stxsd %1,%0"
3637 [(set_attr "type" "fpstore")
3638 (set_attr "isa" "*,p7v,p9v")])
3639
3640 ;; Variable V2DI/V2DF extract shift
3641 (define_insn "vsx_vslo_<mode>"
3642 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=v")
3643 (unspec:<VEC_base> [(match_operand:VSX_D 1 "gpc_reg_operand" "v")
3644 (match_operand:V2DI 2 "gpc_reg_operand" "v")]
3645 UNSPEC_VSX_VSLO))]
3646 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
3647 "vslo %0,%1,%2"
3648 [(set_attr "type" "vecperm")])
3649
3650 ;; Variable V2DI/V2DF extract from a register
3651 (define_insn_and_split "vsx_extract_<mode>_var"
3652 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=v")
3653 (unspec:<VEC_base> [(match_operand:VSX_D 1 "gpc_reg_operand" "v")
3654 (match_operand:DI 2 "gpc_reg_operand" "r")]
3655 UNSPEC_VSX_EXTRACT))
3656 (clobber (match_scratch:DI 3 "=r"))
3657 (clobber (match_scratch:V2DI 4 "=&v"))]
3658 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
3659 "#"
3660 "&& reload_completed"
3661 [(const_int 0)]
3662 {
3663 rs6000_split_vec_extract_var (operands[0], operands[1], operands[2],
3664 operands[3], operands[4]);
3665 DONE;
3666 })
3667
3668 ;; Variable V2DI/V2DF extract from memory
3669 (define_insn_and_split "*vsx_extract_<mode>_var_load"
3670 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=wa,r")
3671 (unspec:<VEC_base> [(match_operand:VSX_D 1 "memory_operand" "Q,Q")
3672 (match_operand:DI 2 "gpc_reg_operand" "r,r")]
3673 UNSPEC_VSX_EXTRACT))
3674 (clobber (match_scratch:DI 3 "=&b,&b"))]
3675 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
3676 "#"
3677 "&& reload_completed"
3678 [(set (match_dup 0) (match_dup 4))]
3679 {
3680 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
3681 operands[3], <VEC_base>mode);
3682 }
3683 [(set_attr "type" "fpload,load")])
3684
3685 ;; Extract a SF element from V4SF
3686 (define_insn_and_split "vsx_extract_v4sf"
3687 [(set (match_operand:SF 0 "vsx_register_operand" "=wa")
3688 (vec_select:SF
3689 (match_operand:V4SF 1 "vsx_register_operand" "wa")
3690 (parallel [(match_operand:QI 2 "u5bit_cint_operand" "n")])))
3691 (clobber (match_scratch:V4SF 3 "=0"))]
3692 "VECTOR_UNIT_VSX_P (V4SFmode)"
3693 "#"
3694 "&& 1"
3695 [(const_int 0)]
3696 {
3697 rtx op0 = operands[0];
3698 rtx op1 = operands[1];
3699 rtx op2 = operands[2];
3700 rtx op3 = operands[3];
3701 rtx tmp;
3702 HOST_WIDE_INT ele = BYTES_BIG_ENDIAN ? INTVAL (op2) : 3 - INTVAL (op2);
3703
3704 if (ele == 0)
3705 tmp = op1;
3706 else
3707 {
3708 if (GET_CODE (op3) == SCRATCH)
3709 op3 = gen_reg_rtx (V4SFmode);
3710 emit_insn (gen_vsx_xxsldwi_v4sf (op3, op1, op1, GEN_INT (ele)));
3711 tmp = op3;
3712 }
3713 emit_insn (gen_vsx_xscvspdp_scalar2 (op0, tmp));
3714 DONE;
3715 }
3716 [(set_attr "length" "8")
3717 (set_attr "type" "fp")])
3718
3719 (define_insn_and_split "*vsx_extract_v4sf_<mode>_load"
3720 [(set (match_operand:SF 0 "register_operand" "=f,v,v,?r")
3721 (vec_select:SF
3722 (match_operand:V4SF 1 "memory_operand" "m,Z,m,m")
3723 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "n,n,n,n")])))
3724 (clobber (match_scratch:P 3 "=&b,&b,&b,&b"))]
3725 "VECTOR_MEM_VSX_P (V4SFmode)"
3726 "#"
3727 "&& reload_completed"
3728 [(set (match_dup 0) (match_dup 4))]
3729 {
3730 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
3731 operands[3], SFmode);
3732 }
3733 [(set_attr "type" "fpload,fpload,fpload,load")
3734 (set_attr "length" "8")
3735 (set_attr "isa" "*,p7v,p9v,*")])
3736
3737 ;; Variable V4SF extract from a register
3738 (define_insn_and_split "vsx_extract_v4sf_var"
3739 [(set (match_operand:SF 0 "gpc_reg_operand" "=wa")
3740 (unspec:SF [(match_operand:V4SF 1 "gpc_reg_operand" "v")
3741 (match_operand:DI 2 "gpc_reg_operand" "r")]
3742 UNSPEC_VSX_EXTRACT))
3743 (clobber (match_scratch:DI 3 "=r"))
3744 (clobber (match_scratch:V2DI 4 "=&v"))]
3745 "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_DIRECT_MOVE_64BIT"
3746 "#"
3747 "&& reload_completed"
3748 [(const_int 0)]
3749 {
3750 rs6000_split_vec_extract_var (operands[0], operands[1], operands[2],
3751 operands[3], operands[4]);
3752 DONE;
3753 })
3754
3755 ;; Variable V4SF extract from memory
3756 (define_insn_and_split "*vsx_extract_v4sf_var_load"
3757 [(set (match_operand:SF 0 "gpc_reg_operand" "=wa,?r")
3758 (unspec:SF [(match_operand:V4SF 1 "memory_operand" "Q,Q")
3759 (match_operand:DI 2 "gpc_reg_operand" "r,r")]
3760 UNSPEC_VSX_EXTRACT))
3761 (clobber (match_scratch:DI 3 "=&b,&b"))]
3762 "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_DIRECT_MOVE_64BIT"
3763 "#"
3764 "&& reload_completed"
3765 [(set (match_dup 0) (match_dup 4))]
3766 {
3767 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
3768 operands[3], SFmode);
3769 }
3770 [(set_attr "type" "fpload,load")])
3771
3772 ;; Expand the builtin form of xxpermdi to canonical rtl.
3773 (define_expand "vsx_xxpermdi_<mode>"
3774 [(match_operand:VSX_L 0 "vsx_register_operand")
3775 (match_operand:VSX_L 1 "vsx_register_operand")
3776 (match_operand:VSX_L 2 "vsx_register_operand")
3777 (match_operand:QI 3 "u5bit_cint_operand")]
3778 "VECTOR_MEM_VSX_P (<MODE>mode)"
3779 {
3780 rtx target = operands[0];
3781 rtx op0 = operands[1];
3782 rtx op1 = operands[2];
3783 int mask = INTVAL (operands[3]);
3784 rtx perm0 = GEN_INT ((mask >> 1) & 1);
3785 rtx perm1 = GEN_INT ((mask & 1) + 2);
3786 rtx (*gen) (rtx, rtx, rtx, rtx, rtx);
3787
3788 if (<MODE>mode == V2DFmode)
3789 gen = gen_vsx_xxpermdi2_v2df_1;
3790 else
3791 {
3792 gen = gen_vsx_xxpermdi2_v2di_1;
3793 if (<MODE>mode != V2DImode)
3794 {
3795 target = gen_lowpart (V2DImode, target);
3796 op0 = gen_lowpart (V2DImode, op0);
3797 op1 = gen_lowpart (V2DImode, op1);
3798 }
3799 }
3800 emit_insn (gen (target, op0, op1, perm0, perm1));
3801 DONE;
3802 })
3803
3804 ;; Special version of xxpermdi that retains big-endian semantics.
3805 (define_expand "vsx_xxpermdi_<mode>_be"
3806 [(match_operand:VSX_L 0 "vsx_register_operand")
3807 (match_operand:VSX_L 1 "vsx_register_operand")
3808 (match_operand:VSX_L 2 "vsx_register_operand")
3809 (match_operand:QI 3 "u5bit_cint_operand")]
3810 "VECTOR_MEM_VSX_P (<MODE>mode)"
3811 {
3812 rtx target = operands[0];
3813 rtx op0 = operands[1];
3814 rtx op1 = operands[2];
3815 int mask = INTVAL (operands[3]);
3816 rtx perm0 = GEN_INT ((mask >> 1) & 1);
3817 rtx perm1 = GEN_INT ((mask & 1) + 2);
3818 rtx (*gen) (rtx, rtx, rtx, rtx, rtx);
3819
3820 if (<MODE>mode == V2DFmode)
3821 gen = gen_vsx_xxpermdi2_v2df_1;
3822 else
3823 {
3824 gen = gen_vsx_xxpermdi2_v2di_1;
3825 if (<MODE>mode != V2DImode)
3826 {
3827 target = gen_lowpart (V2DImode, target);
3828 op0 = gen_lowpart (V2DImode, op0);
3829 op1 = gen_lowpart (V2DImode, op1);
3830 }
3831 }
3832 /* In little endian mode, vsx_xxpermdi2_<mode>_1 will perform a
3833 transformation we don't want; it is necessary for
3834 rs6000_expand_vec_perm_const_1 but not for this use. So we
3835 prepare for that by reversing the transformation here. */
3836 if (BYTES_BIG_ENDIAN)
3837 emit_insn (gen (target, op0, op1, perm0, perm1));
3838 else
3839 {
3840 rtx p0 = GEN_INT (3 - INTVAL (perm1));
3841 rtx p1 = GEN_INT (3 - INTVAL (perm0));
3842 emit_insn (gen (target, op1, op0, p0, p1));
3843 }
3844 DONE;
3845 })
3846
3847 (define_insn "vsx_xxpermdi2_<mode>_1"
3848 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
3849 (vec_select:VSX_D
3850 (vec_concat:<VS_double>
3851 (match_operand:VSX_D 1 "vsx_register_operand" "wa")
3852 (match_operand:VSX_D 2 "vsx_register_operand" "wa"))
3853 (parallel [(match_operand 3 "const_0_to_1_operand" "")
3854 (match_operand 4 "const_2_to_3_operand" "")])))]
3855 "VECTOR_MEM_VSX_P (<MODE>mode)"
3856 {
3857 int op3, op4, mask;
3858
3859 /* For little endian, swap operands and invert/swap selectors
3860 to get the correct xxpermdi. The operand swap sets up the
3861 inputs as a little endian array. The selectors are swapped
3862 because they are defined to use big endian ordering. The
3863 selectors are inverted to get the correct doublewords for
3864 little endian ordering. */
3865 if (BYTES_BIG_ENDIAN)
3866 {
3867 op3 = INTVAL (operands[3]);
3868 op4 = INTVAL (operands[4]);
3869 }
3870 else
3871 {
3872 op3 = 3 - INTVAL (operands[4]);
3873 op4 = 3 - INTVAL (operands[3]);
3874 }
3875
3876 mask = (op3 << 1) | (op4 - 2);
3877 operands[3] = GEN_INT (mask);
3878
3879 if (BYTES_BIG_ENDIAN)
3880 return "xxpermdi %x0,%x1,%x2,%3";
3881 else
3882 return "xxpermdi %x0,%x2,%x1,%3";
3883 }
3884 [(set_attr "type" "vecperm")])
3885
3886 ;; Extraction of a single element in a small integer vector. Until ISA 3.0,
3887 ;; none of the small types were allowed in a vector register, so we had to
3888 ;; extract to a DImode and either do a direct move or store.
3889 (define_expand "vsx_extract_<mode>"
3890 [(parallel [(set (match_operand:<VEC_base> 0 "gpc_reg_operand")
3891 (vec_select:<VEC_base>
3892 (match_operand:VSX_EXTRACT_I2 1 "gpc_reg_operand")
3893 (parallel [(match_operand:QI 2 "const_int_operand")])))
3894 (clobber (match_scratch:VSX_EXTRACT_I2 3))])]
3895 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
3896 {
3897 /* If we have ISA 3.0, we can do a xxextractuw/vextractu{b,h}. */
3898 if (TARGET_P9_VECTOR)
3899 {
3900 emit_insn (gen_vsx_extract_<mode>_p9 (operands[0], operands[1],
3901 operands[2]));
3902 DONE;
3903 }
3904 })
3905
3906 (define_expand "vsx_extract_v4si"
3907 [(parallel [(set (match_operand:SI 0 "gpc_reg_operand")
3908 (vec_select:SI
3909 (match_operand:V4SI 1 "gpc_reg_operand")
3910 (parallel [(match_operand:QI 2 "const_0_to_3_operand")])))
3911 (clobber (match_scratch:V4SI 3))])]
3912 "TARGET_DIRECT_MOVE_64BIT"
3913 {
3914 /* The word 1 (BE order) can be extracted by mfvsrwz/stxsiwx. So just
3915 fall through to vsx_extract_v4si_w1. */
3916 if (TARGET_P9_VECTOR
3917 && INTVAL (operands[2]) != (BYTES_BIG_ENDIAN ? 1 : 2))
3918 {
3919 emit_insn (gen_vsx_extract_v4si_p9 (operands[0], operands[1],
3920 operands[2]));
3921 DONE;
3922 }
3923 })
3924
3925 ;; Extract from word 1 (BE order).
3926 (define_insn "vsx_extract_v4si_w1"
3927 [(set (match_operand:SI 0 "nonimmediate_operand" "=r,wa,Z,wa")
3928 (vec_select:SI
3929 (match_operand:V4SI 1 "gpc_reg_operand" "v,v,v,0")
3930 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "n,n,n,n")])))
3931 (clobber (match_scratch:V4SI 3 "=v,v,v,v"))]
3932 "TARGET_DIRECT_MOVE_64BIT
3933 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 1 : 2)"
3934 {
3935 if (which_alternative == 0)
3936 return "mfvsrwz %0,%x1";
3937
3938 if (which_alternative == 1)
3939 return "xxlor %x0,%x1,%x1";
3940
3941 if (which_alternative == 2)
3942 return "stxsiwx %x1,%y0";
3943
3944 return ASM_COMMENT_START " vec_extract to same register";
3945 }
3946 [(set_attr "type" "mfvsr,veclogical,fpstore,*")
3947 (set_attr "length" "4,4,4,0")
3948 (set_attr "isa" "p8v,*,p8v,*")])
3949
3950 (define_insn "*mfvsrwz"
3951 [(set (match_operand:DI 0 "register_operand" "=r")
3952 (zero_extend:DI
3953 (vec_select:SI
3954 (match_operand:V4SI 1 "vsx_register_operand" "wa")
3955 (parallel [(match_operand:QI 2 "const_int_operand" "n")]))))
3956 (clobber (match_scratch:V4SI 3 "=v"))]
3957 "TARGET_DIRECT_MOVE_64BIT
3958 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 1 : 2)"
3959 "mfvsrwz %0,%x1"
3960 [(set_attr "type" "mfvsr")
3961 (set_attr "isa" "p8v")])
3962
3963 (define_insn "vsx_extract_<mode>_p9"
3964 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=r,<VSX_EX>")
3965 (vec_select:<VEC_base>
3966 (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v,<VSX_EX>")
3967 (parallel [(match_operand:QI 2 "<VSX_EXTRACT_PREDICATE>" "n,n")])))
3968 (clobber (match_scratch:SI 3 "=r,X"))]
3969 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_VEXTRACTUB"
3970 {
3971 if (which_alternative == 0)
3972 return "#";
3973
3974 else
3975 {
3976 HOST_WIDE_INT elt = INTVAL (operands[2]);
3977 HOST_WIDE_INT elt_adj = (!BYTES_BIG_ENDIAN
3978 ? GET_MODE_NUNITS (<MODE>mode) - 1 - elt
3979 : elt);
3980
3981 HOST_WIDE_INT unit_size = GET_MODE_UNIT_SIZE (<MODE>mode);
3982 HOST_WIDE_INT offset = unit_size * elt_adj;
3983
3984 operands[2] = GEN_INT (offset);
3985 if (unit_size == 4)
3986 return "xxextractuw %x0,%x1,%2";
3987 else
3988 return "vextractu<wd> %0,%1,%2";
3989 }
3990 }
3991 [(set_attr "type" "vecsimple")
3992 (set_attr "isa" "p9v,*")])
3993
3994 (define_split
3995 [(set (match_operand:<VEC_base> 0 "int_reg_operand")
3996 (vec_select:<VEC_base>
3997 (match_operand:VSX_EXTRACT_I 1 "altivec_register_operand")
3998 (parallel [(match_operand:QI 2 "const_int_operand")])))
3999 (clobber (match_operand:SI 3 "int_reg_operand"))]
4000 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_VEXTRACTUB && reload_completed"
4001 [(const_int 0)]
4002 {
4003 rtx op0_si = gen_rtx_REG (SImode, REGNO (operands[0]));
4004 rtx op1 = operands[1];
4005 rtx op2 = operands[2];
4006 rtx op3 = operands[3];
4007 HOST_WIDE_INT offset = INTVAL (op2) * GET_MODE_UNIT_SIZE (<MODE>mode);
4008
4009 emit_move_insn (op3, GEN_INT (offset));
4010 if (BYTES_BIG_ENDIAN)
4011 emit_insn (gen_vextu<wd>lx (op0_si, op3, op1));
4012 else
4013 emit_insn (gen_vextu<wd>rx (op0_si, op3, op1));
4014 DONE;
4015 })
4016
4017 ;; Optimize zero extracts to eliminate the AND after the extract.
4018 (define_insn_and_split "*vsx_extract_<mode>_di_p9"
4019 [(set (match_operand:DI 0 "gpc_reg_operand" "=r,<VSX_EX>")
4020 (zero_extend:DI
4021 (vec_select:<VEC_base>
4022 (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v,<VSX_EX>")
4023 (parallel [(match_operand:QI 2 "const_int_operand" "n,n")]))))
4024 (clobber (match_scratch:SI 3 "=r,X"))]
4025 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_VEXTRACTUB"
4026 "#"
4027 "&& reload_completed"
4028 [(parallel [(set (match_dup 4)
4029 (vec_select:<VEC_base>
4030 (match_dup 1)
4031 (parallel [(match_dup 2)])))
4032 (clobber (match_dup 3))])]
4033 {
4034 gcc_assert (<MODE>mode != V4SImode
4035 || INTVAL (operands[2]) != (BYTES_BIG_ENDIAN ? 1 : 2));
4036
4037 operands[4] = gen_rtx_REG (<VEC_base>mode, REGNO (operands[0]));
4038 }
4039 [(set_attr "isa" "p9v,*")])
4040
4041 ;; Optimize stores to use the ISA 3.0 scalar store instructions
4042 (define_insn_and_split "*vsx_extract_<mode>_store_p9"
4043 [(set (match_operand:<VEC_base> 0 "memory_operand" "=Z,m")
4044 (vec_select:<VEC_base>
4045 (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "<VSX_EX>,v")
4046 (parallel [(match_operand:QI 2 "const_int_operand" "n,n")])))
4047 (clobber (match_scratch:<VEC_base> 3 "=<VSX_EX>,&*r"))
4048 (clobber (match_scratch:SI 4 "=X,&r"))]
4049 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_VEXTRACTUB"
4050 "#"
4051 "&& reload_completed"
4052 [(parallel [(set (match_dup 3)
4053 (vec_select:<VEC_base>
4054 (match_dup 1)
4055 (parallel [(match_dup 2)])))
4056 (clobber (match_dup 4))])
4057 (set (match_dup 0)
4058 (match_dup 3))]
4059 {
4060 if (which_alternative == 0
4061 && ((<MODE>mode == V16QImode
4062 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 7 : 8))
4063 || (<MODE>mode == V8HImode
4064 && INTVAL (operands[2]) == (BYTES_BIG_ENDIAN ? 3 : 4))))
4065 {
4066 enum machine_mode dest_mode = GET_MODE (operands[0]);
4067 emit_move_insn (operands[0],
4068 gen_rtx_REG (dest_mode, REGNO (operands[3])));
4069 DONE;
4070 }
4071 })
4072
4073
4074 ;; Extract from word 0, 2, 3 (BE order).
4075 (define_insn_and_split "*vsx_extract_v4si_w023"
4076 [(set (match_operand:SI 0 "nonimmediate_operand" "=r,wa,Z")
4077 (vec_select:SI
4078 (match_operand:V4SI 1 "gpc_reg_operand" "v,v,v")
4079 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "n,n,n")])))
4080 (clobber (match_scratch:V4SI 3 "=v,v,v"))]
4081 "TARGET_DIRECT_MOVE_64BIT"
4082 "#"
4083 "&& INTVAL (operands[2]) != (BYTES_BIG_ENDIAN ? 1 : 2)"
4084 [(const_int 0)]
4085 {
4086 gcc_assert (!TARGET_P9_VECTOR);
4087
4088 rtx dest = operands[0];
4089 rtx src = operands[1];
4090 rtx element = operands[2];
4091 rtx vec_tmp;
4092
4093 if (GET_CODE (operands[3]) == SCRATCH)
4094 vec_tmp = gen_reg_rtx (V4SImode);
4095 else
4096 vec_tmp = operands[3];
4097
4098 /* Adjust index for LE element ordering, the below minuend 3 is computed by
4099 GET_MODE_NUNITS (V4SImode) - 1. */
4100 if (!BYTES_BIG_ENDIAN)
4101 element = GEN_INT (3 - INTVAL (element));
4102
4103 emit_insn (gen_altivec_vspltw_direct (vec_tmp, src, element));
4104
4105 int value = BYTES_BIG_ENDIAN ? 1 : 2;
4106 emit_insn (gen_vsx_extract_v4si_w1 (dest, vec_tmp, GEN_INT (value)));
4107
4108 DONE;
4109 })
4110
4111 (define_insn_and_split "*vsx_extract_<mode>_p8"
4112 [(set (match_operand:<VEC_base> 0 "nonimmediate_operand" "=r")
4113 (vec_select:<VEC_base>
4114 (match_operand:VSX_EXTRACT_I2 1 "gpc_reg_operand" "v")
4115 (parallel [(match_operand:QI 2 "<VSX_EXTRACT_PREDICATE>" "n")])))
4116 (clobber (match_scratch:VSX_EXTRACT_I2 3 "=v"))]
4117 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT
4118 && !TARGET_P9_VECTOR"
4119 "#"
4120 "&& reload_completed"
4121 [(const_int 0)]
4122 {
4123 rtx dest = operands[0];
4124 rtx src = operands[1];
4125 rtx element = operands[2];
4126 rtx vec_tmp = operands[3];
4127 int value;
4128
4129 if (!BYTES_BIG_ENDIAN)
4130 element = GEN_INT (GET_MODE_NUNITS (<MODE>mode) - 1 - INTVAL (element));
4131
4132 /* If the value is in the correct position, we can avoid doing the VSPLT<x>
4133 instruction. */
4134 value = INTVAL (element);
4135 if (<MODE>mode == V16QImode)
4136 {
4137 if (value != 7)
4138 emit_insn (gen_altivec_vspltb_direct (vec_tmp, src, element));
4139 else
4140 vec_tmp = src;
4141 }
4142 else if (<MODE>mode == V8HImode)
4143 {
4144 if (value != 3)
4145 emit_insn (gen_altivec_vsplth_direct (vec_tmp, src, element));
4146 else
4147 vec_tmp = src;
4148 }
4149 else
4150 gcc_unreachable ();
4151
4152 emit_move_insn (gen_rtx_REG (DImode, REGNO (dest)),
4153 gen_rtx_REG (DImode, REGNO (vec_tmp)));
4154 DONE;
4155 }
4156 [(set_attr "type" "mfvsr")])
4157
4158 ;; Optimize extracting a single scalar element from memory.
4159 (define_insn_and_split "*vsx_extract_<mode>_load"
4160 [(set (match_operand:<VEC_base> 0 "register_operand" "=r")
4161 (vec_select:<VEC_base>
4162 (match_operand:VSX_EXTRACT_I 1 "memory_operand" "m")
4163 (parallel [(match_operand:QI 2 "<VSX_EXTRACT_PREDICATE>" "n")])))
4164 (clobber (match_scratch:DI 3 "=&b"))]
4165 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
4166 "#"
4167 "&& reload_completed"
4168 [(set (match_dup 0) (match_dup 4))]
4169 {
4170 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
4171 operands[3], <VEC_base>mode);
4172 }
4173 [(set_attr "type" "load")
4174 (set_attr "length" "8")])
4175
4176 ;; Variable V16QI/V8HI/V4SI extract from a register
4177 (define_insn_and_split "vsx_extract_<mode>_var"
4178 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=r,r")
4179 (unspec:<VEC_base>
4180 [(match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v,v")
4181 (match_operand:DI 2 "gpc_reg_operand" "r,r")]
4182 UNSPEC_VSX_EXTRACT))
4183 (clobber (match_scratch:DI 3 "=r,r"))
4184 (clobber (match_scratch:V2DI 4 "=X,&v"))]
4185 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
4186 "#"
4187 "&& reload_completed"
4188 [(const_int 0)]
4189 {
4190 rs6000_split_vec_extract_var (operands[0], operands[1], operands[2],
4191 operands[3], operands[4]);
4192 DONE;
4193 }
4194 [(set_attr "isa" "p9v,*")])
4195
4196 ;; Variable V16QI/V8HI/V4SI extract from memory
4197 (define_insn_and_split "*vsx_extract_<mode>_var_load"
4198 [(set (match_operand:<VEC_base> 0 "gpc_reg_operand" "=r")
4199 (unspec:<VEC_base>
4200 [(match_operand:VSX_EXTRACT_I 1 "memory_operand" "Q")
4201 (match_operand:DI 2 "gpc_reg_operand" "r")]
4202 UNSPEC_VSX_EXTRACT))
4203 (clobber (match_scratch:DI 3 "=&b"))]
4204 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
4205 "#"
4206 "&& reload_completed"
4207 [(set (match_dup 0) (match_dup 4))]
4208 {
4209 operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
4210 operands[3], <VEC_base>mode);
4211 }
4212 [(set_attr "type" "load")])
4213
4214 ;; ISA 3.1 extract
4215 (define_expand "vextractl<mode>"
4216 [(set (match_operand:V2DI 0 "altivec_register_operand")
4217 (unspec:V2DI [(match_operand:VI2 1 "altivec_register_operand")
4218 (match_operand:VI2 2 "altivec_register_operand")
4219 (match_operand:SI 3 "register_operand")]
4220 UNSPEC_EXTRACTL))]
4221 "TARGET_POWER10"
4222 {
4223 if (BYTES_BIG_ENDIAN)
4224 {
4225 emit_insn (gen_vextractl<mode>_internal (operands[0], operands[1],
4226 operands[2], operands[3]));
4227 emit_insn (gen_xxswapd_v2di (operands[0], operands[0]));
4228 }
4229 else
4230 emit_insn (gen_vextractr<mode>_internal (operands[0], operands[2],
4231 operands[1], operands[3]));
4232 DONE;
4233 })
4234
4235 (define_insn "vextractl<mode>_internal"
4236 [(set (match_operand:V2DI 0 "altivec_register_operand" "=v")
4237 (unspec:V2DI [(match_operand:VEC_I 1 "altivec_register_operand" "v")
4238 (match_operand:VEC_I 2 "altivec_register_operand" "v")
4239 (match_operand:SI 3 "register_operand" "r")]
4240 UNSPEC_EXTRACTL))]
4241 "TARGET_POWER10"
4242 "vext<du_or_d><wd>vlx %0,%1,%2,%3"
4243 [(set_attr "type" "vecsimple")])
4244
4245 (define_expand "vextractr<mode>"
4246 [(set (match_operand:V2DI 0 "altivec_register_operand")
4247 (unspec:V2DI [(match_operand:VI2 1 "altivec_register_operand")
4248 (match_operand:VI2 2 "altivec_register_operand")
4249 (match_operand:SI 3 "register_operand")]
4250 UNSPEC_EXTRACTR))]
4251 "TARGET_POWER10"
4252 {
4253 if (BYTES_BIG_ENDIAN)
4254 {
4255 emit_insn (gen_vextractr<mode>_internal (operands[0], operands[1],
4256 operands[2], operands[3]));
4257 emit_insn (gen_xxswapd_v2di (operands[0], operands[0]));
4258 }
4259 else
4260 emit_insn (gen_vextractl<mode>_internal (operands[0], operands[2],
4261 operands[1], operands[3]));
4262 DONE;
4263 })
4264
4265 (define_insn "vextractr<mode>_internal"
4266 [(set (match_operand:V2DI 0 "altivec_register_operand" "=v")
4267 (unspec:V2DI [(match_operand:VEC_I 1 "altivec_register_operand" "v")
4268 (match_operand:VEC_I 2 "altivec_register_operand" "v")
4269 (match_operand:SI 3 "register_operand" "r")]
4270 UNSPEC_EXTRACTR))]
4271 "TARGET_POWER10"
4272 "vext<du_or_d><wd>vrx %0,%1,%2,%3"
4273 [(set_attr "type" "vecsimple")])
4274
4275 (define_expand "vinsertvl_<mode>"
4276 [(set (match_operand:VI2 0 "altivec_register_operand")
4277 (unspec:VI2 [(match_operand:VI2 1 "altivec_register_operand")
4278 (match_operand:VI2 2 "altivec_register_operand")
4279 (match_operand:SI 3 "register_operand" "r")]
4280 UNSPEC_INSERTL))]
4281 "TARGET_POWER10"
4282 {
4283 if (BYTES_BIG_ENDIAN)
4284 emit_insn (gen_vinsertvl_internal_<mode> (operands[0], operands[3],
4285 operands[1], operands[2]));
4286 else
4287 emit_insn (gen_vinsertvr_internal_<mode> (operands[0], operands[3],
4288 operands[1], operands[2]));
4289 DONE;
4290 })
4291
4292 (define_insn "vinsertvl_internal_<mode>"
4293 [(set (match_operand:VEC_I 0 "altivec_register_operand" "=v")
4294 (unspec:VEC_I [(match_operand:SI 1 "register_operand" "r")
4295 (match_operand:VEC_I 2 "altivec_register_operand" "v")
4296 (match_operand:VEC_I 3 "altivec_register_operand" "0")]
4297 UNSPEC_INSERTL))]
4298 "TARGET_POWER10"
4299 "vins<wd>vlx %0,%1,%2"
4300 [(set_attr "type" "vecsimple")])
4301
4302 (define_expand "vinsertvr_<mode>"
4303 [(set (match_operand:VI2 0 "altivec_register_operand")
4304 (unspec:VI2 [(match_operand:VI2 1 "altivec_register_operand")
4305 (match_operand:VI2 2 "altivec_register_operand")
4306 (match_operand:SI 3 "register_operand" "r")]
4307 UNSPEC_INSERTR))]
4308 "TARGET_POWER10"
4309 {
4310 if (BYTES_BIG_ENDIAN)
4311 emit_insn (gen_vinsertvr_internal_<mode> (operands[0], operands[3],
4312 operands[1], operands[2]));
4313 else
4314 emit_insn (gen_vinsertvl_internal_<mode> (operands[0], operands[3],
4315 operands[1], operands[2]));
4316 DONE;
4317 })
4318
4319 (define_insn "vinsertvr_internal_<mode>"
4320 [(set (match_operand:VEC_I 0 "altivec_register_operand" "=v")
4321 (unspec:VEC_I [(match_operand:SI 1 "register_operand" "r")
4322 (match_operand:VEC_I 2 "altivec_register_operand" "v")
4323 (match_operand:VEC_I 3 "altivec_register_operand" "0")]
4324 UNSPEC_INSERTR))]
4325 "TARGET_POWER10"
4326 "vins<wd>vrx %0,%1,%2"
4327 [(set_attr "type" "vecsimple")])
4328
4329 (define_expand "vinsertgl_<mode>"
4330 [(set (match_operand:VI2 0 "altivec_register_operand")
4331 (unspec:VI2 [(match_operand:SI 1 "register_operand")
4332 (match_operand:VI2 2 "altivec_register_operand")
4333 (match_operand:SI 3 "register_operand")]
4334 UNSPEC_INSERTL))]
4335 "TARGET_POWER10"
4336 {
4337 if (BYTES_BIG_ENDIAN)
4338 emit_insn (gen_vinsertgl_internal_<mode> (operands[0], operands[3],
4339 operands[1], operands[2]));
4340 else
4341 emit_insn (gen_vinsertgr_internal_<mode> (operands[0], operands[3],
4342 operands[1], operands[2]));
4343 DONE;
4344 })
4345
4346 (define_insn "vinsertgl_internal_<mode>"
4347 [(set (match_operand:VEC_I 0 "altivec_register_operand" "=v")
4348 (unspec:VEC_I [(match_operand:SI 1 "register_operand" "r")
4349 (match_operand:SI 2 "register_operand" "r")
4350 (match_operand:VEC_I 3 "altivec_register_operand" "0")]
4351 UNSPEC_INSERTL))]
4352 "TARGET_POWER10"
4353 "vins<wd>lx %0,%1,%2"
4354 [(set_attr "type" "vecsimple")])
4355
4356 (define_expand "vinsertgr_<mode>"
4357 [(set (match_operand:VI2 0 "altivec_register_operand")
4358 (unspec:VI2 [(match_operand:SI 1 "register_operand")
4359 (match_operand:VI2 2 "altivec_register_operand")
4360 (match_operand:SI 3 "register_operand")]
4361 UNSPEC_INSERTR))]
4362 "TARGET_POWER10"
4363 {
4364 if (BYTES_BIG_ENDIAN)
4365 emit_insn (gen_vinsertgr_internal_<mode> (operands[0], operands[3],
4366 operands[1], operands[2]));
4367 else
4368 emit_insn (gen_vinsertgl_internal_<mode> (operands[0], operands[3],
4369 operands[1], operands[2]));
4370 DONE;
4371 })
4372
4373 (define_insn "vinsertgr_internal_<mode>"
4374 [(set (match_operand:VEC_I 0 "altivec_register_operand" "=v")
4375 (unspec:VEC_I [(match_operand:SI 1 "register_operand" "r")
4376 (match_operand:SI 2 "register_operand" "r")
4377 (match_operand:VEC_I 3 "altivec_register_operand" "0")]
4378 UNSPEC_INSERTR))]
4379 "TARGET_POWER10"
4380 "vins<wd>rx %0,%1,%2"
4381 [(set_attr "type" "vecsimple")])
4382
4383 (define_expand "vreplace_elt_<mode>"
4384 [(set (match_operand:REPLACE_ELT_V 0 "register_operand")
4385 (unspec:REPLACE_ELT_V [(match_operand:REPLACE_ELT_V 1 "register_operand")
4386 (match_operand:<VEC_base> 2 "register_operand")
4387 (match_operand:QI 3 "const_0_to_3_operand")]
4388 UNSPEC_REPLACE_ELT))]
4389 "TARGET_POWER10"
4390 {
4391 int index;
4392 /* Immediate value is the word index, convert to byte index and adjust for
4393 Endianness if needed. */
4394 if (BYTES_BIG_ENDIAN)
4395 index = INTVAL (operands[3]) << <REPLACE_ELT_sh>;
4396
4397 else
4398 index = <REPLACE_ELT_max> - (INTVAL (operands[3]) << <REPLACE_ELT_sh>);
4399
4400 emit_insn (gen_vreplace_elt_<mode>_inst (operands[0], operands[1],
4401 operands[2],
4402 GEN_INT (index)));
4403 DONE;
4404 }
4405 [(set_attr "type" "vecsimple")])
4406
4407 (define_insn "vreplace_elt_<mode>_inst"
4408 [(set (match_operand:REPLACE_ELT_V 0 "register_operand" "=v")
4409 (unspec:REPLACE_ELT_V [(match_operand:REPLACE_ELT_V 1 "register_operand" "0")
4410 (match_operand:<VEC_base> 2 "register_operand" "r")
4411 (match_operand:QI 3 "const_0_to_12_operand" "n")]
4412 UNSPEC_REPLACE_ELT))]
4413 "TARGET_POWER10"
4414 "vins<REPLACE_ELT_char> %0,%2,%3"
4415 [(set_attr "type" "vecsimple")])
4416
4417 (define_insn "vreplace_un_<mode>"
4418 [(set (match_operand:V16QI 0 "register_operand" "=v")
4419 (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "0")
4420 (match_operand:REPLACE_ELT 2 "register_operand" "r")
4421 (match_operand:QI 3 "const_0_to_12_operand" "n")]
4422 UNSPEC_REPLACE_UN))]
4423 "TARGET_POWER10"
4424 "vins<REPLACE_ELT_char> %0,%2,%3"
4425 [(set_attr "type" "vecsimple")])
4426
4427 ;; VSX_EXTRACT optimizations
4428 ;; Optimize double d = (double) vec_extract (vi, <n>)
4429 ;; Get the element into the top position and use XVCVSWDP/XVCVUWDP
4430 (define_insn_and_split "*vsx_extract_si_<uns>float_df"
4431 [(set (match_operand:DF 0 "gpc_reg_operand" "=wa")
4432 (any_float:DF
4433 (vec_select:SI
4434 (match_operand:V4SI 1 "gpc_reg_operand" "v")
4435 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "n")]))))
4436 (clobber (match_scratch:V4SI 3 "=v"))]
4437 "VECTOR_MEM_VSX_P (V4SImode) && TARGET_DIRECT_MOVE_64BIT"
4438 "#"
4439 "&& 1"
4440 [(const_int 0)]
4441 {
4442 rtx dest = operands[0];
4443 rtx src = operands[1];
4444 rtx element = operands[2];
4445 rtx v4si_tmp = operands[3];
4446 int value;
4447
4448 /* Adjust index for LE element ordering, the below minuend 3 is computed by
4449 GET_MODE_NUNITS (V4SImode) - 1. */
4450 if (!BYTES_BIG_ENDIAN)
4451 element = GEN_INT (3 - INTVAL (element));
4452
4453 /* If the value is in the correct position, we can avoid doing the VSPLT<x>
4454 instruction. */
4455 value = INTVAL (element);
4456 if (value != 0)
4457 {
4458 if (GET_CODE (v4si_tmp) == SCRATCH)
4459 v4si_tmp = gen_reg_rtx (V4SImode);
4460 emit_insn (gen_altivec_vspltw_direct (v4si_tmp, src, element));
4461 }
4462 else
4463 v4si_tmp = src;
4464
4465 emit_insn (gen_vsx_xvcv<su>xwdp_df (dest, v4si_tmp));
4466 DONE;
4467 })
4468
4469 ;; Optimize <type> f = (<type>) vec_extract (vi, <n>)
4470 ;; where <type> is a floating point type that supported by the hardware that is
4471 ;; not double. First convert the value to double, and then to the desired
4472 ;; type.
4473 (define_insn_and_split "*vsx_extract_si_<uns>float_<mode>"
4474 [(set (match_operand:VSX_EXTRACT_FL 0 "gpc_reg_operand" "=wa")
4475 (any_float:VSX_EXTRACT_FL
4476 (vec_select:SI
4477 (match_operand:V4SI 1 "gpc_reg_operand" "v")
4478 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "n")]))))
4479 (clobber (match_scratch:V4SI 3 "=v"))
4480 (clobber (match_scratch:DF 4 "=wa"))]
4481 "VECTOR_MEM_VSX_P (V4SImode) && TARGET_DIRECT_MOVE_64BIT"
4482 "#"
4483 "&& 1"
4484 [(const_int 0)]
4485 {
4486 rtx dest = operands[0];
4487 rtx src = operands[1];
4488 rtx element = operands[2];
4489 rtx v4si_tmp = operands[3];
4490 rtx df_tmp = operands[4];
4491 int value;
4492
4493 /* Adjust index for LE element ordering, the below minuend 3 is computed by
4494 GET_MODE_NUNITS (V4SImode) - 1. */
4495 if (!BYTES_BIG_ENDIAN)
4496 element = GEN_INT (3 - INTVAL (element));
4497
4498 /* If the value is in the correct position, we can avoid doing the VSPLT<x>
4499 instruction. */
4500 value = INTVAL (element);
4501 if (value != 0)
4502 {
4503 if (GET_CODE (v4si_tmp) == SCRATCH)
4504 v4si_tmp = gen_reg_rtx (V4SImode);
4505 emit_insn (gen_altivec_vspltw_direct (v4si_tmp, src, element));
4506 }
4507 else
4508 v4si_tmp = src;
4509
4510 if (GET_CODE (df_tmp) == SCRATCH)
4511 df_tmp = gen_reg_rtx (DFmode);
4512
4513 emit_insn (gen_vsx_xvcv<su>xwdp_df (df_tmp, v4si_tmp));
4514
4515 if (<MODE>mode == SFmode)
4516 emit_insn (gen_truncdfsf2 (dest, df_tmp));
4517 else if (<MODE>mode == TFmode && FLOAT128_IBM_P (TFmode))
4518 emit_insn (gen_extenddftf2_vsx (dest, df_tmp));
4519 else if (<MODE>mode == TFmode && FLOAT128_IEEE_P (TFmode)
4520 && TARGET_FLOAT128_HW)
4521 emit_insn (gen_extenddftf2_hw (dest, df_tmp));
4522 else if (<MODE>mode == IFmode && FLOAT128_IBM_P (IFmode))
4523 emit_insn (gen_extenddfif2 (dest, df_tmp));
4524 else if (<MODE>mode == KFmode && TARGET_FLOAT128_HW)
4525 emit_insn (gen_extenddfkf2_hw (dest, df_tmp));
4526 else
4527 gcc_unreachable ();
4528
4529 DONE;
4530 })
4531
4532 ;; Optimize <type> f = (<ftype>) vec_extract (<vtype>, <n>)
4533 ;; Where <ftype> is SFmode, DFmode (and KFmode/TFmode if those types are IEEE
4534 ;; 128-bit hardware types) and <vtype> is vector char, vector unsigned char,
4535 ;; vector short or vector unsigned short.
4536 (define_insn_and_split "*vsx_ext_<VSX_EXTRACT_I:VEC_base>_fl_<FL_CONV:mode>"
4537 [(set (match_operand:FL_CONV 0 "gpc_reg_operand" "=wa")
4538 (float:FL_CONV
4539 (vec_select:<VSX_EXTRACT_I:VEC_base>
4540 (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v")
4541 (parallel [(match_operand:QI 2 "const_int_operand" "n")]))))
4542 (clobber (match_scratch:<VSX_EXTRACT_I:VEC_base> 3 "=v"))]
4543 "VECTOR_MEM_VSX_P (<VSX_EXTRACT_I:MODE>mode) && TARGET_DIRECT_MOVE_64BIT
4544 && TARGET_P9_VECTOR"
4545 "#"
4546 "&& reload_completed"
4547 [(parallel [(set (match_dup 3)
4548 (vec_select:<VSX_EXTRACT_I:VEC_base>
4549 (match_dup 1)
4550 (parallel [(match_dup 2)])))
4551 (clobber (scratch:SI))])
4552 (set (match_dup 4)
4553 (sign_extend:DI (match_dup 3)))
4554 (set (match_dup 0)
4555 (float:<FL_CONV:MODE> (match_dup 4)))]
4556 {
4557 operands[4] = gen_rtx_REG (DImode, REGNO (operands[3]));
4558 }
4559 [(set_attr "isa" "<FL_CONV:VSisa>")])
4560
4561 (define_insn_and_split "*vsx_ext_<VSX_EXTRACT_I:VEC_base>_ufl_<FL_CONV:mode>"
4562 [(set (match_operand:FL_CONV 0 "gpc_reg_operand" "=wa")
4563 (unsigned_float:FL_CONV
4564 (vec_select:<VSX_EXTRACT_I:VEC_base>
4565 (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v")
4566 (parallel [(match_operand:QI 2 "const_int_operand" "n")]))))
4567 (clobber (match_scratch:<VSX_EXTRACT_I:VEC_base> 3 "=v"))]
4568 "VECTOR_MEM_VSX_P (<VSX_EXTRACT_I:MODE>mode) && TARGET_DIRECT_MOVE_64BIT
4569 && TARGET_P9_VECTOR"
4570 "#"
4571 "&& reload_completed"
4572 [(parallel [(set (match_dup 3)
4573 (vec_select:<VSX_EXTRACT_I:VEC_base>
4574 (match_dup 1)
4575 (parallel [(match_dup 2)])))
4576 (clobber (scratch:SI))])
4577 (set (match_dup 0)
4578 (float:<FL_CONV:MODE> (match_dup 4)))]
4579 {
4580 operands[4] = gen_rtx_REG (DImode, REGNO (operands[3]));
4581 }
4582 [(set_attr "isa" "<FL_CONV:VSisa>")])
4583
4584 ;; V4SI/V8HI/V16QI set operation on ISA 3.0
4585 (define_insn "vsx_set_<mode>_p9"
4586 [(set (match_operand:VSX_EXTRACT_I 0 "gpc_reg_operand" "=<VSX_EX>")
4587 (unspec:VSX_EXTRACT_I
4588 [(match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "0")
4589 (match_operand:<VEC_base> 2 "gpc_reg_operand" "<VSX_EX>")
4590 (match_operand:QI 3 "<VSX_EXTRACT_PREDICATE>" "n")]
4591 UNSPEC_VSX_SET))]
4592 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_P9_VECTOR && TARGET_POWERPC64"
4593 {
4594 int ele = INTVAL (operands[3]);
4595 int nunits = GET_MODE_NUNITS (<MODE>mode);
4596
4597 if (!BYTES_BIG_ENDIAN)
4598 ele = nunits - 1 - ele;
4599
4600 operands[3] = GEN_INT (GET_MODE_SIZE (<VEC_base>mode) * ele);
4601 if (<MODE>mode == V4SImode)
4602 return "xxinsertw %x0,%x2,%3";
4603 else
4604 return "vinsert<wd> %0,%2,%3";
4605 }
4606 [(set_attr "type" "vecperm")])
4607
4608 (define_insn_and_split "vsx_set_v4sf_p9"
4609 [(set (match_operand:V4SF 0 "gpc_reg_operand" "=wa")
4610 (unspec:V4SF
4611 [(match_operand:V4SF 1 "gpc_reg_operand" "0")
4612 (match_operand:SF 2 "gpc_reg_operand" "wa")
4613 (match_operand:QI 3 "const_0_to_3_operand" "n")]
4614 UNSPEC_VSX_SET))
4615 (clobber (match_scratch:SI 4 "=&wa"))]
4616 "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_P9_VECTOR && TARGET_POWERPC64"
4617 "#"
4618 "&& reload_completed"
4619 [(set (match_dup 5)
4620 (unspec:V4SF [(match_dup 2)]
4621 UNSPEC_VSX_CVDPSPN))
4622 (parallel [(set (match_dup 4)
4623 (vec_select:SI (match_dup 6)
4624 (parallel [(match_dup 7)])))
4625 (clobber (scratch:SI))])
4626 (set (match_dup 8)
4627 (unspec:V4SI [(match_dup 8)
4628 (match_dup 4)
4629 (match_dup 3)]
4630 UNSPEC_VSX_SET))]
4631 {
4632 unsigned int tmp_regno = reg_or_subregno (operands[4]);
4633
4634 operands[5] = gen_rtx_REG (V4SFmode, tmp_regno);
4635 operands[6] = gen_rtx_REG (V4SImode, tmp_regno);
4636 operands[7] = GEN_INT (BYTES_BIG_ENDIAN ? 0 : 3);
4637 operands[8] = gen_rtx_REG (V4SImode, reg_or_subregno (operands[0]));
4638 }
4639 [(set_attr "type" "vecperm")
4640 (set_attr "length" "12")
4641 (set_attr "isa" "p9v")])
4642
4643 ;; Special case setting 0.0f to a V4SF element
4644 (define_insn_and_split "*vsx_set_v4sf_p9_zero"
4645 [(set (match_operand:V4SF 0 "gpc_reg_operand" "=wa")
4646 (unspec:V4SF
4647 [(match_operand:V4SF 1 "gpc_reg_operand" "0")
4648 (match_operand:SF 2 "zero_fp_constant" "j")
4649 (match_operand:QI 3 "const_0_to_3_operand" "n")]
4650 UNSPEC_VSX_SET))
4651 (clobber (match_scratch:SI 4 "=&wa"))]
4652 "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_P9_VECTOR && TARGET_POWERPC64"
4653 "#"
4654 "&& reload_completed"
4655 [(set (match_dup 4)
4656 (const_int 0))
4657 (set (match_dup 5)
4658 (unspec:V4SI [(match_dup 5)
4659 (match_dup 4)
4660 (match_dup 3)]
4661 UNSPEC_VSX_SET))]
4662 {
4663 operands[5] = gen_rtx_REG (V4SImode, reg_or_subregno (operands[0]));
4664 }
4665 [(set_attr "type" "vecperm")
4666 (set_attr "length" "8")
4667 (set_attr "isa" "p9v")])
4668
4669 ;; Optimize x = vec_insert (vec_extract (v2, n), v1, m) if n is the element
4670 ;; that is in the default scalar position (1 for big endian, 2 for little
4671 ;; endian). We just need to do an xxinsertw since the element is in the
4672 ;; correct location.
4673
4674 (define_insn "*vsx_insert_extract_v4sf_p9"
4675 [(set (match_operand:V4SF 0 "gpc_reg_operand" "=wa")
4676 (unspec:V4SF
4677 [(match_operand:V4SF 1 "gpc_reg_operand" "0")
4678 (vec_select:SF (match_operand:V4SF 2 "gpc_reg_operand" "wa")
4679 (parallel
4680 [(match_operand:QI 3 "const_0_to_3_operand" "n")]))
4681 (match_operand:QI 4 "const_0_to_3_operand" "n")]
4682 UNSPEC_VSX_SET))]
4683 "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_P9_VECTOR && TARGET_POWERPC64
4684 && (INTVAL (operands[3]) == (BYTES_BIG_ENDIAN ? 1 : 2))"
4685 {
4686 int ele = INTVAL (operands[4]);
4687
4688 /* Adjust index for LE element ordering, the below minuend 3 is computed by
4689 GET_MODE_NUNITS (V4SFmode) - 1. */
4690 if (!BYTES_BIG_ENDIAN)
4691 ele = 3 - ele;
4692
4693 operands[4] = GEN_INT (GET_MODE_SIZE (SFmode) * ele);
4694 return "xxinsertw %x0,%x2,%4";
4695 }
4696 [(set_attr "type" "vecperm")])
4697
4698 ;; Optimize x = vec_insert (vec_extract (v2, n), v1, m) if n is not the element
4699 ;; that is in the default scalar position (1 for big endian, 2 for little
4700 ;; endian). Convert the insert/extract to int and avoid doing the conversion.
4701
4702 (define_insn_and_split "*vsx_insert_extract_v4sf_p9_2"
4703 [(set (match_operand:V4SF 0 "gpc_reg_operand" "=wa")
4704 (unspec:V4SF
4705 [(match_operand:V4SF 1 "gpc_reg_operand" "0")
4706 (vec_select:SF (match_operand:V4SF 2 "gpc_reg_operand" "wa")
4707 (parallel
4708 [(match_operand:QI 3 "const_0_to_3_operand" "n")]))
4709 (match_operand:QI 4 "const_0_to_3_operand" "n")]
4710 UNSPEC_VSX_SET))
4711 (clobber (match_scratch:SI 5 "=&wa"))]
4712 "VECTOR_MEM_VSX_P (V4SFmode) && VECTOR_MEM_VSX_P (V4SImode)
4713 && TARGET_P9_VECTOR && TARGET_POWERPC64
4714 && (INTVAL (operands[3]) != (BYTES_BIG_ENDIAN ? 1 : 2))"
4715 "#"
4716 "&& 1"
4717 [(parallel [(set (match_dup 5)
4718 (vec_select:SI (match_dup 6)
4719 (parallel [(match_dup 3)])))
4720 (clobber (scratch:SI))])
4721 (set (match_dup 7)
4722 (unspec:V4SI [(match_dup 8)
4723 (match_dup 5)
4724 (match_dup 4)]
4725 UNSPEC_VSX_SET))]
4726 {
4727 if (GET_CODE (operands[5]) == SCRATCH)
4728 operands[5] = gen_reg_rtx (SImode);
4729
4730 operands[6] = gen_lowpart (V4SImode, operands[2]);
4731 operands[7] = gen_lowpart (V4SImode, operands[0]);
4732 operands[8] = gen_lowpart (V4SImode, operands[1]);
4733 }
4734 [(set_attr "type" "vecperm")
4735 (set_attr "isa" "p9v")])
4736
4737 ;; Expanders for builtins
4738 (define_expand "vsx_mergel_<mode>"
4739 [(use (match_operand:VSX_D 0 "vsx_register_operand"))
4740 (use (match_operand:VSX_D 1 "vsx_register_operand"))
4741 (use (match_operand:VSX_D 2 "vsx_register_operand"))]
4742 "VECTOR_MEM_VSX_P (<MODE>mode)"
4743 {
4744 rtvec v = gen_rtvec (2, GEN_INT (1), GEN_INT (3));
4745 rtx x = gen_rtx_VEC_CONCAT (<VS_double>mode, operands[1], operands[2]);
4746 x = gen_rtx_VEC_SELECT (<MODE>mode, x, gen_rtx_PARALLEL (VOIDmode, v));
4747 emit_insn (gen_rtx_SET (operands[0], x));
4748 DONE;
4749 })
4750
4751 (define_expand "vsx_mergeh_<mode>"
4752 [(use (match_operand:VSX_D 0 "vsx_register_operand"))
4753 (use (match_operand:VSX_D 1 "vsx_register_operand"))
4754 (use (match_operand:VSX_D 2 "vsx_register_operand"))]
4755 "VECTOR_MEM_VSX_P (<MODE>mode)"
4756 {
4757 rtvec v = gen_rtvec (2, GEN_INT (0), GEN_INT (2));
4758 rtx x = gen_rtx_VEC_CONCAT (<VS_double>mode, operands[1], operands[2]);
4759 x = gen_rtx_VEC_SELECT (<MODE>mode, x, gen_rtx_PARALLEL (VOIDmode, v));
4760 emit_insn (gen_rtx_SET (operands[0], x));
4761 DONE;
4762 })
4763
4764 ;; V2DF/V2DI splat
4765 ;; We separate the register splat insn from the memory splat insn to force the
4766 ;; register allocator to generate the indexed form of the SPLAT when it is
4767 ;; given an offsettable memory reference. Otherwise, if the register and
4768 ;; memory insns were combined into a single insn, the register allocator will
4769 ;; load the value into a register, and then do a double word permute.
4770 (define_expand "vsx_splat_<mode>"
4771 [(set (match_operand:VSX_D 0 "vsx_register_operand")
4772 (vec_duplicate:VSX_D
4773 (match_operand:<VEC_base> 1 "input_operand")))]
4774 "VECTOR_MEM_VSX_P (<MODE>mode)"
4775 {
4776 rtx op1 = operands[1];
4777 if (MEM_P (op1))
4778 operands[1] = rs6000_force_indexed_or_indirect_mem (op1);
4779 else
4780 operands[1] = force_reg (<VSX_D:VEC_base>mode, op1);
4781 })
4782
4783 (define_insn "vsx_splat_<mode>_reg"
4784 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa,we")
4785 (vec_duplicate:VSX_D
4786 (match_operand:<VEC_base> 1 "gpc_reg_operand" "wa,b")))]
4787 "VECTOR_MEM_VSX_P (<MODE>mode)"
4788 "@
4789 xxpermdi %x0,%x1,%x1,0
4790 mtvsrdd %x0,%1,%1"
4791 [(set_attr "type" "vecperm,vecmove")])
4792
4793 (define_insn "vsx_splat_<mode>_mem"
4794 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
4795 (vec_duplicate:VSX_D
4796 (match_operand:<VSX_D:VEC_base> 1 "memory_operand" "Z")))]
4797 "VECTOR_MEM_VSX_P (<MODE>mode)"
4798 "lxvdsx %x0,%y1"
4799 [(set_attr "type" "vecload")])
4800
4801 ;; V4SI splat support
4802 (define_insn "vsx_splat_v4si"
4803 [(set (match_operand:V4SI 0 "vsx_register_operand" "=wa,wa")
4804 (vec_duplicate:V4SI
4805 (match_operand:SI 1 "splat_input_operand" "r,Z")))]
4806 "TARGET_P9_VECTOR"
4807 "@
4808 mtvsrws %x0,%1
4809 lxvwsx %x0,%y1"
4810 [(set_attr "type" "vecperm,vecload")])
4811
4812 ;; SImode is not currently allowed in vector registers. This pattern
4813 ;; allows us to use direct move to get the value in a vector register
4814 ;; so that we can use XXSPLTW
4815 (define_insn "vsx_splat_v4si_di"
4816 [(set (match_operand:V4SI 0 "vsx_register_operand" "=wa,we")
4817 (vec_duplicate:V4SI
4818 (truncate:SI
4819 (match_operand:DI 1 "gpc_reg_operand" "wa,r"))))]
4820 "VECTOR_MEM_VSX_P (V4SImode) && TARGET_DIRECT_MOVE_64BIT"
4821 "@
4822 xxspltw %x0,%x1,1
4823 mtvsrws %x0,%1"
4824 [(set_attr "type" "vecperm")
4825 (set_attr "isa" "p8v,*")])
4826
4827 ;; V4SF splat (ISA 3.0)
4828 (define_insn_and_split "vsx_splat_v4sf"
4829 [(set (match_operand:V4SF 0 "vsx_register_operand" "=wa,wa,wa")
4830 (vec_duplicate:V4SF
4831 (match_operand:SF 1 "splat_input_operand" "Z,wa,r")))]
4832 "TARGET_P9_VECTOR"
4833 "@
4834 lxvwsx %x0,%y1
4835 #
4836 mtvsrws %x0,%1"
4837 "&& reload_completed && vsx_register_operand (operands[1], SFmode)"
4838 [(set (match_dup 0)
4839 (unspec:V4SF [(match_dup 1)] UNSPEC_VSX_CVDPSPN))
4840 (set (match_dup 0)
4841 (unspec:V4SF [(match_dup 0)
4842 (const_int 0)] UNSPEC_VSX_XXSPLTW))]
4843 ""
4844 [(set_attr "type" "vecload,vecperm,vecperm")
4845 (set_attr "length" "*,8,*")
4846 (set_attr "isa" "*,p8v,*")])
4847
4848 ;; V4SF/V4SI splat from a vector element
4849 (define_insn "vsx_xxspltw_<mode>"
4850 [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
4851 (vec_duplicate:VSX_W
4852 (vec_select:<VEC_base>
4853 (match_operand:VSX_W 1 "vsx_register_operand" "wa")
4854 (parallel
4855 [(match_operand:QI 2 "u5bit_cint_operand" "n")]))))]
4856 "VECTOR_MEM_VSX_P (<MODE>mode)"
4857 {
4858 if (!BYTES_BIG_ENDIAN)
4859 operands[2] = GEN_INT (3 - INTVAL (operands[2]));
4860
4861 return "xxspltw %x0,%x1,%2";
4862 }
4863 [(set_attr "type" "vecperm")])
4864
4865 (define_insn "vsx_xxspltw_<mode>_direct"
4866 [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
4867 (unspec:VSX_W [(match_operand:VSX_W 1 "vsx_register_operand" "wa")
4868 (match_operand:QI 2 "u5bit_cint_operand" "i")]
4869 UNSPEC_VSX_XXSPLTW))]
4870 "VECTOR_MEM_VSX_P (<MODE>mode)"
4871 "xxspltw %x0,%x1,%2"
4872 [(set_attr "type" "vecperm")])
4873
4874 ;; V16QI/V8HI splat support on ISA 2.07
4875 (define_insn "vsx_vsplt<VSX_SPLAT_SUFFIX>_di"
4876 [(set (match_operand:VSX_SPLAT_I 0 "altivec_register_operand" "=v")
4877 (vec_duplicate:VSX_SPLAT_I
4878 (truncate:<VEC_base>
4879 (match_operand:DI 1 "altivec_register_operand" "v"))))]
4880 "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
4881 "vsplt<VSX_SPLAT_SUFFIX> %0,%1,<VSX_SPLAT_COUNT>"
4882 [(set_attr "type" "vecperm")])
4883
4884 ;; V2DF/V2DI splat for use by vec_splat builtin
4885 (define_insn "vsx_xxspltd_<mode>"
4886 [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
4887 (unspec:VSX_D [(match_operand:VSX_D 1 "vsx_register_operand" "wa")
4888 (match_operand:QI 2 "u5bit_cint_operand" "i")]
4889 UNSPEC_VSX_XXSPLTD))]
4890 "VECTOR_MEM_VSX_P (<MODE>mode)"
4891 {
4892 if ((BYTES_BIG_ENDIAN && INTVAL (operands[2]) == 0)
4893 || (!BYTES_BIG_ENDIAN && INTVAL (operands[2]) == 1))
4894 return "xxpermdi %x0,%x1,%x1,0";
4895 else
4896 return "xxpermdi %x0,%x1,%x1,3";
4897 }
4898 [(set_attr "type" "vecperm")])
4899
4900 ;; Shift left double by word immediate
4901 (define_insn "vsx_xxsldwi_<mode>"
4902 [(set (match_operand:VSX_L 0 "vsx_register_operand" "=wa")
4903 (unspec:VSX_L [(match_operand:VSX_L 1 "vsx_register_operand" "wa")
4904 (match_operand:VSX_L 2 "vsx_register_operand" "wa")
4905 (match_operand:QI 3 "u5bit_cint_operand" "i")]
4906 UNSPEC_VSX_SLDWI))]
4907 "VECTOR_MEM_VSX_P (<MODE>mode)"
4908 "xxsldwi %x0,%x1,%x2,%3"
4909 [(set_attr "type" "vecperm")
4910 (set_attr "isa" "<VSisa>")])
4911
4912
4913 ;; Vector reduction insns and splitters
4914
4915 (define_insn_and_split "vsx_reduc_<VEC_reduc_name>_v2df"
4916 [(set (match_operand:V2DF 0 "vfloat_operand" "=&wa,wa")
4917 (VEC_reduc:V2DF
4918 (vec_concat:V2DF
4919 (vec_select:DF
4920 (match_operand:V2DF 1 "vfloat_operand" "wa,wa")
4921 (parallel [(const_int 1)]))
4922 (vec_select:DF
4923 (match_dup 1)
4924 (parallel [(const_int 0)])))
4925 (match_dup 1)))
4926 (clobber (match_scratch:V2DF 2 "=0,&wa"))]
4927 "VECTOR_UNIT_VSX_P (V2DFmode)"
4928 "#"
4929 "&& 1"
4930 [(const_int 0)]
4931 {
4932 rtx tmp = (GET_CODE (operands[2]) == SCRATCH)
4933 ? gen_reg_rtx (V2DFmode)
4934 : operands[2];
4935 emit_insn (gen_vsx_xxsldwi_v2df (tmp, operands[1], operands[1], const2_rtx));
4936 emit_insn (gen_<VEC_reduc_rtx>v2df3 (operands[0], tmp, operands[1]));
4937 DONE;
4938 }
4939 [(set_attr "length" "8")
4940 (set_attr "type" "veccomplex")])
4941
4942 (define_insn_and_split "vsx_reduc_<VEC_reduc_name>_v4sf"
4943 [(set (match_operand:V4SF 0 "vfloat_operand" "=wa")
4944 (VEC_reduc:V4SF
4945 (unspec:V4SF [(const_int 0)] UNSPEC_REDUC)
4946 (match_operand:V4SF 1 "vfloat_operand" "wa")))
4947 (clobber (match_scratch:V4SF 2 "=&wa"))
4948 (clobber (match_scratch:V4SF 3 "=&wa"))]
4949 "VECTOR_UNIT_VSX_P (V4SFmode)"
4950 "#"
4951 "&& 1"
4952 [(const_int 0)]
4953 {
4954 rtx op0 = operands[0];
4955 rtx op1 = operands[1];
4956 rtx tmp2, tmp3, tmp4;
4957
4958 if (can_create_pseudo_p ())
4959 {
4960 tmp2 = gen_reg_rtx (V4SFmode);
4961 tmp3 = gen_reg_rtx (V4SFmode);
4962 tmp4 = gen_reg_rtx (V4SFmode);
4963 }
4964 else
4965 {
4966 tmp2 = operands[2];
4967 tmp3 = operands[3];
4968 tmp4 = tmp2;
4969 }
4970
4971 emit_insn (gen_vsx_xxsldwi_v4sf (tmp2, op1, op1, const2_rtx));
4972 emit_insn (gen_<VEC_reduc_rtx>v4sf3 (tmp3, tmp2, op1));
4973 emit_insn (gen_vsx_xxsldwi_v4sf (tmp4, tmp3, tmp3, GEN_INT (3)));
4974 emit_insn (gen_<VEC_reduc_rtx>v4sf3 (op0, tmp4, tmp3));
4975 DONE;
4976 }
4977 [(set_attr "length" "16")
4978 (set_attr "type" "veccomplex")])
4979
4980 ;; Combiner patterns with the vector reduction patterns that knows we can get
4981 ;; to the top element of the V2DF array without doing an extract.
4982
4983 (define_insn_and_split "*vsx_reduc_<VEC_reduc_name>_v2df_scalar"
4984 [(set (match_operand:DF 0 "vfloat_operand" "=&wa,wa")
4985 (vec_select:DF
4986 (VEC_reduc:V2DF
4987 (vec_concat:V2DF
4988 (vec_select:DF
4989 (match_operand:V2DF 1 "vfloat_operand" "wa,wa")
4990 (parallel [(const_int 1)]))
4991 (vec_select:DF
4992 (match_dup 1)
4993 (parallel [(const_int 0)])))
4994 (match_dup 1))
4995 (parallel [(const_int 1)])))
4996 (clobber (match_scratch:DF 2 "=0,&wa"))]
4997 "BYTES_BIG_ENDIAN && VECTOR_UNIT_VSX_P (V2DFmode)"
4998 "#"
4999 "&& 1"
5000 [(const_int 0)]
5001 {
5002 rtx hi = gen_highpart (DFmode, operands[1]);
5003 rtx lo = (GET_CODE (operands[2]) == SCRATCH)
5004 ? gen_reg_rtx (DFmode)
5005 : operands[2];
5006
5007 emit_insn (gen_vsx_extract_v2df (lo, operands[1], const1_rtx));
5008 emit_insn (gen_<VEC_reduc_rtx>df3 (operands[0], hi, lo));
5009 DONE;
5010 }
5011 [(set_attr "length" "8")
5012 (set_attr "type" "veccomplex")])
5013
5014 (define_insn_and_split "*vsx_reduc_<VEC_reduc_name>_v4sf_scalar"
5015 [(set (match_operand:SF 0 "vfloat_operand" "=f")
5016 (vec_select:SF
5017 (VEC_reduc:V4SF
5018 (unspec:V4SF [(const_int 0)] UNSPEC_REDUC)
5019 (match_operand:V4SF 1 "vfloat_operand" "wa"))
5020 (parallel [(const_int 3)])))
5021 (clobber (match_scratch:V4SF 2 "=&wa"))
5022 (clobber (match_scratch:V4SF 3 "=&wa"))
5023 (clobber (match_scratch:V4SF 4 "=0"))]
5024 "BYTES_BIG_ENDIAN && VECTOR_UNIT_VSX_P (V4SFmode)"
5025 "#"
5026 "&& 1"
5027 [(const_int 0)]
5028 {
5029 rtx op0 = operands[0];
5030 rtx op1 = operands[1];
5031 rtx tmp2, tmp3, tmp4, tmp5;
5032
5033 if (can_create_pseudo_p ())
5034 {
5035 tmp2 = gen_reg_rtx (V4SFmode);
5036 tmp3 = gen_reg_rtx (V4SFmode);
5037 tmp4 = gen_reg_rtx (V4SFmode);
5038 tmp5 = gen_reg_rtx (V4SFmode);
5039 }
5040 else
5041 {
5042 tmp2 = operands[2];
5043 tmp3 = operands[3];
5044 tmp4 = tmp2;
5045 tmp5 = operands[4];
5046 }
5047
5048 emit_insn (gen_vsx_xxsldwi_v4sf (tmp2, op1, op1, const2_rtx));
5049 emit_insn (gen_<VEC_reduc_rtx>v4sf3 (tmp3, tmp2, op1));
5050 emit_insn (gen_vsx_xxsldwi_v4sf (tmp4, tmp3, tmp3, GEN_INT (3)));
5051 emit_insn (gen_<VEC_reduc_rtx>v4sf3 (tmp5, tmp4, tmp3));
5052 emit_insn (gen_vsx_xscvspdp_scalar2 (op0, tmp5));
5053 DONE;
5054 }
5055 [(set_attr "length" "20")
5056 (set_attr "type" "veccomplex")])
5057
5058
5059 ;; Power8 Vector fusion. The fused ops must be physically adjacent.
5060 (define_peephole
5061 [(set (match_operand:P 0 "base_reg_operand")
5062 (match_operand:P 1 "short_cint_operand"))
5063 (set (match_operand:VSX_M 2 "vsx_register_operand")
5064 (mem:VSX_M (plus:P (match_dup 0)
5065 (match_operand:P 3 "int_reg_operand"))))]
5066 "TARGET_VSX && TARGET_P8_FUSION && !TARGET_P9_VECTOR"
5067 "li %0,%1\;lx<VSX_M:VSm>x %x2,%0,%3\t\t\t# vector load fusion"
5068 [(set_attr "length" "8")
5069 (set_attr "type" "vecload")])
5070
5071 (define_peephole
5072 [(set (match_operand:P 0 "base_reg_operand")
5073 (match_operand:P 1 "short_cint_operand"))
5074 (set (match_operand:VSX_M 2 "vsx_register_operand")
5075 (mem:VSX_M (plus:P (match_operand:P 3 "int_reg_operand")
5076 (match_dup 0))))]
5077 "TARGET_VSX && TARGET_P8_FUSION && !TARGET_P9_VECTOR"
5078 "li %0,%1\;lx<VSX_M:VSm>x %x2,%0,%3\t\t\t# vector load fusion"
5079 [(set_attr "length" "8")
5080 (set_attr "type" "vecload")])
5081
5082
5083 ;; ISA 3.1 vector extend sign support
5084 (define_insn "vsx_sign_extend_v2di_v1ti"
5085 [(set (match_operand:V1TI 0 "vsx_register_operand" "=v")
5086 (unspec:V1TI [(match_operand:V2DI 1 "vsx_register_operand" "v")]
5087 UNSPEC_VSX_SIGN_EXTEND))]
5088 "TARGET_POWER10"
5089 "vextsd2q %0,%1"
5090 [(set_attr "type" "vecexts")])
5091
5092 ;; ISA 3.0 vector extend sign support
5093
5094 (define_insn "vsx_sign_extend_v16qi_<mode>"
5095 [(set (match_operand:VSINT_84 0 "vsx_register_operand" "=v")
5096 (unspec:VSINT_84
5097 [(match_operand:V16QI 1 "vsx_register_operand" "v")]
5098 UNSPEC_VSX_SIGN_EXTEND))]
5099 "TARGET_P9_VECTOR"
5100 "vextsb2<wd> %0,%1"
5101 [(set_attr "type" "vecexts")])
5102
5103 (define_insn "vsx_sign_extend_v8hi_<mode>"
5104 [(set (match_operand:VSINT_84 0 "vsx_register_operand" "=v")
5105 (unspec:VSINT_84
5106 [(match_operand:V8HI 1 "vsx_register_operand" "v")]
5107 UNSPEC_VSX_SIGN_EXTEND))]
5108 "TARGET_P9_VECTOR"
5109 "vextsh2<wd> %0,%1"
5110 [(set_attr "type" "vecexts")])
5111
5112 (define_insn "vsx_sign_extend_v4si_v2di"
5113 [(set (match_operand:V2DI 0 "vsx_register_operand" "=v")
5114 (unspec:V2DI [(match_operand:V4SI 1 "vsx_register_operand" "v")]
5115 UNSPEC_VSX_SIGN_EXTEND))]
5116 "TARGET_P9_VECTOR"
5117 "vextsw2d %0,%1"
5118 [(set_attr "type" "vecexts")])
5119
5120 ;; Sign extend DI to TI. We provide both GPR targets and Altivec targets on
5121 ;; power10. On earlier systems, the machine independent code will generate a
5122 ;; shift left to sign extend the 64-bit value to 128-bit.
5123 ;;
5124 ;; If the register allocator prefers to use GPR registers, we will use a shift
5125 ;; left instruction to sign extend the 64-bit value to 128-bit.
5126 ;;
5127 ;; If the register allocator prefers to use Altivec registers on power10,
5128 ;; generate the vextsd2q instruction.
5129 (define_insn_and_split "extendditi2"
5130 [(set (match_operand:TI 0 "register_operand" "=r,r,v,v,v")
5131 (sign_extend:TI (match_operand:DI 1 "input_operand" "r,m,b,wa,Z")))
5132 (clobber (reg:DI CA_REGNO))]
5133 "TARGET_POWERPC64 && TARGET_POWER10"
5134 "#"
5135 "&& reload_completed"
5136 [(pc)]
5137 {
5138 rtx dest = operands[0];
5139 rtx src = operands[1];
5140 int dest_regno = reg_or_subregno (dest);
5141
5142 /* Handle conversion to GPR registers. Load up the low part and then do
5143 a sign extension to the upper part. */
5144 if (INT_REGNO_P (dest_regno))
5145 {
5146 rtx dest_hi = gen_highpart (DImode, dest);
5147 rtx dest_lo = gen_lowpart (DImode, dest);
5148
5149 emit_move_insn (dest_lo, src);
5150 /* In case src is a MEM, we have to use the destination, which is a
5151 register, instead of re-using the source. */
5152 rtx src2 = (REG_P (src) || SUBREG_P (src)) ? src : dest_lo;
5153 emit_insn (gen_ashrdi3 (dest_hi, src2, GEN_INT (63)));
5154 DONE;
5155 }
5156
5157 /* For conversion to an Altivec register, generate either a splat operation
5158 or a load rightmost double word instruction. Both instructions gets the
5159 DImode value into the lower 64 bits, and then do the vextsd2q
5160 instruction. */
5161
5162 else if (ALTIVEC_REGNO_P (dest_regno))
5163 {
5164 if (MEM_P (src))
5165 emit_insn (gen_vsx_lxvrdx (dest, src));
5166 else
5167 {
5168 rtx dest_v2di = gen_rtx_REG (V2DImode, dest_regno);
5169 emit_insn (gen_vsx_splat_v2di (dest_v2di, src));
5170 }
5171
5172 emit_insn (gen_extendditi2_vector (dest, dest));
5173 DONE;
5174 }
5175
5176 else
5177 gcc_unreachable ();
5178 }
5179 [(set_attr "length" "8")
5180 (set_attr "type" "shift,load,vecmove,vecperm,load")])
5181
5182 ;; Sign extend 64-bit value in TI reg, word 1, to 128-bit value in TI reg
5183 (define_insn "extendditi2_vector"
5184 [(set (match_operand:TI 0 "gpc_reg_operand" "=v")
5185 (unspec:TI [(match_operand:TI 1 "gpc_reg_operand" "v")]
5186 UNSPEC_EXTENDDITI2))]
5187 "TARGET_POWER10"
5188 "vextsd2q %0,%1"
5189 [(set_attr "type" "vecexts")])
5190
5191
5192 ;; ISA 3.0 Binary Floating-Point Support
5193
5194 ;; VSX Scalar Extract Exponent Quad-Precision
5195 (define_insn "xsxexpqp_<IEEE128:mode>_<V2DI_DI:mode>"
5196 [(set (match_operand:V2DI_DI 0 "altivec_register_operand" "=v")
5197 (unspec:V2DI_DI
5198 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
5199 UNSPEC_VSX_SXEXPDP))]
5200 "TARGET_FLOAT128_HW"
5201 "xsxexpqp %0,%1"
5202 [(set_attr "type" "vecmove")])
5203
5204 ;; VSX Scalar Extract Exponent Double-Precision
5205 (define_insn "xsxexpdp_<mode>"
5206 [(set (match_operand:GPR 0 "register_operand" "=r")
5207 (unspec:GPR [(match_operand:DF 1 "vsx_register_operand" "wa")]
5208 UNSPEC_VSX_SXEXPDP))]
5209 "TARGET_P9_VECTOR"
5210 "xsxexpdp %0,%x1"
5211 [(set_attr "type" "integer")])
5212
5213 ;; VSX Scalar Extract Significand Quad-Precision
5214 (define_insn "xsxsigqp_<IEEE128:mode>_<VEC_TI:mode>"
5215 [(set (match_operand:VEC_TI 0 "altivec_register_operand" "=v")
5216 (unspec:VEC_TI [(match_operand:IEEE128 1
5217 "altivec_register_operand" "v")]
5218 UNSPEC_VSX_SXSIG))]
5219 "TARGET_FLOAT128_HW"
5220 "xsxsigqp %0,%1"
5221 [(set_attr "type" "vecmove")])
5222
5223 ;; VSX Scalar Extract Significand Double-Precision
5224 (define_insn "xsxsigdp"
5225 [(set (match_operand:DI 0 "register_operand" "=r")
5226 (unspec:DI [(match_operand:DF 1 "vsx_register_operand" "wa")]
5227 UNSPEC_VSX_SXSIG))]
5228 "TARGET_P9_VECTOR && TARGET_POWERPC64"
5229 "xsxsigdp %0,%x1"
5230 [(set_attr "type" "integer")])
5231
5232 ;; VSX Scalar Insert Exponent Quad-Precision Floating Point Argument
5233 (define_insn "xsiexpqpf_<mode>"
5234 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
5235 (unspec:IEEE128
5236 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
5237 (match_operand:DI 2 "altivec_register_operand" "v")]
5238 UNSPEC_VSX_SIEXPQP))]
5239 "TARGET_FLOAT128_HW"
5240 "xsiexpqp %0,%1,%2"
5241 [(set_attr "type" "vecmove")])
5242
5243 ;; VSX Scalar Insert Exponent Quad-Precision
5244 (define_insn "xsiexpqp_<IEEE128:mode>_<V2DI_DI:mode>"
5245 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
5246 (unspec:IEEE128 [(match_operand:<DI_to_TI> 1
5247 "altivec_register_operand" "v")
5248 (match_operand:V2DI_DI 2
5249 "altivec_register_operand" "v")]
5250 UNSPEC_VSX_SIEXPQP))]
5251 "TARGET_FLOAT128_HW"
5252 "xsiexpqp %0,%1,%2"
5253 [(set_attr "type" "vecmove")])
5254
5255 ;; VSX Scalar Insert Exponent Double-Precision
5256 (define_insn "xsiexpdp_<mode>"
5257 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
5258 (unspec:DF [(match_operand:DI 1 "register_operand" "r")
5259 (match_operand:GPR 2 "register_operand" "r")]
5260 UNSPEC_VSX_SIEXPDP))]
5261 "TARGET_P9_VECTOR && TARGET_POWERPC64"
5262 "xsiexpdp %x0,%1,%2"
5263 [(set_attr "type" "fpsimple")])
5264
5265 ;; VSX Scalar Insert Exponent Double-Precision Floating Point Argument
5266 (define_insn "xsiexpdpf_<mode>"
5267 [(set (match_operand:DF 0 "vsx_register_operand" "=wa")
5268 (unspec:DF [(match_operand:DF 1 "register_operand" "r")
5269 (match_operand:GPR 2 "register_operand" "r")]
5270 UNSPEC_VSX_SIEXPDP))]
5271 "TARGET_P9_VECTOR && TARGET_POWERPC64"
5272 "xsiexpdp %x0,%1,%2"
5273 [(set_attr "type" "fpsimple")])
5274
5275 ;; VSX Scalar Compare Exponents Double-Precision
5276 (define_expand "xscmpexpdp_<code>"
5277 [(set (match_dup 3)
5278 (compare:CCFP
5279 (unspec:DF
5280 [(match_operand:DF 1 "vsx_register_operand" "wa")
5281 (match_operand:DF 2 "vsx_register_operand" "wa")]
5282 UNSPEC_VSX_SCMPEXPDP)
5283 (const_int 0)))
5284 (set (match_operand:SI 0 "register_operand" "=r")
5285 (CMP_TEST:SI (match_dup 3)
5286 (const_int 0)))]
5287 "TARGET_P9_VECTOR"
5288 {
5289 if (<CODE> == UNORDERED && !HONOR_NANS (DFmode))
5290 {
5291 emit_move_insn (operands[0], const0_rtx);
5292 DONE;
5293 }
5294
5295 operands[3] = gen_reg_rtx (CCFPmode);
5296 })
5297
5298 (define_insn "*xscmpexpdp"
5299 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5300 (compare:CCFP
5301 (unspec:DF [(match_operand:DF 1 "vsx_register_operand" "wa")
5302 (match_operand:DF 2 "vsx_register_operand" "wa")]
5303 UNSPEC_VSX_SCMPEXPDP)
5304 (match_operand:SI 3 "zero_constant" "j")))]
5305 "TARGET_P9_VECTOR"
5306 "xscmpexpdp %0,%x1,%x2"
5307 [(set_attr "type" "fpcompare")])
5308
5309 ;; VSX Scalar Compare Exponents Quad-Precision
5310 (define_expand "xscmpexpqp_<code>_<mode>"
5311 [(set (match_dup 3)
5312 (compare:CCFP
5313 (unspec:IEEE128
5314 [(match_operand:IEEE128 1 "vsx_register_operand" "v")
5315 (match_operand:IEEE128 2 "vsx_register_operand" "v")]
5316 UNSPEC_VSX_SCMPEXPQP)
5317 (const_int 0)))
5318 (set (match_operand:SI 0 "register_operand" "=r")
5319 (CMP_TEST:SI (match_dup 3)
5320 (const_int 0)))]
5321 "TARGET_FLOAT128_HW"
5322 {
5323 if (<CODE> == UNORDERED && !HONOR_NANS (<MODE>mode))
5324 {
5325 emit_move_insn (operands[0], const0_rtx);
5326 DONE;
5327 }
5328
5329 operands[3] = gen_reg_rtx (CCFPmode);
5330 })
5331
5332 (define_insn "*xscmpexpqp"
5333 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
5334 (compare:CCFP
5335 (unspec:IEEE128 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
5336 (match_operand:IEEE128 2 "altivec_register_operand" "v")]
5337 UNSPEC_VSX_SCMPEXPQP)
5338 (match_operand:SI 3 "zero_constant" "j")))]
5339 "TARGET_FLOAT128_HW"
5340 "xscmpexpqp %0,%1,%2"
5341 [(set_attr "type" "fpcompare")])
5342
5343 ;; VSX Scalar Test Data Class Quad-/Double-/Single-Precision
5344 ;; (The lt bit is set if operand 1 is negative. The eq bit is set
5345 ;; if any of the conditions tested by operand 2 are satisfied.
5346 ;; The gt and unordered bits are cleared to zero.)
5347 (define_expand "xststdc_<mode>"
5348 [(set (match_dup 3)
5349 (compare:CCFP
5350 (unspec:IEEE_FP
5351 [(match_operand:IEEE_FP 1 "<fp_register_op>" "<wa_v>")
5352 (match_operand:SI 2 "u7bit_cint_operand" "n")]
5353 UNSPEC_VSX_STSTDC)
5354 (match_dup 4)))
5355 (set (match_operand:SI 0 "register_operand" "=r")
5356 (eq:SI (match_dup 3)
5357 (const_int 0)))]
5358 "TARGET_P9_VECTOR
5359 && (!FLOAT128_IEEE_P (<MODE>mode) || TARGET_FLOAT128_HW)"
5360 {
5361 operands[3] = gen_reg_rtx (CCFPmode);
5362 operands[4] = CONST0_RTX (SImode);
5363 })
5364
5365 (define_expand "isinf<mode>2"
5366 [(use (match_operand:SI 0 "gpc_reg_operand"))
5367 (use (match_operand:IEEE_FP 1 "<fp_register_op>"))]
5368 "TARGET_P9_VECTOR
5369 && (!FLOAT128_IEEE_P (<MODE>mode) || TARGET_FLOAT128_HW)"
5370 {
5371 int mask = VSX_TEST_DATA_CLASS_POS_INF | VSX_TEST_DATA_CLASS_NEG_INF;
5372 emit_insn (gen_xststdc_<mode> (operands[0], operands[1], GEN_INT (mask)));
5373 DONE;
5374 })
5375
5376 (define_expand "isfinite<mode>2"
5377 [(use (match_operand:SI 0 "gpc_reg_operand"))
5378 (use (match_operand:IEEE_FP 1 "<fp_register_op>"))]
5379 "TARGET_P9_VECTOR
5380 && (!FLOAT128_IEEE_P (<MODE>mode) || TARGET_FLOAT128_HW)"
5381 {
5382 rtx tmp = gen_reg_rtx (SImode);
5383 /* It is neither infinite nor NAN. */
5384 int mask = VSX_TEST_DATA_CLASS_POS_INF | VSX_TEST_DATA_CLASS_NEG_INF
5385 | VSX_TEST_DATA_CLASS_NAN;
5386 emit_insn (gen_xststdc_<mode> (tmp, operands[1], GEN_INT (mask)));
5387 emit_insn (gen_xorsi3 (operands[0], tmp, const1_rtx));
5388 DONE;
5389 })
5390
5391 (define_expand "isnormal<mode>2"
5392 [(use (match_operand:SI 0 "gpc_reg_operand"))
5393 (use (match_operand:IEEE_FP 1 "<fp_register_op>"))]
5394 "TARGET_P9_VECTOR
5395 && (!FLOAT128_IEEE_P (<MODE>mode) || TARGET_FLOAT128_HW)"
5396 {
5397 rtx tmp = gen_reg_rtx (SImode);
5398 /* It is neither NAN, infinite, zero, nor denormal. */
5399 int mask = VSX_TEST_DATA_CLASS_NAN
5400 | VSX_TEST_DATA_CLASS_POS_INF | VSX_TEST_DATA_CLASS_NEG_INF
5401 | VSX_TEST_DATA_CLASS_POS_ZERO | VSX_TEST_DATA_CLASS_NEG_ZERO
5402 | VSX_TEST_DATA_CLASS_POS_DENORMAL
5403 | VSX_TEST_DATA_CLASS_NEG_DENORMAL;
5404 emit_insn (gen_xststdc_<mode> (tmp, operands[1], GEN_INT (mask)));
5405 emit_insn (gen_xorsi3 (operands[0], tmp, const1_rtx));
5406 DONE;
5407 })
5408
5409 ;; The VSX Scalar Test Negative Quad-Precision
5410 (define_expand "xststdcnegqp_<mode>"
5411 [(set (match_dup 2)
5412 (compare:CCFP
5413 (unspec:IEEE128
5414 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
5415 (const_int 0)]
5416 UNSPEC_VSX_STSTDC)
5417 (const_int 0)))
5418 (set (match_operand:SI 0 "register_operand" "=r")
5419 (lt:SI (match_dup 2)
5420 (const_int 0)))]
5421 "TARGET_FLOAT128_HW"
5422 {
5423 operands[2] = gen_reg_rtx (CCFPmode);
5424 })
5425
5426 ;; The VSX Scalar Test Negative Double- and Single-Precision
5427 (define_expand "xststdcneg<sd>p"
5428 [(set (match_dup 2)
5429 (compare:CCFP
5430 (unspec:SFDF
5431 [(match_operand:SFDF 1 "vsx_register_operand" "wa")
5432 (const_int 0)]
5433 UNSPEC_VSX_STSTDC)
5434 (match_dup 3)))
5435 (set (match_operand:SI 0 "register_operand" "=r")
5436 (lt:SI (match_dup 2)
5437 (const_int 0)))]
5438 "TARGET_P9_VECTOR"
5439 {
5440 operands[2] = gen_reg_rtx (CCFPmode);
5441 operands[3] = CONST0_RTX (SImode);
5442 })
5443
5444 (define_insn "*xststdc_<mode>"
5445 [(set (match_operand:CCFP 0 "" "=y")
5446 (compare:CCFP
5447 (unspec:IEEE_FP
5448 [(match_operand:IEEE_FP 1 "<fp_register_op>" "<wa_v>")
5449 (match_operand:SI 2 "u7bit_cint_operand" "n")]
5450 UNSPEC_VSX_STSTDC)
5451 (const_int 0)))]
5452 "TARGET_P9_VECTOR
5453 && (!FLOAT128_IEEE_P (<MODE>mode) || TARGET_FLOAT128_HW)"
5454 "xststdc<sdq>p %0,%<x>1,%2"
5455 [(set_attr "type" "fpcompare")])
5456
5457 ;; VSX Vector Extract Exponent Double and Single Precision
5458 (define_insn "xvxexp<sd>p"
5459 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
5460 (unspec:VSX_F
5461 [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
5462 UNSPEC_VSX_VXEXP))]
5463 "TARGET_P9_VECTOR"
5464 "xvxexp<sd>p %x0,%x1"
5465 [(set_attr "type" "vecsimple")])
5466
5467 ;; VSX Vector Extract Significand Double and Single Precision
5468 (define_insn "xvxsig<sd>p"
5469 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
5470 (unspec:VSX_F
5471 [(match_operand:VSX_F 1 "vsx_register_operand" "wa")]
5472 UNSPEC_VSX_VXSIG))]
5473 "TARGET_P9_VECTOR"
5474 "xvxsig<sd>p %x0,%x1"
5475 [(set_attr "type" "vecsimple")])
5476
5477 ;; VSX Vector Insert Exponent Double and Single Precision
5478 (define_insn "xviexp<sd>p"
5479 [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa")
5480 (unspec:VSX_F
5481 [(match_operand:VSX_F 1 "vsx_register_operand" "wa")
5482 (match_operand:VSX_F 2 "vsx_register_operand" "wa")]
5483 UNSPEC_VSX_VIEXP))]
5484 "TARGET_P9_VECTOR"
5485 "xviexp<sd>p %x0,%x1,%x2"
5486 [(set_attr "type" "vecsimple")])
5487
5488 ;; VSX Vector Test Data Class Double and Single Precision
5489 ;; The corresponding elements of the result vector are all ones
5490 ;; if any of the conditions tested by operand 3 are satisfied.
5491 (define_insn "xvtstdc<sd>p"
5492 [(set (match_operand:<VSI> 0 "vsx_register_operand" "=wa")
5493 (unspec:<VSI>
5494 [(match_operand:VSX_F 1 "vsx_register_operand" "wa")
5495 (match_operand:SI 2 "u7bit_cint_operand" "n")]
5496 UNSPEC_VSX_VTSTDC))]
5497 "TARGET_P9_VECTOR"
5498 "xvtstdc<sd>p %x0,%x1,%2"
5499 [(set_attr "type" "vecsimple")])
5500
5501 ;; ISA 3.0 String Operations Support
5502
5503 ;; Compare vectors producing a vector result and a predicate, setting CR6
5504 ;; to indicate a combined status. This pattern matches v16qi, v8hi, and
5505 ;; v4si modes. It does not match v2df, v4sf, or v2di modes. There's no
5506 ;; need to match v4sf, v2df, or v2di modes because those are expanded
5507 ;; to use Power8 instructions.
5508 (define_insn "*vsx_ne_<mode>_p"
5509 [(set (reg:CC CR6_REGNO)
5510 (unspec:CC
5511 [(ne:CC (match_operand:VSX_EXTRACT_I 1 "gpc_reg_operand" "v")
5512 (match_operand:VSX_EXTRACT_I 2 "gpc_reg_operand" "v"))]
5513 UNSPEC_PREDICATE))
5514 (set (match_operand:VSX_EXTRACT_I 0 "gpc_reg_operand" "=v")
5515 (ne:VSX_EXTRACT_I (match_dup 1)
5516 (match_dup 2)))]
5517 "TARGET_P9_VECTOR"
5518 "vcmpne<VSX_EXTRACT_WIDTH>. %0,%1,%2"
5519 [(set_attr "type" "vecsimple")])
5520
5521 (define_insn "*vector_nez_<mode>_p"
5522 [(set (reg:CC CR6_REGNO)
5523 (unspec:CC [(unspec:VI
5524 [(match_operand:VI 1 "gpc_reg_operand" "v")
5525 (match_operand:VI 2 "gpc_reg_operand" "v")]
5526 UNSPEC_NEZ_P)]
5527 UNSPEC_PREDICATE))
5528 (set (match_operand:VI 0 "gpc_reg_operand" "=v")
5529 (unspec:VI [(match_dup 1)
5530 (match_dup 2)]
5531 UNSPEC_NEZ_P))]
5532 "TARGET_P9_VECTOR"
5533 "vcmpnez<VSX_EXTRACT_WIDTH>. %0,%1,%2"
5534 [(set_attr "type" "vecsimple")])
5535
5536 ;; Return first position of match between vectors using natural order
5537 ;; for both LE and BE execution modes.
5538 (define_expand "first_match_index_<mode>"
5539 [(match_operand:SI 0 "register_operand")
5540 (unspec:SI [(match_operand:VSX_EXTRACT_I 1 "register_operand")
5541 (match_operand:VSX_EXTRACT_I 2 "register_operand")]
5542 UNSPEC_VSX_FIRST_MATCH_INDEX)]
5543 "TARGET_P9_VECTOR"
5544 {
5545 int sh;
5546
5547 rtx cmp_result = gen_reg_rtx (<MODE>mode);
5548 rtx not_result = gen_reg_rtx (<MODE>mode);
5549
5550 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmp_result, operands[1],
5551 operands[2]));
5552 emit_insn (gen_one_cmpl<mode>2 (not_result, cmp_result));
5553
5554 sh = GET_MODE_SIZE (GET_MODE_INNER (<MODE>mode)) / 2;
5555
5556 if (<MODE>mode == V16QImode)
5557 {
5558 if (!BYTES_BIG_ENDIAN)
5559 emit_insn (gen_vctzlsbb_<mode> (operands[0], not_result));
5560 else
5561 emit_insn (gen_vclzlsbb_<mode> (operands[0], not_result));
5562 }
5563 else
5564 {
5565 rtx tmp = gen_reg_rtx (SImode);
5566 if (!BYTES_BIG_ENDIAN)
5567 emit_insn (gen_vctzlsbb_<mode> (tmp, not_result));
5568 else
5569 emit_insn (gen_vclzlsbb_<mode> (tmp, not_result));
5570 emit_insn (gen_lshrsi3 (operands[0], tmp, GEN_INT (sh)));
5571 }
5572 DONE;
5573 })
5574
5575 ;; Return first position of match between vectors or end of string (EOS) using
5576 ;; natural element order for both LE and BE execution modes.
5577 (define_expand "first_match_or_eos_index_<mode>"
5578 [(match_operand:SI 0 "register_operand")
5579 (unspec: SI [(match_operand:VSX_EXTRACT_I 1 "register_operand")
5580 (match_operand:VSX_EXTRACT_I 2 "register_operand")]
5581 UNSPEC_VSX_FIRST_MATCH_EOS_INDEX)]
5582 "TARGET_P9_VECTOR"
5583 {
5584 int sh;
5585 rtx cmpz1_result = gen_reg_rtx (<MODE>mode);
5586 rtx cmpz2_result = gen_reg_rtx (<MODE>mode);
5587 rtx cmpz_result = gen_reg_rtx (<MODE>mode);
5588 rtx and_result = gen_reg_rtx (<MODE>mode);
5589 rtx result = gen_reg_rtx (<MODE>mode);
5590 rtx vzero = gen_reg_rtx (<MODE>mode);
5591
5592 /* Vector with zeros in elements that correspond to zeros in operands. */
5593 emit_move_insn (vzero, CONST0_RTX (<MODE>mode));
5594 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmpz1_result, operands[1], vzero));
5595 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmpz2_result, operands[2], vzero));
5596 emit_insn (gen_and<mode>3 (and_result, cmpz1_result, cmpz2_result));
5597
5598 /* Vector with ones in elments that do not match. */
5599 emit_insn (gen_vcmpnez<VSX_EXTRACT_WIDTH> (cmpz_result, operands[1],
5600 operands[2]));
5601
5602 /* Create vector with ones in elements where there was a zero in one of
5603 the source elements or the elements that match. */
5604 emit_insn (gen_nand<mode>3 (result, and_result, cmpz_result));
5605 sh = GET_MODE_SIZE (GET_MODE_INNER (<MODE>mode)) / 2;
5606
5607 if (<MODE>mode == V16QImode)
5608 {
5609 if (!BYTES_BIG_ENDIAN)
5610 emit_insn (gen_vctzlsbb_<mode> (operands[0], result));
5611 else
5612 emit_insn (gen_vclzlsbb_<mode> (operands[0], result));
5613 }
5614 else
5615 {
5616 rtx tmp = gen_reg_rtx (SImode);
5617 if (!BYTES_BIG_ENDIAN)
5618 emit_insn (gen_vctzlsbb_<mode> (tmp, result));
5619 else
5620 emit_insn (gen_vclzlsbb_<mode> (tmp, result));
5621 emit_insn (gen_lshrsi3 (operands[0], tmp, GEN_INT (sh)));
5622 }
5623 DONE;
5624 })
5625
5626 ;; Return first position of mismatch between vectors using natural
5627 ;; element order for both LE and BE execution modes.
5628 (define_expand "first_mismatch_index_<mode>"
5629 [(match_operand:SI 0 "register_operand")
5630 (unspec: SI [(match_operand:VSX_EXTRACT_I 1 "register_operand")
5631 (match_operand:VSX_EXTRACT_I 2 "register_operand")]
5632 UNSPEC_VSX_FIRST_MISMATCH_INDEX)]
5633 "TARGET_P9_VECTOR"
5634 {
5635 int sh;
5636 rtx cmp_result = gen_reg_rtx (<MODE>mode);
5637
5638 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmp_result, operands[1],
5639 operands[2]));
5640 sh = GET_MODE_SIZE (GET_MODE_INNER (<MODE>mode)) / 2;
5641
5642 if (<MODE>mode == V16QImode)
5643 {
5644 if (!BYTES_BIG_ENDIAN)
5645 emit_insn (gen_vctzlsbb_<mode> (operands[0], cmp_result));
5646 else
5647 emit_insn (gen_vclzlsbb_<mode> (operands[0], cmp_result));
5648 }
5649 else
5650 {
5651 rtx tmp = gen_reg_rtx (SImode);
5652 if (!BYTES_BIG_ENDIAN)
5653 emit_insn (gen_vctzlsbb_<mode> (tmp, cmp_result));
5654 else
5655 emit_insn (gen_vclzlsbb_<mode> (tmp, cmp_result));
5656 emit_insn (gen_lshrsi3 (operands[0], tmp, GEN_INT (sh)));
5657 }
5658 DONE;
5659 })
5660
5661 ;; Return first position of mismatch between vectors or end of string (EOS)
5662 ;; using natural element order for both LE and BE execution modes.
5663 (define_expand "first_mismatch_or_eos_index_<mode>"
5664 [(match_operand:SI 0 "register_operand")
5665 (unspec: SI [(match_operand:VSX_EXTRACT_I 1 "register_operand")
5666 (match_operand:VSX_EXTRACT_I 2 "register_operand")]
5667 UNSPEC_VSX_FIRST_MISMATCH_EOS_INDEX)]
5668 "TARGET_P9_VECTOR"
5669 {
5670 int sh;
5671 rtx cmpz1_result = gen_reg_rtx (<MODE>mode);
5672 rtx cmpz2_result = gen_reg_rtx (<MODE>mode);
5673 rtx cmpz_result = gen_reg_rtx (<MODE>mode);
5674 rtx not_cmpz_result = gen_reg_rtx (<MODE>mode);
5675 rtx and_result = gen_reg_rtx (<MODE>mode);
5676 rtx result = gen_reg_rtx (<MODE>mode);
5677 rtx vzero = gen_reg_rtx (<MODE>mode);
5678
5679 /* Vector with zeros in elements that correspond to zeros in operands. */
5680 emit_move_insn (vzero, CONST0_RTX (<MODE>mode));
5681
5682 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmpz1_result, operands[1], vzero));
5683 emit_insn (gen_vcmpne<VSX_EXTRACT_WIDTH> (cmpz2_result, operands[2], vzero));
5684 emit_insn (gen_and<mode>3 (and_result, cmpz1_result, cmpz2_result));
5685
5686 /* Vector with ones in elments that match. */
5687 emit_insn (gen_vcmpnez<VSX_EXTRACT_WIDTH> (cmpz_result, operands[1],
5688 operands[2]));
5689 emit_insn (gen_one_cmpl<mode>2 (not_cmpz_result, cmpz_result));
5690
5691 /* Create vector with ones in elements where there was a zero in one of
5692 the source elements or the elements did not match. */
5693 emit_insn (gen_nand<mode>3 (result, and_result, not_cmpz_result));
5694 sh = GET_MODE_SIZE (GET_MODE_INNER (<MODE>mode)) / 2;
5695
5696 if (<MODE>mode == V16QImode)
5697 {
5698 if (!BYTES_BIG_ENDIAN)
5699 emit_insn (gen_vctzlsbb_<mode> (operands[0], result));
5700 else
5701 emit_insn (gen_vclzlsbb_<mode> (operands[0], result));
5702 }
5703 else
5704 {
5705 rtx tmp = gen_reg_rtx (SImode);
5706 if (!BYTES_BIG_ENDIAN)
5707 emit_insn (gen_vctzlsbb_<mode> (tmp, result));
5708 else
5709 emit_insn (gen_vclzlsbb_<mode> (tmp, result));
5710 emit_insn (gen_lshrsi3 (operands[0], tmp, GEN_INT (sh)));
5711 }
5712 DONE;
5713 })
5714
5715 ;; Load VSX Vector with Length
5716 (define_expand "lxvl"
5717 [(set (match_dup 3)
5718 (ashift:DI (match_operand:DI 2 "register_operand")
5719 (const_int 56)))
5720 (set (match_operand:V16QI 0 "vsx_register_operand")
5721 (unspec:V16QI
5722 [(match_operand:DI 1 "gpc_reg_operand")
5723 (mem:V16QI (match_dup 1))
5724 (match_dup 3)]
5725 UNSPEC_LXVL))]
5726 "TARGET_P9_VECTOR && TARGET_64BIT"
5727 {
5728 operands[3] = gen_reg_rtx (DImode);
5729 })
5730
5731 (define_insn "*lxvl"
5732 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
5733 (unspec:V16QI
5734 [(match_operand:DI 1 "gpc_reg_operand" "b")
5735 (mem:V16QI (match_dup 1))
5736 (match_operand:DI 2 "register_operand" "r")]
5737 UNSPEC_LXVL))]
5738 "TARGET_P9_VECTOR && TARGET_64BIT"
5739 "lxvl %x0,%1,%2"
5740 [(set_attr "type" "vecload")])
5741
5742 (define_insn "lxvll"
5743 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
5744 (unspec:V16QI [(match_operand:DI 1 "gpc_reg_operand" "b")
5745 (mem:V16QI (match_dup 1))
5746 (match_operand:DI 2 "register_operand" "r")]
5747 UNSPEC_LXVLL))]
5748 "TARGET_P9_VECTOR"
5749 "lxvll %x0,%1,%2"
5750 [(set_attr "type" "vecload")])
5751
5752 ;; Expand for builtin xl_len_r
5753 (define_expand "xl_len_r"
5754 [(match_operand:V16QI 0 "vsx_register_operand")
5755 (match_operand:DI 1 "register_operand")
5756 (match_operand:DI 2 "register_operand")]
5757 ""
5758 {
5759 rtx shift_mask = gen_reg_rtx (V16QImode);
5760 rtx rtx_vtmp = gen_reg_rtx (V16QImode);
5761 rtx tmp = gen_reg_rtx (DImode);
5762
5763 emit_insn (gen_altivec_lvsl_reg_di (shift_mask, operands[2]));
5764 emit_insn (gen_ashldi3 (tmp, operands[2], GEN_INT (56)));
5765 emit_insn (gen_lxvll (rtx_vtmp, operands[1], tmp));
5766 emit_insn (gen_altivec_vperm_v8hiv16qi (operands[0], rtx_vtmp, rtx_vtmp,
5767 shift_mask));
5768 DONE;
5769 })
5770
5771 (define_insn "stxvll"
5772 [(set (mem:V16QI (match_operand:DI 1 "gpc_reg_operand" "b"))
5773 (unspec:V16QI [(match_operand:V16QI 0 "vsx_register_operand" "wa")
5774 (mem:V16QI (match_dup 1))
5775 (match_operand:DI 2 "register_operand" "r")]
5776 UNSPEC_STXVLL))]
5777 "TARGET_P9_VECTOR"
5778 "stxvll %x0,%1,%2"
5779 [(set_attr "type" "vecstore")])
5780
5781 ;; Store VSX Vector with Length
5782 (define_expand "stxvl"
5783 [(set (match_dup 3)
5784 (ashift:DI (match_operand:DI 2 "register_operand")
5785 (const_int 56)))
5786 (set (mem:V16QI (match_operand:DI 1 "gpc_reg_operand"))
5787 (unspec:V16QI
5788 [(match_operand:V16QI 0 "vsx_register_operand")
5789 (mem:V16QI (match_dup 1))
5790 (match_dup 3)]
5791 UNSPEC_STXVL))]
5792 "TARGET_P9_VECTOR && TARGET_64BIT"
5793 {
5794 operands[3] = gen_reg_rtx (DImode);
5795 })
5796
5797 ;; Define optab for vector access with length vectorization exploitation.
5798 (define_expand "len_load_v16qi"
5799 [(match_operand:V16QI 0 "vlogical_operand")
5800 (match_operand:V16QI 1 "memory_operand")
5801 (match_operand:QI 2 "gpc_reg_operand")
5802 (match_operand:QI 3 "zero_constant")]
5803 "TARGET_P9_VECTOR && TARGET_64BIT"
5804 {
5805 rtx mem = XEXP (operands[1], 0);
5806 mem = force_reg (DImode, mem);
5807 rtx len = gen_lowpart (DImode, operands[2]);
5808 emit_insn (gen_lxvl (operands[0], mem, len));
5809 DONE;
5810 })
5811
5812 (define_expand "len_store_v16qi"
5813 [(match_operand:V16QI 0 "memory_operand")
5814 (match_operand:V16QI 1 "vlogical_operand")
5815 (match_operand:QI 2 "gpc_reg_operand")
5816 (match_operand:QI 3 "zero_constant")
5817 ]
5818 "TARGET_P9_VECTOR && TARGET_64BIT"
5819 {
5820 rtx mem = XEXP (operands[0], 0);
5821 mem = force_reg (DImode, mem);
5822 rtx len = gen_lowpart (DImode, operands[2]);
5823 emit_insn (gen_stxvl (operands[1], mem, len));
5824 DONE;
5825 })
5826
5827 (define_insn "*stxvl"
5828 [(set (mem:V16QI (match_operand:DI 1 "gpc_reg_operand" "b"))
5829 (unspec:V16QI
5830 [(match_operand:V16QI 0 "vsx_register_operand" "wa")
5831 (mem:V16QI (match_dup 1))
5832 (match_operand:DI 2 "register_operand" "r")]
5833 UNSPEC_STXVL))]
5834 "TARGET_P9_VECTOR && TARGET_64BIT"
5835 "stxvl %x0,%1,%2"
5836 [(set_attr "type" "vecstore")])
5837
5838 ;; Expand for builtin xst_len_r
5839 (define_expand "xst_len_r"
5840 [(match_operand:V16QI 0 "vsx_register_operand" "=wa")
5841 (match_operand:DI 1 "register_operand" "b")
5842 (match_operand:DI 2 "register_operand" "r")]
5843 "UNSPEC_XST_LEN_R"
5844 {
5845 rtx shift_mask = gen_reg_rtx (V16QImode);
5846 rtx rtx_vtmp = gen_reg_rtx (V16QImode);
5847 rtx tmp = gen_reg_rtx (DImode);
5848
5849 emit_insn (gen_altivec_lvsr_reg_di (shift_mask, operands[2]));
5850 emit_insn (gen_altivec_vperm_v8hiv16qi (rtx_vtmp, operands[0], operands[0],
5851 shift_mask));
5852 emit_insn (gen_ashldi3 (tmp, operands[2], GEN_INT (56)));
5853 emit_insn (gen_stxvll (rtx_vtmp, operands[1], tmp));
5854 DONE;
5855 })
5856
5857 ;; Vector Compare Not Equal Byte (specified/not+eq:)
5858 (define_insn "vcmpneb"
5859 [(set (match_operand:V16QI 0 "altivec_register_operand" "=v")
5860 (not:V16QI
5861 (eq:V16QI (match_operand:V16QI 1 "altivec_register_operand" "v")
5862 (match_operand:V16QI 2 "altivec_register_operand" "v"))))]
5863 "TARGET_P9_VECTOR"
5864 "vcmpneb %0,%1,%2"
5865 [(set_attr "type" "vecsimple")])
5866
5867 ;; Vector Compare Not Equal v1ti (specified/not+eq:)
5868 (define_expand "vcmpnet"
5869 [(set (match_operand:V1TI 0 "altivec_register_operand")
5870 (not:V1TI
5871 (eq:V1TI (match_operand:V1TI 1 "altivec_register_operand")
5872 (match_operand:V1TI 2 "altivec_register_operand"))))]
5873 "TARGET_POWER10"
5874 {
5875 emit_insn (gen_eqvv1ti3 (operands[0], operands[1], operands[2]));
5876 emit_insn (gen_one_cmplv1ti2 (operands[0], operands[0]));
5877 DONE;
5878 })
5879
5880 ;; Vector Compare Not Equal or Zero Byte
5881 (define_insn "vcmpnezb"
5882 [(set (match_operand:V16QI 0 "altivec_register_operand" "=v")
5883 (unspec:V16QI
5884 [(match_operand:V16QI 1 "altivec_register_operand" "v")
5885 (match_operand:V16QI 2 "altivec_register_operand" "v")]
5886 UNSPEC_VCMPNEZB))]
5887 "TARGET_P9_VECTOR"
5888 "vcmpnezb %0,%1,%2"
5889 [(set_attr "type" "vecsimple")])
5890
5891 ;; Vector Compare Not Equal or Zero Byte predicate or record-form
5892 (define_insn "vcmpnezb_p"
5893 [(set (reg:CC CR6_REGNO)
5894 (unspec:CC
5895 [(match_operand:V16QI 1 "altivec_register_operand" "v")
5896 (match_operand:V16QI 2 "altivec_register_operand" "v")]
5897 UNSPEC_VCMPNEZB))
5898 (set (match_operand:V16QI 0 "altivec_register_operand" "=v")
5899 (unspec:V16QI
5900 [(match_dup 1)
5901 (match_dup 2)]
5902 UNSPEC_VCMPNEZB))]
5903 "TARGET_P9_VECTOR"
5904 "vcmpnezb. %0,%1,%2"
5905 [(set_attr "type" "vecsimple")])
5906
5907 ;; Vector Compare Not Equal Half Word (specified/not+eq:)
5908 (define_insn "vcmpneh"
5909 [(set (match_operand:V8HI 0 "altivec_register_operand" "=v")
5910 (not:V8HI
5911 (eq:V8HI (match_operand:V8HI 1 "altivec_register_operand" "v")
5912 (match_operand:V8HI 2 "altivec_register_operand" "v"))))]
5913 "TARGET_P9_VECTOR"
5914 "vcmpneh %0,%1,%2"
5915 [(set_attr "type" "vecsimple")])
5916
5917 ;; Vector Compare Not Equal or Zero Half Word
5918 (define_insn "vcmpnezh"
5919 [(set (match_operand:V8HI 0 "altivec_register_operand" "=v")
5920 (unspec:V8HI [(match_operand:V8HI 1 "altivec_register_operand" "v")
5921 (match_operand:V8HI 2 "altivec_register_operand" "v")]
5922 UNSPEC_VCMPNEZH))]
5923 "TARGET_P9_VECTOR"
5924 "vcmpnezh %0,%1,%2"
5925 [(set_attr "type" "vecsimple")])
5926
5927 ;; Vector Compare Not Equal Word (specified/not+eq:)
5928 (define_insn "vcmpnew"
5929 [(set (match_operand:V4SI 0 "altivec_register_operand" "=v")
5930 (not:V4SI
5931 (eq:V4SI (match_operand:V4SI 1 "altivec_register_operand" "v")
5932 (match_operand:V4SI 2 "altivec_register_operand" "v"))))]
5933 "TARGET_P9_VECTOR"
5934 "vcmpnew %0,%1,%2"
5935 [(set_attr "type" "vecsimple")])
5936
5937 ;; Vector Compare Not Equal or Zero Word
5938 (define_insn "vcmpnezw"
5939 [(set (match_operand:V4SI 0 "altivec_register_operand" "=v")
5940 (unspec:V4SI [(match_operand:V4SI 1 "altivec_register_operand" "v")
5941 (match_operand:V4SI 2 "altivec_register_operand" "v")]
5942 UNSPEC_VCMPNEZW))]
5943 "TARGET_P9_VECTOR"
5944 "vcmpnezw %0,%1,%2"
5945 [(set_attr "type" "vecsimple")])
5946
5947 ;; Vector Count Leading/Trailing Zero Least-Significant Bits Byte
5948 (define_insn "*vc<vczlsbb_char>zlsbb_zext_<mode>"
5949 [(set (match_operand:DI 0 "register_operand" "=r")
5950 (zero_extend:DI
5951 (unspec:SI
5952 [(match_operand:VSX_EXTRACT_I 1 "altivec_register_operand" "v")]
5953 VCZLSBB)))]
5954 "TARGET_P9_VECTOR"
5955 "vc<vczlsbb_char>zlsbb %0,%1"
5956 [(set_attr "type" "vecsimple")])
5957
5958 (define_insn "vc<vczlsbb_char>zlsbb_<mode>"
5959 [(set (match_operand:SI 0 "register_operand" "=r")
5960 (unspec:SI
5961 [(match_operand:VSX_EXTRACT_I 1 "altivec_register_operand" "v")]
5962 VCZLSBB))]
5963 "TARGET_P9_VECTOR"
5964 "vc<vczlsbb_char>zlsbb %0,%1"
5965 [(set_attr "type" "vecsimple")])
5966
5967 ;; Vector Extract Unsigned Byte Left-Indexed
5968 (define_insn "vextublx"
5969 [(set (match_operand:SI 0 "register_operand" "=r")
5970 (unspec:SI
5971 [(match_operand:SI 1 "register_operand" "r")
5972 (match_operand:V16QI 2 "altivec_register_operand" "v")]
5973 UNSPEC_VEXTUBLX))]
5974 "TARGET_P9_VECTOR"
5975 "vextublx %0,%1,%2"
5976 [(set_attr "type" "vecsimple")])
5977
5978 ;; Vector Extract Unsigned Byte Right-Indexed
5979 (define_insn "vextubrx"
5980 [(set (match_operand:SI 0 "register_operand" "=r")
5981 (unspec:SI
5982 [(match_operand:SI 1 "register_operand" "r")
5983 (match_operand:V16QI 2 "altivec_register_operand" "v")]
5984 UNSPEC_VEXTUBRX))]
5985 "TARGET_P9_VECTOR"
5986 "vextubrx %0,%1,%2"
5987 [(set_attr "type" "vecsimple")])
5988
5989 ;; Vector Extract Unsigned Half Word Left-Indexed
5990 (define_insn "vextuhlx"
5991 [(set (match_operand:SI 0 "register_operand" "=r")
5992 (unspec:SI
5993 [(match_operand:SI 1 "register_operand" "r")
5994 (match_operand:V8HI 2 "altivec_register_operand" "v")]
5995 UNSPEC_VEXTUHLX))]
5996 "TARGET_P9_VECTOR"
5997 "vextuhlx %0,%1,%2"
5998 [(set_attr "type" "vecsimple")])
5999
6000 ;; Vector Extract Unsigned Half Word Right-Indexed
6001 (define_insn "vextuhrx"
6002 [(set (match_operand:SI 0 "register_operand" "=r")
6003 (unspec:SI
6004 [(match_operand:SI 1 "register_operand" "r")
6005 (match_operand:V8HI 2 "altivec_register_operand" "v")]
6006 UNSPEC_VEXTUHRX))]
6007 "TARGET_P9_VECTOR"
6008 "vextuhrx %0,%1,%2"
6009 [(set_attr "type" "vecsimple")])
6010
6011 ;; Vector Extract Unsigned Word Left-Indexed
6012 (define_insn "vextuwlx"
6013 [(set (match_operand:SI 0 "register_operand" "=r")
6014 (unspec:SI
6015 [(match_operand:SI 1 "register_operand" "r")
6016 (match_operand:V4SI 2 "altivec_register_operand" "v")]
6017 UNSPEC_VEXTUWLX))]
6018 "TARGET_P9_VECTOR"
6019 "vextuwlx %0,%1,%2"
6020 [(set_attr "type" "vecsimple")])
6021
6022 ;; Vector Extract Unsigned Word Right-Indexed
6023 (define_insn "vextuwrx"
6024 [(set (match_operand:SI 0 "register_operand" "=r")
6025 (unspec:SI
6026 [(match_operand:SI 1 "register_operand" "r")
6027 (match_operand:V4SI 2 "altivec_register_operand" "v")]
6028 UNSPEC_VEXTUWRX))]
6029 "TARGET_P9_VECTOR"
6030 "vextuwrx %0,%1,%2"
6031 [(set_attr "type" "vecsimple")])
6032
6033 ;; Vector insert/extract word at arbitrary byte values. Note, the little
6034 ;; endian version needs to adjust the byte number, and the V4SI element in
6035 ;; vinsert4b.
6036 (define_insn "extract4b"
6037 [(set (match_operand:V2DI 0 "vsx_register_operand")
6038 (unspec:V2DI [(match_operand:V16QI 1 "vsx_register_operand" "wa")
6039 (match_operand:QI 2 "const_0_to_12_operand" "n")]
6040 UNSPEC_XXEXTRACTUW))]
6041 "TARGET_P9_VECTOR"
6042 {
6043 if (!BYTES_BIG_ENDIAN)
6044 operands[2] = GEN_INT (12 - INTVAL (operands[2]));
6045
6046 return "xxextractuw %x0,%x1,%2";
6047 })
6048
6049 (define_expand "insert4b"
6050 [(set (match_operand:V16QI 0 "vsx_register_operand")
6051 (unspec:V16QI [(match_operand:V4SI 1 "vsx_register_operand")
6052 (match_operand:V16QI 2 "vsx_register_operand")
6053 (match_operand:QI 3 "const_0_to_12_operand")]
6054 UNSPEC_XXINSERTW))]
6055 "TARGET_P9_VECTOR"
6056 {
6057 if (!BYTES_BIG_ENDIAN)
6058 {
6059 rtx op1 = operands[1];
6060 rtx v4si_tmp = gen_reg_rtx (V4SImode);
6061 emit_insn (gen_vsx_xxpermdi_v4si_be (v4si_tmp, op1, op1, const1_rtx));
6062 operands[1] = v4si_tmp;
6063 operands[3] = GEN_INT (12 - INTVAL (operands[3]));
6064 }
6065 })
6066
6067 (define_insn "*insert4b_internal"
6068 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
6069 (unspec:V16QI [(match_operand:V4SI 1 "vsx_register_operand" "wa")
6070 (match_operand:V16QI 2 "vsx_register_operand" "0")
6071 (match_operand:QI 3 "const_0_to_12_operand" "n")]
6072 UNSPEC_XXINSERTW))]
6073 "TARGET_P9_VECTOR"
6074 "xxinsertw %x0,%x1,%3"
6075 [(set_attr "type" "vecperm")])
6076
6077
6078 ;; Generate vector extract four float 32 values from left four elements
6079 ;; of eight element vector of float 16 values.
6080 (define_expand "vextract_fp_from_shorth"
6081 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6082 (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "wa")]
6083 UNSPEC_VSX_VEXTRACT_FP_FROM_SHORTH))]
6084 "TARGET_P9_VECTOR"
6085 {
6086 int i;
6087 int vals_le[16] = {15, 14, 0, 0, 13, 12, 0, 0, 11, 10, 0, 0, 9, 8, 0, 0};
6088 int vals_be[16] = {0, 0, 0, 1, 0, 0, 2, 3, 0, 0, 4, 5, 0, 0, 6, 7};
6089
6090 rtx rvals[16];
6091 rtx mask = gen_reg_rtx (V16QImode);
6092 rtx tmp = gen_reg_rtx (V16QImode);
6093 rtvec v;
6094
6095 for (i = 0; i < 16; i++)
6096 if (!BYTES_BIG_ENDIAN)
6097 rvals[i] = GEN_INT (vals_le[i]);
6098 else
6099 rvals[i] = GEN_INT (vals_be[i]);
6100
6101 /* xvcvhpsp - vector convert F16 to vector F32 requires the four F16
6102 inputs in half words 1,3,5,7 (IBM numbering). Use xxperm to move
6103 src half words 0,1,2,3 (LE), src half words 4,5,6,7 (BE) for the
6104 conversion instruction. */
6105 v = gen_rtvec_v (16, rvals);
6106 emit_insn (gen_vec_initv16qiqi (mask, gen_rtx_PARALLEL (V16QImode, v)));
6107 emit_insn (gen_altivec_vperm_v8hiv16qi (tmp, operands[1],
6108 operands[1], mask));
6109 emit_insn (gen_vsx_xvcvhpsp (operands[0], tmp));
6110 DONE;
6111 })
6112
6113 ;; Generate vector extract four float 32 values from right four elements
6114 ;; of eight element vector of float 16 values.
6115 (define_expand "vextract_fp_from_shortl"
6116 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6117 (unspec:V4SF [(match_operand:V8HI 1 "register_operand" "wa")]
6118 UNSPEC_VSX_VEXTRACT_FP_FROM_SHORTL))]
6119 "TARGET_P9_VECTOR"
6120 {
6121 int vals_le[16] = {7, 6, 0, 0, 5, 4, 0, 0, 3, 2, 0, 0, 1, 0, 0, 0};
6122 int vals_be[16] = {0, 0, 8, 9, 0, 0, 10, 11, 0, 0, 12, 13, 0, 0, 14, 15};
6123
6124 int i;
6125 rtx rvals[16];
6126 rtx mask = gen_reg_rtx (V16QImode);
6127 rtx tmp = gen_reg_rtx (V16QImode);
6128 rtvec v;
6129
6130 for (i = 0; i < 16; i++)
6131 if (!BYTES_BIG_ENDIAN)
6132 rvals[i] = GEN_INT (vals_le[i]);
6133 else
6134 rvals[i] = GEN_INT (vals_be[i]);
6135
6136 /* xvcvhpsp - vector convert F16 to vector F32 requires the four F16
6137 inputs in half words 1,3,5,7 (IBM numbering). Use xxperm to move
6138 src half words 4,5,6,7 (LE), src half words 0,1,2,3 (BE) for the
6139 conversion instruction. */
6140 v = gen_rtvec_v (16, rvals);
6141 emit_insn (gen_vec_initv16qiqi (mask, gen_rtx_PARALLEL (V16QImode, v)));
6142 emit_insn (gen_altivec_vperm_v8hiv16qi (tmp, operands[1],
6143 operands[1], mask));
6144 emit_insn (gen_vsx_xvcvhpsp (operands[0], tmp));
6145 DONE;
6146 })
6147
6148 ;; Support for ISA 3.0 vector byte reverse
6149
6150 ;; Swap all bytes with in a vector
6151 (define_insn "p9_xxbrq_v1ti"
6152 [(set (match_operand:V1TI 0 "vsx_register_operand" "=wa")
6153 (bswap:V1TI (match_operand:V1TI 1 "vsx_register_operand" "wa")))]
6154 "TARGET_P9_VECTOR"
6155 "xxbrq %x0,%x1"
6156 [(set_attr "type" "vecperm")])
6157
6158 (define_expand "p9_xxbrq_v16qi"
6159 [(use (match_operand:V16QI 0 "vsx_register_operand" "=wa"))
6160 (use (match_operand:V16QI 1 "vsx_register_operand" "wa"))]
6161 "TARGET_P9_VECTOR"
6162 {
6163 rtx op0 = gen_reg_rtx (V1TImode);
6164 rtx op1 = gen_lowpart (V1TImode, operands[1]);
6165 emit_insn (gen_p9_xxbrq_v1ti (op0, op1));
6166 emit_move_insn (operands[0], gen_lowpart (V16QImode, op0));
6167 DONE;
6168 })
6169
6170 ;; Swap all bytes in each 64-bit element
6171 (define_insn "p9_xxbrd_v2di"
6172 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
6173 (bswap:V2DI (match_operand:V2DI 1 "vsx_register_operand" "wa")))]
6174 "TARGET_P9_VECTOR"
6175 "xxbrd %x0,%x1"
6176 [(set_attr "type" "vecperm")])
6177
6178 (define_expand "p9_xxbrd_v2df"
6179 [(use (match_operand:V2DF 0 "vsx_register_operand" "=wa"))
6180 (use (match_operand:V2DF 1 "vsx_register_operand" "wa"))]
6181 "TARGET_P9_VECTOR"
6182 {
6183 rtx op0 = gen_reg_rtx (V2DImode);
6184 rtx op1 = gen_lowpart (V2DImode, operands[1]);
6185 emit_insn (gen_p9_xxbrd_v2di (op0, op1));
6186 emit_move_insn (operands[0], gen_lowpart (V2DFmode, op0));
6187 DONE;
6188 })
6189
6190 ;; Swap all bytes in each 32-bit element
6191 (define_insn "p9_xxbrw_v4si"
6192 [(set (match_operand:V4SI 0 "vsx_register_operand" "=wa")
6193 (bswap:V4SI (match_operand:V4SI 1 "vsx_register_operand" "wa")))]
6194 "TARGET_P9_VECTOR"
6195 "xxbrw %x0,%x1"
6196 [(set_attr "type" "vecperm")])
6197
6198 (define_expand "p9_xxbrw_v4sf"
6199 [(use (match_operand:V4SF 0 "vsx_register_operand" "=wa"))
6200 (use (match_operand:V4SF 1 "vsx_register_operand" "wa"))]
6201 "TARGET_P9_VECTOR"
6202 {
6203 rtx op0 = gen_reg_rtx (V4SImode);
6204 rtx op1 = gen_lowpart (V4SImode, operands[1]);
6205 emit_insn (gen_p9_xxbrw_v4si (op0, op1));
6206 emit_move_insn (operands[0], gen_lowpart (V4SFmode, op0));
6207 DONE;
6208 })
6209
6210 ;; Swap all bytes in each element of vector
6211 (define_expand "revb_<mode>"
6212 [(use (match_operand:VEC_REVB 0 "vsx_register_operand"))
6213 (use (match_operand:VEC_REVB 1 "vsx_register_operand"))]
6214 ""
6215 {
6216 if (TARGET_P9_VECTOR)
6217 emit_insn (gen_p9_xxbr<VSX_XXBR>_<mode> (operands[0], operands[1]));
6218 else
6219 {
6220 if (<MODE>mode == V8HImode)
6221 {
6222 rtx splt = gen_reg_rtx (V8HImode);
6223 emit_insn (gen_altivec_vspltish (splt, GEN_INT (8)));
6224 emit_insn (gen_altivec_vrlh (operands[0], operands[1], splt));
6225 }
6226 else
6227 {
6228 /* Want to have the elements in reverse order relative
6229 to the endian mode in use, i.e. in LE mode, put elements
6230 in BE order. */
6231 rtx sel = swap_endian_selector_for_mode (<MODE>mode);
6232 emit_insn (gen_altivec_vperm_<mode>_direct (operands[0], operands[1],
6233 operands[1], sel));
6234 }
6235 }
6236
6237 DONE;
6238 })
6239
6240 ;; Reversing bytes in vector char is just a NOP.
6241 (define_expand "revb_v16qi"
6242 [(set (match_operand:V16QI 0 "vsx_register_operand")
6243 (bswap:V16QI (match_operand:V16QI 1 "vsx_register_operand")))]
6244 ""
6245 {
6246 emit_move_insn (operands[0], operands[1]);
6247 DONE;
6248 })
6249
6250 ;; Swap all bytes in each 16-bit element
6251 (define_insn "p9_xxbrh_v8hi"
6252 [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
6253 (bswap:V8HI (match_operand:V8HI 1 "vsx_register_operand" "wa")))]
6254 "TARGET_P9_VECTOR"
6255 "xxbrh %x0,%x1"
6256 [(set_attr "type" "vecperm")])
6257
6258
6259 ;; Operand numbers for the following peephole2
6260 (define_constants
6261 [(SFBOOL_TMP_GPR 0) ;; GPR temporary
6262 (SFBOOL_TMP_VSX 1) ;; vector temporary
6263 (SFBOOL_MFVSR_D 2) ;; move to gpr dest
6264 (SFBOOL_MFVSR_A 3) ;; move to gpr src
6265 (SFBOOL_BOOL_D 4) ;; and/ior/xor dest
6266 (SFBOOL_BOOL_A1 5) ;; and/ior/xor arg1
6267 (SFBOOL_BOOL_A2 6) ;; and/ior/xor arg1
6268 (SFBOOL_SHL_D 7) ;; shift left dest
6269 (SFBOOL_SHL_A 8) ;; shift left arg
6270 (SFBOOL_MTVSR_D 9) ;; move to vecter dest
6271 (SFBOOL_MFVSR_A_V4SF 10) ;; SFBOOL_MFVSR_A as V4SFmode
6272 (SFBOOL_BOOL_A_DI 11) ;; SFBOOL_BOOL_A1/A2 as DImode
6273 (SFBOOL_TMP_VSX_DI 12) ;; SFBOOL_TMP_VSX as DImode
6274 (SFBOOL_MTVSR_D_V4SF 13)]) ;; SFBOOL_MTVSRD_D as V4SFmode
6275
6276 ;; Attempt to optimize some common GLIBC operations using logical operations to
6277 ;; pick apart SFmode operations. For example, there is code from e_powf.c
6278 ;; after macro expansion that looks like:
6279 ;;
6280 ;; typedef union {
6281 ;; float value;
6282 ;; uint32_t word;
6283 ;; } ieee_float_shape_type;
6284 ;;
6285 ;; float t1;
6286 ;; int32_t is;
6287 ;;
6288 ;; do {
6289 ;; ieee_float_shape_type gf_u;
6290 ;; gf_u.value = (t1);
6291 ;; (is) = gf_u.word;
6292 ;; } while (0);
6293 ;;
6294 ;; do {
6295 ;; ieee_float_shape_type sf_u;
6296 ;; sf_u.word = (is & 0xfffff000);
6297 ;; (t1) = sf_u.value;
6298 ;; } while (0);
6299 ;;
6300 ;;
6301 ;; This would result in two direct move operations (convert to memory format,
6302 ;; direct move to GPR, do the AND operation, direct move to VSX, convert to
6303 ;; scalar format). With this peephole, we eliminate the direct move to the
6304 ;; GPR, and instead move the integer mask value to the vector register after a
6305 ;; shift and do the VSX logical operation.
6306
6307 ;; The insns for dealing with SFmode in GPR registers looks like:
6308 ;; (set (reg:V4SF reg2) (unspec:V4SF [(reg:SF reg1)] UNSPEC_VSX_CVDPSPN))
6309 ;;
6310 ;; (set (reg:DI reg3) (unspec:DI [(reg:V4SF reg2)] UNSPEC_P8V_RELOAD_FROM_VSX))
6311 ;;
6312 ;; (set (reg:DI reg4) (and:DI (reg:DI reg3) (reg:DI reg3)))
6313 ;;
6314 ;; (set (reg:DI reg5) (ashift:DI (reg:DI reg4) (const_int 32)))
6315 ;;
6316 ;; (set (reg:SF reg6) (unspec:SF [(reg:DI reg5)] UNSPEC_P8V_MTVSRD))
6317 ;;
6318 ;; (set (reg:SF reg6) (unspec:SF [(reg:SF reg6)] UNSPEC_VSX_CVSPDPN))
6319
6320 (define_peephole2
6321 [(match_scratch:DI SFBOOL_TMP_GPR "r")
6322 (match_scratch:V4SF SFBOOL_TMP_VSX "wa")
6323
6324 ;; MFVSRWZ (aka zero_extend)
6325 (set (match_operand:DI SFBOOL_MFVSR_D "int_reg_operand")
6326 (zero_extend:DI
6327 (match_operand:SI SFBOOL_MFVSR_A "vsx_register_operand")))
6328
6329 ;; AND/IOR/XOR operation on int
6330 (set (match_operand:SI SFBOOL_BOOL_D "int_reg_operand")
6331 (and_ior_xor:SI (match_operand:SI SFBOOL_BOOL_A1 "int_reg_operand")
6332 (match_operand:SI SFBOOL_BOOL_A2 "reg_or_cint_operand")))
6333
6334 ;; SLDI
6335 (set (match_operand:DI SFBOOL_SHL_D "int_reg_operand")
6336 (ashift:DI (match_operand:DI SFBOOL_SHL_A "int_reg_operand")
6337 (const_int 32)))
6338
6339 ;; MTVSRD
6340 (set (match_operand:SF SFBOOL_MTVSR_D "vsx_register_operand")
6341 (unspec:SF [(match_dup SFBOOL_SHL_D)] UNSPEC_P8V_MTVSRD))]
6342
6343 "TARGET_DIRECT_MOVE_64BIT
6344 /* The REG_P (xxx) tests prevents SUBREG's, which allows us to use REGNO
6345 to compare registers, when the mode is different. */
6346 && REG_P (operands[SFBOOL_MFVSR_D]) && REG_P (operands[SFBOOL_BOOL_D])
6347 && REG_P (operands[SFBOOL_BOOL_A1]) && REG_P (operands[SFBOOL_SHL_D])
6348 && REG_P (operands[SFBOOL_SHL_A]) && REG_P (operands[SFBOOL_MTVSR_D])
6349 && (REG_P (operands[SFBOOL_BOOL_A2])
6350 || CONST_INT_P (operands[SFBOOL_BOOL_A2]))
6351 && (REGNO (operands[SFBOOL_BOOL_D]) == REGNO (operands[SFBOOL_MFVSR_D])
6352 || peep2_reg_dead_p (2, operands[SFBOOL_MFVSR_D]))
6353 && (REGNO (operands[SFBOOL_MFVSR_D]) == REGNO (operands[SFBOOL_BOOL_A1])
6354 || (REG_P (operands[SFBOOL_BOOL_A2])
6355 && REGNO (operands[SFBOOL_MFVSR_D])
6356 == REGNO (operands[SFBOOL_BOOL_A2])))
6357 && REGNO (operands[SFBOOL_BOOL_D]) == REGNO (operands[SFBOOL_SHL_A])
6358 && (REGNO (operands[SFBOOL_SHL_D]) == REGNO (operands[SFBOOL_BOOL_D])
6359 || peep2_reg_dead_p (3, operands[SFBOOL_BOOL_D]))
6360 && peep2_reg_dead_p (4, operands[SFBOOL_SHL_D])"
6361 [(set (match_dup SFBOOL_TMP_GPR)
6362 (ashift:DI (match_dup SFBOOL_BOOL_A_DI)
6363 (const_int 32)))
6364
6365 (set (match_dup SFBOOL_TMP_VSX_DI)
6366 (match_dup SFBOOL_TMP_GPR))
6367
6368 (set (match_dup SFBOOL_MTVSR_D_V4SF)
6369 (and_ior_xor:V4SF (match_dup SFBOOL_MFVSR_A_V4SF)
6370 (match_dup SFBOOL_TMP_VSX)))]
6371 {
6372 rtx bool_a1 = operands[SFBOOL_BOOL_A1];
6373 rtx bool_a2 = operands[SFBOOL_BOOL_A2];
6374 int regno_mfvsr_d = REGNO (operands[SFBOOL_MFVSR_D]);
6375 int regno_mfvsr_a = REGNO (operands[SFBOOL_MFVSR_A]);
6376 int regno_tmp_vsx = REGNO (operands[SFBOOL_TMP_VSX]);
6377 int regno_mtvsr_d = REGNO (operands[SFBOOL_MTVSR_D]);
6378
6379 if (CONST_INT_P (bool_a2))
6380 {
6381 rtx tmp_gpr = operands[SFBOOL_TMP_GPR];
6382 emit_move_insn (tmp_gpr, bool_a2);
6383 operands[SFBOOL_BOOL_A_DI] = tmp_gpr;
6384 }
6385 else
6386 {
6387 int regno_bool_a1 = REGNO (bool_a1);
6388 int regno_bool_a2 = REGNO (bool_a2);
6389 int regno_bool_a = (regno_mfvsr_d == regno_bool_a1
6390 ? regno_bool_a2 : regno_bool_a1);
6391 operands[SFBOOL_BOOL_A_DI] = gen_rtx_REG (DImode, regno_bool_a);
6392 }
6393
6394 operands[SFBOOL_MFVSR_A_V4SF] = gen_rtx_REG (V4SFmode, regno_mfvsr_a);
6395 operands[SFBOOL_TMP_VSX_DI] = gen_rtx_REG (DImode, regno_tmp_vsx);
6396 operands[SFBOOL_MTVSR_D_V4SF] = gen_rtx_REG (V4SFmode, regno_mtvsr_d);
6397 })
6398
6399 ;; Support signed/unsigned long long to float conversion vectorization.
6400 ;; Note that any_float (pc) here is just for code attribute <su>.
6401 (define_expand "vec_pack<su>_float_v2di"
6402 [(match_operand:V4SF 0 "vfloat_operand")
6403 (match_operand:V2DI 1 "vint_operand")
6404 (match_operand:V2DI 2 "vint_operand")
6405 (any_float (pc))]
6406 "TARGET_VSX"
6407 {
6408 rtx r1 = gen_reg_rtx (V4SFmode);
6409 rtx r2 = gen_reg_rtx (V4SFmode);
6410 emit_insn (gen_vsx_xvcv<su>xdsp (r1, operands[1]));
6411 emit_insn (gen_vsx_xvcv<su>xdsp (r2, operands[2]));
6412 rs6000_expand_extract_even (operands[0], r1, r2);
6413 DONE;
6414 })
6415
6416 ;; Support float to signed/unsigned long long conversion vectorization.
6417 ;; Note that any_fix (pc) here is just for code attribute <su>.
6418 (define_expand "vec_unpack_<su>fix_trunc_hi_v4sf"
6419 [(match_operand:V2DI 0 "vint_operand")
6420 (match_operand:V4SF 1 "vfloat_operand")
6421 (any_fix (pc))]
6422 "TARGET_VSX"
6423 {
6424 rtx reg = gen_reg_rtx (V4SFmode);
6425 rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN);
6426 emit_insn (gen_vsx_xvcvsp<su>xds (operands[0], reg));
6427 DONE;
6428 })
6429
6430 ;; Note that any_fix (pc) here is just for code attribute <su>.
6431 (define_expand "vec_unpack_<su>fix_trunc_lo_v4sf"
6432 [(match_operand:V2DI 0 "vint_operand")
6433 (match_operand:V4SF 1 "vfloat_operand")
6434 (any_fix (pc))]
6435 "TARGET_VSX"
6436 {
6437 rtx reg = gen_reg_rtx (V4SFmode);
6438 rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN);
6439 emit_insn (gen_vsx_xvcvsp<su>xds (operands[0], reg));
6440 DONE;
6441 })
6442
6443 (define_insn "vsx_<xvcvbf16>"
6444 [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
6445 (unspec:V16QI [(match_operand:V16QI 1 "vsx_register_operand" "wa")]
6446 XVCVBF16))]
6447 "TARGET_POWER10"
6448 "<xvcvbf16> %x0,%x1"
6449 [(set_attr "type" "vecfloat")])
6450
6451 (define_insn "vec_mtvsrbmi"
6452 [(set (match_operand:V16QI 0 "altivec_register_operand" "=v")
6453 (unspec:V16QI [(match_operand:QI 1 "u6bit_cint_operand" "n")]
6454 UNSPEC_MTVSBM))]
6455 "TARGET_POWER10"
6456 "mtvsrbmi %0,%1"
6457 )
6458
6459 (define_insn "vec_mtvsr_<mode>"
6460 [(set (match_operand:VSX_MM 0 "altivec_register_operand" "=v")
6461 (unspec:VSX_MM [(match_operand:DI 1 "gpc_reg_operand" "r")]
6462 UNSPEC_MTVSBM))]
6463 "TARGET_POWER10"
6464 "mtvsr<wd>m %0,%1";
6465 [(set_attr "type" "vecsimple")])
6466
6467 (define_insn "vec_cntmb_<mode>"
6468 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
6469 (unspec:DI [(match_operand:VSX_MM4 1 "altivec_register_operand" "v")
6470 (match_operand:QI 2 "const_0_to_1_operand" "n")]
6471 UNSPEC_VCNTMB))]
6472 "TARGET_POWER10"
6473 "vcntmb<wd> %0,%1,%2"
6474 [(set_attr "type" "vecsimple")])
6475
6476 (define_insn "vec_extract_<mode>"
6477 [(set (match_operand:SI 0 "register_operand" "=r")
6478 (unspec:SI [(match_operand:VSX_MM 1 "altivec_register_operand" "v")]
6479 UNSPEC_VEXTRACT))]
6480 "TARGET_POWER10"
6481 "vextract<wd>m %0,%1"
6482 [(set_attr "type" "vecsimple")])
6483
6484 (define_insn "vec_expand_<mode>"
6485 [(set (match_operand:VSX_MM 0 "vsx_register_operand" "=v")
6486 (unspec:VSX_MM [(match_operand:VSX_MM 1 "vsx_register_operand" "v")]
6487 UNSPEC_VEXPAND))]
6488 "TARGET_POWER10"
6489 "vexpand<wd>m %0,%1"
6490 [(set_attr "type" "vecsimple")])
6491
6492 (define_insn "dives_<mode>"
6493 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6494 (unspec:VIlong [(match_operand:VIlong 1 "vsx_register_operand" "v")
6495 (match_operand:VIlong 2 "vsx_register_operand" "v")]
6496 UNSPEC_VDIVES))]
6497 "TARGET_POWER10"
6498 "vdives<wd> %0,%1,%2"
6499 [(set_attr "type" "vecdiv")
6500 (set_attr "size" "<bits>")])
6501
6502 (define_insn "diveu_<mode>"
6503 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6504 (unspec:VIlong [(match_operand:VIlong 1 "vsx_register_operand" "v")
6505 (match_operand:VIlong 2 "vsx_register_operand" "v")]
6506 UNSPEC_VDIVEU))]
6507 "TARGET_POWER10"
6508 "vdiveu<wd> %0,%1,%2"
6509 [(set_attr "type" "vecdiv")
6510 (set_attr "size" "<bits>")])
6511
6512 (define_insn "div<mode>3"
6513 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6514 (div:VIlong (match_operand:VIlong 1 "vsx_register_operand" "v")
6515 (match_operand:VIlong 2 "vsx_register_operand" "v")))]
6516 "TARGET_POWER10"
6517 "vdivs<wd> %0,%1,%2"
6518 [(set_attr "type" "vecdiv")
6519 (set_attr "size" "<bits>")])
6520
6521 (define_insn "udiv<mode>3"
6522 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6523 (udiv:VIlong (match_operand:VIlong 1 "vsx_register_operand" "v")
6524 (match_operand:VIlong 2 "vsx_register_operand" "v")))]
6525 "TARGET_POWER10"
6526 "vdivu<wd> %0,%1,%2"
6527 [(set_attr "type" "vecdiv")
6528 (set_attr "size" "<bits>")])
6529
6530 (define_insn "mod<mode>3"
6531 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6532 (mod:VIlong (match_operand:VIlong 1 "vsx_register_operand" "v")
6533 (match_operand:VIlong 2 "vsx_register_operand" "v")))]
6534 "TARGET_POWER10"
6535 "vmods<wd> %0,%1,%2"
6536 [(set_attr "type" "vecdiv")
6537 (set_attr "size" "<bits>")])
6538
6539 (define_insn "umod<mode>3"
6540 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6541 (umod:VIlong (match_operand:VIlong 1 "vsx_register_operand" "v")
6542 (match_operand:VIlong 2 "vsx_register_operand" "v")))]
6543 "TARGET_POWER10"
6544 "vmodu<wd> %0,%1,%2"
6545 [(set_attr "type" "vecdiv")
6546 (set_attr "size" "<bits>")])
6547
6548 (define_insn "smul<mode>3_highpart"
6549 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6550 (mult:VIlong (ashiftrt
6551 (match_operand:VIlong 1 "vsx_register_operand" "v")
6552 (const_int 32))
6553 (ashiftrt
6554 (match_operand:VIlong 2 "vsx_register_operand" "v")
6555 (const_int 32))))]
6556 "TARGET_POWER10"
6557 "vmulhs<wd> %0,%1,%2"
6558 [(set_attr "type" "veccomplex")])
6559
6560 (define_insn "umul<mode>3_highpart"
6561 [(set (match_operand:VIlong 0 "vsx_register_operand" "=v")
6562 (us_mult:VIlong (ashiftrt
6563 (match_operand:VIlong 1 "vsx_register_operand" "v")
6564 (const_int 32))
6565 (ashiftrt
6566 (match_operand:VIlong 2 "vsx_register_operand" "v")
6567 (const_int 32))))]
6568 "TARGET_POWER10"
6569 "vmulhu<wd> %0,%1,%2"
6570 [(set_attr "type" "veccomplex")])
6571
6572 ;; Vector multiply low double word
6573 (define_insn "mulv2di3"
6574 [(set (match_operand:V2DI 0 "vsx_register_operand" "=v")
6575 (mult:V2DI (match_operand:V2DI 1 "vsx_register_operand" "v")
6576 (match_operand:V2DI 2 "vsx_register_operand" "v")))]
6577 "TARGET_POWER10"
6578 "vmulld %0,%1,%2"
6579 [(set_attr "type" "veccomplex")])
6580
6581
6582 ;; XXSPLTIW built-in function support
6583 (define_insn "xxspltiw_v4si"
6584 [(set (match_operand:V4SI 0 "register_operand" "=wa")
6585 (unspec:V4SI [(match_operand:SI 1 "s32bit_cint_operand" "n")]
6586 UNSPEC_XXSPLTIW))]
6587 "TARGET_POWER10"
6588 "xxspltiw %x0,%1"
6589 [(set_attr "type" "vecperm")
6590 (set_attr "prefixed" "yes")])
6591
6592 (define_expand "xxspltiw_v4sf"
6593 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6594 (unspec:V4SF [(match_operand:SF 1 "const_double_operand" "n")]
6595 UNSPEC_XXSPLTIW))]
6596 "TARGET_POWER10"
6597 {
6598 long value = rs6000_const_f32_to_i32 (operands[1]);
6599 emit_insn (gen_xxspltiw_v4sf_inst (operands[0], GEN_INT (value)));
6600 DONE;
6601 })
6602
6603 (define_insn "xxspltiw_v4sf_inst"
6604 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6605 (unspec:V4SF [(match_operand:SI 1 "c32bit_cint_operand" "n")]
6606 UNSPEC_XXSPLTIW))]
6607 "TARGET_POWER10"
6608 "xxspltiw %x0,%1"
6609 [(set_attr "type" "vecperm")
6610 (set_attr "prefixed" "yes")])
6611
6612 ;; XXSPLTIDP built-in function support
6613 (define_expand "xxspltidp_v2df"
6614 [(set (match_operand:V2DF 0 "register_operand" )
6615 (unspec:V2DF [(match_operand:SF 1 "const_double_operand")]
6616 UNSPEC_XXSPLTIDP))]
6617 "TARGET_POWER10"
6618 {
6619 long value = rs6000_const_f32_to_i32 (operands[1]);
6620 rs6000_emit_xxspltidp_v2df (operands[0], value);
6621 DONE;
6622 })
6623
6624 (define_insn "xxspltidp_v2df_inst"
6625 [(set (match_operand:V2DF 0 "register_operand" "=wa")
6626 (unspec:V2DF [(match_operand:SI 1 "c32bit_cint_operand" "n")]
6627 UNSPEC_XXSPLTIDP))]
6628 "TARGET_POWER10"
6629 "xxspltidp %x0,%1"
6630 [(set_attr "type" "vecperm")
6631 (set_attr "prefixed" "yes")])
6632
6633 ;; XXSPLTI32DX built-in function support
6634 (define_expand "xxsplti32dx_v4si"
6635 [(set (match_operand:V4SI 0 "register_operand" "=wa")
6636 (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "0")
6637 (match_operand:QI 2 "u1bit_cint_operand" "n")
6638 (match_operand:SI 3 "s32bit_cint_operand" "n")]
6639 UNSPEC_XXSPLTI32DX))]
6640 "TARGET_POWER10"
6641 {
6642 int index = INTVAL (operands[2]);
6643
6644 if (!BYTES_BIG_ENDIAN)
6645 index = 1 - index;
6646
6647 emit_insn (gen_xxsplti32dx_v4si_inst (operands[0], operands[1],
6648 GEN_INT (index), operands[3]));
6649 DONE;
6650 }
6651 [(set_attr "type" "vecperm")])
6652
6653 (define_insn "xxsplti32dx_v4si_inst"
6654 [(set (match_operand:V4SI 0 "register_operand" "=wa")
6655 (unspec:V4SI [(match_operand:V4SI 1 "register_operand" "0")
6656 (match_operand:QI 2 "u1bit_cint_operand" "n")
6657 (match_operand:SI 3 "s32bit_cint_operand" "n")]
6658 UNSPEC_XXSPLTI32DX))]
6659 "TARGET_POWER10"
6660 "xxsplti32dx %x0,%2,%3"
6661 [(set_attr "type" "vecperm")
6662 (set_attr "prefixed" "yes")])
6663
6664 (define_expand "xxsplti32dx_v4sf"
6665 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6666 (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
6667 (match_operand:QI 2 "u1bit_cint_operand" "n")
6668 (match_operand:SF 3 "const_double_operand" "n")]
6669 UNSPEC_XXSPLTI32DX))]
6670 "TARGET_POWER10"
6671 {
6672 int index = INTVAL (operands[2]);
6673 long value = rs6000_const_f32_to_i32 (operands[3]);
6674 if (!BYTES_BIG_ENDIAN)
6675 index = 1 - index;
6676
6677 emit_insn (gen_xxsplti32dx_v4sf_inst (operands[0], operands[1],
6678 GEN_INT (index), GEN_INT (value)));
6679 DONE;
6680 })
6681
6682 (define_insn "xxsplti32dx_v4sf_inst"
6683 [(set (match_operand:V4SF 0 "register_operand" "=wa")
6684 (unspec:V4SF [(match_operand:V4SF 1 "register_operand" "0")
6685 (match_operand:QI 2 "u1bit_cint_operand" "n")
6686 (match_operand:SI 3 "s32bit_cint_operand" "n")]
6687 UNSPEC_XXSPLTI32DX))]
6688 "TARGET_POWER10"
6689 "xxsplti32dx %x0,%2,%3"
6690 [(set_attr "type" "vecperm")
6691 (set_attr "prefixed" "yes")])
6692
6693 ;; XXBLEND built-in function support
6694 (define_insn "xxblend_<mode>"
6695 [(set (match_operand:VM3 0 "register_operand" "=wa")
6696 (unspec:VM3 [(match_operand:VM3 1 "register_operand" "wa")
6697 (match_operand:VM3 2 "register_operand" "wa")
6698 (match_operand:VM3 3 "register_operand" "wa")]
6699 UNSPEC_XXBLEND))]
6700 "TARGET_POWER10"
6701 "xxblendv<VM3_char> %x0,%x1,%x2,%x3"
6702 [(set_attr "type" "vecperm")
6703 (set_attr "prefixed" "yes")])
6704
6705 ;; XXPERMX built-in function support
6706 (define_expand "xxpermx"
6707 [(set (match_operand:V2DI 0 "register_operand" "+wa")
6708 (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "wa")
6709 (match_operand:V2DI 2 "register_operand" "wa")
6710 (match_operand:V16QI 3 "register_operand" "wa")
6711 (match_operand:QI 4 "u8bit_cint_operand" "n")]
6712 UNSPEC_XXPERMX))]
6713 "TARGET_POWER10"
6714 {
6715 if (BYTES_BIG_ENDIAN)
6716 emit_insn (gen_xxpermx_inst (operands[0], operands[1],
6717 operands[2], operands[3],
6718 operands[4]));
6719 else
6720 {
6721 /* Reverse value of byte element indexes by XORing with 0xFF.
6722 Reverse the 32-byte section identifier match by subracting bits [0:2]
6723 of elemet from 7. */
6724 int value = INTVAL (operands[4]);
6725 rtx vreg = gen_reg_rtx (V16QImode);
6726
6727 emit_insn (gen_xxspltib_v16qi (vreg, GEN_INT (-1)));
6728 emit_insn (gen_xorv16qi3 (operands[3], operands[3], vreg));
6729 value = 7 - value;
6730 emit_insn (gen_xxpermx_inst (operands[0], operands[2],
6731 operands[1], operands[3],
6732 GEN_INT (value)));
6733 }
6734
6735 DONE;
6736 }
6737 [(set_attr "type" "vecperm")])
6738
6739 (define_insn "xxpermx_inst"
6740 [(set (match_operand:V2DI 0 "register_operand" "+v")
6741 (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "v")
6742 (match_operand:V2DI 2 "register_operand" "v")
6743 (match_operand:V16QI 3 "register_operand" "v")
6744 (match_operand:QI 4 "u3bit_cint_operand" "n")]
6745 UNSPEC_XXPERMX))]
6746 "TARGET_POWER10"
6747 "xxpermx %x0,%x1,%x2,%x3,%4"
6748 [(set_attr "type" "vecperm")
6749 (set_attr "prefixed" "yes")])
6750
6751 ;; XXEVAL built-in function support
6752 (define_insn "xxeval"
6753 [(set (match_operand:V2DI 0 "register_operand" "=wa")
6754 (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "wa")
6755 (match_operand:V2DI 2 "register_operand" "wa")
6756 (match_operand:V2DI 3 "register_operand" "wa")
6757 (match_operand:QI 4 "u8bit_cint_operand" "n")]
6758 UNSPEC_XXEVAL))]
6759 "TARGET_POWER10"
6760 "xxeval %x0,%x1,%x2,%x3,%4"
6761 [(set_attr "type" "vecperm")
6762 (set_attr "prefixed" "yes")])
6763
6764 ;; Construct V1TI by vsx_concat_v2di
6765 (define_split
6766 [(set (match_operand:V1TI 0 "vsx_register_operand")
6767 (subreg:V1TI
6768 (match_operand:TI 1 "int_reg_operand") 0 ))]
6769 "TARGET_P9_VECTOR && !reload_completed"
6770 [(const_int 0)]
6771 {
6772 rtx tmp1 = simplify_gen_subreg (DImode, operands[1], TImode, 0);
6773 rtx tmp2 = simplify_gen_subreg (DImode, operands[1], TImode, 8);
6774 rtx tmp3 = gen_reg_rtx (V2DImode);
6775 emit_insn (gen_vsx_concat_v2di (tmp3, tmp1, tmp2));
6776 rtx tmp4 = simplify_gen_subreg (V1TImode, tmp3, V2DImode, 0);
6777 emit_move_insn (operands[0], tmp4);
6778 DONE;
6779 })
6780
6781 ;; vmsumcud
6782 (define_insn "vmsumcud"
6783 [(set (match_operand:V1TI 0 "register_operand" "+v")
6784 (unspec:V1TI [(match_operand:V2DI 1 "register_operand" "v")
6785 (match_operand:V2DI 2 "register_operand" "v")
6786 (match_operand:V1TI 3 "register_operand" "v")]
6787 UNSPEC_VMSUMCUD))]
6788 "TARGET_POWER10"
6789 "vmsumcud %0,%1,%2,%3"
6790 [(set_attr "type" "veccomplex")]
6791 )
6792
6793 (define_split
6794 [(set (match_operand:V1TI 0 "gpc_reg_operand")
6795 (match_operand:V1TI 1 "vsx_register_operand"))]
6796 "reload_completed
6797 && TARGET_DIRECT_MOVE_64BIT
6798 && int_reg_operand (operands[0], V1TImode)
6799 && vsx_register_operand (operands[1], V1TImode)"
6800 [(pc)]
6801 {
6802 rtx src_op = gen_rtx_REG (V2DImode, REGNO (operands[1]));
6803 rtx dest_op0 = gen_rtx_REG (DImode, REGNO (operands[0]));
6804 rtx dest_op1 = gen_rtx_REG (DImode, REGNO (operands[0]) + 1);
6805 emit_insn (gen_vsx_extract_v2di (dest_op0, src_op, const0_rtx));
6806 emit_insn (gen_vsx_extract_v2di (dest_op1, src_op, const1_rtx));
6807 DONE;
6808 })