| 1 |
;; Expander definitions for vector support between altivec & vsx. No |
| 2 |
;; instructions are in this file, this file provides the generic vector |
| 3 |
;; expander, and the actual vector instructions will be in altivec.md and |
| 4 |
;; vsx.md |
| 5 |
|
| 6 |
;; Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 7 |
;; Contributed by Michael Meissner <[email protected]> |
| 8 |
|
| 9 |
;; This file is part of GCC. |
| 10 |
|
| 11 |
;; GCC is free software; you can redistribute it and/or modify it |
| 12 |
;; under the terms of the GNU General Public License as published |
| 13 |
;; by the Free Software Foundation; either version 3, or (at your |
| 14 |
;; option) any later version. |
| 15 |
|
| 16 |
;; GCC is distributed in the hope that it will be useful, but WITHOUT |
| 17 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 19 |
;; License for more details. |
| 20 |
|
| 21 |
;; You should have received a copy of the GNU General Public License |
| 22 |
;; along with GCC; see the file COPYING3. If not see |
| 23 |
;; <http://www.gnu.org/licenses/>. |
| 24 |
|
| 25 |
|
| 26 |
;; Vector int modes |
| 27 |
(define_mode_iterator VEC_I [V16QI V8HI V4SI V2DI]) |
| 28 |
|
| 29 |
;; Vector int modes for comparison, shift and rotation. ISA 3.1 adds the V1TI mode |
| 30 |
;; for the vector int128 type. |
| 31 |
(define_mode_iterator VEC_IC [V16QI V8HI V4SI V2DI (V1TI "TARGET_POWER10")]) |
| 32 |
|
| 33 |
;; 128-bit int modes |
| 34 |
(define_mode_iterator VEC_TI [V1TI TI]) |
| 35 |
|
| 36 |
;; Vector int modes for parity |
| 37 |
(define_mode_iterator VEC_IP [V8HI |
| 38 |
V4SI |
| 39 |
V2DI |
| 40 |
V1TI |
| 41 |
TI]) |
| 42 |
|
| 43 |
;; Vector float modes |
| 44 |
(define_mode_iterator VEC_F [V4SF V2DF]) |
| 45 |
|
| 46 |
;; Vector arithmetic modes |
| 47 |
(define_mode_iterator VEC_A [V16QI V8HI V4SI V2DI V4SF V2DF]) |
| 48 |
|
| 49 |
;; Vector modes that need alginment via permutes |
| 50 |
(define_mode_iterator VEC_K [V16QI V8HI V4SI V4SF]) |
| 51 |
|
| 52 |
;; Vector logical modes |
| 53 |
(define_mode_iterator VEC_L [V16QI V8HI V4SI V2DI V4SF V2DF V1TI TI KF TF]) |
| 54 |
|
| 55 |
;; Vector modes for moves. Don't do TImode or TFmode here, since their |
| 56 |
;; moves are handled elsewhere. |
| 57 |
(define_mode_iterator VEC_M [V16QI V8HI V4SI V2DI V4SF V2DF V1TI KF]) |
| 58 |
|
| 59 |
;; Vector modes for types that don't need a realignment under VSX |
| 60 |
(define_mode_iterator VEC_N [V4SI V4SF V2DI V2DF V1TI KF TF]) |
| 61 |
|
| 62 |
;; Vector comparison modes |
| 63 |
(define_mode_iterator VEC_C [V16QI V8HI V4SI V2DI V4SF V2DF V1TI]) |
| 64 |
|
| 65 |
;; Vector init/extract modes |
| 66 |
(define_mode_iterator VEC_E [V16QI V8HI V4SI V2DI V4SF V2DF]) |
| 67 |
|
| 68 |
;; Vector modes for 64-bit base types |
| 69 |
(define_mode_iterator VEC_64 [V2DI V2DF]) |
| 70 |
|
| 71 |
;; Vector integer modes |
| 72 |
(define_mode_iterator VI [V4SI V8HI V16QI]) |
| 73 |
|
| 74 |
;; Base type from vector mode |
| 75 |
(define_mode_attr VEC_base [(V16QI "QI") |
| 76 |
(V8HI "HI") |
| 77 |
(V4SI "SI") |
| 78 |
(V2DI "DI") |
| 79 |
(V4SF "SF") |
| 80 |
(V2DF "DF") |
| 81 |
(V1TI "TI") |
| 82 |
(TI "TI")]) |
| 83 |
|
| 84 |
;; As above, but in lower case |
| 85 |
(define_mode_attr VEC_base_l [(V16QI "qi") |
| 86 |
(V8HI "hi") |
| 87 |
(V4SI "si") |
| 88 |
(V2DI "di") |
| 89 |
(V4SF "sf") |
| 90 |
(V2DF "df") |
| 91 |
(V1TI "ti") |
| 92 |
(TI "ti")]) |
| 93 |
|
| 94 |
;; Same size integer type for floating point data |
| 95 |
(define_mode_attr VEC_int [(V4SF "v4si") |
| 96 |
(V2DF "v2di")]) |
| 97 |
|
| 98 |
(define_mode_attr VEC_INT [(V4SF "V4SI") |
| 99 |
(V2DF "V2DI")]) |
| 100 |
|
| 101 |
;; constants for unspec |
| 102 |
(define_c_enum "unspec" [UNSPEC_PREDICATE |
| 103 |
UNSPEC_REDUC |
| 104 |
UNSPEC_NEZ_P]) |
| 105 |
|
| 106 |
;; Vector reduction code iterators |
| 107 |
(define_code_iterator VEC_reduc [plus smin smax]) |
| 108 |
|
| 109 |
(define_code_attr VEC_reduc_name [(plus "plus") |
| 110 |
(smin "smin") |
| 111 |
(smax "smax")]) |
| 112 |
|
| 113 |
(define_code_attr VEC_reduc_rtx [(plus "add") |
| 114 |
(smin "smin") |
| 115 |
(smax "smax")]) |
| 116 |
|
| 117 |
;; code iterators and attributes for vector FP comparison operators: |
| 118 |
(define_code_iterator |
| 119 |
vector_fp_comparison_simple [lt le ne ungt unge unlt unle]) |
| 120 |
(define_code_iterator |
| 121 |
vector_fp_comparison_complex [ltgt uneq unordered ordered]) |
| 122 |
|
| 123 |
|
| 124 |
;; Vector move instructions. Little-endian VSX loads and stores require |
| 125 |
;; special handling to circumvent "element endianness." |
| 126 |
(define_expand "mov<mode>" |
| 127 |
[(set (match_operand:VEC_M 0 "nonimmediate_operand") |
| 128 |
(match_operand:VEC_M 1 "any_operand"))] |
| 129 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 130 |
{ |
| 131 |
if (can_create_pseudo_p ()) |
| 132 |
{ |
| 133 |
if (CONSTANT_P (operands[1])) |
| 134 |
{ |
| 135 |
if (FLOAT128_VECTOR_P (<MODE>mode)) |
| 136 |
{ |
| 137 |
if (!easy_fp_constant (operands[1], <MODE>mode)) |
| 138 |
operands[1] = force_const_mem (<MODE>mode, operands[1]); |
| 139 |
} |
| 140 |
else if (!easy_vector_constant (operands[1], <MODE>mode)) |
| 141 |
operands[1] = force_const_mem (<MODE>mode, operands[1]); |
| 142 |
} |
| 143 |
|
| 144 |
if (!vlogical_operand (operands[0], <MODE>mode) |
| 145 |
&& !vlogical_operand (operands[1], <MODE>mode)) |
| 146 |
operands[1] = force_reg (<MODE>mode, operands[1]); |
| 147 |
} |
| 148 |
/* When generating load/store instructions to/from VSX registers on |
| 149 |
pre-power9 hardware in little endian mode, we need to emit register |
| 150 |
permute instructions to byte swap the contents, since the VSX load/store |
| 151 |
instructions do not include a byte swap as part of their operation. |
| 152 |
Altivec loads and stores have no such problem, so we skip them below. */ |
| 153 |
if (!BYTES_BIG_ENDIAN |
| 154 |
&& VECTOR_MEM_VSX_P (<MODE>mode) |
| 155 |
&& !TARGET_P9_VECTOR |
| 156 |
&& !gpr_or_gpr_p (operands[0], operands[1]) |
| 157 |
&& ((memory_operand (operands[0], <MODE>mode) |
| 158 |
&& !altivec_indexed_or_indirect_operand(operands[0], <MODE>mode)) |
| 159 |
^ (memory_operand (operands[1], <MODE>mode) |
| 160 |
&& !altivec_indexed_or_indirect_operand(operands[1], <MODE>mode)))) |
| 161 |
{ |
| 162 |
rs6000_emit_le_vsx_move (operands[0], operands[1], <MODE>mode); |
| 163 |
DONE; |
| 164 |
} |
| 165 |
}) |
| 166 |
|
| 167 |
;; Splits if a GPR register was chosen for the move |
| 168 |
(define_split |
| 169 |
[(set (match_operand:VEC_L 0 "nonimmediate_operand") |
| 170 |
(match_operand:VEC_L 1 "input_operand"))] |
| 171 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode) |
| 172 |
&& reload_completed |
| 173 |
&& gpr_or_gpr_p (operands[0], operands[1]) |
| 174 |
&& !direct_move_p (operands[0], operands[1]) |
| 175 |
&& !quad_load_store_p (operands[0], operands[1])" |
| 176 |
[(pc)] |
| 177 |
{ |
| 178 |
rs6000_split_multireg_move (operands[0], operands[1]); |
| 179 |
DONE; |
| 180 |
}) |
| 181 |
|
| 182 |
|
| 183 |
;; Generic floating point vector arithmetic support |
| 184 |
(define_expand "add<mode>3" |
| 185 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 186 |
(plus:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 187 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 188 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 189 |
"") |
| 190 |
|
| 191 |
(define_expand "sub<mode>3" |
| 192 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 193 |
(minus:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 194 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 195 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 196 |
"") |
| 197 |
|
| 198 |
(define_expand "mul<mode>3" |
| 199 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 200 |
(mult:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 201 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 202 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 203 |
{ |
| 204 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 205 |
{ |
| 206 |
emit_insn (gen_altivec_mulv4sf3 (operands[0], operands[1], operands[2])); |
| 207 |
DONE; |
| 208 |
} |
| 209 |
}) |
| 210 |
|
| 211 |
(define_expand "div<mode>3" |
| 212 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 213 |
(div:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 214 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 215 |
"VECTOR_UNIT_VSX_P (<MODE>mode)" |
| 216 |
{ |
| 217 |
if (RS6000_RECIP_AUTO_RE_P (<MODE>mode) |
| 218 |
&& can_create_pseudo_p () && flag_finite_math_only |
| 219 |
&& !flag_trapping_math && flag_reciprocal_math) |
| 220 |
{ |
| 221 |
rs6000_emit_swdiv (operands[0], operands[1], operands[2], true); |
| 222 |
DONE; |
| 223 |
} |
| 224 |
}) |
| 225 |
|
| 226 |
(define_expand "neg<mode>2" |
| 227 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 228 |
(neg:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))] |
| 229 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 230 |
{ |
| 231 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 232 |
{ |
| 233 |
emit_insn (gen_altivec_negv4sf2 (operands[0], operands[1])); |
| 234 |
DONE; |
| 235 |
} |
| 236 |
}) |
| 237 |
|
| 238 |
(define_expand "abs<mode>2" |
| 239 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 240 |
(abs:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))] |
| 241 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 242 |
{ |
| 243 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 244 |
{ |
| 245 |
emit_insn (gen_altivec_absv4sf2 (operands[0], operands[1])); |
| 246 |
DONE; |
| 247 |
} |
| 248 |
}) |
| 249 |
|
| 250 |
(define_expand "smin<mode>3" |
| 251 |
[(set (match_operand:VEC_F 0 "register_operand") |
| 252 |
(smin:VEC_F (match_operand:VEC_F 1 "register_operand") |
| 253 |
(match_operand:VEC_F 2 "register_operand")))] |
| 254 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 255 |
"") |
| 256 |
|
| 257 |
(define_expand "smax<mode>3" |
| 258 |
[(set (match_operand:VEC_F 0 "register_operand") |
| 259 |
(smax:VEC_F (match_operand:VEC_F 1 "register_operand") |
| 260 |
(match_operand:VEC_F 2 "register_operand")))] |
| 261 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 262 |
"") |
| 263 |
|
| 264 |
|
| 265 |
(define_expand "sqrt<mode>2" |
| 266 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 267 |
(sqrt:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))] |
| 268 |
"VECTOR_UNIT_VSX_P (<MODE>mode)" |
| 269 |
{ |
| 270 |
if (<MODE>mode == V4SFmode |
| 271 |
&& !optimize_function_for_size_p (cfun) |
| 272 |
&& flag_finite_math_only && !flag_trapping_math |
| 273 |
&& flag_unsafe_math_optimizations) |
| 274 |
{ |
| 275 |
rs6000_emit_swsqrt (operands[0], operands[1], 0); |
| 276 |
DONE; |
| 277 |
} |
| 278 |
}) |
| 279 |
|
| 280 |
(define_expand "rsqrte<mode>2" |
| 281 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 282 |
(unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")] |
| 283 |
UNSPEC_RSQRT))] |
| 284 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 285 |
"") |
| 286 |
|
| 287 |
(define_expand "re<mode>2" |
| 288 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 289 |
(unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")] |
| 290 |
UNSPEC_FRES))] |
| 291 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 292 |
"") |
| 293 |
|
| 294 |
(define_expand "ftrunc<mode>2" |
| 295 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 296 |
(fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))] |
| 297 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 298 |
"") |
| 299 |
|
| 300 |
(define_expand "vector_ceil<mode>2" |
| 301 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 302 |
(unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")] |
| 303 |
UNSPEC_FRIP))] |
| 304 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 305 |
"") |
| 306 |
|
| 307 |
(define_expand "vector_floor<mode>2" |
| 308 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 309 |
(unspec:VEC_F [(match_operand:VEC_F 1 "vfloat_operand")] |
| 310 |
UNSPEC_FRIM))] |
| 311 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 312 |
"") |
| 313 |
|
| 314 |
(define_expand "vector_btrunc<mode>2" |
| 315 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 316 |
(fix:VEC_F (match_operand:VEC_F 1 "vfloat_operand")))] |
| 317 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 318 |
"") |
| 319 |
|
| 320 |
(define_expand "vector_copysign<mode>3" |
| 321 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 322 |
(copysign:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 323 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 324 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 325 |
{ |
| 326 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 327 |
{ |
| 328 |
emit_insn (gen_altivec_copysign_v4sf3 (operands[0], operands[1], |
| 329 |
operands[2])); |
| 330 |
DONE; |
| 331 |
} |
| 332 |
}) |
| 333 |
|
| 334 |
|
| 335 |
;; To support vector condition vectorization, define vcond_mask and vec_cmp. |
| 336 |
|
| 337 |
;; Same mode for condition true/false values and predicate operand. |
| 338 |
(define_expand "vcond_mask_<mode><mode>" |
| 339 |
[(match_operand:VEC_I 0 "vint_operand") |
| 340 |
(match_operand:VEC_I 1 "vint_operand") |
| 341 |
(match_operand:VEC_I 2 "vint_operand") |
| 342 |
(match_operand:VEC_I 3 "vint_operand")] |
| 343 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 344 |
{ |
| 345 |
emit_insn (gen_vector_select_<mode> (operands[0], operands[2], operands[1], |
| 346 |
operands[3])); |
| 347 |
DONE; |
| 348 |
}) |
| 349 |
|
| 350 |
;; Condition true/false values are float but predicate operand is of |
| 351 |
;; type integer vector with same element size. |
| 352 |
(define_expand "vcond_mask_<mode><VEC_int>" |
| 353 |
[(match_operand:VEC_F 0 "vfloat_operand") |
| 354 |
(match_operand:VEC_F 1 "vfloat_operand") |
| 355 |
(match_operand:VEC_F 2 "vfloat_operand") |
| 356 |
(match_operand:<VEC_INT> 3 "vint_operand")] |
| 357 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 358 |
{ |
| 359 |
emit_insn (gen_vector_select_<mode> (operands[0], operands[2], operands[1], |
| 360 |
gen_lowpart (<MODE>mode, operands[3]))); |
| 361 |
DONE; |
| 362 |
}) |
| 363 |
|
| 364 |
;; For signed integer vectors comparison. |
| 365 |
(define_expand "vec_cmp<mode><mode>" |
| 366 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 367 |
(match_operator 1 "signed_or_equality_comparison_operator" |
| 368 |
[(match_operand:VEC_IC 2 "vint_operand") |
| 369 |
(match_operand:VEC_IC 3 "vint_operand")]))] |
| 370 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 371 |
{ |
| 372 |
enum rtx_code code = GET_CODE (operands[1]); |
| 373 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 374 |
switch (code) |
| 375 |
{ |
| 376 |
case NE: |
| 377 |
emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3])); |
| 378 |
emit_insn (gen_one_cmpl<mode>2 (operands[0], operands[0])); |
| 379 |
break; |
| 380 |
case EQ: |
| 381 |
emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3])); |
| 382 |
break; |
| 383 |
case GE: |
| 384 |
emit_insn (gen_vector_nlt<mode> (operands[0],operands[2], operands[3], |
| 385 |
tmp)); |
| 386 |
break; |
| 387 |
case GT: |
| 388 |
emit_insn (gen_vector_gt<mode> (operands[0], operands[2], operands[3])); |
| 389 |
break; |
| 390 |
case LE: |
| 391 |
emit_insn (gen_vector_ngt<mode> (operands[0], operands[2], operands[3], |
| 392 |
tmp)); |
| 393 |
break; |
| 394 |
case LT: |
| 395 |
emit_insn (gen_vector_gt<mode> (operands[0], operands[3], operands[2])); |
| 396 |
break; |
| 397 |
default: |
| 398 |
gcc_unreachable (); |
| 399 |
break; |
| 400 |
} |
| 401 |
DONE; |
| 402 |
}) |
| 403 |
|
| 404 |
;; For unsigned integer vectors comparison. |
| 405 |
(define_expand "vec_cmpu<mode><mode>" |
| 406 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 407 |
(match_operator 1 "unsigned_or_equality_comparison_operator" |
| 408 |
[(match_operand:VEC_IC 2 "vint_operand") |
| 409 |
(match_operand:VEC_IC 3 "vint_operand")]))] |
| 410 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 411 |
{ |
| 412 |
enum rtx_code code = GET_CODE (operands[1]); |
| 413 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 414 |
switch (code) |
| 415 |
{ |
| 416 |
case NE: |
| 417 |
emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3])); |
| 418 |
emit_insn (gen_one_cmpl<mode>2 (operands[0], operands[0])); |
| 419 |
break; |
| 420 |
case EQ: |
| 421 |
emit_insn (gen_vector_eq<mode> (operands[0], operands[2], operands[3])); |
| 422 |
break; |
| 423 |
case GEU: |
| 424 |
emit_insn (gen_vector_nltu<mode> (operands[0], operands[2], operands[3], |
| 425 |
tmp)); |
| 426 |
break; |
| 427 |
case GTU: |
| 428 |
emit_insn (gen_vector_gtu<mode> (operands[0], operands[2], operands[3])); |
| 429 |
break; |
| 430 |
case LEU: |
| 431 |
emit_insn (gen_vector_ngtu<mode> (operands[0], operands[2], operands[3], |
| 432 |
tmp)); |
| 433 |
break; |
| 434 |
case LTU: |
| 435 |
emit_insn (gen_vector_gtu<mode> (operands[0], operands[3], operands[2])); |
| 436 |
break; |
| 437 |
default: |
| 438 |
gcc_unreachable (); |
| 439 |
break; |
| 440 |
} |
| 441 |
DONE; |
| 442 |
}) |
| 443 |
|
| 444 |
;; For float point vectors comparison. |
| 445 |
(define_expand "vec_cmp<mode><VEC_int>" |
| 446 |
[(set (match_operand:<VEC_INT> 0 "vint_operand") |
| 447 |
(match_operator 1 "comparison_operator" |
| 448 |
[(match_operand:VEC_F 2 "vfloat_operand") |
| 449 |
(match_operand:VEC_F 3 "vfloat_operand")]))] |
| 450 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 451 |
{ |
| 452 |
enum rtx_code code = GET_CODE (operands[1]); |
| 453 |
rtx res = gen_reg_rtx (<MODE>mode); |
| 454 |
switch (code) |
| 455 |
{ |
| 456 |
case NE: |
| 457 |
emit_insn (gen_vector_ne<mode> (res, operands[2], operands[3])); |
| 458 |
break; |
| 459 |
case EQ: |
| 460 |
emit_insn (gen_vector_eq<mode> (res, operands[2], operands[3])); |
| 461 |
break; |
| 462 |
case GE: |
| 463 |
emit_insn (gen_vector_ge<mode> (res, operands[2], operands[3])); |
| 464 |
break; |
| 465 |
case GT: |
| 466 |
emit_insn (gen_vector_gt<mode> (res, operands[2], operands[3])); |
| 467 |
break; |
| 468 |
case LE: |
| 469 |
emit_insn (gen_vector_le<mode> (res, operands[2], operands[3])); |
| 470 |
break; |
| 471 |
case LT: |
| 472 |
emit_insn (gen_vector_lt<mode> (res, operands[2], operands[3])); |
| 473 |
break; |
| 474 |
case LTGT: |
| 475 |
emit_insn (gen_vector_ltgt<mode> (res, operands[2], operands[3])); |
| 476 |
break; |
| 477 |
case UNORDERED: |
| 478 |
emit_insn (gen_vector_unordered<mode> (res, operands[2], operands[3])); |
| 479 |
break; |
| 480 |
case ORDERED: |
| 481 |
emit_insn (gen_vector_ordered<mode> (res, operands[2], operands[3])); |
| 482 |
break; |
| 483 |
case UNEQ: |
| 484 |
emit_insn (gen_vector_uneq<mode> (res, operands[2], operands[3])); |
| 485 |
break; |
| 486 |
case UNGE: |
| 487 |
emit_insn (gen_vector_unge<mode> (res, operands[2], operands[3])); |
| 488 |
break; |
| 489 |
case UNGT: |
| 490 |
emit_insn (gen_vector_ungt<mode> (res, operands[2], operands[3])); |
| 491 |
break; |
| 492 |
case UNLE: |
| 493 |
emit_insn (gen_vector_unle<mode> (res, operands[2], operands[3])); |
| 494 |
break; |
| 495 |
case UNLT: |
| 496 |
emit_insn (gen_vector_unlt<mode> (res, operands[2], operands[3])); |
| 497 |
break; |
| 498 |
|
| 499 |
default: |
| 500 |
gcc_unreachable (); |
| 501 |
} |
| 502 |
|
| 503 |
emit_insn (gen_move_insn (operands[0], gen_lowpart (<VEC_INT>mode, res))); |
| 504 |
DONE; |
| 505 |
}) |
| 506 |
|
| 507 |
(define_expand "vector_eq<mode>" |
| 508 |
[(set (match_operand:VEC_C 0 "vlogical_operand") |
| 509 |
(eq:VEC_C (match_operand:VEC_C 1 "vlogical_operand") |
| 510 |
(match_operand:VEC_C 2 "vlogical_operand")))] |
| 511 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 512 |
"") |
| 513 |
|
| 514 |
(define_expand "vector_gt<mode>" |
| 515 |
[(set (match_operand:VEC_C 0 "vlogical_operand") |
| 516 |
(gt:VEC_C (match_operand:VEC_C 1 "vlogical_operand") |
| 517 |
(match_operand:VEC_C 2 "vlogical_operand")))] |
| 518 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 519 |
"") |
| 520 |
|
| 521 |
; >= for integer vectors: swap operands and apply not-greater-than |
| 522 |
(define_expand "vector_nlt<mode>" |
| 523 |
[(set (match_operand:VEC_IC 3 "vlogical_operand") |
| 524 |
(gt:VEC_IC (match_operand:VEC_IC 2 "vlogical_operand") |
| 525 |
(match_operand:VEC_IC 1 "vlogical_operand"))) |
| 526 |
(set (match_operand:VEC_IC 0 "vlogical_operand") |
| 527 |
(not:VEC_IC (match_dup 3)))] |
| 528 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 529 |
{ |
| 530 |
operands[3] = gen_reg_rtx_and_attrs (operands[0]); |
| 531 |
}) |
| 532 |
|
| 533 |
(define_expand "vector_gtu<mode>" |
| 534 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 535 |
(gtu:VEC_IC (match_operand:VEC_IC 1 "vint_operand") |
| 536 |
(match_operand:VEC_IC 2 "vint_operand")))] |
| 537 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 538 |
"") |
| 539 |
|
| 540 |
; >= for integer vectors: swap operands and apply not-greater-than |
| 541 |
(define_expand "vector_nltu<mode>" |
| 542 |
[(set (match_operand:VEC_IC 3 "vlogical_operand") |
| 543 |
(gtu:VEC_IC (match_operand:VEC_IC 2 "vlogical_operand") |
| 544 |
(match_operand:VEC_IC 1 "vlogical_operand"))) |
| 545 |
(set (match_operand:VEC_IC 0 "vlogical_operand") |
| 546 |
(not:VEC_IC (match_dup 3)))] |
| 547 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 548 |
{ |
| 549 |
operands[3] = gen_reg_rtx_and_attrs (operands[0]); |
| 550 |
}) |
| 551 |
|
| 552 |
(define_expand "vector_geu<mode>" |
| 553 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 554 |
(geu:VEC_IC (match_operand:VEC_IC 1 "vint_operand") |
| 555 |
(match_operand:VEC_IC 2 "vint_operand")))] |
| 556 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 557 |
"") |
| 558 |
|
| 559 |
; <= for integer vectors: apply not-greater-than |
| 560 |
(define_expand "vector_ngt<mode>" |
| 561 |
[(set (match_operand:VEC_IC 3 "vlogical_operand") |
| 562 |
(gt:VEC_IC (match_operand:VEC_IC 1 "vlogical_operand") |
| 563 |
(match_operand:VEC_IC 2 "vlogical_operand"))) |
| 564 |
(set (match_operand:VEC_IC 0 "vlogical_operand") |
| 565 |
(not:VEC_IC (match_dup 3)))] |
| 566 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 567 |
{ |
| 568 |
operands[3] = gen_reg_rtx_and_attrs (operands[0]); |
| 569 |
}) |
| 570 |
|
| 571 |
(define_expand "vector_ngtu<mode>" |
| 572 |
[(set (match_operand:VEC_IC 3 "vlogical_operand") |
| 573 |
(gtu:VEC_IC (match_operand:VEC_IC 1 "vlogical_operand") |
| 574 |
(match_operand:VEC_IC 2 "vlogical_operand"))) |
| 575 |
(set (match_operand:VEC_IC 0 "vlogical_operand") |
| 576 |
(not:VEC_IC (match_dup 3)))] |
| 577 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 578 |
{ |
| 579 |
operands[3] = gen_reg_rtx_and_attrs (operands[0]); |
| 580 |
}) |
| 581 |
|
| 582 |
; There are 14 possible vector FP comparison operators, gt and eq of them have |
| 583 |
; been expanded above, so just support 12 remaining operators here. |
| 584 |
|
| 585 |
; For ge: |
| 586 |
(define_expand "vector_ge<mode>" |
| 587 |
[(set (match_operand:VEC_F 0 "vlogical_operand") |
| 588 |
(ge:VEC_F (match_operand:VEC_F 1 "vlogical_operand") |
| 589 |
(match_operand:VEC_F 2 "vlogical_operand")))] |
| 590 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 591 |
"") |
| 592 |
|
| 593 |
; For lt/le/ne/ungt/unge/unlt/unle: |
| 594 |
; lt(a,b) = gt(b,a) |
| 595 |
; le(a,b) = ge(b,a) |
| 596 |
; unge(a,b) = ~lt(a,b) |
| 597 |
; unle(a,b) = ~gt(a,b) |
| 598 |
; ne(a,b) = ~eq(a,b) |
| 599 |
; ungt(a,b) = ~le(a,b) |
| 600 |
; unlt(a,b) = ~ge(a,b) |
| 601 |
(define_insn_and_split "vector_<code><mode>" |
| 602 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 603 |
(vector_fp_comparison_simple:VEC_F |
| 604 |
(match_operand:VEC_F 1 "vfloat_operand") |
| 605 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 606 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && can_create_pseudo_p ()" |
| 607 |
"#" |
| 608 |
"&& can_create_pseudo_p ()" |
| 609 |
[(pc)] |
| 610 |
{ |
| 611 |
enum rtx_code cond = <CODE>; |
| 612 |
bool need_invert = false; |
| 613 |
|
| 614 |
if (cond == UNLE || cond == UNLT || cond == NE || cond == UNGE |
| 615 |
|| cond == UNGT) |
| 616 |
{ |
| 617 |
cond = reverse_condition_maybe_unordered (cond); |
| 618 |
need_invert = true; |
| 619 |
} |
| 620 |
|
| 621 |
if (cond == LT || cond == LE) |
| 622 |
{ |
| 623 |
cond = swap_condition (cond); |
| 624 |
std::swap (operands[1], operands[2]); |
| 625 |
} |
| 626 |
|
| 627 |
gcc_assert (cond == EQ || cond == GE || cond == GT); |
| 628 |
|
| 629 |
rtx comp = gen_rtx_fmt_ee (cond, <MODE>mode, operands[1], operands[2]); |
| 630 |
|
| 631 |
if (need_invert) |
| 632 |
{ |
| 633 |
rtx res = gen_reg_rtx (<MODE>mode); |
| 634 |
emit_insn (gen_rtx_SET (res, comp)); |
| 635 |
emit_insn (gen_one_cmpl<mode>2 (operands[0], res)); |
| 636 |
} |
| 637 |
else |
| 638 |
emit_insn (gen_rtx_SET (operands[0], comp)); |
| 639 |
|
| 640 |
DONE; |
| 641 |
}) |
| 642 |
|
| 643 |
; For ltgt/uneq/ordered/unordered: |
| 644 |
; ltgt: gt(a,b) | gt(b,a) |
| 645 |
; uneq: ~(gt(a,b) | gt(b,a)) |
| 646 |
; ordered: ge(a,b) | ge(b,a) |
| 647 |
; unordered: ~(ge(a,b) | ge(b,a)) |
| 648 |
(define_insn_and_split "vector_<code><mode>" |
| 649 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 650 |
(vector_fp_comparison_complex:VEC_F |
| 651 |
(match_operand:VEC_F 1 "vfloat_operand") |
| 652 |
(match_operand:VEC_F 2 "vfloat_operand")))] |
| 653 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode) && can_create_pseudo_p ()" |
| 654 |
"#" |
| 655 |
"&& can_create_pseudo_p ()" |
| 656 |
[(pc)] |
| 657 |
{ |
| 658 |
enum rtx_code cond = <CODE>; |
| 659 |
bool need_invert = false; |
| 660 |
|
| 661 |
if (cond == UNORDERED || cond == UNEQ) |
| 662 |
{ |
| 663 |
cond = reverse_condition_maybe_unordered (cond); |
| 664 |
need_invert = true; |
| 665 |
} |
| 666 |
|
| 667 |
if (cond == LTGT) |
| 668 |
cond = GT; |
| 669 |
else if (cond == ORDERED) |
| 670 |
cond = GE; |
| 671 |
else |
| 672 |
gcc_unreachable (); |
| 673 |
|
| 674 |
rtx comp1 = gen_rtx_fmt_ee (cond, <MODE>mode, operands[1], operands[2]); |
| 675 |
rtx res1 = gen_reg_rtx (<MODE>mode); |
| 676 |
emit_insn (gen_rtx_SET (res1, comp1)); |
| 677 |
rtx comp2 = gen_rtx_fmt_ee (cond, <MODE>mode, operands[2], operands[1]); |
| 678 |
rtx res2 = gen_reg_rtx (<MODE>mode); |
| 679 |
emit_insn (gen_rtx_SET (res2, comp2)); |
| 680 |
|
| 681 |
if (need_invert) |
| 682 |
{ |
| 683 |
rtx not1 = gen_rtx_fmt_e (NOT, <MODE>mode, res1); |
| 684 |
rtx not2 = gen_rtx_fmt_e (NOT, <MODE>mode, res2); |
| 685 |
rtx comp3 = gen_rtx_fmt_ee (AND, <MODE>mode, not1, not2); |
| 686 |
emit_insn (gen_rtx_SET (operands[0], comp3)); |
| 687 |
} |
| 688 |
else |
| 689 |
emit_insn (gen_ior<mode>3 (operands[0], res1, res2)); |
| 690 |
|
| 691 |
DONE; |
| 692 |
}) |
| 693 |
|
| 694 |
;; Note the arguments for __builtin_altivec_vsel are op2, op1, mask |
| 695 |
;; which is in the reverse order that we want |
| 696 |
(define_expand "vector_select_<mode>" |
| 697 |
[(set (match_operand:VEC_L 0 "vlogical_operand") |
| 698 |
(ior:VEC_L |
| 699 |
(and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand")) |
| 700 |
(match_operand:VEC_L 1 "vlogical_operand")) |
| 701 |
(and:VEC_L (match_dup 3) |
| 702 |
(match_operand:VEC_L 2 "vlogical_operand"))))] |
| 703 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)") |
| 704 |
|
| 705 |
(define_expand "vector_select_<mode>_uns" |
| 706 |
[(set (match_operand:VEC_L 0 "vlogical_operand") |
| 707 |
(ior:VEC_L |
| 708 |
(and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand")) |
| 709 |
(match_operand:VEC_L 1 "vlogical_operand")) |
| 710 |
(and:VEC_L (match_dup 3) |
| 711 |
(match_operand:VEC_L 2 "vlogical_operand"))))] |
| 712 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)") |
| 713 |
|
| 714 |
;; Expansions that compare vectors producing a vector result and a predicate, |
| 715 |
;; setting CR6 to indicate a combined status |
| 716 |
(define_expand "vector_eq_<mode>_p" |
| 717 |
[(parallel |
| 718 |
[(set (reg:CC CR6_REGNO) |
| 719 |
(unspec:CC [(eq:CC (match_operand:VEC_A 1 "vlogical_operand") |
| 720 |
(match_operand:VEC_A 2 "vlogical_operand"))] |
| 721 |
UNSPEC_PREDICATE)) |
| 722 |
(set (match_operand:VEC_A 0 "vlogical_operand") |
| 723 |
(eq:VEC_A (match_dup 1) |
| 724 |
(match_dup 2)))])] |
| 725 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 726 |
"") |
| 727 |
|
| 728 |
(define_expand "vector_eq_v1ti_p" |
| 729 |
[(parallel |
| 730 |
[(set (reg:CC CR6_REGNO) |
| 731 |
(unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand") |
| 732 |
(match_operand:V1TI 2 "altivec_register_operand"))] |
| 733 |
UNSPEC_PREDICATE)) |
| 734 |
(set (match_operand:V1TI 0 "vlogical_operand") |
| 735 |
(eq:V1TI (match_dup 1) |
| 736 |
(match_dup 2)))])] |
| 737 |
"TARGET_POWER10" |
| 738 |
"") |
| 739 |
|
| 740 |
;; This expansion handles the V16QI, V8HI, and V4SI modes in the |
| 741 |
;; implementation of the vec_all_ne built-in functions on Power9. |
| 742 |
(define_expand "vector_ne_<mode>_p" |
| 743 |
[(parallel |
| 744 |
[(set (reg:CC CR6_REGNO) |
| 745 |
(unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand") |
| 746 |
(match_operand:VI 2 "vlogical_operand"))] |
| 747 |
UNSPEC_PREDICATE)) |
| 748 |
(set (match_dup 3) |
| 749 |
(ne:VI (match_dup 1) |
| 750 |
(match_dup 2)))]) |
| 751 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 752 |
(lt:SI (reg:CC CR6_REGNO) |
| 753 |
(const_int 0)))] |
| 754 |
"TARGET_P9_VECTOR" |
| 755 |
{ |
| 756 |
operands[3] = gen_reg_rtx (<MODE>mode); |
| 757 |
}) |
| 758 |
|
| 759 |
;; This expansion handles the V16QI, V8HI, and V4SI modes in the |
| 760 |
;; implementation of the vec_any_eq built-in functions on Power9. |
| 761 |
(define_expand "vector_ae_<mode>_p" |
| 762 |
[(parallel |
| 763 |
[(set (reg:CC CR6_REGNO) |
| 764 |
(unspec:CC [(ne:CC (match_operand:VI 1 "vlogical_operand") |
| 765 |
(match_operand:VI 2 "vlogical_operand"))] |
| 766 |
UNSPEC_PREDICATE)) |
| 767 |
(set (match_dup 3) |
| 768 |
(ne:VI (match_dup 1) |
| 769 |
(match_dup 2)))]) |
| 770 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 771 |
(lt:SI (reg:CC CR6_REGNO) |
| 772 |
(const_int 0))) |
| 773 |
(set (match_dup 0) |
| 774 |
(xor:SI (match_dup 0) |
| 775 |
(const_int 1)))] |
| 776 |
"TARGET_P9_VECTOR" |
| 777 |
{ |
| 778 |
operands[3] = gen_reg_rtx (<MODE>mode); |
| 779 |
}) |
| 780 |
|
| 781 |
;; This expansion handles the V16QI, V8HI, and V4SI modes in the |
| 782 |
;; implementation of the vec_all_nez and vec_any_eqz built-in |
| 783 |
;; functions on Power9. |
| 784 |
(define_expand "vector_nez_<mode>_p" |
| 785 |
[(parallel |
| 786 |
[(set (reg:CC CR6_REGNO) |
| 787 |
(unspec:CC [(unspec:VI |
| 788 |
[(match_operand:VI 1 "vlogical_operand") |
| 789 |
(match_operand:VI 2 "vlogical_operand")] |
| 790 |
UNSPEC_NEZ_P)] |
| 791 |
UNSPEC_PREDICATE)) |
| 792 |
(set (match_operand:VI 0 "vlogical_operand") |
| 793 |
(unspec:VI [(match_dup 1) |
| 794 |
(match_dup 2)] |
| 795 |
UNSPEC_NEZ_P))])] |
| 796 |
"TARGET_P9_VECTOR" |
| 797 |
"") |
| 798 |
|
| 799 |
;; This expansion handles the V2DI mode in the implementation of the |
| 800 |
;; vec_all_ne built-in function on Power9. |
| 801 |
;; |
| 802 |
;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode, |
| 803 |
;; this expands into the same rtl that would be used for the Power8 |
| 804 |
;; architecture. |
| 805 |
(define_expand "vector_ne_v2di_p" |
| 806 |
[(parallel |
| 807 |
[(set (reg:CC CR6_REGNO) |
| 808 |
(unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand") |
| 809 |
(match_operand:V2DI 2 "vlogical_operand"))] |
| 810 |
UNSPEC_PREDICATE)) |
| 811 |
(set (match_dup 3) |
| 812 |
(eq:V2DI (match_dup 1) |
| 813 |
(match_dup 2)))]) |
| 814 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 815 |
(eq:SI (reg:CC CR6_REGNO) |
| 816 |
(const_int 0)))] |
| 817 |
"TARGET_P9_VECTOR" |
| 818 |
{ |
| 819 |
operands[3] = gen_reg_rtx (V2DImode); |
| 820 |
}) |
| 821 |
|
| 822 |
(define_expand "vector_ne_v1ti_p" |
| 823 |
[(parallel |
| 824 |
[(set (reg:CC CR6_REGNO) |
| 825 |
(unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand") |
| 826 |
(match_operand:V1TI 2 "altivec_register_operand"))] |
| 827 |
UNSPEC_PREDICATE)) |
| 828 |
(set (match_dup 3) |
| 829 |
(eq:V1TI (match_dup 1) |
| 830 |
(match_dup 2)))]) |
| 831 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 832 |
(eq:SI (reg:CC CR6_REGNO) |
| 833 |
(const_int 0)))] |
| 834 |
"TARGET_POWER10" |
| 835 |
{ |
| 836 |
operands[3] = gen_reg_rtx (V1TImode); |
| 837 |
}) |
| 838 |
|
| 839 |
;; This expansion handles the V2DI mode in the implementation of the |
| 840 |
;; vec_any_eq built-in function on Power9. |
| 841 |
;; |
| 842 |
;; Since the Power9 "xvcmpne<mode>." instruction does not support DImode, |
| 843 |
;; this expands into the same rtl that would be used for the Power8 |
| 844 |
;; architecture. |
| 845 |
(define_expand "vector_ae_v2di_p" |
| 846 |
[(parallel |
| 847 |
[(set (reg:CC CR6_REGNO) |
| 848 |
(unspec:CC [(eq:CC (match_operand:V2DI 1 "vlogical_operand") |
| 849 |
(match_operand:V2DI 2 "vlogical_operand"))] |
| 850 |
UNSPEC_PREDICATE)) |
| 851 |
(set (match_dup 3) |
| 852 |
(eq:V2DI (match_dup 1) |
| 853 |
(match_dup 2)))]) |
| 854 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 855 |
(eq:SI (reg:CC CR6_REGNO) |
| 856 |
(const_int 0))) |
| 857 |
(set (match_dup 0) |
| 858 |
(xor:SI (match_dup 0) |
| 859 |
(const_int 1)))] |
| 860 |
"TARGET_P9_VECTOR" |
| 861 |
{ |
| 862 |
operands[3] = gen_reg_rtx (V2DImode); |
| 863 |
}) |
| 864 |
|
| 865 |
(define_expand "vector_ae_v1ti_p" |
| 866 |
[(parallel |
| 867 |
[(set (reg:CC CR6_REGNO) |
| 868 |
(unspec:CC [(eq:CC (match_operand:V1TI 1 "altivec_register_operand") |
| 869 |
(match_operand:V1TI 2 "altivec_register_operand"))] |
| 870 |
UNSPEC_PREDICATE)) |
| 871 |
(set (match_dup 3) |
| 872 |
(eq:V1TI (match_dup 1) |
| 873 |
(match_dup 2)))]) |
| 874 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 875 |
(eq:SI (reg:CC CR6_REGNO) |
| 876 |
(const_int 0))) |
| 877 |
(set (match_dup 0) |
| 878 |
(xor:SI (match_dup 0) |
| 879 |
(const_int 1)))] |
| 880 |
"TARGET_POWER10" |
| 881 |
{ |
| 882 |
operands[3] = gen_reg_rtx (V1TImode); |
| 883 |
}) |
| 884 |
|
| 885 |
;; This expansion handles the V4SF and V2DF modes in the Power9 |
| 886 |
;; implementation of the vec_all_ne built-in functions. Note that the |
| 887 |
;; expansions for this pattern with these modes makes no use of power9- |
| 888 |
;; specific instructions since there are no new power9 instructions |
| 889 |
;; for vector compare not equal with floating point arguments. |
| 890 |
(define_expand "vector_ne_<mode>_p" |
| 891 |
[(parallel |
| 892 |
[(set (reg:CC CR6_REGNO) |
| 893 |
(unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand") |
| 894 |
(match_operand:VEC_F 2 "vlogical_operand"))] |
| 895 |
UNSPEC_PREDICATE)) |
| 896 |
(set (match_dup 3) |
| 897 |
(eq:VEC_F (match_dup 1) |
| 898 |
(match_dup 2)))]) |
| 899 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 900 |
(eq:SI (reg:CC CR6_REGNO) |
| 901 |
(const_int 0)))] |
| 902 |
"TARGET_P9_VECTOR" |
| 903 |
{ |
| 904 |
operands[3] = gen_reg_rtx (<MODE>mode); |
| 905 |
}) |
| 906 |
|
| 907 |
;; This expansion handles the V4SF and V2DF modes in the Power9 |
| 908 |
;; implementation of the vec_any_eq built-in functions. Note that the |
| 909 |
;; expansions for this pattern with these modes makes no use of power9- |
| 910 |
;; specific instructions since there are no new power9 instructions |
| 911 |
;; for vector compare not equal with floating point arguments. |
| 912 |
(define_expand "vector_ae_<mode>_p" |
| 913 |
[(parallel |
| 914 |
[(set (reg:CC CR6_REGNO) |
| 915 |
(unspec:CC [(eq:CC (match_operand:VEC_F 1 "vlogical_operand") |
| 916 |
(match_operand:VEC_F 2 "vlogical_operand"))] |
| 917 |
UNSPEC_PREDICATE)) |
| 918 |
(set (match_dup 3) |
| 919 |
(eq:VEC_F (match_dup 1) |
| 920 |
(match_dup 2)))]) |
| 921 |
(set (match_operand:SI 0 "register_operand" "=r") |
| 922 |
(eq:SI (reg:CC CR6_REGNO) |
| 923 |
(const_int 0))) |
| 924 |
(set (match_dup 0) |
| 925 |
(xor:SI (match_dup 0) |
| 926 |
(const_int 1)))] |
| 927 |
"TARGET_P9_VECTOR" |
| 928 |
{ |
| 929 |
operands[3] = gen_reg_rtx (<MODE>mode); |
| 930 |
}) |
| 931 |
|
| 932 |
(define_expand "vector_gt_<mode>_p" |
| 933 |
[(parallel |
| 934 |
[(set (reg:CC CR6_REGNO) |
| 935 |
(unspec:CC [(gt:CC (match_operand:VEC_A 1 "vlogical_operand") |
| 936 |
(match_operand:VEC_A 2 "vlogical_operand"))] |
| 937 |
UNSPEC_PREDICATE)) |
| 938 |
(set (match_operand:VEC_A 0 "vlogical_operand") |
| 939 |
(gt:VEC_A (match_dup 1) |
| 940 |
(match_dup 2)))])] |
| 941 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 942 |
"") |
| 943 |
|
| 944 |
(define_expand "vector_gt_v1ti_p" |
| 945 |
[(parallel |
| 946 |
[(set (reg:CC CR6_REGNO) |
| 947 |
(unspec:CC [(gt:CC (match_operand:V1TI 1 "vlogical_operand") |
| 948 |
(match_operand:V1TI 2 "vlogical_operand"))] |
| 949 |
UNSPEC_PREDICATE)) |
| 950 |
(set (match_operand:V1TI 0 "vlogical_operand") |
| 951 |
(gt:V1TI (match_dup 1) |
| 952 |
(match_dup 2)))])] |
| 953 |
"TARGET_POWER10" |
| 954 |
"") |
| 955 |
|
| 956 |
(define_expand "vector_ge_<mode>_p" |
| 957 |
[(parallel |
| 958 |
[(set (reg:CC CR6_REGNO) |
| 959 |
(unspec:CC [(ge:CC (match_operand:VEC_F 1 "vfloat_operand") |
| 960 |
(match_operand:VEC_F 2 "vfloat_operand"))] |
| 961 |
UNSPEC_PREDICATE)) |
| 962 |
(set (match_operand:VEC_F 0 "vfloat_operand") |
| 963 |
(ge:VEC_F (match_dup 1) |
| 964 |
(match_dup 2)))])] |
| 965 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 966 |
"") |
| 967 |
|
| 968 |
(define_expand "vector_gtu_<mode>_p" |
| 969 |
[(parallel |
| 970 |
[(set (reg:CC CR6_REGNO) |
| 971 |
(unspec:CC [(gtu:CC (match_operand:VEC_IC 1 "vint_operand") |
| 972 |
(match_operand:VEC_IC 2 "vint_operand"))] |
| 973 |
UNSPEC_PREDICATE)) |
| 974 |
(set (match_operand:VEC_IC 0 "vlogical_operand") |
| 975 |
(gtu:VEC_IC (match_dup 1) |
| 976 |
(match_dup 2)))])] |
| 977 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 978 |
"") |
| 979 |
|
| 980 |
;; AltiVec/VSX predicates. |
| 981 |
|
| 982 |
;; This expansion is triggered during expansion of predicate built-in |
| 983 |
;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the |
| 984 |
;; altivec_expand_predicate_builtin() function when the value of the |
| 985 |
;; integer constant first argument equals zero (aka __CR6_EQ in altivec.h). |
| 986 |
(define_expand "cr6_test_for_zero" |
| 987 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 988 |
(eq:SI (reg:CC CR6_REGNO) |
| 989 |
(const_int 0)))] |
| 990 |
"TARGET_ALTIVEC || TARGET_VSX" |
| 991 |
"") |
| 992 |
|
| 993 |
;; This expansion is triggered during expansion of predicate built-in |
| 994 |
;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the |
| 995 |
;; altivec_expand_predicate_builtin() function when the value of the |
| 996 |
;; integer constant first argument equals one (aka __CR6_EQ_REV in altivec.h). |
| 997 |
(define_expand "cr6_test_for_zero_reverse" |
| 998 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 999 |
(eq:SI (reg:CC CR6_REGNO) |
| 1000 |
(const_int 0))) |
| 1001 |
(set (match_dup 0) |
| 1002 |
(xor:SI (match_dup 0) |
| 1003 |
(const_int 1)))] |
| 1004 |
"TARGET_ALTIVEC || TARGET_VSX" |
| 1005 |
"") |
| 1006 |
|
| 1007 |
;; This expansion is triggered during expansion of predicate built-in |
| 1008 |
;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the |
| 1009 |
;; altivec_expand_predicate_builtin() function when the value of the |
| 1010 |
;; integer constant first argument equals two (aka __CR6_LT in altivec.h). |
| 1011 |
(define_expand "cr6_test_for_lt" |
| 1012 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1013 |
(lt:SI (reg:CC CR6_REGNO) |
| 1014 |
(const_int 0)))] |
| 1015 |
"TARGET_ALTIVEC || TARGET_VSX" |
| 1016 |
"") |
| 1017 |
|
| 1018 |
;; This expansion is triggered during expansion of predicate built-in |
| 1019 |
;; functions (built-ins defined with the RS6000_BUILTIN_P macro) by the |
| 1020 |
;; altivec_expand_predicate_builtin() function when the value of the |
| 1021 |
;; integer constant first argument equals three |
| 1022 |
;; (aka __CR6_LT_REV in altivec.h). |
| 1023 |
(define_expand "cr6_test_for_lt_reverse" |
| 1024 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1025 |
(lt:SI (reg:CC CR6_REGNO) |
| 1026 |
(const_int 0))) |
| 1027 |
(set (match_dup 0) |
| 1028 |
(xor:SI (match_dup 0) |
| 1029 |
(const_int 1)))] |
| 1030 |
"TARGET_ALTIVEC || TARGET_VSX" |
| 1031 |
"") |
| 1032 |
|
| 1033 |
|
| 1034 |
;; Vector count leading zeros |
| 1035 |
(define_expand "clz<mode>2" |
| 1036 |
[(set (match_operand:VEC_I 0 "register_operand") |
| 1037 |
(clz:VEC_I (match_operand:VEC_I 1 "register_operand")))] |
| 1038 |
"TARGET_P8_VECTOR") |
| 1039 |
|
| 1040 |
;; Vector count trailing zeros |
| 1041 |
(define_expand "ctz<mode>2" |
| 1042 |
[(set (match_operand:VEC_I 0 "register_operand") |
| 1043 |
(ctz:VEC_I (match_operand:VEC_I 1 "register_operand")))] |
| 1044 |
"TARGET_P9_VECTOR") |
| 1045 |
|
| 1046 |
;; Vector population count |
| 1047 |
(define_expand "popcount<mode>2" |
| 1048 |
[(set (match_operand:VEC_I 0 "register_operand") |
| 1049 |
(popcount:VEC_I (match_operand:VEC_I 1 "register_operand")))] |
| 1050 |
"TARGET_P8_VECTOR") |
| 1051 |
|
| 1052 |
;; Vector parity |
| 1053 |
(define_expand "parity<mode>2" |
| 1054 |
[(set (match_operand:VEC_IP 0 "register_operand") |
| 1055 |
(parity:VEC_IP (match_operand:VEC_IP 1 "register_operand")))] |
| 1056 |
"TARGET_P9_VECTOR" |
| 1057 |
{ |
| 1058 |
rtx op1 = gen_lowpart (V16QImode, operands[1]); |
| 1059 |
rtx res = gen_reg_rtx (V16QImode); |
| 1060 |
emit_insn (gen_popcountv16qi2 (res, op1)); |
| 1061 |
emit_insn (gen_rs6000_vprtyb<mode>2 (operands[0], |
| 1062 |
gen_lowpart (<MODE>mode, res))); |
| 1063 |
|
| 1064 |
DONE; |
| 1065 |
}) |
| 1066 |
|
| 1067 |
|
| 1068 |
;; Same size conversions |
| 1069 |
(define_expand "float<VEC_int><mode>2" |
| 1070 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 1071 |
(float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))] |
| 1072 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1073 |
{ |
| 1074 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 1075 |
{ |
| 1076 |
emit_insn (gen_altivec_vcfsx (operands[0], operands[1], const0_rtx)); |
| 1077 |
DONE; |
| 1078 |
} |
| 1079 |
}) |
| 1080 |
|
| 1081 |
(define_expand "floatuns<VEC_int><mode>2" |
| 1082 |
[(set (match_operand:VEC_F 0 "vfloat_operand") |
| 1083 |
(unsigned_float:VEC_F (match_operand:<VEC_INT> 1 "vint_operand")))] |
| 1084 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1085 |
{ |
| 1086 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 1087 |
{ |
| 1088 |
emit_insn (gen_altivec_vcfux (operands[0], operands[1], const0_rtx)); |
| 1089 |
DONE; |
| 1090 |
} |
| 1091 |
}) |
| 1092 |
|
| 1093 |
(define_expand "fix_trunc<mode><VEC_int>2" |
| 1094 |
[(set (match_operand:<VEC_INT> 0 "vint_operand") |
| 1095 |
(fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))] |
| 1096 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1097 |
{ |
| 1098 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 1099 |
{ |
| 1100 |
emit_insn (gen_altivec_vctsxs (operands[0], operands[1], const0_rtx)); |
| 1101 |
DONE; |
| 1102 |
} |
| 1103 |
}) |
| 1104 |
|
| 1105 |
(define_expand "fixuns_trunc<mode><VEC_int>2" |
| 1106 |
[(set (match_operand:<VEC_INT> 0 "vint_operand") |
| 1107 |
(unsigned_fix:<VEC_INT> (match_operand:VEC_F 1 "vfloat_operand")))] |
| 1108 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1109 |
{ |
| 1110 |
if (<MODE>mode == V4SFmode && VECTOR_UNIT_ALTIVEC_P (<MODE>mode)) |
| 1111 |
{ |
| 1112 |
emit_insn (gen_altivec_vctuxs (operands[0], operands[1], const0_rtx)); |
| 1113 |
DONE; |
| 1114 |
} |
| 1115 |
}) |
| 1116 |
|
| 1117 |
|
| 1118 |
;; Vector initialization, set, extract |
| 1119 |
(define_expand "vec_init<mode><VEC_base_l>" |
| 1120 |
[(match_operand:VEC_E 0 "vlogical_operand") |
| 1121 |
(match_operand:VEC_E 1 "")] |
| 1122 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1123 |
{ |
| 1124 |
rs6000_expand_vector_init (operands[0], operands[1]); |
| 1125 |
DONE; |
| 1126 |
}) |
| 1127 |
|
| 1128 |
(define_expand "vec_set<mode>" |
| 1129 |
[(match_operand:VEC_E 0 "vlogical_operand") |
| 1130 |
(match_operand:<VEC_base> 1 "register_operand") |
| 1131 |
(match_operand 2 "vec_set_index_operand")] |
| 1132 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1133 |
{ |
| 1134 |
rs6000_expand_vector_set (operands[0], operands[1], operands[2]); |
| 1135 |
DONE; |
| 1136 |
}) |
| 1137 |
|
| 1138 |
(define_expand "vec_extract<mode><VEC_base_l>" |
| 1139 |
[(match_operand:<VEC_base> 0 "register_operand") |
| 1140 |
(match_operand:VEC_E 1 "vlogical_operand") |
| 1141 |
(match_operand 2 "const_int_operand")] |
| 1142 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1143 |
{ |
| 1144 |
rs6000_expand_vector_extract (operands[0], operands[1], operands[2]); |
| 1145 |
DONE; |
| 1146 |
}) |
| 1147 |
|
| 1148 |
;; Convert double word types to single word types |
| 1149 |
(define_expand "vec_pack_trunc_v2df" |
| 1150 |
[(match_operand:V4SF 0 "vfloat_operand") |
| 1151 |
(match_operand:V2DF 1 "vfloat_operand") |
| 1152 |
(match_operand:V2DF 2 "vfloat_operand")] |
| 1153 |
"VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC" |
| 1154 |
{ |
| 1155 |
rtx r1 = gen_reg_rtx (V4SFmode); |
| 1156 |
rtx r2 = gen_reg_rtx (V4SFmode); |
| 1157 |
|
| 1158 |
emit_insn (gen_vsx_xvcvdpsp (r1, operands[1])); |
| 1159 |
emit_insn (gen_vsx_xvcvdpsp (r2, operands[2])); |
| 1160 |
rs6000_expand_extract_even (operands[0], r1, r2); |
| 1161 |
DONE; |
| 1162 |
}) |
| 1163 |
|
| 1164 |
(define_expand "vec_pack_sfix_trunc_v2df" |
| 1165 |
[(match_operand:V4SI 0 "vint_operand") |
| 1166 |
(match_operand:V2DF 1 "vfloat_operand") |
| 1167 |
(match_operand:V2DF 2 "vfloat_operand")] |
| 1168 |
"VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC" |
| 1169 |
{ |
| 1170 |
rtx r1 = gen_reg_rtx (V4SImode); |
| 1171 |
rtx r2 = gen_reg_rtx (V4SImode); |
| 1172 |
|
| 1173 |
emit_insn (gen_vsx_xvcvdpsxws (r1, operands[1])); |
| 1174 |
emit_insn (gen_vsx_xvcvdpsxws (r2, operands[2])); |
| 1175 |
rs6000_expand_extract_even (operands[0], r1, r2); |
| 1176 |
DONE; |
| 1177 |
}) |
| 1178 |
|
| 1179 |
(define_expand "vec_pack_ufix_trunc_v2df" |
| 1180 |
[(match_operand:V4SI 0 "vint_operand") |
| 1181 |
(match_operand:V2DF 1 "vfloat_operand") |
| 1182 |
(match_operand:V2DF 2 "vfloat_operand")] |
| 1183 |
"VECTOR_UNIT_VSX_P (V2DFmode) && TARGET_ALTIVEC" |
| 1184 |
{ |
| 1185 |
rtx r1 = gen_reg_rtx (V4SImode); |
| 1186 |
rtx r2 = gen_reg_rtx (V4SImode); |
| 1187 |
|
| 1188 |
emit_insn (gen_vsx_xvcvdpuxws (r1, operands[1])); |
| 1189 |
emit_insn (gen_vsx_xvcvdpuxws (r2, operands[2])); |
| 1190 |
rs6000_expand_extract_even (operands[0], r1, r2); |
| 1191 |
DONE; |
| 1192 |
}) |
| 1193 |
|
| 1194 |
;; Convert single word types to double word |
| 1195 |
(define_expand "vec_unpacks_hi_v4sf" |
| 1196 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1197 |
(match_operand:V4SF 1 "vfloat_operand")] |
| 1198 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)" |
| 1199 |
{ |
| 1200 |
rtx reg = gen_reg_rtx (V4SFmode); |
| 1201 |
|
| 1202 |
rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN); |
| 1203 |
emit_insn (gen_vsx_xvcvspdp (operands[0], reg)); |
| 1204 |
DONE; |
| 1205 |
}) |
| 1206 |
|
| 1207 |
(define_expand "vec_unpacks_lo_v4sf" |
| 1208 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1209 |
(match_operand:V4SF 1 "vfloat_operand")] |
| 1210 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)" |
| 1211 |
{ |
| 1212 |
rtx reg = gen_reg_rtx (V4SFmode); |
| 1213 |
|
| 1214 |
rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN); |
| 1215 |
emit_insn (gen_vsx_xvcvspdp (operands[0], reg)); |
| 1216 |
DONE; |
| 1217 |
}) |
| 1218 |
|
| 1219 |
(define_expand "vec_unpacks_float_hi_v4si" |
| 1220 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1221 |
(match_operand:V4SI 1 "vint_operand")] |
| 1222 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)" |
| 1223 |
{ |
| 1224 |
rtx reg = gen_reg_rtx (V4SImode); |
| 1225 |
|
| 1226 |
rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN); |
| 1227 |
emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg)); |
| 1228 |
DONE; |
| 1229 |
}) |
| 1230 |
|
| 1231 |
(define_expand "vec_unpacks_float_lo_v4si" |
| 1232 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1233 |
(match_operand:V4SI 1 "vint_operand")] |
| 1234 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)" |
| 1235 |
{ |
| 1236 |
rtx reg = gen_reg_rtx (V4SImode); |
| 1237 |
|
| 1238 |
rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN); |
| 1239 |
emit_insn (gen_vsx_xvcvsxwdp (operands[0], reg)); |
| 1240 |
DONE; |
| 1241 |
}) |
| 1242 |
|
| 1243 |
(define_expand "vec_unpacku_float_hi_v4si" |
| 1244 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1245 |
(match_operand:V4SI 1 "vint_operand")] |
| 1246 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)" |
| 1247 |
{ |
| 1248 |
rtx reg = gen_reg_rtx (V4SImode); |
| 1249 |
|
| 1250 |
rs6000_expand_interleave (reg, operands[1], operands[1], BYTES_BIG_ENDIAN); |
| 1251 |
emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg)); |
| 1252 |
DONE; |
| 1253 |
}) |
| 1254 |
|
| 1255 |
(define_expand "vec_unpacku_float_lo_v4si" |
| 1256 |
[(match_operand:V2DF 0 "vfloat_operand") |
| 1257 |
(match_operand:V4SI 1 "vint_operand")] |
| 1258 |
"VECTOR_UNIT_VSX_P (V2DFmode) && VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SImode)" |
| 1259 |
{ |
| 1260 |
rtx reg = gen_reg_rtx (V4SImode); |
| 1261 |
|
| 1262 |
rs6000_expand_interleave (reg, operands[1], operands[1], !BYTES_BIG_ENDIAN); |
| 1263 |
emit_insn (gen_vsx_xvcvuxwdp (operands[0], reg)); |
| 1264 |
DONE; |
| 1265 |
}) |
| 1266 |
|
| 1267 |
|
| 1268 |
;; Align vector loads with a permute. |
| 1269 |
(define_expand "vec_realign_load_<mode>" |
| 1270 |
[(match_operand:VEC_K 0 "vlogical_operand") |
| 1271 |
(match_operand:VEC_K 1 "vlogical_operand") |
| 1272 |
(match_operand:VEC_K 2 "vlogical_operand") |
| 1273 |
(match_operand:V16QI 3 "vlogical_operand")] |
| 1274 |
"VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1275 |
{ |
| 1276 |
if (BYTES_BIG_ENDIAN) |
| 1277 |
emit_insn (gen_altivec_vperm_<mode> (operands[0], operands[1], |
| 1278 |
operands[2], operands[3])); |
| 1279 |
else |
| 1280 |
{ |
| 1281 |
/* We have changed lvsr to lvsl, so to complete the transformation |
| 1282 |
of vperm for LE, we must swap the inputs. */ |
| 1283 |
rtx unspec = gen_rtx_UNSPEC (<MODE>mode, |
| 1284 |
gen_rtvec (3, operands[2], |
| 1285 |
operands[1], operands[3]), |
| 1286 |
UNSPEC_VPERM); |
| 1287 |
emit_move_insn (operands[0], unspec); |
| 1288 |
} |
| 1289 |
DONE; |
| 1290 |
}) |
| 1291 |
|
| 1292 |
;; Under VSX, vectors of 4/8 byte alignments do not need to be aligned |
| 1293 |
;; since the load already handles it. |
| 1294 |
(define_expand "movmisalign<mode>" |
| 1295 |
[(set (match_operand:VEC_N 0 "nonimmediate_operand") |
| 1296 |
(match_operand:VEC_N 1 "any_operand"))] |
| 1297 |
"VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_ALLOW_MOVMISALIGN" |
| 1298 |
{ |
| 1299 |
rs6000_emit_move (operands[0], operands[1], <MODE>mode); |
| 1300 |
DONE; |
| 1301 |
}) |
| 1302 |
|
| 1303 |
;; Vector shift right in bits. Currently supported ony for shift |
| 1304 |
;; amounts that can be expressed as byte shifts (divisible by 8). |
| 1305 |
;; General shift amounts can be supported using vsro + vsr. We're |
| 1306 |
;; not expecting to see these yet (the vectorizer currently |
| 1307 |
;; generates only shifts by a whole number of vector elements). |
| 1308 |
;; Note that the vec_shr operation is actually defined as |
| 1309 |
;; 'shift toward element 0' so is a shr for LE and shl for BE. |
| 1310 |
(define_expand "vec_shr_<mode>" |
| 1311 |
[(match_operand:VEC_L 0 "vlogical_operand") |
| 1312 |
(match_operand:VEC_L 1 "vlogical_operand") |
| 1313 |
(match_operand:QI 2 "reg_or_short_operand")] |
| 1314 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1315 |
{ |
| 1316 |
rtx bitshift = operands[2]; |
| 1317 |
rtx shift; |
| 1318 |
rtx insn; |
| 1319 |
rtx zero_reg, op1, op2; |
| 1320 |
HOST_WIDE_INT bitshift_val; |
| 1321 |
HOST_WIDE_INT byteshift_val; |
| 1322 |
|
| 1323 |
if (! CONSTANT_P (bitshift)) |
| 1324 |
FAIL; |
| 1325 |
bitshift_val = INTVAL (bitshift); |
| 1326 |
if (bitshift_val & 0x7) |
| 1327 |
FAIL; |
| 1328 |
byteshift_val = (bitshift_val >> 3); |
| 1329 |
zero_reg = gen_reg_rtx (<MODE>mode); |
| 1330 |
emit_move_insn (zero_reg, CONST0_RTX (<MODE>mode)); |
| 1331 |
if (!BYTES_BIG_ENDIAN) |
| 1332 |
{ |
| 1333 |
/* Note, byteshift_val can be 0! */ |
| 1334 |
byteshift_val = -byteshift_val & 15; |
| 1335 |
op1 = zero_reg; |
| 1336 |
op2 = operands[1]; |
| 1337 |
} |
| 1338 |
else |
| 1339 |
{ |
| 1340 |
op1 = operands[1]; |
| 1341 |
op2 = zero_reg; |
| 1342 |
} |
| 1343 |
|
| 1344 |
if (TARGET_VSX && (byteshift_val & 0x3) == 0) |
| 1345 |
{ |
| 1346 |
shift = gen_rtx_CONST_INT (QImode, byteshift_val >> 2); |
| 1347 |
insn = gen_vsx_xxsldwi_<mode> (operands[0], op1, op2, shift); |
| 1348 |
} |
| 1349 |
else |
| 1350 |
{ |
| 1351 |
shift = gen_rtx_CONST_INT (QImode, byteshift_val); |
| 1352 |
insn = gen_altivec_vsldoi_<mode> (operands[0], op1, op2, shift); |
| 1353 |
} |
| 1354 |
|
| 1355 |
emit_insn (insn); |
| 1356 |
DONE; |
| 1357 |
}) |
| 1358 |
|
| 1359 |
;; Expanders for rotate each element in a vector |
| 1360 |
(define_expand "vrotl<mode>3" |
| 1361 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 1362 |
(rotate:VEC_IC (match_operand:VEC_IC 1 "vint_operand") |
| 1363 |
(match_operand:VEC_IC 2 "vint_operand")))] |
| 1364 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1365 |
{ |
| 1366 |
/* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */ |
| 1367 |
if (<MODE>mode == V1TImode) |
| 1368 |
{ |
| 1369 |
rtx tmp = gen_reg_rtx (V1TImode); |
| 1370 |
|
| 1371 |
emit_insn (gen_xxswapd_v1ti (tmp, operands[2])); |
| 1372 |
emit_insn (gen_altivec_vrlq (operands[0], operands[1], tmp)); |
| 1373 |
DONE; |
| 1374 |
} |
| 1375 |
}) |
| 1376 |
|
| 1377 |
;; Expanders for rotatert to make use of vrotl |
| 1378 |
(define_expand "vrotr<mode>3" |
| 1379 |
[(set (match_operand:VEC_I 0 "vint_operand") |
| 1380 |
(rotatert:VEC_I (match_operand:VEC_I 1 "vint_operand") |
| 1381 |
(match_operand:VEC_I 2 "vint_operand")))] |
| 1382 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1383 |
{ |
| 1384 |
rtx rot_count = gen_reg_rtx (<MODE>mode); |
| 1385 |
emit_insn (gen_neg<mode>2 (rot_count, operands[2])); |
| 1386 |
emit_insn (gen_vrotl<mode>3 (operands[0], operands[1], rot_count)); |
| 1387 |
DONE; |
| 1388 |
}) |
| 1389 |
|
| 1390 |
;; Expanders for arithmetic shift left on each vector element |
| 1391 |
(define_expand "vashl<mode>3" |
| 1392 |
[(set (match_operand:VEC_I 0 "vint_operand") |
| 1393 |
(ashift:VEC_I (match_operand:VEC_I 1 "vint_operand") |
| 1394 |
(match_operand:VEC_I 2 "vint_operand")))] |
| 1395 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1396 |
"") |
| 1397 |
|
| 1398 |
;; No immediate version of this 128-bit instruction |
| 1399 |
(define_expand "vashl<mode>3" |
| 1400 |
[(set (match_operand:VEC_TI 0 "vsx_register_operand" "=v") |
| 1401 |
(ashift:VEC_TI (match_operand:VEC_TI 1 "vsx_register_operand") |
| 1402 |
(match_operand:VEC_TI 2 "vsx_register_operand")))] |
| 1403 |
"TARGET_POWER10" |
| 1404 |
{ |
| 1405 |
/* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */ |
| 1406 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 1407 |
|
| 1408 |
emit_insn (gen_xxswapd_v1ti (tmp, operands[2])); |
| 1409 |
emit_insn(gen_altivec_vslq_<mode> (operands[0], operands[1], tmp)); |
| 1410 |
DONE; |
| 1411 |
}) |
| 1412 |
|
| 1413 |
;; Expanders for logical shift right on each vector element |
| 1414 |
(define_expand "vlshr<mode>3" |
| 1415 |
[(set (match_operand:VEC_I 0 "vint_operand") |
| 1416 |
(lshiftrt:VEC_I (match_operand:VEC_I 1 "vint_operand") |
| 1417 |
(match_operand:VEC_I 2 "vint_operand")))] |
| 1418 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1419 |
"") |
| 1420 |
|
| 1421 |
;; No immediate version of this 128-bit instruction |
| 1422 |
(define_expand "vlshr<mode>3" |
| 1423 |
[(set (match_operand:VEC_TI 0 "vsx_register_operand" "=v") |
| 1424 |
(lshiftrt:VEC_TI (match_operand:VEC_TI 1 "vsx_register_operand") |
| 1425 |
(match_operand:VEC_TI 2 "vsx_register_operand")))] |
| 1426 |
"TARGET_POWER10" |
| 1427 |
{ |
| 1428 |
/* Shift amount in needs to be put into bits[57:63] of 128-bit operand2. */ |
| 1429 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 1430 |
|
| 1431 |
emit_insn (gen_xxswapd_v1ti (tmp, operands[2])); |
| 1432 |
emit_insn(gen_altivec_vsrq_<mode> (operands[0], operands[1], tmp)); |
| 1433 |
DONE; |
| 1434 |
}) |
| 1435 |
|
| 1436 |
;; Expanders for arithmetic shift right on each vector element |
| 1437 |
(define_expand "vashr<mode>3" |
| 1438 |
[(set (match_operand:VEC_IC 0 "vint_operand") |
| 1439 |
(ashiftrt:VEC_IC (match_operand:VEC_IC 1 "vint_operand") |
| 1440 |
(match_operand:VEC_IC 2 "vint_operand")))] |
| 1441 |
"VECTOR_UNIT_ALTIVEC_OR_VSX_P (<MODE>mode)" |
| 1442 |
{ |
| 1443 |
/* Shift amount in needs to be put in bits[57:63] of 128-bit operand2. */ |
| 1444 |
if (<MODE>mode == V1TImode) |
| 1445 |
{ |
| 1446 |
rtx tmp = gen_reg_rtx (V1TImode); |
| 1447 |
|
| 1448 |
emit_insn (gen_xxswapd_v1ti (tmp, operands[2])); |
| 1449 |
emit_insn (gen_altivec_vsraq (operands[0], operands[1], tmp)); |
| 1450 |
DONE; |
| 1451 |
} |
| 1452 |
}) |
| 1453 |
|
| 1454 |
|
| 1455 |
;; Vector reduction expanders for VSX |
| 1456 |
; The (VEC_reduc:... |
| 1457 |
; (op1) |
| 1458 |
; (unspec:... [(const_int 0)] UNSPEC_REDUC)) |
| 1459 |
; |
| 1460 |
; is to allow us to use a code iterator, but not completely list all of the |
| 1461 |
; vector rotates, etc. to prevent canonicalization |
| 1462 |
|
| 1463 |
|
| 1464 |
(define_expand "reduc_<VEC_reduc:VEC_reduc_name>_scal_<VEC_F:mode>" |
| 1465 |
[(match_operand:<VEC_base> 0 "register_operand") |
| 1466 |
(VEC_reduc:VEC_F (match_operand:VEC_F 1 "vfloat_operand") |
| 1467 |
(unspec:VEC_F [(const_int 0)] UNSPEC_REDUC))] |
| 1468 |
"VECTOR_UNIT_VSX_P (<VEC_F:MODE>mode)" |
| 1469 |
{ |
| 1470 |
rtx vec = gen_reg_rtx (<VEC_F:MODE>mode); |
| 1471 |
rtx elt = BYTES_BIG_ENDIAN |
| 1472 |
? gen_int_mode (GET_MODE_NUNITS (<VEC_F:MODE>mode) - 1, QImode) |
| 1473 |
: const0_rtx; |
| 1474 |
emit_insn (gen_vsx_reduc_<VEC_reduc:VEC_reduc_name>_<VEC_F:mode> (vec, |
| 1475 |
operand1)); |
| 1476 |
emit_insn (gen_vsx_extract_<VEC_F:mode> (operand0, vec, elt)); |
| 1477 |
DONE; |
| 1478 |
}) |