| 1 |
;; Machine Description for LoongArch SIMD instructions for GNU compiler. |
| 2 |
;; Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
;; This file is part of GCC. |
| 5 |
|
| 6 |
;; GCC is free software; you can redistribute it and/or modify |
| 7 |
;; it under the terms of the GNU General Public License as published by |
| 8 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 9 |
;; any later version. |
| 10 |
|
| 11 |
;; GCC is distributed in the hope that it will be useful, |
| 12 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
;; GNU General Public License for more details. |
| 15 |
|
| 16 |
;; You should have received a copy of the GNU General Public License |
| 17 |
;; along with GCC; see the file COPYING3. If not see |
| 18 |
;; <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
;; Integer modes supported by LSX. |
| 21 |
(define_mode_iterator ILSX [V2DI V4SI V8HI V16QI]) |
| 22 |
|
| 23 |
;; Integer modes supported by LASX. |
| 24 |
(define_mode_iterator ILASX [V4DI V8SI V16HI V32QI]) |
| 25 |
|
| 26 |
;; FP modes supported by LSX |
| 27 |
(define_mode_iterator FLSX [V2DF V4SF]) |
| 28 |
|
| 29 |
;; FP modes supported by LASX |
| 30 |
(define_mode_iterator FLASX [V4DF V8SF]) |
| 31 |
|
| 32 |
;; All modes supported by LSX |
| 33 |
(define_mode_iterator LSX [ILSX FLSX]) |
| 34 |
|
| 35 |
;; ALL modes supported by LASX |
| 36 |
(define_mode_iterator LASX [ILASX FLASX]) |
| 37 |
|
| 38 |
;; All integer modes available |
| 39 |
(define_mode_iterator IVEC [(ILSX "ISA_HAS_LSX") (ILASX "ISA_HAS_LASX")]) |
| 40 |
|
| 41 |
;; All FP modes available |
| 42 |
(define_mode_iterator FVEC [(FLSX "ISA_HAS_LSX") (FLASX "ISA_HAS_LASX")]) |
| 43 |
|
| 44 |
;; All vector modes available |
| 45 |
(define_mode_iterator ALLVEC [(LSX "ISA_HAS_LSX") (LASX "ISA_HAS_LASX")]) |
| 46 |
|
| 47 |
;; Mnemonic prefix, "x" for LASX modes. |
| 48 |
(define_mode_attr x [(V2DI "") (V4SI "") (V8HI "") (V16QI "") |
| 49 |
(V2DF "") (V4SF "") |
| 50 |
(V4DI "x") (V8SI "x") (V16HI "x") (V32QI "x") |
| 51 |
(V4DF "x") (V8SF "x")]) |
| 52 |
|
| 53 |
;; Modifier for vector register, "w" for LSX modes, "u" for LASX modes. |
| 54 |
(define_mode_attr wu [(V2DI "w") (V4SI "w") (V8HI "w") (V16QI "w") |
| 55 |
(V2DF "w") (V4SF "w") |
| 56 |
(V4DI "u") (V8SI "u") (V16HI "u") (V32QI "u") |
| 57 |
(V4DF "u") (V8SF "u")]) |
| 58 |
|
| 59 |
;; define_insn name prefix, "lsx" or "lasx" |
| 60 |
(define_mode_attr simd_isa |
| 61 |
[(V2DI "lsx") (V4SI "lsx") (V8HI "lsx") (V16QI "lsx") |
| 62 |
(V2DF "lsx") (V4SF "lsx") |
| 63 |
(V4DI "lasx") (V8SI "lasx") (V16HI "lasx") (V32QI "lasx") |
| 64 |
(V4DF "lasx") (V8SF "lasx")]) |
| 65 |
|
| 66 |
;; Widen integer modes for intermediate values in RTX pattern. |
| 67 |
(define_mode_attr WVEC [(V2DI "V2TI") (V4DI "V4TI") |
| 68 |
(V4SI "V4DI") (V8SI "V8DI") |
| 69 |
(V8HI "V8SI") (V16HI "V16SI") |
| 70 |
(V16QI "V16HI") (V32QI "V32HI")]) |
| 71 |
|
| 72 |
;; The element type is not changed but the number of elements is halved. |
| 73 |
(define_mode_attr VEC_HALF [(V2DI "V1DI") (V4DI "V2DI") |
| 74 |
(V4SI "V2SI") (V8SI "V4SI") |
| 75 |
(V8HI "V4HI") (V16HI "V8HI") |
| 76 |
(V16QI "V8QI") (V32QI "V16QI")]) |
| 77 |
|
| 78 |
;; Modes with doubled length for intermediate values in RTX pattern. |
| 79 |
(define_mode_attr LVEC [(V2DF "V4DF") (V4DF "V8DF") |
| 80 |
(V4SF "V8SF") (V8SF "V16SF") |
| 81 |
(V2DI "V4DI") (V4DI "V8DI") |
| 82 |
(V4SI "V8SI") (V8SI "V16SI") |
| 83 |
(V8HI "V16HI") (V16HI "V32HI") |
| 84 |
(V16QI "V32QI") (V32QI "V64QI")]) |
| 85 |
|
| 86 |
;; The elements are widen but the total size is unchanged |
| 87 |
;; (i.e. the number of elements is halfed). |
| 88 |
(define_mode_attr WVEC_HALF [(V2DI "V1TI") (V4DI "V2TI") |
| 89 |
(V4SI "V2DI") (V8SI "V4DI") |
| 90 |
(V8HI "V4SI") (V16HI "V8SI") |
| 91 |
(V16QI "V8HI") (V32QI "V16HI")]) |
| 92 |
|
| 93 |
;; Lower-case version. |
| 94 |
(define_mode_attr wvec_half [(V2DI "v1ti") (V4DI "v2ti") |
| 95 |
(V4SI "v2di") (V8SI "v4di") |
| 96 |
(V8HI "v4si") (V16HI "v8si") |
| 97 |
(V16QI "v8hi") (V32QI "v16hi")]) |
| 98 |
|
| 99 |
;; Integer vector modes with the same length and unit size as a mode. |
| 100 |
(define_mode_attr VIMODE [(V2DI "V2DI") (V4SI "V4SI") |
| 101 |
(V8HI "V8HI") (V16QI "V16QI") |
| 102 |
(V2DF "V2DI") (V4SF "V4SI") |
| 103 |
(V4DI "V4DI") (V8SI "V8SI") |
| 104 |
(V16HI "V16HI") (V32QI "V32QI") |
| 105 |
(V4DF "V4DI") (V8SF "V8SI")]) |
| 106 |
|
| 107 |
;; Lower-case version. |
| 108 |
(define_mode_attr vimode [(V2DF "v2di") (V4SF "v4si") |
| 109 |
(V4DF "v4di") (V8SF "v8si")]) |
| 110 |
|
| 111 |
;; Integer vector modes with the same size, in lower-case. |
| 112 |
(define_mode_attr allmode_i [(V2DI "v2di") (V4SI "v4si") |
| 113 |
(V8HI "v8hi") (V16QI "v16qi") |
| 114 |
(V2DF "v2di") (V4SF "v4si") |
| 115 |
(V4DI "v4di") (V8SI "v8si") |
| 116 |
(V16HI "v16hi") (V32QI "v32qi") |
| 117 |
(V4DF "v4di") (V8SF "v8si")]) |
| 118 |
|
| 119 |
;; Suffix for LSX or LASX instructions. |
| 120 |
(define_mode_attr simdfmt [(V2DF "d") (V4DF "d") |
| 121 |
(V4SF "s") (V8SF "s") |
| 122 |
(V2DI "d") (V4DI "d") |
| 123 |
(V4SI "w") (V8SI "w") |
| 124 |
(V8HI "h") (V16HI "h") |
| 125 |
(V16QI "b") (V32QI "b")]) |
| 126 |
|
| 127 |
;; Suffix for widening LSX or LASX instructions. |
| 128 |
(define_mode_attr simdfmt_w [(V2DI "q") (V4DI "q") |
| 129 |
(V4SI "d") (V8SI "d") |
| 130 |
(V8HI "w") (V16HI "w") |
| 131 |
(V16QI "h") (V32QI "h")]) |
| 132 |
|
| 133 |
;; Suffix for integer mode in LSX or LASX instructions with FP input but |
| 134 |
;; integer output. |
| 135 |
(define_mode_attr simdifmt_for_f [(V2DF "l") (V4DF "l") |
| 136 |
(V4SF "w") (V8SF "w")]) |
| 137 |
|
| 138 |
;; Suffix for integer mode in LSX or LASX instructions to operate FP |
| 139 |
;; vectors using integer vector operations. |
| 140 |
(define_mode_attr simdfmt_as_i [(V2DF "d") (V4DF "d") |
| 141 |
(V4SF "w") (V8SF "w") |
| 142 |
(V2DI "d") (V4DI "d") |
| 143 |
(V4SI "w") (V8SI "w") |
| 144 |
(V8HI "h") (V16HI "h") |
| 145 |
(V16QI "b") (V32QI "b")]) |
| 146 |
|
| 147 |
;; "_f" for FP vectors, "" for integer vectors |
| 148 |
(define_mode_attr _f [(V2DF "_f") (V4DF "_f") |
| 149 |
(V4SF "_f") (V8SF "_f") |
| 150 |
(V2DI "") (V4DI "") |
| 151 |
(V4SI "") (V8SI "") |
| 152 |
(V8HI "") (V16HI "") |
| 153 |
(V16QI "") (V32QI "")]) |
| 154 |
|
| 155 |
;; Size of vector elements in bits. |
| 156 |
(define_mode_attr elmbits [(V2DI "64") (V4DI "64") |
| 157 |
(V4SI "32") (V8SI "32") |
| 158 |
(V8HI "16") (V16HI "16") |
| 159 |
(V16QI "8") (V32QI "8")]) |
| 160 |
|
| 161 |
;; The index of sign bit in FP vector elements. |
| 162 |
(define_mode_attr elmsgnbit [(V2DF "63") (V4DF "63") |
| 163 |
(V4SF "31") (V8SF "31")]) |
| 164 |
|
| 165 |
;; This attribute is used to form an immediate operand constraint using |
| 166 |
;; "const_<bitimm>_operand". |
| 167 |
(define_mode_attr bitimm [(V16QI "uimm3") (V32QI "uimm3") |
| 168 |
(V8HI "uimm4") (V16HI "uimm4") |
| 169 |
(V4SI "uimm5") (V8SI "uimm5") |
| 170 |
(V2DI "uimm6") (V4DI "uimm6")]) |
| 171 |
|
| 172 |
;; ======================================================================= |
| 173 |
;; For many LASX instructions, the only difference of it from the LSX |
| 174 |
;; counterpart is the length of vector operands. Describe these LSX/LASX |
| 175 |
;; instruction here so we can avoid duplicating logics. |
| 176 |
;; ======================================================================= |
| 177 |
|
| 178 |
|
| 179 |
;; Move |
| 180 |
|
| 181 |
;; Some immediate values in V1TI or V2TI may be stored in LSX or LASX |
| 182 |
;; registers, thus we need to allow moving them for reload. |
| 183 |
(define_mode_iterator ALLVEC_TI [ALLVEC |
| 184 |
(V1TI "ISA_HAS_LSX") |
| 185 |
(V2TI "ISA_HAS_LASX")]) |
| 186 |
|
| 187 |
(define_expand "mov<mode>" |
| 188 |
[(set (match_operand:ALLVEC_TI 0) |
| 189 |
(match_operand:ALLVEC_TI 1))] |
| 190 |
"" |
| 191 |
{ |
| 192 |
if (loongarch_legitimize_move (<MODE>mode, operands[0], operands[1])) |
| 193 |
DONE; |
| 194 |
}) |
| 195 |
|
| 196 |
(define_expand "movmisalign<mode>" |
| 197 |
[(set (match_operand:ALLVEC_TI 0) |
| 198 |
(match_operand:ALLVEC_TI 1))] |
| 199 |
"" |
| 200 |
{ |
| 201 |
if (loongarch_legitimize_move (<MODE>mode, operands[0], operands[1])) |
| 202 |
DONE; |
| 203 |
}) |
| 204 |
|
| 205 |
(define_insn_and_split "mov<mode>_simd" |
| 206 |
[(set (match_operand:ALLVEC_TI 0 "nonimmediate_operand" "=f,f,R,*r,*f,*r") |
| 207 |
(match_operand:ALLVEC_TI 1 "move_operand" "fYGYI,R,f,*f,*r,*r"))] |
| 208 |
"" |
| 209 |
{ return loongarch_output_move (operands); } |
| 210 |
"reload_completed && loongarch_split_move_p (operands[0], operands[1])" |
| 211 |
[(const_int 0)] |
| 212 |
{ |
| 213 |
loongarch_split_move (operands[0], operands[1]); |
| 214 |
DONE; |
| 215 |
} |
| 216 |
[(set_attr "type" "simd_move,simd_load,simd_store,simd_copy,simd_insert,simd_copy") |
| 217 |
(set_attr "mode" "<MODE>")]) |
| 218 |
|
| 219 |
|
| 220 |
;; REG + REG load |
| 221 |
|
| 222 |
(define_mode_iterator QIVEC [(V16QI "ISA_HAS_LSX") (V32QI "ISA_HAS_LASX")]) |
| 223 |
(define_expand "<simd_isa>_<x>vldx" |
| 224 |
[(set (match_operand:QIVEC 0 "register_operand" "=f") |
| 225 |
(mem:QIVEC (plus:DI (match_operand:DI 1 "register_operand") |
| 226 |
(match_operand:DI 2 "register_operand"))))] |
| 227 |
"TARGET_64BIT") |
| 228 |
|
| 229 |
;; |
| 230 |
;; FP vector rounding instructions |
| 231 |
;; |
| 232 |
|
| 233 |
(define_c_enum "unspec" |
| 234 |
[UNSPEC_SIMD_FRINTRP |
| 235 |
UNSPEC_SIMD_FRINTRZ |
| 236 |
UNSPEC_SIMD_FRINT |
| 237 |
UNSPEC_SIMD_FRINTRM |
| 238 |
UNSPEC_SIMD_FRINTRNE]) |
| 239 |
|
| 240 |
(define_int_iterator SIMD_FRINT |
| 241 |
[UNSPEC_SIMD_FRINTRP |
| 242 |
UNSPEC_SIMD_FRINTRZ |
| 243 |
UNSPEC_SIMD_FRINT |
| 244 |
UNSPEC_SIMD_FRINTRM |
| 245 |
UNSPEC_SIMD_FRINTRNE]) |
| 246 |
|
| 247 |
(define_int_attr simd_frint_rounding |
| 248 |
[(UNSPEC_SIMD_FRINTRP "rp") |
| 249 |
(UNSPEC_SIMD_FRINTRZ "rz") |
| 250 |
(UNSPEC_SIMD_FRINT "") |
| 251 |
(UNSPEC_SIMD_FRINTRM "rm") |
| 252 |
(UNSPEC_SIMD_FRINTRNE "rne")]) |
| 253 |
|
| 254 |
;; All these, but rint, are controlled by -ffp-int-builtin-inexact. |
| 255 |
;; Note: nearbyint is NOT allowed to raise FE_INEXACT even if |
| 256 |
;; -ffp-int-builtin-inexact, but rint is ALLOWED to raise it even if |
| 257 |
;; -fno-fp-int-builtin-inexact. |
| 258 |
(define_int_attr simd_frint_pattern |
| 259 |
[(UNSPEC_SIMD_FRINTRP "ceil") |
| 260 |
(UNSPEC_SIMD_FRINTRZ "btrunc") |
| 261 |
(UNSPEC_SIMD_FRINT "rint") |
| 262 |
(UNSPEC_SIMD_FRINTRNE "roundeven") |
| 263 |
(UNSPEC_SIMD_FRINTRM "floor")]) |
| 264 |
|
| 265 |
;; <x>vfrint.{/rp/rz/rm} |
| 266 |
(define_insn "<simd_isa>_<x>vfrint<simd_frint_rounding>_<simdfmt>" |
| 267 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 268 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f")] |
| 269 |
SIMD_FRINT))] |
| 270 |
"" |
| 271 |
"<x>vfrint<simd_frint_rounding>.<simdfmt>\t%<wu>0,%<wu>1" |
| 272 |
[(set_attr "type" "simd_fcvt") |
| 273 |
(set_attr "mode" "<MODE>")]) |
| 274 |
|
| 275 |
;; Expand the standard-named patterns to <x>vfrint instructions if |
| 276 |
;; raising inexact exception is allowed. |
| 277 |
|
| 278 |
(define_expand "<simd_frint_pattern><mode>2" |
| 279 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 280 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f")] |
| 281 |
SIMD_FRINT))] |
| 282 |
"<SIMD_FRINT> == UNSPEC_SIMD_FRINT || |
| 283 |
flag_fp_int_builtin_inexact || |
| 284 |
!flag_trapping_math") |
| 285 |
|
| 286 |
;; ftrunc is like btrunc, but it's allowed to raise inexact exception |
| 287 |
;; even if -fno-fp-int-builtin-inexact. |
| 288 |
(define_expand "ftrunc<mode>2" |
| 289 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 290 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f")] |
| 291 |
UNSPEC_SIMD_FRINTRZ))] |
| 292 |
"") |
| 293 |
|
| 294 |
;; Use LSX for scalar ceil/floor/trunc/roundeven when -mlsx and -ffp-int- |
| 295 |
;; builtin-inexact. The base FP instruction set lacks these operations. |
| 296 |
;; Yes we are wasting 50% or even 75% of the CPU horsepower, but it's still |
| 297 |
;; much faster than calling a libc function: on LA464 and LA664 there is a |
| 298 |
;; 3x ~ 5x speed up. |
| 299 |
;; |
| 300 |
;; Note that a vreplvei instruction is needed or we'll also operate on the |
| 301 |
;; junk in high bits of the vector register and produce random FP exceptions. |
| 302 |
|
| 303 |
(define_int_iterator LSX_SCALAR_FRINT |
| 304 |
[UNSPEC_SIMD_FRINTRP |
| 305 |
UNSPEC_SIMD_FRINTRZ |
| 306 |
UNSPEC_SIMD_FRINTRM |
| 307 |
UNSPEC_SIMD_FRINTRNE]) |
| 308 |
|
| 309 |
(define_mode_attr VLSX_FOR_FMODE [(DF "V2DF") (SF "V4SF")]) |
| 310 |
|
| 311 |
(define_expand "<simd_frint_pattern><mode>2" |
| 312 |
[(set (match_dup 2) |
| 313 |
(vec_duplicate:<VLSX_FOR_FMODE> |
| 314 |
(match_operand:ANYF 1 "register_operand"))) |
| 315 |
(set (match_dup 2) |
| 316 |
(unspec:<VLSX_FOR_FMODE> [(match_dup 2)] LSX_SCALAR_FRINT)) |
| 317 |
(set (match_operand:ANYF 0 "register_operand") |
| 318 |
(vec_select:ANYF (match_dup 2) (parallel [(const_int 0)])))] |
| 319 |
"ISA_HAS_LSX && (flag_fp_int_builtin_inexact || !flag_trapping_math)" |
| 320 |
"operands[2] = gen_reg_rtx (<VLSX_FOR_FMODE>mode);") |
| 321 |
|
| 322 |
;; <x>vftint.{/rp/rz/rm} |
| 323 |
(define_insn |
| 324 |
"<simd_isa>_<x>vftint<simd_frint_rounding>_<simdifmt_for_f>_<simdfmt>" |
| 325 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 326 |
(fix:<VIMODE> |
| 327 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f")] |
| 328 |
SIMD_FRINT)))] |
| 329 |
"" |
| 330 |
"<x>vftint<simd_frint_rounding>.<simdifmt_for_f>.<simdfmt>\t%<wu>0,%<wu>1" |
| 331 |
[(set_attr "type" "simd_fcvt") |
| 332 |
(set_attr "mode" "<MODE>")]) |
| 333 |
|
| 334 |
;; Expand the standard-named patterns to <x>vftint instructions if |
| 335 |
;; raising inexact exception. |
| 336 |
|
| 337 |
(define_expand "l<simd_frint_pattern><mode><vimode>2" |
| 338 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 339 |
(fix:<VIMODE> |
| 340 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f")] |
| 341 |
SIMD_FRINT)))] |
| 342 |
"<SIMD_FRINT> == UNSPEC_SIMD_FRINT || |
| 343 |
flag_fp_int_builtin_inexact || |
| 344 |
!flag_trapping_math") |
| 345 |
|
| 346 |
;; fix_trunc is allowed to raise inexact exception even if |
| 347 |
;; -fno-fp-int-builtin-inexact. Because the middle end trys to match |
| 348 |
;; (FIX x) and it does not know (FIX (UNSPEC_SIMD_FRINTRZ x)), we need |
| 349 |
;; to use define_insn_and_split instead of define_expand (expanders are |
| 350 |
;; not considered during matching). |
| 351 |
(define_insn_and_split "fix_trunc<mode><vimode>2" |
| 352 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 353 |
(fix:<VIMODE> (match_operand:FVEC 1 "register_operand" "f")))] |
| 354 |
"" |
| 355 |
"#" |
| 356 |
"" |
| 357 |
[(const_int 0)] |
| 358 |
{ |
| 359 |
emit_insn (gen_<simd_isa>_<x>vftintrz_<simdifmt_for_f>_<simdfmt> ( |
| 360 |
operands[0], operands[1])); |
| 361 |
DONE; |
| 362 |
} |
| 363 |
[(set_attr "type" "simd_fcvt") |
| 364 |
(set_attr "mode" "<MODE>")]) |
| 365 |
|
| 366 |
;; <x>vmuh.{b/h/w/d} |
| 367 |
|
| 368 |
(define_code_attr muh |
| 369 |
[(sign_extend "smul_highpart") |
| 370 |
(zero_extend "umul_highpart")]) |
| 371 |
|
| 372 |
(define_insn "<su>mul<mode>3_highpart" |
| 373 |
[(set (match_operand:IVEC 0 "register_operand" "=f") |
| 374 |
(<muh>:IVEC (match_operand:IVEC 1 "register_operand" "f") |
| 375 |
(match_operand:IVEC 2 "register_operand" "f"))) |
| 376 |
(any_extend (const_int 0))] |
| 377 |
"" |
| 378 |
"<x>vmuh.<simdfmt><u>\t%<wu>0,%<wu>1,%<wu>2" |
| 379 |
[(set_attr "type" "simd_int_arith") |
| 380 |
(set_attr "mode" "<MODE>")]) |
| 381 |
|
| 382 |
;; <x>vrotr.{b/h/w/d} |
| 383 |
|
| 384 |
(define_insn "vrotr<mode>3" |
| 385 |
[(set (match_operand:IVEC 0 "register_operand" "=f") |
| 386 |
(rotatert:IVEC (match_operand:IVEC 1 "register_operand" "f") |
| 387 |
(match_operand:IVEC 2 "register_operand" "f")))] |
| 388 |
"" |
| 389 |
"<x>vrotr.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 390 |
[(set_attr "type" "simd_int_arith") |
| 391 |
(set_attr "mode" "<MODE>")]) |
| 392 |
|
| 393 |
;; Expand left rotate to right rotate. |
| 394 |
(define_expand "vrotl<mode>3" |
| 395 |
[(set (match_dup 3) |
| 396 |
(neg:IVEC (match_operand:IVEC 2 "register_operand"))) |
| 397 |
(set (match_operand:IVEC 0 "register_operand") |
| 398 |
(rotatert:IVEC (match_operand:IVEC 1 "register_operand") |
| 399 |
(match_dup 3)))] |
| 400 |
"" |
| 401 |
{ |
| 402 |
operands[3] = gen_reg_rtx (<MODE>mode); |
| 403 |
}); |
| 404 |
|
| 405 |
;; Expand left rotate with a scalar amount to right rotate: negate the |
| 406 |
;; scalar before broadcasting it because scalar negation is cheaper than |
| 407 |
;; vector negation. |
| 408 |
(define_expand "rotl<mode>3" |
| 409 |
[(set (match_dup 3) |
| 410 |
(neg:SI (match_operand:SI 2 "register_operand"))) |
| 411 |
(set (match_dup 4) |
| 412 |
(vec_duplicate:IVEC (subreg:<IVEC:UNITMODE> (match_dup 3) 0))) |
| 413 |
(set (match_operand:IVEC 0 "register_operand") |
| 414 |
(rotatert:IVEC (match_operand:IVEC 1 "register_operand") |
| 415 |
(match_dup 4)))] |
| 416 |
"" |
| 417 |
{ |
| 418 |
operands[3] = gen_reg_rtx (SImode); |
| 419 |
operands[4] = gen_reg_rtx (<MODE>mode); |
| 420 |
}); |
| 421 |
|
| 422 |
;; <x>v{rotr/sll/sra/srl}i.{b/h/w/d} |
| 423 |
|
| 424 |
(define_insn "<optab><mode>3" |
| 425 |
[(set (match_operand:IVEC 0 "register_operand" "=f") |
| 426 |
(shift_w:IVEC |
| 427 |
(match_operand:IVEC 1 "register_operand" "f") |
| 428 |
(match_operand:SI 2 "const_<bitimm>_operand")))] |
| 429 |
"ISA_HAS_LSX" |
| 430 |
"<x>v<insn>i.<simdfmt>\t%<wu>0,%<wu>1,%2" |
| 431 |
[(set_attr "type" "simd_int_arith") |
| 432 |
(set_attr "mode" "<MODE>")]) |
| 433 |
|
| 434 |
;; <x>vfnmsub.{s/d} |
| 435 |
(define_insn "fnma<mode>4" |
| 436 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 437 |
(fma:FVEC (neg:FVEC (match_operand:FVEC 1 "register_operand" "f")) |
| 438 |
(match_operand:FVEC 2 "register_operand" "f") |
| 439 |
(match_operand:FVEC 3 "register_operand" "f")))] |
| 440 |
"!HONOR_SIGNED_ZEROS (<MODE>mode)" |
| 441 |
"<x>vfnmsub.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2,%<wu>3" |
| 442 |
[(set_attr "type" "simd_fmadd") |
| 443 |
(set_attr "mode" "<MODE>")]) |
| 444 |
|
| 445 |
;; <x>vfcmp.*.{s/d} with defined RTX code |
| 446 |
;; There are no fcmp.{sugt/suge/cgt/cge}.{s/d} menmonics in GAS, so we have |
| 447 |
;; to reverse the operands ourselves :(. |
| 448 |
(define_code_iterator fcond_simd [unordered uneq unlt unle eq lt le |
| 449 |
ordered ltgt ne]) |
| 450 |
(define_insn "<simd_isa>_<x>vfcmp_<fcond>_<simdfmt>" |
| 451 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 452 |
(fcond_simd:<VIMODE> |
| 453 |
(match_operand:FVEC 1 "register_operand" "f") |
| 454 |
(match_operand:FVEC 2 "register_operand" "f")))] |
| 455 |
"" |
| 456 |
"<x>vfcmp.<fcond>.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 457 |
[(set_attr "type" "simd_fcmp") |
| 458 |
(set_attr "mode" "<MODE>")]) |
| 459 |
|
| 460 |
;; There are no fcmp.{sge/sgt/cuge/cugt}.{s/d} menmonics in GAS, so we have |
| 461 |
;; to reverse the operands ourselves. |
| 462 |
(define_code_iterator fcond_simd_rev [ge gt unge ungt]) |
| 463 |
|
| 464 |
(define_code_attr fcond_rev_asm |
| 465 |
[(ge "sle") |
| 466 |
(gt "slt") |
| 467 |
(unge "cule") |
| 468 |
(ungt "cult")]) |
| 469 |
|
| 470 |
(define_insn "<simd_isa>_<x>vfcmp_<fcond>_<simdfmt>" |
| 471 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 472 |
(fcond_simd_rev:<VIMODE> |
| 473 |
(match_operand:FVEC 1 "register_operand" "f") |
| 474 |
(match_operand:FVEC 2 "register_operand" "f")))] |
| 475 |
"" |
| 476 |
"<x>vfcmp.<fcond_rev_asm>.<simdfmt>\t%<wu>0,%<wu>2,%<wu>1"; |
| 477 |
[(set_attr "type" "simd_fcmp") |
| 478 |
(set_attr "mode" "<MODE>")]) |
| 479 |
|
| 480 |
;; <x>vfcmp.*.{s/d} without defined RTX code, but with defined RTX code for |
| 481 |
;; its inverse. Again, there are no fcmp.{sugt/suge/cgt/cge}.{s/d} |
| 482 |
;; menmonics in GAS, so we have to reverse the operands ourselves. |
| 483 |
(define_code_iterator fcond_inv [ge gt unge ungt]) |
| 484 |
(define_code_iterator fcond_inv_rev [le lt unle unlt]) |
| 485 |
(define_code_attr fcond_inv |
| 486 |
[(ge "sult") |
| 487 |
(gt "sule") |
| 488 |
(unge "clt") |
| 489 |
(ungt "cle") |
| 490 |
(le "sugt") |
| 491 |
(lt "suge") |
| 492 |
(unle "cgt") |
| 493 |
(unlt "cge")]) |
| 494 |
(define_code_attr fcond_inv_rev_asm |
| 495 |
[(le "sult") |
| 496 |
(lt "sule") |
| 497 |
(unle "clt") |
| 498 |
(unlt "cle")]) |
| 499 |
|
| 500 |
(define_insn "<simd_isa>_<x>vfcmp_<fcond_inv>_<simdfmt>" |
| 501 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 502 |
(not:<VIMODE> |
| 503 |
(fcond_inv:<VIMODE> |
| 504 |
(match_operand:FVEC 1 "register_operand" "f") |
| 505 |
(match_operand:FVEC 2 "register_operand" "f"))))] |
| 506 |
"" |
| 507 |
"<x>vfcmp.<fcond_inv>.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 508 |
[(set_attr "type" "simd_fcmp") |
| 509 |
(set_attr "mode" "<MODE>")]) |
| 510 |
|
| 511 |
(define_insn "<simd_isa>_<x>vfcmp_<fcond_inv>_<simdfmt>" |
| 512 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 513 |
(not:<VIMODE> |
| 514 |
(fcond_inv_rev:<VIMODE> |
| 515 |
(match_operand:FVEC 1 "register_operand" "f") |
| 516 |
(match_operand:FVEC 2 "register_operand" "f"))))] |
| 517 |
"" |
| 518 |
"<x>vfcmp.<fcond_inv_rev_asm>.<simdfmt>\t%<wu>0,%<wu>2,%<wu>1" |
| 519 |
[(set_attr "type" "simd_fcmp") |
| 520 |
(set_attr "mode" "<MODE>")]) |
| 521 |
|
| 522 |
;; <x>vfcmp.*.{s/d} instructions only as instrinsics |
| 523 |
(define_c_enum "unspec" |
| 524 |
[UNSPEC_SIMD_FCMP_CAF |
| 525 |
UNSPEC_SIMD_FCMP_SAF |
| 526 |
UNSPEC_SIMD_FCMP_SEQ |
| 527 |
UNSPEC_SIMD_FCMP_SUN |
| 528 |
UNSPEC_SIMD_FCMP_SUEQ |
| 529 |
UNSPEC_SIMD_FCMP_CNE |
| 530 |
UNSPEC_SIMD_FCMP_SOR |
| 531 |
UNSPEC_SIMD_FCMP_SUNE]) |
| 532 |
|
| 533 |
(define_int_iterator SIMD_FCMP |
| 534 |
[UNSPEC_SIMD_FCMP_CAF |
| 535 |
UNSPEC_SIMD_FCMP_SAF |
| 536 |
UNSPEC_SIMD_FCMP_SEQ |
| 537 |
UNSPEC_SIMD_FCMP_SUN |
| 538 |
UNSPEC_SIMD_FCMP_SUEQ |
| 539 |
UNSPEC_SIMD_FCMP_CNE |
| 540 |
UNSPEC_SIMD_FCMP_SOR |
| 541 |
UNSPEC_SIMD_FCMP_SUNE]) |
| 542 |
|
| 543 |
(define_int_attr fcond_unspec |
| 544 |
[(UNSPEC_SIMD_FCMP_CAF "caf") |
| 545 |
(UNSPEC_SIMD_FCMP_SAF "saf") |
| 546 |
(UNSPEC_SIMD_FCMP_SEQ "seq") |
| 547 |
(UNSPEC_SIMD_FCMP_SUN "sun") |
| 548 |
(UNSPEC_SIMD_FCMP_SUEQ "sueq") |
| 549 |
(UNSPEC_SIMD_FCMP_CNE "cne") |
| 550 |
(UNSPEC_SIMD_FCMP_SOR "sor") |
| 551 |
(UNSPEC_SIMD_FCMP_SUNE "sune")]) |
| 552 |
|
| 553 |
(define_insn "<simd_isa>_<x>vfcmp_<fcond_unspec>_<simdfmt>" |
| 554 |
[(set (match_operand:<VIMODE> 0 "register_operand" "=f") |
| 555 |
(unspec:<VIMODE> [(match_operand:FVEC 1 "register_operand" "f") |
| 556 |
(match_operand:FVEC 2 "register_operand" "f")] |
| 557 |
SIMD_FCMP))] |
| 558 |
"" |
| 559 |
"<x>vfcmp.<fcond_unspec>.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 560 |
[(set_attr "type" "simd_fcmp") |
| 561 |
(set_attr "mode" "<MODE>")]) |
| 562 |
|
| 563 |
; [x]vf{min/max} instructions are IEEE-754-2008 conforming, use them for |
| 564 |
; the corresponding IEEE-754-2008 operations. We must use UNSPEC instead |
| 565 |
; of smin/smax though, see PR105414 and PR107013. |
| 566 |
|
| 567 |
(define_int_iterator UNSPEC_FMAXMIN [UNSPEC_FMAX UNSPEC_FMIN]) |
| 568 |
(define_int_attr fmaxmin [(UNSPEC_FMAX "fmax") (UNSPEC_FMIN "fmin")]) |
| 569 |
|
| 570 |
(define_insn "<fmaxmin><mode>3" |
| 571 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 572 |
(unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f") |
| 573 |
(match_operand:FVEC 2 "register_operand" "f")] |
| 574 |
UNSPEC_FMAXMIN))] |
| 575 |
"" |
| 576 |
"<x>v<fmaxmin>.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 577 |
[(set_attr "type" "simd_fminmax") |
| 578 |
(set_attr "mode" "<MODE>")]) |
| 579 |
|
| 580 |
;; ... and also reduc operations. |
| 581 |
(define_expand "reduc_<fmaxmin>_scal_<mode>" |
| 582 |
[(match_operand:<UNITMODE> 0 "register_operand") |
| 583 |
(match_operand:FVEC 1 "register_operand") |
| 584 |
(const_int UNSPEC_FMAXMIN)] |
| 585 |
"" |
| 586 |
{ |
| 587 |
rtx tmp = gen_reg_rtx (<MODE>mode); |
| 588 |
loongarch_expand_vector_reduc (gen_<fmaxmin><mode>3, tmp, operands[1]); |
| 589 |
emit_insn (gen_vec_extract<mode><unitmode> (operands[0], tmp, |
| 590 |
const0_rtx)); |
| 591 |
DONE; |
| 592 |
}) |
| 593 |
|
| 594 |
;; FP negation. |
| 595 |
(define_insn "neg<mode>2" |
| 596 |
[(set (match_operand:FVEC 0 "register_operand" "=f") |
| 597 |
(neg:FVEC (match_operand:FVEC 1 "register_operand" "f")))] |
| 598 |
"" |
| 599 |
"<x>vbitrevi.<simdfmt_as_i>\t%<wu>0,%<wu>1,<elmsgnbit>" |
| 600 |
[(set_attr "type" "simd_logic") |
| 601 |
(set_attr "mode" "<MODE>")]) |
| 602 |
|
| 603 |
;; vector compare |
| 604 |
(define_expand "vec_cmp<mode><allmode_i>" |
| 605 |
[(set (match_operand:<VIMODE> 0 "register_operand") |
| 606 |
(match_operator 1 "" |
| 607 |
[(match_operand:ALLVEC 2 "register_operand") |
| 608 |
(match_operand:ALLVEC 3 "nonmemory_operand")]))] |
| 609 |
"" |
| 610 |
{ |
| 611 |
loongarch_expand_vec_cmp (operands); |
| 612 |
DONE; |
| 613 |
}) |
| 614 |
|
| 615 |
(define_expand "vec_cmpu<mode><allmode_i>" |
| 616 |
[(set (match_operand:<VIMODE> 0 "register_operand") |
| 617 |
(match_operator 1 "" |
| 618 |
[(match_operand:IVEC 2 "register_operand") |
| 619 |
(match_operand:IVEC 3 "nonmemory_operand")]))] |
| 620 |
"" |
| 621 |
{ |
| 622 |
loongarch_expand_vec_cmp (operands); |
| 623 |
DONE; |
| 624 |
}) |
| 625 |
|
| 626 |
;; cbranch |
| 627 |
(define_expand "cbranch<mode>4" |
| 628 |
[(set (pc) |
| 629 |
(if_then_else |
| 630 |
(match_operator 0 "equality_operator" |
| 631 |
[(match_operand:IVEC 1 "register_operand") |
| 632 |
(match_operand:IVEC 2 "reg_or_vector_same_val_operand")]) |
| 633 |
(label_ref (match_operand 3 "")) |
| 634 |
(pc)))] |
| 635 |
"" |
| 636 |
{ |
| 637 |
RTX_CODE code = GET_CODE (operands[0]); |
| 638 |
rtx tmp = operands[1]; |
| 639 |
rtx const0 = CONST0_RTX (SImode); |
| 640 |
|
| 641 |
/* If comparing against a non-zero vector we have to do a comparison first |
| 642 |
so we can have a != 0 comparison with the result. */ |
| 643 |
if (operands[2] != CONST0_RTX (<MODE>mode)) |
| 644 |
{ |
| 645 |
tmp = gen_reg_rtx (<MODE>mode); |
| 646 |
emit_insn (gen_xor<mode>3 (tmp, operands[1], operands[2])); |
| 647 |
} |
| 648 |
|
| 649 |
if (code == NE) |
| 650 |
emit_jump_insn (gen_<simd_isa>_<x>bnz_v_b (operands[3], tmp, const0)); |
| 651 |
else |
| 652 |
emit_jump_insn (gen_<simd_isa>_<x>bz_v_b (operands[3], tmp, const0)); |
| 653 |
DONE; |
| 654 |
}) |
| 655 |
|
| 656 |
;; Operations on elements at even/odd indices. |
| 657 |
(define_int_iterator zero_one [0 1]) |
| 658 |
(define_int_attr ev_od [(0 "ev") (1 "od")]) |
| 659 |
(define_int_attr even_odd [(0 "even") (1 "odd")]) |
| 660 |
|
| 661 |
;; Integer widening add/sub/mult. |
| 662 |
(define_insn "simd_<optab>w_evod_<mode>_<su>" |
| 663 |
[(set (match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 664 |
(addsubmul:<WVEC_HALF> |
| 665 |
(any_extend:<WVEC_HALF> |
| 666 |
(vec_select:<VEC_HALF> |
| 667 |
(match_operand:IVEC 1 "register_operand" "f") |
| 668 |
(match_operand:IVEC 3 "vect_par_cnst_even_or_odd_half"))) |
| 669 |
(any_extend:<WVEC_HALF> |
| 670 |
(vec_select:<VEC_HALF> |
| 671 |
(match_operand:IVEC 2 "register_operand" "f") |
| 672 |
(match_dup 3)))))] |
| 673 |
"" |
| 674 |
"<x>v<optab>w%O3.<simdfmt_w>.<simdfmt><u>\t%<wu>0,%<wu>1,%<wu>2" |
| 675 |
[(set_attr "type" "simd_int_arith") |
| 676 |
(set_attr "mode" "<WVEC_HALF>")]) |
| 677 |
|
| 678 |
(define_expand "<simd_isa>_<x>v<optab>w<ev_od>_<simdfmt_w>_<simdfmt><u>" |
| 679 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 680 |
(match_operand:IVEC 1 "register_operand" " f") |
| 681 |
(match_operand:IVEC 2 "register_operand" " f") |
| 682 |
(any_extend (const_int 0)) |
| 683 |
(addsubmul (const_int 0) (const_int 0)) |
| 684 |
(const_int zero_one)] |
| 685 |
"" |
| 686 |
{ |
| 687 |
int nelts = GET_MODE_NUNITS (<WVEC_HALF>mode); |
| 688 |
rtx op3 = loongarch_gen_stepped_int_parallel (nelts, <zero_one>, 2); |
| 689 |
rtx insn = gen_simd_<optab>w_evod_<mode>_<su> (operands[0], operands[1], |
| 690 |
operands[2], op3); |
| 691 |
emit_insn (insn); |
| 692 |
DONE; |
| 693 |
}) |
| 694 |
|
| 695 |
(define_expand "vec_widen_<su>mult_<even_odd>_<mode>" |
| 696 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 697 |
(match_operand:IVEC 1 "register_operand" " f") |
| 698 |
(match_operand:IVEC 2 "register_operand" " f") |
| 699 |
(any_extend (const_int 0)) |
| 700 |
(const_int zero_one)] |
| 701 |
"" |
| 702 |
{ |
| 703 |
emit_insn ( |
| 704 |
gen_<simd_isa>_<x>vmulw<ev_od>_<simdfmt_w>_<simdfmt><u> (operands[0], |
| 705 |
operands[1], |
| 706 |
operands[2])); |
| 707 |
DONE; |
| 708 |
}) |
| 709 |
|
| 710 |
(define_insn "simd_<optab>w_evod_<mode>_hetero" |
| 711 |
[(set (match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 712 |
(addsubmul:<WVEC_HALF> |
| 713 |
(zero_extend:<WVEC_HALF> |
| 714 |
(vec_select:<VEC_HALF> |
| 715 |
(match_operand:IVEC 1 "register_operand" "f") |
| 716 |
(match_operand:IVEC 3 "vect_par_cnst_even_or_odd_half"))) |
| 717 |
(sign_extend:<WVEC> |
| 718 |
(vec_select:<VEC_HALF> |
| 719 |
(match_operand:IVEC 2 "register_operand" "f") |
| 720 |
(match_dup 3)))))] |
| 721 |
"" |
| 722 |
"<x>v<optab>w%O3.<simdfmt_w>.<simdfmt>u.<simdfmt>\t%<wu>0,%<wu>1,%<wu>2" |
| 723 |
[(set_attr "type" "simd_int_arith") |
| 724 |
(set_attr "mode" "<WVEC_HALF>")]) |
| 725 |
|
| 726 |
(define_expand "<simd_isa>_<x>v<optab>w<ev_od>_<simdfmt_w>_<simdfmt>u_<simdfmt>" |
| 727 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 728 |
(match_operand:IVEC 1 "register_operand" " f") |
| 729 |
(match_operand:IVEC 2 "register_operand" " f") |
| 730 |
(addmul (const_int 0) (const_int 0)) |
| 731 |
(const_int zero_one)] |
| 732 |
"" |
| 733 |
{ |
| 734 |
int nelts = GET_MODE_NUNITS (<WVEC_HALF>mode); |
| 735 |
rtx op3 = loongarch_gen_stepped_int_parallel (nelts, <zero_one>, 2); |
| 736 |
rtx insn = gen_simd_<optab>w_evod_<mode>_hetero (operands[0], operands[1], |
| 737 |
operands[2], op3); |
| 738 |
emit_insn (insn); |
| 739 |
DONE; |
| 740 |
}) |
| 741 |
|
| 742 |
(define_insn "simd_h<optab>w_<mode>_<su>" |
| 743 |
[(set (match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 744 |
(addsub:<WVEC_HALF> |
| 745 |
(any_extend:<WVEC_HALF> |
| 746 |
(vec_select:<VEC_HALF> |
| 747 |
(match_operand:IVEC 1 "register_operand" "f") |
| 748 |
(match_operand:IVEC 3 "vect_par_cnst_even_or_odd_half"))) |
| 749 |
(any_extend:<WVEC_HALF> |
| 750 |
(vec_select:<VEC_HALF> |
| 751 |
(match_operand:IVEC 2 "register_operand" "f") |
| 752 |
(match_operand:IVEC 4 "vect_par_cnst_even_or_odd_half")))))] |
| 753 |
"!rtx_equal_p (operands[3], operands[4])" |
| 754 |
{ |
| 755 |
if (!INTVAL (XVECEXP (operands[3], 0, 0))) |
| 756 |
std::swap (operands[1], operands[2]); |
| 757 |
return "<x>vh<optab>w.<simdfmt_w><u>.<simdfmt><u>\t%<wu>0,%<wu>1,%<wu>2"; |
| 758 |
} |
| 759 |
[(set_attr "type" "simd_int_arith") |
| 760 |
(set_attr "mode" "<WVEC_HALF>")]) |
| 761 |
|
| 762 |
(define_expand "<simd_isa>_<x>vh<optab>w_<simdfmt_w><u>_<simdfmt><u>" |
| 763 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 764 |
(match_operand:IVEC 1 "register_operand" " f") |
| 765 |
(match_operand:IVEC 2 "register_operand" " f") |
| 766 |
(any_extend (const_int 0)) |
| 767 |
(addsub (const_int 0) (const_int 0))] |
| 768 |
"" |
| 769 |
{ |
| 770 |
int nelts = GET_MODE_NUNITS (<WVEC_HALF>mode); |
| 771 |
rtx op3 = loongarch_gen_stepped_int_parallel (nelts, 1, 2); |
| 772 |
rtx op4 = loongarch_gen_stepped_int_parallel (nelts, 0, 2); |
| 773 |
rtx insn = gen_simd_h<optab>w_<mode>_<su> (operands[0], operands[1], |
| 774 |
operands[2], op3, op4); |
| 775 |
emit_insn (insn); |
| 776 |
DONE; |
| 777 |
}) |
| 778 |
|
| 779 |
(define_insn "simd_maddw_evod_<mode>_<su>" |
| 780 |
[(set (match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 781 |
(plus:<WVEC_HALF> |
| 782 |
(mult:<WVEC_HALF> |
| 783 |
(any_extend:<WVEC_HALF> |
| 784 |
(vec_select:<VEC_HALF> |
| 785 |
(match_operand:IVEC 2 "register_operand" "f") |
| 786 |
(match_operand:IVEC 4 "vect_par_cnst_even_or_odd_half"))) |
| 787 |
(any_extend:<WVEC_HALF> |
| 788 |
(vec_select:<VEC_HALF> |
| 789 |
(match_operand:IVEC 3 "register_operand" "f") |
| 790 |
(match_dup 4)))) |
| 791 |
(match_operand:<WVEC_HALF> 1 "register_operand" "0")))] |
| 792 |
"" |
| 793 |
"<x>vmaddw%O4.<simdfmt_w>.<simdfmt><u>\t%<wu>0,%<wu>2,%<wu>3" |
| 794 |
[(set_attr "type" "simd_int_arith") |
| 795 |
(set_attr "mode" "<WVEC_HALF>")]) |
| 796 |
|
| 797 |
(define_expand "<simd_isa>_<x>vmaddw<ev_od>_<simdfmt_w>_<simdfmt><u>" |
| 798 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 799 |
(match_operand:<WVEC_HALF> 1 "register_operand" " 0") |
| 800 |
(match_operand:IVEC 2 "register_operand" " f") |
| 801 |
(match_operand:IVEC 3 "register_operand" " f") |
| 802 |
(any_extend (const_int 0)) |
| 803 |
(const_int zero_one)] |
| 804 |
"" |
| 805 |
{ |
| 806 |
int nelts = GET_MODE_NUNITS (<WVEC_HALF>mode); |
| 807 |
rtx op4 = loongarch_gen_stepped_int_parallel (nelts, <zero_one>, 2); |
| 808 |
rtx insn = gen_simd_maddw_evod_<mode>_<su> (operands[0], operands[1], |
| 809 |
operands[2], operands[3], |
| 810 |
op4); |
| 811 |
emit_insn (insn); |
| 812 |
DONE; |
| 813 |
}) |
| 814 |
|
| 815 |
(define_expand "<su>dot_prod<wvec_half><mode>" |
| 816 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f,f") |
| 817 |
(match_operand:IVEC 1 "register_operand" " f,f") |
| 818 |
(match_operand:IVEC 2 "register_operand" " f,f") |
| 819 |
(match_operand:<WVEC_HALF> 3 "reg_or_0_operand" " 0,YG") |
| 820 |
(any_extend (const_int 0))] |
| 821 |
"" |
| 822 |
{ |
| 823 |
rtx *op = operands; |
| 824 |
|
| 825 |
if (op[3] == CONST0_RTX (<WVEC_HALF>mode)) |
| 826 |
emit_insn ( |
| 827 |
gen_<simd_isa>_<x>vmulwev_<simdfmt_w>_<simdfmt><u> (op[0], op[1], |
| 828 |
op[2])); |
| 829 |
else |
| 830 |
emit_insn ( |
| 831 |
gen_<simd_isa>_<x>vmaddwev_<simdfmt_w>_<simdfmt><u> (op[0], op[3], |
| 832 |
op[1], op[2])); |
| 833 |
|
| 834 |
emit_insn ( |
| 835 |
gen_<simd_isa>_<x>vmaddwod_<simdfmt_w>_<simdfmt><u> (op[0], op[0], |
| 836 |
op[1], op[2])); |
| 837 |
DONE; |
| 838 |
}) |
| 839 |
|
| 840 |
(define_insn "simd_maddw_evod_<mode>_hetero" |
| 841 |
[(set (match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 842 |
(plus:<WVEC_HALF> |
| 843 |
(mult:<WVEC_HALF> |
| 844 |
(zero_extend:<WVEC_HALF> |
| 845 |
(vec_select:<VEC_HALF> |
| 846 |
(match_operand:IVEC 2 "register_operand" "f") |
| 847 |
(match_operand:IVEC 4 "vect_par_cnst_even_or_odd_half"))) |
| 848 |
(sign_extend:<WVEC_HALF> |
| 849 |
(vec_select:<VEC_HALF> |
| 850 |
(match_operand:IVEC 3 "register_operand" "f") |
| 851 |
(match_dup 4)))) |
| 852 |
(match_operand:<WVEC_HALF> 1 "register_operand" "0")))] |
| 853 |
"" |
| 854 |
"<x>vmaddw%O4.<simdfmt_w>.<simdfmt>u.<simdfmt>\t%<wu>0,%<wu>2,%<wu>3" |
| 855 |
[(set_attr "type" "simd_int_arith") |
| 856 |
(set_attr "mode" "<WVEC_HALF>")]) |
| 857 |
|
| 858 |
(define_expand "<simd_isa>_<x>vmaddw<ev_od>_<simdfmt_w>_<simdfmt>u_<simdfmt>" |
| 859 |
[(match_operand:<WVEC_HALF> 0 "register_operand" "=f") |
| 860 |
(match_operand:<WVEC_HALF> 1 "register_operand" " 0") |
| 861 |
(match_operand:IVEC 2 "register_operand" " f") |
| 862 |
(match_operand:IVEC 3 "register_operand" " f") |
| 863 |
(const_int zero_one)] |
| 864 |
"" |
| 865 |
{ |
| 866 |
int nelts = GET_MODE_NUNITS (<WVEC_HALF>mode); |
| 867 |
rtx op4 = loongarch_gen_stepped_int_parallel (nelts, <zero_one>, 2); |
| 868 |
rtx insn = gen_simd_maddw_evod_<mode>_hetero (operands[0], operands[1], |
| 869 |
operands[2], operands[3], |
| 870 |
op4); |
| 871 |
emit_insn (insn); |
| 872 |
DONE; |
| 873 |
}) |
| 874 |
|
| 875 |
; For "historical" reason we need a punned version of q_d variants. |
| 876 |
(define_mode_iterator DIVEC [(V2DI "ISA_HAS_LSX") (V4DI "ISA_HAS_LASX")]) |
| 877 |
|
| 878 |
(define_expand "<simd_isa>_<optab>w<ev_od>_q_d<u>_punned" |
| 879 |
[(match_operand:DIVEC 0 "register_operand" "=f") |
| 880 |
(match_operand:DIVEC 1 "register_operand" " f") |
| 881 |
(match_operand:DIVEC 2 "register_operand" " f") |
| 882 |
(any_extend (const_int 0)) |
| 883 |
(addsubmul (const_int 0) (const_int 0)) |
| 884 |
(const_int zero_one)] |
| 885 |
"" |
| 886 |
{ |
| 887 |
rtx t = gen_reg_rtx (<WVEC_HALF>mode); |
| 888 |
emit_insn (gen_<simd_isa>_<x>v<optab>w<ev_od>_q_d<u> (t, operands[1], |
| 889 |
operands[2])); |
| 890 |
emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t)); |
| 891 |
DONE; |
| 892 |
}) |
| 893 |
|
| 894 |
(define_expand "<simd_isa>_<optab>w<ev_od>_q_du_d_punned" |
| 895 |
[(match_operand:DIVEC 0 "register_operand" "=f") |
| 896 |
(match_operand:DIVEC 1 "register_operand" " f") |
| 897 |
(match_operand:DIVEC 2 "register_operand" " f") |
| 898 |
(addmul (const_int 0) (const_int 0)) |
| 899 |
(const_int zero_one)] |
| 900 |
"" |
| 901 |
{ |
| 902 |
rtx t = gen_reg_rtx (<WVEC_HALF>mode); |
| 903 |
emit_insn (gen_<simd_isa>_<x>v<optab>w<ev_od>_q_du_d (t, operands[1], |
| 904 |
operands[2])); |
| 905 |
emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t)); |
| 906 |
DONE; |
| 907 |
}) |
| 908 |
|
| 909 |
(define_expand "<simd_isa>_h<optab>w_q<u>_d<u>_punned" |
| 910 |
[(match_operand:DIVEC 0 "register_operand" "=f") |
| 911 |
(match_operand:DIVEC 1 "register_operand" "f") |
| 912 |
(match_operand:DIVEC 2 "register_operand" "f") |
| 913 |
(any_extend (const_int 0)) |
| 914 |
(addsub (const_int 0) (const_int 0))] |
| 915 |
"" |
| 916 |
{ |
| 917 |
rtx t = gen_reg_rtx (<WVEC_HALF>mode); |
| 918 |
emit_insn (gen_<simd_isa>_<x>vh<optab>w_q<u>_d<u> (t, operands[1], |
| 919 |
operands[2])); |
| 920 |
emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t)); |
| 921 |
DONE; |
| 922 |
}) |
| 923 |
|
| 924 |
(define_expand "<simd_isa>_maddw<ev_od>_q_d<u>_punned" |
| 925 |
[(match_operand:DIVEC 0 "register_operand" "=f") |
| 926 |
(match_operand:DIVEC 1 "register_operand" " 0") |
| 927 |
(match_operand:DIVEC 2 "register_operand" " f") |
| 928 |
(match_operand:DIVEC 3 "register_operand" " f") |
| 929 |
(const_int zero_one) |
| 930 |
(any_extend (const_int 0))] |
| 931 |
"" |
| 932 |
{ |
| 933 |
rtx t = gen_reg_rtx (<WVEC_HALF>mode); |
| 934 |
rtx op1 = gen_lowpart (<WVEC_HALF>mode, operands[1]); |
| 935 |
emit_insn (gen_<simd_isa>_<x>vmaddw<ev_od>_q_d<u> (t, op1, operands[2], |
| 936 |
operands[3])); |
| 937 |
emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t)); |
| 938 |
DONE; |
| 939 |
}) |
| 940 |
|
| 941 |
(define_expand "<simd_isa>_maddw<ev_od>_q_du_d_punned" |
| 942 |
[(match_operand:DIVEC 0 "register_operand" "=f") |
| 943 |
(match_operand:DIVEC 1 "register_operand" " 0") |
| 944 |
(match_operand:DIVEC 2 "register_operand" " f") |
| 945 |
(match_operand:DIVEC 3 "register_operand" " f") |
| 946 |
(const_int zero_one)] |
| 947 |
"" |
| 948 |
{ |
| 949 |
rtx t = gen_reg_rtx (<WVEC_HALF>mode); |
| 950 |
rtx op1 = gen_lowpart (<WVEC_HALF>mode, operands[1]); |
| 951 |
emit_insn (gen_<simd_isa>_<x>vmaddw<ev_od>_q_du_d (t, op1, operands[2], |
| 952 |
operands[3])); |
| 953 |
emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t)); |
| 954 |
DONE; |
| 955 |
}) |
| 956 |
|
| 957 |
;; Integer shift right with rounding. |
| 958 |
(define_insn "simd_<optab>_imm_round_<mode>" |
| 959 |
[(set (match_operand:IVEC 0 "register_operand" "=f") |
| 960 |
(any_shiftrt:IVEC |
| 961 |
(plus:IVEC |
| 962 |
(match_operand:IVEC 1 "register_operand" "f") |
| 963 |
(match_operand:IVEC 2 "const_vector_same_val_operand" "Uuvx")) |
| 964 |
(match_operand:SI 3 "const_<bitimm>_operand" "I")))] |
| 965 |
"(HOST_WIDE_INT_1U << UINTVAL (operands[3]) >> 1) |
| 966 |
== UINTVAL (CONST_VECTOR_ELT (operands[2], 0))" |
| 967 |
"<x>v<insn>ri.<simdfmt>\t%<wu>0,%<wu>1,%d3" |
| 968 |
[(set_attr "type" "simd_shift") |
| 969 |
(set_attr "mode" "<MODE>")]) |
| 970 |
|
| 971 |
(define_expand "<simd_isa>_<x>v<insn>ri_<simdfmt>" |
| 972 |
[(match_operand:IVEC 0 "register_operand" "=f") |
| 973 |
(match_operand:IVEC 1 "register_operand" " f") |
| 974 |
(match_operand 2 "const_<bitimm>_operand") |
| 975 |
(any_shiftrt (const_int 0) (const_int 0))] |
| 976 |
"" |
| 977 |
{ |
| 978 |
auto addend = HOST_WIDE_INT_1U << UINTVAL (operands[2]) >> 1; |
| 979 |
rtx addend_v = loongarch_gen_const_int_vector (<MODE>mode, addend); |
| 980 |
|
| 981 |
emit_insn (gen_simd_<optab>_imm_round_<mode> (operands[0], operands[1], |
| 982 |
addend_v, operands[2])); |
| 983 |
DONE; |
| 984 |
}) |
| 985 |
|
| 986 |
(define_insn "xor<mode>3" |
| 987 |
[(set (match_operand:IVEC 0 "register_operand" "=f,f,f") |
| 988 |
(xor:IVEC |
| 989 |
(match_operand:IVEC 1 "register_operand" "f,f,f") |
| 990 |
(match_operand:IVEC 2 "reg_or_vector_same_val_operand" "f,YC,Urv8")))] |
| 991 |
"" |
| 992 |
"@ |
| 993 |
<x>vxor.v\t%<wu>0,%<wu>1,%<wu>2 |
| 994 |
<x>vbitrevi.%v0\t%<wu>0,%<wu>1,%V2 |
| 995 |
<x>vxori.b\t%<wu>0,%<wu>1,%B2" |
| 996 |
[(set_attr "type" "simd_logic,simd_bit,simd_logic") |
| 997 |
(set_attr "mode" "<MODE>")]) |
| 998 |
|
| 999 |
(define_insn "ior<mode>3" |
| 1000 |
[(set (match_operand:IVEC 0 "register_operand" "=f,f,f") |
| 1001 |
(ior:IVEC |
| 1002 |
(match_operand:IVEC 1 "register_operand" "f,f,f") |
| 1003 |
(match_operand:IVEC 2 "reg_or_vector_same_val_operand" "f,YC,Urv8")))] |
| 1004 |
"" |
| 1005 |
"@ |
| 1006 |
<x>vor.v\t%<wu>0,%<wu>1,%<wu>2 |
| 1007 |
<x>vbitseti.%v0\t%<wu>0,%<wu>1,%V2 |
| 1008 |
<x>vori.b\t%<wu>0,%<wu>1,%B2" |
| 1009 |
[(set_attr "type" "simd_logic,simd_bit,simd_logic") |
| 1010 |
(set_attr "mode" "<MODE>")]) |
| 1011 |
|
| 1012 |
(define_insn "and<mode>3" |
| 1013 |
[(set (match_operand:IVEC 0 "register_operand" "=f,f,f") |
| 1014 |
(and:IVEC |
| 1015 |
(match_operand:IVEC 1 "register_operand" "f,f,f") |
| 1016 |
(match_operand:IVEC 2 "reg_or_vector_same_val_operand" "f,YZ,Urv8")))] |
| 1017 |
"" |
| 1018 |
{ |
| 1019 |
switch (which_alternative) |
| 1020 |
{ |
| 1021 |
case 0: |
| 1022 |
return "<x>vand.v\t%<wu>0,%<wu>1,%<wu>2"; |
| 1023 |
case 1: |
| 1024 |
{ |
| 1025 |
operands[2] = simplify_const_unary_operation (NOT, <MODE>mode, |
| 1026 |
operands[2], |
| 1027 |
<MODE>mode); |
| 1028 |
return "<x>vbitclri.%v0\t%<wu>0,%<wu>1,%V2"; |
| 1029 |
} |
| 1030 |
case 2: |
| 1031 |
return "<x>vandi.b\t%<wu>0,%<wu>1,%B2"; |
| 1032 |
default: |
| 1033 |
gcc_unreachable (); |
| 1034 |
} |
| 1035 |
} |
| 1036 |
[(set_attr "type" "simd_logic,simd_bit,simd_logic") |
| 1037 |
(set_attr "mode" "<MODE>")]) |
| 1038 |
|
| 1039 |
(define_expand "copysign<mode>3" |
| 1040 |
[(match_operand:FVEC 0 "register_operand") |
| 1041 |
(match_operand:FVEC 1 "register_operand") |
| 1042 |
(match_operand:FVEC 2 "reg_or_vector_neg_fp_operand")] |
| 1043 |
"" |
| 1044 |
{ |
| 1045 |
machine_mode imode = <VIMODE>mode; |
| 1046 |
rtx op[3], mask = loongarch_build_signbit_mask (imode, 1, 0); |
| 1047 |
|
| 1048 |
/* Pun the operation into fixed-point bitwise operations. */ |
| 1049 |
for (int i = 0; i < 3; i++) |
| 1050 |
op[i] = lowpart_subreg (imode, operands[i], <MODE>mode); |
| 1051 |
|
| 1052 |
/* Copysign from a positive const should have been already simplified |
| 1053 |
to abs, ignore the case here. Copysign from a negative const is |
| 1054 |
a simple vbitset which is an alternative of ior (see above). */ |
| 1055 |
if (const_vector_neg_fp_operand (operands[2], <MODE>mode)) |
| 1056 |
emit_insn (gen_ior<vimode>3 (op[0], op[1], mask)); |
| 1057 |
else |
| 1058 |
{ |
| 1059 |
mask = force_reg (imode, mask); |
| 1060 |
emit_insn (gen_<simd_isa>_<x>vbitsel_<simdfmt_as_i> (op[0], op[1], |
| 1061 |
op[2], mask)); |
| 1062 |
} |
| 1063 |
|
| 1064 |
DONE; |
| 1065 |
}) |
| 1066 |
|
| 1067 |
(define_expand "@xorsign<mode>3" |
| 1068 |
[(match_operand:FVEC 0 "register_operand") |
| 1069 |
(match_operand:FVEC 1 "register_operand") |
| 1070 |
(match_operand:FVEC 2 "register_operand")] |
| 1071 |
"" |
| 1072 |
{ |
| 1073 |
machine_mode imode = <VIMODE>mode; |
| 1074 |
rtx op[3]; |
| 1075 |
|
| 1076 |
for (int i = 0; i < 3; i++) |
| 1077 |
op[i] = lowpart_subreg (imode, operands[i], <MODE>mode); |
| 1078 |
|
| 1079 |
rtx t = loongarch_build_signbit_mask (imode, 1, 0); |
| 1080 |
t = force_reg (imode, simplify_gen_binary (AND, imode, op[2], t)); |
| 1081 |
emit_move_insn (op[0], simplify_gen_binary (XOR, imode, op[1], t)); |
| 1082 |
DONE; |
| 1083 |
}) |
| 1084 |
|
| 1085 |
; The LoongArch SX Instructions. |
| 1086 |
(include "lsx.md") |
| 1087 |
|
| 1088 |
; The LoongArch ASX Instructions. |
| 1089 |
(include "lasx.md") |